| 1 | //! Converts [`QRCode`] to SVG |
| 2 | //! |
| 3 | //! ```rust |
| 4 | //! use fast_qr::convert::ConvertError; |
| 5 | //! use fast_qr::convert::{svg::SvgBuilder, Builder, Shape}; |
| 6 | //! use fast_qr::qr::QRBuilder; |
| 7 | //! |
| 8 | //! # fn main() -> Result<(), ConvertError> { |
| 9 | //! // QRBuilde::new can fail if content is too big for version, |
| 10 | //! // please check before unwrapping. |
| 11 | //! let qrcode = QRBuilder::new("https://example.com/") |
| 12 | //! .build() |
| 13 | //! .unwrap(); |
| 14 | //! |
| 15 | //! let _svg = SvgBuilder::default() |
| 16 | //! .shape(Shape::RoundedSquare) |
| 17 | //! .to_file(&qrcode, "out.svg"); |
| 18 | //! |
| 19 | //! # std::fs::remove_file("out.svg"); |
| 20 | //! # Ok(()) |
| 21 | //! # } |
| 22 | //! ``` |
| 23 | |
| 24 | use craterust-analyzer cargo fast_qr 0.13.1 crate/::{QRCoderust-analyzer cargo fast_qr 0.13.1 qr/QRCode#, Versionrust-analyzer cargo fast_qr 0.13.1 version/Version#}; |
| 25 | |
| 26 | use superrust-analyzer cargo fast_qr 0.13.1 convert/::{Builderrust-analyzer cargo fast_qr 0.13.1 convert/Builder#, Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#, ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#, ModuleFunctionrust-analyzer cargo fast_qr 0.13.1 convert/ModuleFunction#, Shaperust-analyzer cargo fast_qr 0.13.1 convert/Shape#}; |
| 27 | |
| 28 | /// Builder for svg, can set shape, margin, background_color, dot_color |
| 29 | pub struct SvgBuilderrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder# { |
| 30 | /// Command vector allows predefined or custom shapes |
| 31 | /// The default is square, commands can be added using `.shape()` |
| 32 | commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ModuleFunctionrust-analyzer cargo fast_qr 0.13.1 convert/ModuleFunction#>, |
| 33 | /// Commands can also have a custom color |
| 34 | /// The default is `dot_color`, commands with specific colors can be |
| 35 | /// added using `.shape_color()` |
| 36 | command_colorsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#command_colors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>>, |
| 37 | /// The margin for the svg, default is 4 |
| 38 | marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin.: usize, |
| 39 | /// The background color for the svg, default is #FFFFFF |
| 40 | background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#background_color.: Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#, |
| 41 | /// The color for each module, default is #000000 |
| 42 | dot_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#dot_color.: Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#, |
| 43 | |
| 44 | // Image Embedding |
| 45 | /// Image to embed in the svg, can be a path or a base64 string |
| 46 | imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 47 | /// Background color for the image, default is #FFFFFF |
| 48 | image_background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_color.: Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#, |
| 49 | /// Background shape for the image, default is square |
| 50 | image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_shape.: ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#, |
| 51 | /// Size of the image (in module size), default is ~1/3 of the svg |
| 52 | image_sizerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_size.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f64>, |
| 53 | /// Gap between the image and the border (in module size), default is calculated |
| 54 | image_gaprust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_gap.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f64>, |
| 55 | /// Position of the image, default is center |
| 56 | image_positionrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_position.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(f64, f64)>, |
| 57 | } |
| 58 | |
| 59 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 60 | /// Possible errors when converting to SVG |
| 61 | pub enum SvgErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError# { |
| 62 | /// Error while writing file |
| 63 | #[cfg(not(feature = "wasm-bindgen"))] |
| 64 | IoErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#IoError#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 65 | /// Error while creating svg |
| 66 | SvgErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#SvgError#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 67 | } |
| 68 | |
| 69 | /// Creates a Builder instance |
| 70 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SvgBuilderrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder# { |
| 71 | fn defaultrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Default]default().() -> Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Default] { |
| 72 | SvgBuilderrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder# { |
| 73 | background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#background_color.: [255; 4].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 74 | dot_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#dot_color.: [0, 0, 0, 255].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 75 | marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin.: 4, |
| 76 | commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 77 | command_colorsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#command_colors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 78 | |
| 79 | // Image Embedding |
| 80 | imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 81 | image_background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_color.: [255; 4].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 82 | image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_shape.: ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#::Squarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Square#, |
| 83 | image_sizerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_size.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 84 | image_gaprust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_gap.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 85 | image_positionrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_position.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | impl Builderrust-analyzer cargo fast_qr 0.13.1 convert/Builder# for SvgBuilderrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder# { |
| 91 | fn marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]margin().(&mut self, margin: usize) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 92 | self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin. = margin; |
| 93 | self |
| 94 | } |
| 95 | |
| 96 | fn module_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]module_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>>(&mut self, dot_color: C) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 97 | self.dot_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#dot_color. = dot_color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 98 | self |
| 99 | } |
| 100 | |
| 101 | fn background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]background_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>>(&mut self, background_color: C) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 102 | self.background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#background_color. = background_color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 103 | self |
| 104 | } |
| 105 | |
| 106 | fn shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]shape().(&mut self, shape: Shaperust-analyzer cargo fast_qr 0.13.1 convert/Shape#) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 107 | self.commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(*rust-analyzer cargo fast_qr 0.13.1 convert/impl#[Shape][Deref]deref().shape); |
| 108 | self.command_colorsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#command_colors..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 109 | self |
| 110 | } |
| 111 | |
| 112 | fn shape_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]shape_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>>(&mut self, shape: Shaperust-analyzer cargo fast_qr 0.13.1 convert/Shape#, color: C) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 113 | self.commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(*rust-analyzer cargo fast_qr 0.13.1 convert/impl#[Shape][Deref]deref().shape); |
| 114 | self.command_colorsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#command_colors..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())); |
| 115 | self |
| 116 | } |
| 117 | |
| 118 | fn imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image().(&mut self, image: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 119 | self.imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(image); |
| 120 | self |
| 121 | } |
| 122 | |
| 123 | fn image_background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image_background_color().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>>(&mut self, image_background_color: C) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 124 | self.image_background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_color. = image_background_color.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 125 | self |
| 126 | } |
| 127 | |
| 128 | fn image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image_background_shape().( |
| 129 | &mut self, |
| 130 | image_background_shape: ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#, |
| 131 | ) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 132 | self.image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_shape. = image_background_shape; |
| 133 | self |
| 134 | } |
| 135 | |
| 136 | fn image_sizerust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image_size().(&mut self, image_size: f64) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 137 | self.image_sizerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_size. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(image_size); |
| 138 | self |
| 139 | } |
| 140 | |
| 141 | fn image_gaprust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image_gap().(&mut self, gap: f64) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 142 | self.image_gaprust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_gap. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gap); |
| 143 | self |
| 144 | } |
| 145 | |
| 146 | fn image_positionrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder]image_position().(&mut self, x: f64, y: f64) -> &mut Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder][Builder] { |
| 147 | self.image_positionrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_position. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((x, y)); |
| 148 | self |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | impl SvgBuilderrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder# { |
| 153 | fn image_placementrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]image_placement().(image_background_shape: ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#, n: usize) -> (f64, f64) { |
| 154 | use ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#::{Circlerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Circle#, RoundedSquarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#RoundedSquare#, Squarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Square#}; |
| 155 | |
| 156 | #[rustfmt::skip] |
| 157 | const SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/SQUARE.: [f64; 40] = [ |
| 158 | 5f64, 9f64, 9f64, 11f64, 13f64, |
| 159 | 13f64, 15f64, 17f64, 17f64, 19f64, |
| 160 | 21f64, 21f64, 23f64, 25f64, 25f64, |
| 161 | 27f64, 29f64, 29f64, 31f64, 33f64, |
| 162 | 33f64, 35f64, 37f64, 37f64, 39f64, |
| 163 | 41f64, 41f64, 43f64, 45f64, 45f64, |
| 164 | 47f64, 49f64, 49f64, 51f64, 53f64, |
| 165 | 53f64, 55f64, 57f64, 57f64, 59f64, |
| 166 | ]; |
| 167 | const ROUNDED_SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/ROUNDED_SQUARE.: [f64; 40] = SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/SQUARE.; |
| 168 | const CIRCLErust-analyzer cargo fast_qr 0.13.1 convert/svg/CIRCLE.: [f64; 40] = SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/SQUARE.; |
| 169 | |
| 170 | // Using hardcoded values |
| 171 | let version = Versionrust-analyzer cargo fast_qr 0.13.1 version/Version#::from_nrust-analyzer cargo fast_qr 0.13.1 version/impl#[Version]from_n().(n) as usize; |
| 172 | let border_size = match image_background_shape { |
| 173 | Squarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Square# => SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/SQUARE.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().version]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., |
| 174 | RoundedSquarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#RoundedSquare# => ROUNDED_SQUARErust-analyzer cargo fast_qr 0.13.1 convert/svg/ROUNDED_SQUARE.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().version]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., |
| 175 | Circlerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Circle# => CIRCLErust-analyzer cargo fast_qr 0.13.1 convert/svg/CIRCLE.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().version]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., |
| 176 | }; |
| 177 | |
| 178 | // Allows for a module gap between the image and the border |
| 179 | let gap = match image_background_shape { |
| 180 | Squarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Square# | RoundedSquarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#RoundedSquare# => 2f64, |
| 181 | Circlerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Circle# => 3f64, |
| 182 | }; |
| 183 | // Make the image border bigger for bigger versions |
| 184 | let gap = gap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().(version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().10) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().10f64; |
| 185 | (border_size, (border_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().gap).roundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]round().()) |
| 186 | } |
| 187 | |
| 188 | fn imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]image().(&self, n: usize) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 189 | if self.imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 190 | return Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 191 | } |
| 192 | |
| 193 | let image = self.imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 194 | let mut out = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(image.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().100); |
| 195 | |
| 196 | let (mut border_size, mut image_size) = |
| 197 | Selfrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]::image_placementrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]image_placement().(self.image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_shape., n); |
| 198 | |
| 199 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(override_size) = self.image_sizerust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_size. { |
| 200 | let gap = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().(image_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().border_size); |
| 201 | border_size = override_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().gap; |
| 202 | image_size = override_size; |
| 203 | } |
| 204 | |
| 205 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(override_gap) = self.image_gaprust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_gap. { |
| 206 | border_size = image_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().override_gap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().2f64; |
| 207 | } |
| 208 | |
| 209 | let mut placed_coord_x = (self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().n) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().border_size; |
| 210 | |
| 211 | // Adjust for non-integer initial x coordinates so as not to partially cover bits by rounding down. |
| 212 | if placed_coord_x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem().2f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().0f64 { |
| 213 | placed_coord_x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`AddAssign<Self>`]add_assign().1f64; |
| 214 | border_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`SubAssign<Self>`]sub_assign().1f64; |
| 215 | } |
| 216 | |
| 217 | placed_coord_x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign().2f64; |
| 218 | |
| 219 | let mut placed_coord = (placed_coord_x, placed_coord_x); |
| 220 | |
| 221 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((x, y)) = self.image_positionrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_position. { |
| 222 | placed_coord = (x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().border_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().2f64, y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().border_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().2f64); |
| 223 | } |
| 224 | |
| 225 | let format = match self.image_background_shaperust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_shape. { |
| 226 | ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#::Squarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Square# => { |
| 227 | r#"<rect x="{0}" y="{1}" width="{2}" height="{2}" fill="{3}"/>"# |
| 228 | } |
| 229 | ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#::Circlerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#Circle# => { |
| 230 | r#"<rect x="{0}" y="{1}" width="{2}" height="{2}" fill="{3}" rx="1000px"/>"# |
| 231 | } |
| 232 | ImageBackgroundShaperust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#::RoundedSquarerust-analyzer cargo fast_qr 0.13.1 convert/ImageBackgroundShape#RoundedSquare# => { |
| 233 | r#"<rect x="{0}" y="{1}" width="{2}" height="{2}" fill="{3}" rx="1px"/>"# |
| 234 | } |
| 235 | }; |
| 236 | |
| 237 | let format = format |
| 238 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{0}", &placed_coord.0.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 239 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{1}", &placed_coord.1.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 240 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{2}", &border_size.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 241 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{3}", self.image_background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#image_background_color..to_strrust-analyzer cargo fast_qr 0.13.1 convert/impl#[Color]to_str().()); |
| 242 | |
| 243 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&format); |
| 244 | |
| 245 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 246 | r#"<image x="{0:.2}" y="{1:.2}" width="{2:.2}" height="{2:.2}" href="{3}" />"#, |
| 247 | placed_coord.0 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). (border_size -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). image_size) /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 2f64, |
| 248 | placed_coord.1 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). (border_size -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). image_size) /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). 2f64, |
| 249 | image_size, |
| 250 | image |
| 251 | )); |
| 252 | |
| 253 | out |
| 254 | } |
| 255 | |
| 256 | fn pathrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]path().(&self, qr: &QRCoderust-analyzer cargo fast_qr 0.13.1 qr/QRCode#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 257 | const DEFAULT_COMMANDrust-analyzer cargo fast_qr 0.13.1 convert/svg/DEFAULT_COMMAND.: [ModuleFunctionrust-analyzer cargo fast_qr 0.13.1 convert/ModuleFunction#; 1] = [Shaperust-analyzer cargo fast_qr 0.13.1 convert/Shape#::squarerust-analyzer cargo fast_qr 0.13.1 convert/impl#[Shape]square().]; |
| 258 | const DEFAULT_COMMAND_COLORrust-analyzer cargo fast_qr 0.13.1 convert/svg/DEFAULT_COMMAND_COLOR.: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>; 1] = [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#]; |
| 259 | |
| 260 | // TODO: cleanup this basic logic |
| 261 | let command_colors: &[Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Colorrust-analyzer cargo fast_qr 0.13.1 convert/Color#>] = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 262 | &self.command_colorsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#command_colors. |
| 263 | } else { |
| 264 | &DEFAULT_COMMAND_COLORrust-analyzer cargo fast_qr 0.13.1 convert/svg/DEFAULT_COMMAND_COLOR. |
| 265 | }; |
| 266 | let commands: &[ModuleFunctionrust-analyzer cargo fast_qr 0.13.1 convert/ModuleFunction#] = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 267 | &self.commandsrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#commands. |
| 268 | } else { |
| 269 | &DEFAULT_COMMANDrust-analyzer cargo fast_qr 0.13.1 convert/svg/DEFAULT_COMMAND. |
| 270 | }; |
| 271 | |
| 272 | let mut paths = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(10 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). qr.sizerust-analyzer cargo fast_qr 0.13.1 qr/QRCode#size. *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). qr.sizerust-analyzer cargo fast_qr 0.13.1 qr/QRCode#size.); commands.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]; |
| 273 | for path in paths.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() { |
| 274 | path.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(r#"<path d=""#); |
| 275 | } |
| 276 | |
| 277 | for y in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#qr.sizerust-analyzer cargo fast_qr 0.13.1 qr/QRCode#size. { |
| 278 | let line = &qr[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().y]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 279 | for (x, &cell) in line.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 280 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cell.valuerust-analyzer cargo fast_qr 0.13.1 module/impl#[Module]value().() { |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | for (i, command) in commands.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 285 | paths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&command(y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin., x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin., cell)); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | for (i, &command) in commands.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 291 | let command_color = command_colors[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&self.dot_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#dot_color.); |
| 292 | // Allows to compare if two function pointers are the same |
| 293 | // This works because there is no notion of Generics for `rounded_square` |
| 294 | if command as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().Shaperust-analyzer cargo fast_qr 0.13.1 convert/Shape#::rounded_squarerust-analyzer cargo fast_qr 0.13.1 convert/impl#[Shape]rounded_square(). as usize { |
| 295 | paths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 296 | r##"" stroke-width=".3" stroke-linejoin="round" stroke="{}"##, |
| 297 | command_color.to_strrust-analyzer cargo fast_qr 0.13.1 convert/impl#[Color]to_str().() |
| 298 | )); |
| 299 | } |
| 300 | |
| 301 | paths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(r#"" fill="{}"/>"#, command_color.to_strrust-analyzer cargo fast_qr 0.13.1 convert/impl#[Color]to_str().())); |
| 302 | } |
| 303 | |
| 304 | paths.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("") |
| 305 | } |
| 306 | |
| 307 | /// Return a string containing the svg for a qr code |
| 308 | pub fn to_strrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]to_str().(&self, qr: &QRCoderust-analyzer cargo fast_qr 0.13.1 qr/QRCode#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 309 | let n = qr.sizerust-analyzer cargo fast_qr 0.13.1 qr/QRCode#size.; |
| 310 | |
| 311 | let mut out = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2); |
| 312 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 313 | r#"<svg viewBox="0 0 {0} {0}" xmlns="http://www.w3.org/2000/svg">"#, |
| 314 | self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin. *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). n |
| 315 | )); |
| 316 | |
| 317 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 318 | r#"<rect width="{0}px" height="{0}px" fill="{1}"/>"#, |
| 319 | self.marginrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#margin. *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). n, |
| 320 | self.background_colorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgBuilder#background_color..to_strrust-analyzer cargo fast_qr 0.13.1 convert/impl#[Color]to_str().() |
| 321 | )); |
| 322 | |
| 323 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&self.pathrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]path().(qr)); |
| 324 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&self.imagerust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]image().(n)); |
| 325 | |
| 326 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("</svg>"); |
| 327 | out |
| 328 | } |
| 329 | |
| 330 | /// Saves the svg for a qr code to a file |
| 331 | #[cfg(not(feature = "wasm-bindgen"))] |
| 332 | pub fn to_filerust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]to_file().(&self, qr: &QRCoderust-analyzer cargo fast_qr 0.13.1 qr/QRCode#, file: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), SvgErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#> { |
| 333 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 334 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#; |
| 335 | |
| 336 | let out = self.to_strrust-analyzer cargo fast_qr 0.13.1 convert/svg/impl#[SvgBuilder]to_str().(qr); |
| 337 | |
| 338 | let mut f = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(file).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(SvgErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#::IoErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#IoError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 339 | f.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(out.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(SvgErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#::IoErrorrust-analyzer cargo fast_qr 0.13.1 convert/svg/SvgError#IoError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 340 | |
| 341 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 342 | } |
| 343 | } |