Skip to content

Commit 1c43cfb

Browse files
committed
Port to usvg 0.32
Fixes #23 Fixes #24
1 parent dc69bc3 commit 1c43cfb

6 files changed

Lines changed: 215 additions & 174 deletions

File tree

Cargo.toml

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

2020
[dependencies]
21-
miniz_oxide = "0.5"
22-
pdf-writer = "0.6"
23-
usvg = { version = "0.22", default-features = false }
21+
miniz_oxide = "0.7"
22+
pdf-writer = "0.7"
23+
usvg = { version = "0.32", default-features = false }
2424
clap = { version = "3", features = ["derive"], optional = true }
25-
fontdb = { version = "0.9", optional = true }
25+
fontdb = { version = "0.13", optional = true }
2626
image = { version = "0.24", default-features = false, optional = true }
2727
termcolor = { version = "1", optional = true }
2828

src/defer.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
//! and functions to ultimately populate them to the file.
66
77
use std::collections::HashMap;
8+
use std::rc::Rc;
89

910
use pdf_writer::types::{MaskType, ShadingType};
1011
use pdf_writer::writers::{ExtGraphicsState, Resources, ShadingPattern};
1112
use pdf_writer::{Finish, Name, PdfWriter, Rect, Ref};
12-
use usvg::{NodeKind, Transform, Tree};
13+
use usvg::{Transform, Tree};
1314

1415
use super::{content_stream, form_xobject, Context, CoordToPdf};
1516
use crate::render::Gradient;
@@ -230,32 +231,38 @@ pub fn write_xobjects(pending_xobjects: &[(u32, Ref)], resources: &mut Resources
230231
/// Write the content streams of the used masks stored in the context to the
231232
/// file.
232233
pub(crate) fn write_masks(tree: &Tree, writer: &mut PdfWriter, ctx: &mut Context) {
233-
for (id, gp) in ctx.pending_groups.clone() {
234-
let mask_node = tree.defs_by_id(&id).unwrap();
235-
let borrowed = mask_node.borrow();
234+
let mut masks: Vec<Rc<usvg::Mask>> = Vec::new();
235+
tree.masks(|mask| {
236+
if masks.iter().find(|m| m.id == mask.id).is_some() {
237+
return;
238+
}
236239

237-
if let NodeKind::Mask(_) = *borrowed {
238-
ctx.push();
239-
ctx.initial_mask = gp.initial_mask;
240+
masks.push(mask);
241+
});
240242

241-
// Get the context of where the pending group was originally in the tree
242-
let old = ctx.c.set_transform(gp.transform);
243+
for (id, gp) in ctx.pending_groups.clone() {
244+
let mask_node = masks.iter().find(|m| m.id == id).unwrap();
243245

244-
let content = content_stream(&mask_node, writer, ctx);
246+
ctx.push();
247+
ctx.initial_mask = gp.initial_mask;
245248

246-
let mut group =
247-
form_xobject(writer, gp.reference, &content, gp.bbox, ctx.compress, true);
249+
// Get the context of where the pending group was originally in the tree
250+
let old = ctx.c.set_transform(gp.transform);
248251

249-
if let Some(matrix) = gp.matrix {
250-
group.matrix(matrix);
251-
}
252+
let content = content_stream(&mask_node.root, writer, ctx);
252253

253-
ctx.c.set_transform(old);
254+
let mut group =
255+
form_xobject(writer, gp.reference, &content, gp.bbox, ctx.compress, true);
254256

255-
let mut resources = group.resources();
256-
ctx.pop(&mut resources);
257-
resources.finish();
257+
if let Some(matrix) = gp.matrix {
258+
group.matrix(matrix);
258259
}
260+
261+
ctx.c.set_transform(old);
262+
263+
let mut resources = group.resources();
264+
ctx.pop(&mut resources);
265+
resources.finish();
259266
}
260267

261268
ctx.initial_mask = None;

0 commit comments

Comments
 (0)