@@ -45,6 +45,16 @@ pub fn render(
4545 gs. finish ( ) ;
4646 content. set_parameters ( rc. add_graphics_state ( gs_ref) . to_pdf_name ( ) ) ;
4747
48+ // We need to render the mask here instead of in `create_to_stream` so that
49+ // if we have a child as an image with a SMask, it won't override
50+ // the soft mask of the group. Unfortunately, this means we need this ugly
51+ // hack of setting and then reversing the transform.
52+ if let Some ( mask) = group. mask ( ) {
53+ content. transform ( group. transform ( ) . to_pdf_transform ( ) ) ;
54+ mask:: render ( group, mask, chunk, content, ctx, rc) ;
55+ content. transform ( group. transform ( ) . invert ( ) . unwrap ( ) . to_pdf_transform ( ) ) ;
56+ }
57+
4858 // We don't need to pass the accumulated transform here because if a pattern appears in a
4959 // XObject, it will be mapped to the coordinate space of where the XObject was invoked, meaning
5060 // that it will also be affected by the transforms in the content stream. If we passed on the
@@ -115,10 +125,6 @@ fn create_to_stream(
115125 content. transform ( group. transform ( ) . to_pdf_transform ( ) ) ;
116126 let accumulated_transform = accumulated_transform. pre_concat ( group. transform ( ) ) ;
117127
118- if let Some ( mask) = & group. mask ( ) {
119- mask:: render ( group, mask, chunk, content, ctx, rc) ;
120- }
121-
122128 if let Some ( clip_path) = & group. clip_path ( ) {
123129 clip_path:: render ( group, clip_path, chunk, content, ctx, rc) ;
124130 }
0 commit comments