104
104
105
105
#include <fpdfview.h>
106
106
#include <fpdf_doc.h>
107
+ #include <fpdf_edit.h>
107
108
108
109
typedef struct _VipsForeignLoadPdf {
109
110
VipsForeignLoad parent_object ;
@@ -151,9 +152,9 @@ typedef struct _VipsForeignLoadPdf {
151
152
VipsRect image ;
152
153
VipsRect * pages ;
153
154
154
- /* The [double] background converted to the image format.
155
+ /* The [double] background converted to the PDFium format.
155
156
*/
156
- VipsPel * ink ;
157
+ FPDF_DWORD ink ;
157
158
158
159
} VipsForeignLoadPdf ;
159
160
@@ -437,6 +438,7 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
437
438
438
439
int top ;
439
440
int i ;
441
+ VipsPel * ink ;
440
442
441
443
#ifdef DEBUG
442
444
printf ( "vips_foreign_load_pdf_header: %p\n" , pdf );
@@ -518,12 +520,14 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
518
520
519
521
/* Convert the background to the image format.
520
522
*/
521
- if ( !(pdf -> ink = vips__vector_to_ink ( class -> nickname ,
523
+ if ( !(ink = vips__vector_to_ink ( class -> nickname ,
522
524
load -> out ,
523
525
VIPS_AREA ( pdf -> background )-> data , NULL ,
524
526
VIPS_AREA ( pdf -> background )-> n )) )
525
527
return ( -1 );
526
528
529
+ pdf -> ink = (ink [0 ] << 24 ) + (ink [1 ] << 16 ) + (ink [2 ] << 8 ) + ink [3 ];
530
+
527
531
return ( 0 );
528
532
}
529
533
@@ -550,10 +554,6 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
550
554
r->left, r->top, r->width, r->height );
551
555
*/
552
556
553
- /* PDFium won't always paint the background.
554
- */
555
- vips_region_paint_pel ( or , r , pdf -> ink );
556
-
557
557
/* Search through the pages we are drawing for the first containing
558
558
* this rect. This could be quicker, perhaps a binary search, but who
559
559
* cares.
@@ -580,6 +580,11 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
580
580
VIPS_REGION_ADDR ( or , rect .left , rect .top ),
581
581
VIPS_REGION_LSKIP ( or ) );
582
582
583
+ /* PDFium won't always paint the background.
584
+ */
585
+ if ( !FPDFPage_HasTransparency (pdf -> page ) )
586
+ FPDFBitmap_FillRect (bitmap , 0 , 0 , rect .width , rect .height , pdf -> ink );
587
+
583
588
FPDF_RenderPageBitmap ( bitmap , pdf -> page ,
584
589
0 , 0 , rect .width , rect .height ,
585
590
0 , 0 );
0 commit comments