From c28708aa196eaca247cdab6b5e8af9751b4f1dad Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Thu, 10 Jun 2021 23:08:52 +0200 Subject: Text decorations --- src/export/pdf.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/export') diff --git a/src/export/pdf.rs b/src/export/pdf.rs index 1cc62332..da3c9369 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -183,12 +183,17 @@ impl<'a> PdfExporter<'a> { content.rect(x, y - h, w, h, false, true); } } - Shape::Ellipse(size) => { let path = geom::Path::ellipse(size); write_path(&mut content, x, y, &path, false, true); } - + Shape::Line(target, stroke) => { + write_stroke(&mut content, fill, stroke.to_pt() as f32); + content.path(true, false).move_to(x, y).line_to( + x + target.x.to_pt() as f32, + y - target.y.to_pt() as f32, + ); + } Shape::Path(ref path) => { write_path(&mut content, x, y, path, false, true) } @@ -371,6 +376,20 @@ fn write_fill(content: &mut Content, fill: Fill) { } } +/// Write a stroke change into a content stream. +fn write_stroke(content: &mut Content, fill: Fill, thickness: f32) { + match fill { + Fill::Color(Color::Rgba(c)) => { + content.stroke_rgb( + c.r as f32 / 255.0, + c.g as f32 / 255.0, + c.b as f32 / 255.0, + ); + } + } + content.line_width(thickness); +} + /// Write a path into a content stream. fn write_path( content: &mut Content, -- cgit v1.2.3