Skip to content

Commit a127d6f

Browse files
committed
Scale XObject to (1,1) dimensions.
1 parent 3cafa54 commit a127d6f

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ system-fonts = ["usvg/system-fonts", "usvg/memmap-fonts"]
1414
[dependencies]
1515
image = { version = "0.23", default-features = false, optional = true }
1616
miniz_oxide = "0.4"
17-
pdf-writer = { git = "https://github.com/typst/pdf-writer", rev = "141aa01" }
17+
pdf-writer = { git = "https://github.com/typst/pdf-writer", rev = "e1ec200" }
1818
usvg = { version = "0.19", default-features = false }

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ pub fn convert_tree(tree: &Tree, options: Options) -> Vec<u8> {
251251
/// Convert a [`usvg` tree](Tree) into a Form XObject that can be used as part
252252
/// of a larger document.
253253
///
254-
/// This method is intended for use in an existing [`PdfWriter`] workflow.
254+
/// This method is intended for use in an existing [`PdfWriter`] workflow. It
255+
/// will always return an XObject with the width and height of one printer's
256+
/// point, just like an [`ImageXObject`](pdf_writer::writers::ImageXObject)
257+
/// would.
255258
///
256259
/// The resulting object can be used by registering a name and the `id` with a
257260
/// page's [`/XObject`](pdf_writer::writers::Resources::x_objects) resources
@@ -281,6 +284,15 @@ pub fn convert_tree_into(
281284

282285
let mut xobject = writer.form_xobject(id, &content);
283286
xobject.bbox(bbox);
287+
xobject.matrix([
288+
1.0 / (bbox.x2 - bbox.x1),
289+
0.0,
290+
0.0,
291+
1.0 / (bbox.y2 - bbox.y1),
292+
0.0,
293+
0.0,
294+
]);
295+
284296
let mut resources = xobject.resources();
285297
ctx.pop(&mut resources);
286298

0 commit comments

Comments
 (0)