//! SVG rendering support. //! //! # Example //! //! ``` //! use qrcode::QrCode; //! use qrcode::render::svg; //! //! let code = QrCode::new(b"Hello").unwrap(); //! let svg_xml = code.render::().build(); //! println!("{}", svg_xml); #![cfg(feature="svg")] use std::fmt::Write; use std::marker::PhantomData; use crate::render::{Canvas as RenderCanvas, Pixel}; use crate::types::Color as ModuleColor; /// An SVG color. #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Color<'a>(pub &'a str); impl<'a> Pixel for Color<'a> { type Canvas = Canvas<'a>; type Image = String; fn default_color(color: ModuleColor) -> Self { Color(color.select("#000", "#fff")) } } #[doc(hidden)] pub struct Canvas<'a> { svg: String, marker: PhantomData>, } impl<'a> RenderCanvas for Canvas<'a> { type Pixel = Color<'a>; type Image = String; fn new(width: u32, height: u32, dark_pixel: Color<'a>, light_pixel: Color<'a>) -> Self { Canvas { svg: format!( concat!( r#""#, r#""#, r#""#, r#" String { self.svg.push_str(r#""/>"#); self.svg } }