Debian Codegraph @

src/render/pic.rs

raw symbols SCIP
1 //! PIC rendering support.
2 //!
3 //! # Example
4 //!
5 //! ```
6 //! use qrcode::QrCode;
7 //! use qrcode::render::pic;
8 //!
9 //! let code = QrCode::new(b"Hello").unwrap();
10 //! let pic = code.render::<pic::Color>().build();
11 //! println!("{}", pic);
12
13 #![cfg(feature = "pic")]
14
15 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
16
17 use craterust-analyzer cargo qrcode 0.14.1 crate/::renderrust-analyzer cargo qrcode 0.14.1 render/::{Canvasrust-analyzer cargo qrcode 0.14.1 render/Canvas# as RenderCanvasrust-analyzer cargo qrcode 0.14.1 render/Canvas#, Pixelrust-analyzer cargo qrcode 0.14.1 render/Pixel#};
18 use craterust-analyzer cargo qrcode 0.14.1 crate/::typesrust-analyzer cargo qrcode 0.14.1 types/::Colorrust-analyzer cargo qrcode 0.14.1 types/Color# as ModuleColorrust-analyzer cargo qrcode 0.14.1 types/Color#;
19
20 /// A PIC color.
21 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
22 pub struct Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color#;
23
24 impl Pixelrust-analyzer cargo qrcode 0.14.1 render/Pixel# for Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color# {
25 type Canvasrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Color][Pixel]Canvas# = Canvasrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas#;
26 type Imagerust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Color][Pixel]Image# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
27
28 fn default_colorrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Color][Pixel]default_color().(_color: ModuleColorrust-analyzer cargo qrcode 0.14.1 types/Color#) -> Selfrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Color][Pixel] {
29 Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color#
30 }
31 }
32
33 #[doc(hidden)]
34 pub struct Canvasrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas# {
35 picrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas#pic.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
36 }
37
38 impl RenderCanvasrust-analyzer cargo qrcode 0.14.1 render/Canvas# for Canvasrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas# {
39 type Pixelrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]Pixel# = Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color#;
40 type Imagerust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]Image# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
41
42 fn newrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]new().(width: u32, height: u32, _dark_pixel: Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color#, _light_pixel: Colorrust-analyzer cargo qrcode 0.14.1 render/pic/Color#) -> Selfrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas] {
43 Canvasrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas# {
44 picrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas#pic.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
45 concatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/concat!!(
46 "maxpswid={w};maxpsht={h};movewid=0;moveht=1;boxwid=1;boxht=1\n",
47 "define p {{ box wid $3 ht $4 fill 1 with .nw at $1,-$2 }}\n",
48 "box wid maxpswid ht maxpsht with .nw at 0,0\n",
49 ),
50 w = width,
51 h = height
52 ),
53 }
54 }
55
56 fn draw_dark_pixelrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]draw_dark_pixel().(&mut self, x: u32, y: u32) {
57 self.draw_dark_rectrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]draw_dark_rect().(x, y, 1, 1);
58 }
59
60 fn draw_dark_rectrust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]draw_dark_rect().(&mut self, left: u32, top: u32, width: u32, height: u32) {
61 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(self.picrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas#pic., "p({left},{top},{width},{height})").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
62 }
63
64 fn into_imagerust-analyzer cargo qrcode 0.14.1 render/pic/impl#[Canvas][Canvas]into_image().(self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
65 self.picrust-analyzer cargo qrcode 0.14.1 render/pic/Canvas#pic.
66 }
67 }