@@ -9,7 +9,7 @@ use std::collections::HashMap;
99use pdf_writer:: types:: { MaskType , ShadingType } ;
1010use pdf_writer:: writers:: { ExtGraphicsState , Resources , ShadingPattern } ;
1111use pdf_writer:: { Finish , Name , PdfWriter , Rect , Ref } ;
12- use usvg:: { NodeKind , Tree } ;
12+ use usvg:: { NodeKind , Transform , Tree } ;
1313
1414use super :: { content_stream, form_xobject, Context , CoordToPdf } ;
1515use crate :: render:: Gradient ;
@@ -130,6 +130,9 @@ pub struct PendingGroup {
130130 /// A transformation matrix to allow for a different coordinate system use
131131 /// in the object.
132132 pub matrix : Option < [ f32 ; 6 ] > ,
133+ // Contains the transform of the context where the pending group
134+ // was in the tree
135+ pub transform : Transform ,
133136 /// An SVG ID to a mask that should be applied at the start of the content
134137 /// stream.
135138 pub initial_mask : Option < String > ,
@@ -236,6 +239,9 @@ pub(crate) fn write_masks(tree: &Tree, writer: &mut PdfWriter, ctx: &mut Context
236239 ctx. push ( ) ;
237240 ctx. initial_mask = gp. initial_mask ;
238241
242+ // Get the context of where the pending group was originally in the tree
243+ let old = ctx. c . set_transform ( gp. transform ) ;
244+
239245 let content = content_stream ( & mask_node, writer, ctx) ;
240246
241247 let mut group =
@@ -245,6 +251,8 @@ pub(crate) fn write_masks(tree: &Tree, writer: &mut PdfWriter, ctx: &mut Context
245251 group. matrix ( matrix) ;
246252 }
247253
254+ ctx. c . set_transform ( old) ;
255+
248256 let mut resources = group. resources ( ) ;
249257 ctx. pop ( & mut resources) ;
250258 resources. finish ( ) ;
0 commit comments