From 3a813c968a8eb84c6730893795c6fe1a5d8ea74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 27 Nov 2017 04:01:02 +0100 Subject: [PATCH] Fixed set_outline_thickness function --- Cargo.toml | 2 +- README.md | 7 ++++--- examples/graphics.rs | 18 +++++++++--------- src/lib.rs | 7 ++++--- src/types/pdf_layer.rs | 9 ++++++--- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f5df6e..b699181 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "printpdf" -version = "0.2.0" +version = "0.2.1" authors = ["Felix Schütt "] repository = "https://github.com/sharazam/printpdf" homepage = "https://github.com/sharazam/printpdf" diff --git a/README.md b/README.md index f1542e9..dad2e28 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ current_layer.set_fill_color(fill_color); current_layer.set_outline_color(outline_color); - current_layer.set_outline_thickness(10); + current_layer.set_outline_thickness(10.0); // Draw first line current_layer.add_shape(line1); @@ -98,7 +98,7 @@ current_layer.set_fill_color(fill_color_2); current_layer.set_outline_color(outline_color_2); - current_layer.set_outline_thickness(15); + current_layer.set_outline_thickness(15.0); // draw second line current_layer.add_shape(line2); @@ -207,13 +207,14 @@ current_layer.end_text_section(); ``` - # Upgrading to `0.2.0` / Changelog + # Upgrading to `0.2.1` / Changelog - The `document.save()` method now needs a `BufWriter`, to enforce buffered output (breaking change). - The `PdfDocument` now implements `Clone`, so you can write one document to multiple outputs. - You can disable the automatic embedding of an ICC profile by using a `CustomPdfConformance`. See `examples/no_icc.rs` for usage information. - `add_font` changed to `add_external_font` + added `add_builtin_font` function (see example folder) + - `set_outline_thickness` now accepts floating-point units # Further reading diff --git a/examples/graphics.rs b/examples/graphics.rs index e836d96..b34f5af 100644 --- a/examples/graphics.rs +++ b/examples/graphics.rs @@ -9,18 +9,18 @@ fn main() { let (doc, page1, layer1) = PdfDocument::new("printpdf graphics test",297.0, 210.0, "Layer 1"); let current_layer = doc.get_page(page1).get_layer(layer1); - // Quadratic shape. The "false" determines if the next (following) + // Quadratic shape. The "false" determines if the next (following) // point is a bezier handle (for curves) - // If you want holes, simply reorder the winding of the points to be + // If you want holes, simply reorder the winding of the points to be // counterclockwise instead of clockwise. let points1 = vec![(Point::new(100.0, 100.0), false), (Point::new(100.0, 200.0), false), (Point::new(300.0, 200.0), false), (Point::new(300.0, 100.0), false)]; - + // Is the shape stroked? Is the shape closed? Is the shape filled? let line1 = Line::new(points1, true, true, true); - + // Triangle shape let points2 = vec![(Point::new(150.0, 150.0), false), (Point::new(150.0, 250.0), false), @@ -31,10 +31,10 @@ fn main() { let outline_color = Color::Rgb(Rgb::new(0.75, 1.0, 0.64, None)); let mut dash_pattern = LineDashPattern::default(); dash_pattern.dash_1 = Some(20); - + current_layer.set_fill_color(fill_color); current_layer.set_outline_color(outline_color); - current_layer.set_outline_thickness(10); + current_layer.set_outline_thickness(10.0); // Draw first line current_layer.add_shape(line1); @@ -49,12 +49,12 @@ fn main() { current_layer.set_line_join_style(LineJoinStyle::Round); current_layer.set_fill_color(fill_color_2); current_layer.set_outline_color(outline_color_2); - current_layer.set_outline_thickness(15); + current_layer.set_outline_thickness(15.0); // draw second line current_layer.add_shape(line2); // If this is successful, you should see a PDF two shapes, one rectangle - // and a dotted line + // and a dotted line doc.save(&mut BufWriter::new(File::create("test_graphics.pdf").unwrap())).unwrap(); -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index d9d0cb6..c128f38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,7 +80,7 @@ //! //! current_layer.set_fill_color(fill_color); //! current_layer.set_outline_color(outline_color); -//! current_layer.set_outline_thickness(10); +//! current_layer.set_outline_thickness(10.0); //! //! // Draw first line //! current_layer.add_shape(line1); @@ -96,7 +96,7 @@ //! //! current_layer.set_fill_color(fill_color_2); //! current_layer.set_outline_color(outline_color_2); -//! current_layer.set_outline_thickness(15); +//! current_layer.set_outline_thickness(15.0); //! //! // draw second line //! current_layer.add_shape(line2); @@ -205,12 +205,13 @@ //! current_layer.end_text_section(); //! ``` //! -//! # Upgrading to `0.2.0` / Changelog +//! # Upgrading to `0.2.1` / Changelog //! //! - The `document.save()` method now needs a `BufWriter`, to enforce buffered output (breaking change). //! - The `PdfDocument` now implements `Clone`, so you can write one document to multiple outputs. //! - You can disable the automatic embedding of an ICC profile by using a `CustomPdfConformance`. //! See `examples/no_icc.rs` for usage information. +//! - `set_outline_thickness` now accepts floating-point units //! //! # Further reading //! diff --git a/src/types/pdf_layer.rs b/src/types/pdf_layer.rs index 25ab07b..f51d9c9 100644 --- a/src/types/pdf_layer.rs +++ b/src/types/pdf_layer.rs @@ -243,12 +243,15 @@ impl PdfLayerReference { )); } - /// Set the current line thickness + /// Set the current line thickness, in points + /// + /// __NOTE__: 0.0 is a special value, it does not make the line disappear, but rather + /// makes it appear 1px wide across all devices #[inline] - pub fn set_outline_thickness(&self, outline_thickness: i64) + pub fn set_outline_thickness(&self, outline_thickness: f64) { use lopdf::Object::*; - self.internal_add_operation(Operation::new(OP_PATH_STATE_SET_LINE_WIDTH, vec![Integer(outline_thickness)])); + self.internal_add_operation(Operation::new(OP_PATH_STATE_SET_LINE_WIDTH, vec![Real(outline_thickness)])); } /// Set the current line join style for outlines