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,15 +520,13 @@ 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
527
- /* Swap B and R.
528
- */
529
- vips__bgra2rgba ( (guint32 * ) pdf -> ink , 1 );
529
+ pdf -> ink = (ink [3 ] << 24 ) + (ink [0 ] << 16 ) + (ink [1 ] << 8 ) + ink [2 ];
530
530
531
531
return ( 0 );
532
532
}
@@ -554,10 +554,6 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
554
554
r->left, r->top, r->width, r->height );
555
555
*/
556
556
557
- /* PDFium won't always paint the background.
558
- */
559
- vips_region_paint_pel ( or , r , pdf -> ink );
560
-
561
557
/* Search through the pages we are drawing for the first containing
562
558
* this rect. This could be quicker, perhaps a binary search, but who
563
559
* cares.
@@ -584,6 +580,11 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
584
580
VIPS_REGION_ADDR ( or , rect .left , rect .top ),
585
581
VIPS_REGION_LSKIP ( or ) );
586
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
+
587
588
FPDF_RenderPageBitmap ( bitmap , pdf -> page ,
588
589
0 , 0 , rect .width , rect .height ,
589
590
0 , 0 );
0 commit comments