example_set_line_join_style/
example_set_line_join_style.rs1use fpdf::{Fpdf, Orientation, PageSize, Pdf, Unit, UnitVec2, RGB};
2
3fn main() {
4 const OFFSET: Unit = Unit::mm(75.0);
5 let mut pdf = Fpdf::new(Orientation::Landscape, PageSize::A4, "", UnitVec2::default());
6 pdf.add_page();
7 let draw = |pdf: &mut Fpdf, cap: &str, join: &str, x0: f64, y0: f64, x1: f64, y1: f64| {
8 let x0 = Unit::mm(x0);
9 let y0 = Unit::mm(y0);
10 let x1 = Unit::mm(x1);
11 let y1 = Unit::mm(y1);
12
13 pdf.set_line_cap_style(cap);
14 pdf.set_line_join_style(join);
15
16 pdf.set_draw_color(RGB::new(0x33, 0x33, 0x33));
17 pdf.set_line_width(Unit::mm(30.0));
18 pdf.move_to(x0, y0);
19 pdf.line_to((x0+x1) / 2.0 + OFFSET, (y0+y1)/2.0);
20 pdf.line_to(x1, y1);
21 pdf.draw_path("D");
22
23 pdf.set_draw_color(RGB::new(0xFF, 0x33, 0x33));
24 pdf.set_line_width(Unit::mm(2.56));
25 pdf.move_to(x0, y0);
26 pdf.line_to((x0+x1)/2.0+OFFSET, (y0+y1)/2.0);
27 pdf.line_to(x1, y1);
28 pdf.draw_path("D");
29 };
30 let mut x = 35.0;
31 let caps = ["butt", "square", "round"];
32 let joins = ["bevel", "miter", "round"];
33 for i in 0..3 {
34 draw(&mut pdf, caps[i], joins[i], x, 50.0, x, 160.0);
35 x += OFFSET.to_mm();
36 }
37 pdf.output_file_and_close("example_set_line_join_style.pdf").unwrap();
38}