Skip to content

Commit

Permalink
Scale XObject to (1,1) dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih committed Dec 6, 2021
1 parent 3cafa54 commit a127d6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ system-fonts = ["usvg/system-fonts", "usvg/memmap-fonts"]
[dependencies]
image = { version = "0.23", default-features = false, optional = true }
miniz_oxide = "0.4"
pdf-writer = { git = "https://github.com/typst/pdf-writer", rev = "141aa01" }
pdf-writer = { git = "https://github.com/typst/pdf-writer", rev = "e1ec200" }
usvg = { version = "0.19", default-features = false }
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
/// Convert a [`usvg` tree](Tree) into a Form XObject that can be used as part
/// of a larger document.
///
/// This method is intended for use in an existing [`PdfWriter`] workflow.
/// This method is intended for use in an existing [`PdfWriter`] workflow. It
/// will always return an XObject with the width and height of one printer's
/// point, just like an [`ImageXObject`](pdf_writer::writers::ImageXObject)
/// would.
///
/// The resulting object can be used by registering a name and the `id` with a
/// page's [`/XObject`](pdf_writer::writers::Resources::x_objects) resources
Expand Down Expand Up @@ -281,6 +284,15 @@ pub fn convert_tree_into(

let mut xobject = writer.form_xobject(id, &content);
xobject.bbox(bbox);
xobject.matrix([
1.0 / (bbox.x2 - bbox.x1),
0.0,
0.0,
1.0 / (bbox.y2 - bbox.y1),
0.0,
0.0,
]);

let mut resources = xobject.resources();
ctx.pop(&mut resources);

Expand Down

0 comments on commit a127d6f

Please sign in to comment.