Skip to content

Commit

Permalink
Fixed set_outline_thickness function
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 27, 2017
1 parent bf0cc3a commit 3a813c9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "printpdf"
version = "0.2.0"
version = "0.2.1"
authors = ["Felix Schütt <[email protected]>"]
repository = "https://github.com/sharazam/printpdf"
homepage = "https://github.com/sharazam/printpdf"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions examples/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand All @@ -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();
}
}
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
//!
Expand Down
9 changes: 6 additions & 3 deletions src/types/pdf_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a813c9

Please sign in to comment.