@@ -445,30 +445,35 @@ def write_page(
445445 ):
446446 # Calculate input page transformation
447447 t = Matrix (Identity )
448+ mbox = self .reader [real_page ].mediabox
448449 if spec .hflip :
449450 t .concat (t , Matrix (- 1 , 0 , 0 , 1 , self .in_size .width , 0 ))
450451 elif spec .vflip :
451452 t .concat (t , Matrix (1 , 0 , 0 , - 1 , 0 , self .in_size .height ))
453+ if spec .rotate != 0 :
454+ t .prerotate (spec .rotate % 360 )
452455 if spec .scale != 1.0 :
453- t = t .prescale (spec .scale , spec .scale )
456+ t .prescale (spec .scale , spec .scale )
454457 if spec .off != Offset (0.0 , 0.0 ):
455- t = t .pretranslate (spec .off .x , spec .off .y )
458+ # (t.prerotate applies translation according to original axes)
459+ t .e += spec .off .x
460+ t .f += spec .off .y
456461 # Transform input page mediabox
457462 t .concat (t , outpdf_page .transformation_matrix )
458- mbox = self . reader [ real_page ]. mediabox .transform (t )
463+ mbox .transform (t )
459464 # Merge input page into the output document
460465 outpdf_page .show_pdf_page (
461466 mbox , self .reader , real_page , rotate = spec .rotate % 360
462467 )
463- if self .draw > 0 : # FIXME: draw the line at the requested width
468+ if self .draw > 0 :
464469 line = [
465- (mbox .x0 + spec . off . x , mbox .y1 + spec . off . y ),
466- (mbox .x0 + spec . off . x , mbox .y0 + spec . off . y ),
467- (mbox .x1 + spec . off . x , mbox .y0 + spec . off . y ),
468- (mbox .x1 + spec . off . x , mbox .y1 + spec . off . y ),
469- (mbox .x0 + spec . off . x , mbox .y1 + spec . off . y ),
470+ (mbox .x0 , mbox .y1 ),
471+ (mbox .x0 , mbox .y0 ),
472+ (mbox .x1 , mbox .y0 ),
473+ (mbox .x1 , mbox .y1 ),
474+ (mbox .x0 , mbox .y1 ),
470475 ]
471- outpdf_page .draw_polyline (line )
476+ outpdf_page .draw_polyline (line , width = self . draw )
472477
473478 def finalize (self ) -> None :
474479 self .outfile .write (self .writer .convert_to_pdf ())
0 commit comments