Skip to content

Commit 419f3e6

Browse files
committed
Upgrade dependencies and more fixes
1 parent 0b7a14e commit 419f3e6

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.DS_Store

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ gif = ["image/gif"]
1818
cli = ["clap", "termcolor", "usvg/text", "fontdb"]
1919

2020
[dependencies]
21-
miniz_oxide = "0.4"
22-
pdf-writer = { git = "https://github.com/typst/pdf-writer" }
21+
miniz_oxide = "0.5"
22+
pdf-writer = "0.6"
2323
usvg = { version = "0.22", default-features = false }
2424
clap = { version = "3", features = ["derive"], optional = true }
2525
fontdb = { version = "0.9", optional = true }

src/render.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ fn prep_pattern(
470470
inner_matrix[4] += rect.x();
471471
inner_matrix[5] += rect.y();
472472

473-
ctx.c.transform(inner_matrix);
473+
let old = ctx.c.transform(inner_matrix);
474474

475475
let pattern_stream = content_stream(node, writer, ctx);
476-
ctx.c.identity();
476+
ctx.c.transform(old);
477477

478478
let pattern_ref = ctx.alloc_ref();
479479
let mut pdf_pattern = writer.tiling_pattern(pattern_ref, &pattern_stream);
@@ -517,6 +517,14 @@ impl Render for usvg::Group {
517517
.unwrap_or_else(|| usvg::Rect::new(0.0, 0.0, 1.0, 1.0).unwrap());
518518

519519
let pdf_bbox = ctx.c.pdf_rect(bbox);
520+
let old = ctx.c.transform([
521+
self.transform.a,
522+
self.transform.b,
523+
self.transform.c,
524+
self.transform.d,
525+
self.transform.e,
526+
self.transform.f,
527+
]);
520528

521529
// Every group is an isolated transparency group, it needs to be painted
522530
// onto its own canvas.
@@ -528,6 +536,7 @@ impl Render for usvg::Group {
528536
ctx.compress,
529537
true,
530538
);
539+
531540
let mut resources = form.resources();
532541
ctx.pop(&mut resources);
533542

@@ -536,6 +545,7 @@ impl Render for usvg::Group {
536545
content.save_state();
537546

538547
apply_clip_path(self.clip_path.as_ref(), content, ctx);
548+
ctx.c.transform(old);
539549

540550
if let Some(reference) = apply_mask(self.mask.as_ref(), bbox, pdf_bbox, ctx) {
541551
let num = ctx.alloc_gs();
@@ -739,14 +749,13 @@ impl Render for usvg::Image {
739749
);
740750

741751
content.save_state();
742-
let (x, y) = converter.point((rect.x(), rect.y()));
743752
content.transform([
744753
(width as f64 * converter.factor_x()) as f32,
745754
0.0,
746755
0.0,
747756
(height as f64 * converter.factor_y()) as f32,
748-
converter.offset_x() as f32 + x,
749-
converter.offset_y() as f32 + y,
757+
converter.offset_x() as f32,
758+
converter.offset_y() as f32,
750759
]);
751760
content.x_object(xobj_name);
752761
content.restore_state();
@@ -760,7 +769,12 @@ impl Render for usvg::Image {
760769
resources.x_objects().pair(xobj_name, image_ref);
761770
resources.finish();
762771

763-
xobject.bbox(ctx.c.pdf_rect(rect));
772+
xobject.bbox(Rect::new(
773+
0.0,
774+
0.0,
775+
rect.width() as f32,
776+
rect.height() as f32,
777+
));
764778

765779
let scaling = 72.0 / ctx.c.dpi();
766780
let mut transform = self.transform.clone();
@@ -783,8 +797,8 @@ impl Render for usvg::Image {
783797
ctx.pending_xobjects.push((num, image_ref));
784798
let name = format!("xo{}", num);
785799

786-
let (x, y) = ctx.c.point((rect.x(), rect.y()));
787-
content.move_to(x, y);
800+
let (x, y) = ctx.c.point((rect.x(), rect.y() + rect.height()));
801+
content.transform([1.0, 0.0, 0.0, 1.0, x, y]);
788802
content.x_object(Name(name.as_bytes()));
789803
}
790804
}

src/scale.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ impl CoordToPdf {
168168
}
169169

170170
/// Set a pre-transformation, overriding the old one.
171-
pub fn transform(&mut self, matrix: [f64; 6]) {
172-
self.matrix = matrix
173-
}
174-
175-
/// Set the identity transform
176-
pub fn identity(&mut self) {
177-
self.matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0];
171+
pub fn transform(&mut self, matrix: [f64; 6]) -> [f64; 6] {
172+
let old = self.matrix;
173+
self.matrix = matrix;
174+
old
178175
}
179176
}

0 commit comments

Comments
 (0)