@@ -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 }
0 commit comments