pub struct Canvas<'a> { /* private fields */ }
Expand description
A visual area where content can be drawn (a page).
Provides methods for defining and stroking or filling paths, as well as placing text objects.
TODO Everything here that takes a BuiltinFont
should take any
FontSource
instead.
Implementations§
Source§impl<'a> Canvas<'a>
impl<'a> Canvas<'a>
Sourcepub fn rectangle(
&mut self,
x: f32,
y: f32,
width: f32,
height: f32,
) -> Result<()>
pub fn rectangle( &mut self, x: f32, y: f32, width: f32, height: f32, ) -> Result<()>
Append a closed rectangle with a corner at (x, y) and extending width × height to the to the current path.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn set_line_join_style(&mut self, style: JoinStyle) -> Result<()>
pub fn set_line_join_style(&mut self, style: JoinStyle) -> Result<()>
Set the line join style in the graphics state.
Sourcepub fn set_line_cap_style(&mut self, style: CapStyle) -> Result<()>
pub fn set_line_cap_style(&mut self, style: CapStyle) -> Result<()>
Set the line join style in the graphics state.
Sourcepub fn set_line_width(&mut self, w: f32) -> Result<()>
pub fn set_line_width(&mut self, w: f32) -> Result<()>
Set the line width in the graphics state.
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
Sourcepub fn set_stroke_color(&mut self, color: Color) -> Result<()>
pub fn set_stroke_color(&mut self, color: Color) -> Result<()>
Set color for stroking operations.
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
More examples
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn set_fill_color(&mut self, color: Color) -> Result<()>
pub fn set_fill_color(&mut self, color: Color) -> Result<()>
Set color for non-stroking operations.
Sourcepub fn concat(&mut self, m: Matrix) -> Result<()>
pub fn concat(&mut self, m: Matrix) -> Result<()>
Modify the current transformation matrix for coordinates by concatenating the specified matrix.
Examples found in repository?
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn line(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> Result<()>
pub fn line(&mut self, x1: f32, y1: f32, x2: f32, y2: f32) -> Result<()>
Append a straight line from (x1, y1) to (x2, y2) to the current path.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn move_to(&mut self, x: f32, y: f32) -> Result<()>
pub fn move_to(&mut self, x: f32, y: f32) -> Result<()>
Begin a new subpath at the point (x, y).
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
More examples
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn line_to(&mut self, x: f32, y: f32) -> Result<()>
pub fn line_to(&mut self, x: f32, y: f32) -> Result<()>
Add a straight line from the current point to (x, y) to the current path.
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
More examples
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn curve_to(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
x3: f32,
y3: f32,
) -> Result<()>
pub fn curve_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, ) -> Result<()>
Add a Bézier curve from the current point to (x3, y3) with (x1, y1) and (x2, y2) as Bézier controll points.
Sourcepub fn circle(&mut self, x: f32, y: f32, r: f32) -> Result<()>
pub fn circle(&mut self, x: f32, y: f32, r: f32) -> Result<()>
Add a circle approximated by four cubic Bézier curves to the current path. Based on http://spencermortensen.com/articles/bezier-circle/
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
More examples
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn stroke(&mut self) -> Result<()>
pub fn stroke(&mut self) -> Result<()>
Stroke the current path.
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
More examples
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn close_and_stroke(&mut self) -> Result<()>
pub fn close_and_stroke(&mut self) -> Result<()>
Close and stroke the current path.
Examples found in repository?
14fn main() {
15 // Open our pdf document.
16 let mut document = Pdf::create("circles.pdf").unwrap();
17
18 // Add a 400x400 pt page.
19
20 // Render-page writes the pdf file structure for a page and
21 // creates a Canvas which is sent to the function that is the last
22 // argument of the render_page method.
23 // That function then puts content on the page by calling methods
24 // on the canvas.
25 document
26 .render_page(400.0, 400.0, |c| {
27 let (x, y) = (200.0, 200.0);
28 let r = 190.0;
29
30 // Set a wide black pen and stroke a circle
31 c.set_stroke_color(Color::rgb(0, 0, 0))?;
32 c.set_line_width(2.0)?;
33 c.circle(x, y, r)?;
34 c.stroke()?;
35
36 // Set a finer yellow pen and stroke a 200-sided polygon
37 c.set_stroke_color(Color::rgb(255, 230, 150))?;
38 c.set_line_width(1.0)?;
39 c.move_to(x + r, y)?;
40 let sides: u8 = 200;
41 for n in 1..sides {
42 let phi = f32::from(n) * 2.0 * PI / f32::from(sides);
43 c.line_to(x + r * phi.cos(), y + r * phi.sin())?;
44 }
45 c.close_and_stroke()
46 })
47 .unwrap();
48 document.finish().unwrap();
49}
Sourcepub fn get_font(&mut self, font: BuiltinFont) -> FontRef
pub fn get_font(&mut self, font: BuiltinFont) -> FontRef
Get a FontRef for a specific font.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn text<F, T>(&mut self, render_text: F) -> Result<T>
pub fn text<F, T>(&mut self, render_text: F) -> Result<T>
Create a text object.
The contents of the text object is defined by the function render_text, by applying methods to the TextObject it gets as an argument. On success, return the value returned by render_text.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn left_text(
&mut self,
x: f32,
y: f32,
font: BuiltinFont,
size: f32,
text: &str,
) -> Result<()>
pub fn left_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>
Utility method for placing a string of text.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn right_text(
&mut self,
x: f32,
y: f32,
font: BuiltinFont,
size: f32,
text: &str,
) -> Result<()>
pub fn right_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>
Utility method for placing a string of text.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn center_text(
&mut self,
x: f32,
y: f32,
font: BuiltinFont,
size: f32,
text: &str,
) -> Result<()>
pub fn center_text( &mut self, x: f32, y: f32, font: BuiltinFont, size: f32, text: &str, ) -> Result<()>
Utility method for placing a string of text.
Examples found in repository?
9fn main() {
10 let mut document = Pdf::create("text.pdf").unwrap();
11 document.set_title("Text example");
12 document
13 .render_page(300.0, 400.0, |c| {
14 c.set_stroke_color(Color::rgb(200, 200, 255))?;
15 c.rectangle(10.0, 10.0, 280.0, 380.0)?;
16 c.line(10.0, 300.0, 290.0, 300.0)?;
17 c.line(150.0, 10.0, 150.0, 390.0)?;
18 c.stroke()?;
19 let helvetica = BuiltinFont::Helvetica;
20 c.left_text(10.0, 380.0, helvetica, 12.0, "Top left")?;
21 c.left_text(10.0, 10.0, helvetica, 12.0, "Bottom left")?;
22 c.right_text(290.0, 380.0, helvetica, 12.0, "Top right")?;
23 c.right_text(290.0, 10.0, helvetica, 12.0, "Bottom right")?;
24 c.center_text(
25 150.0,
26 330.0,
27 BuiltinFont::Times_Bold,
28 18.0,
29 "Centered",
30 )?;
31 let times = c.get_font(BuiltinFont::Times_Roman);
32 c.text(|t| {
33 t.set_font(×, 14.0)?;
34 t.set_leading(18.0)?;
35 t.pos(10.0, 300.0)?;
36 t.show("Some lines of text in what might look like a")?;
37 t.show_line("paragraph of three lines. Lorem ipsum dolor")?;
38 t.show_line("sit amet. Blahonga. ")?;
39 t.show_adjusted(&[("W", 130), ("AN", -40), ("D", 0)])?;
40 t.pos(0., -30.)?;
41 t.show_adjusted(
42 &(-19..21).map(|i| ("o", 16 * i)).collect::<Vec<_>>(),
43 )
44 })?;
45
46 // In Swedish, we use the letters å, ä, and ö
47 // in words like sloe liqueur. That is why rust-pdf
48 // uses /WinAnsiEncoding for text.
49 let times_italic = BuiltinFont::Times_Italic;
50 c.right_text(
51 290.0,
52 200.0,
53 times_italic,
54 14.0,
55 "På svenska använder vi bokstäverna å, ä & ö",
56 )?;
57 c.right_text(
58 290.0,
59 182.0,
60 times_italic,
61 14.0,
62 "i ord som slånbärslikör. Därför använder",
63 )?;
64 c.right_text(
65 290.0,
66 164.0,
67 times_italic,
68 14.0,
69 "rust-pdf /WinAnsiEncoding för text.",
70 )?;
71
72 c.center_text(
73 150.0,
74 130.0,
75 BuiltinFont::Symbol,
76 14.0,
77 "Hellas ΑΒΓΔαβγδ",
78 )?;
79 c.center_text(
80 150.0,
81 114.0,
82 BuiltinFont::Symbol,
83 14.0,
84 "∀ μ < δ : ∃ σ ∈ Σ",
85 )?;
86 c.center_text(
87 150.0,
88 90.0,
89 BuiltinFont::ZapfDingbats,
90 14.0,
91 "♥♠♦♣",
92 )?;
93 Ok(())
94 })
95 .unwrap();
96 document.finish().unwrap();
97}
Sourcepub fn add_outline(&mut self, title: &str)
pub fn add_outline(&mut self, title: &str)
Add an item for this page in the document outline.
An outline item associates a name (contained in an ordered tree) with a location in the document. The PDF standard supports several ways to specify an exact location on a page, but this implementation currently only supports linking to a specific page (the page that this Canvas is for).