@@ -47,7 +47,7 @@ static int write_header_footer(pdfio_stream_t *st, const char *title, int number
47
47
static pdfio_obj_t * write_image_object (pdfio_file_t * pdf , _pdfio_predictor_t predictor );
48
48
static int write_images_test (pdfio_file_t * pdf , int number , pdfio_obj_t * font );
49
49
static int write_jpeg_test (pdfio_file_t * pdf , const char * title , int number , pdfio_obj_t * font , pdfio_obj_t * image );
50
- static int write_png_test (pdfio_file_t * pdf , int number , pdfio_obj_t * font );
50
+ static int write_png_tests (pdfio_file_t * pdf , int number , pdfio_obj_t * font );
51
51
static int write_text_test (pdfio_file_t * pdf , int first_page , pdfio_obj_t * font , const char * filename );
52
52
static int write_unit_file (pdfio_file_t * inpdf , const char * outname , pdfio_file_t * outpdf , size_t * num_pages , size_t * first_image );
53
53
@@ -2989,19 +2989,84 @@ write_jpeg_test(pdfio_file_t *pdf, // I - PDF file
2989
2989
2990
2990
2991
2991
//
2992
- // 'write_png_test ()' - Write a page of PNG test images.
2992
+ // 'write_png_tests ()' - Write pages of PNG test images.
2993
2993
//
2994
2994
2995
2995
static int // O - 0 on success, 1 on failure
2996
- write_png_test (pdfio_file_t * pdf , // I - PDF file
2997
- int number , // I - Page number
2998
- pdfio_obj_t * font ) // I - Page number font
2996
+ write_png_tests (pdfio_file_t * pdf , // I - PDF file
2997
+ int number , // I - Page number
2998
+ pdfio_obj_t * font ) // I - Page number font
2999
2999
{
3000
3000
pdfio_dict_t * dict ; // Page dictionary
3001
3001
pdfio_stream_t * st ; // Page contents stream
3002
3002
pdfio_obj_t * color , // pdfio-color.png
3003
3003
* gray , // pdfio-gray.png
3004
3004
* indexed ; // pdfio-indexed.png
3005
+ #ifdef HAVE_LIBPNG
3006
+ size_t i ; // Looping var
3007
+ char imgname [32 ]; // Image name
3008
+ pdfio_obj_t * pngsuite [80 ]; // PngSuite test file objects
3009
+ static const char * const pngsuite_files [80 ] =
3010
+ { // PngSuite test filenames
3011
+ "testfiles/pngsuite/basi0g01.png" , "testfiles/pngsuite/basi0g02.png" ,
3012
+ "testfiles/pngsuite/basi0g04.png" , "testfiles/pngsuite/basi0g08.png" ,
3013
+ "testfiles/pngsuite/basi2c08.png" , "testfiles/pngsuite/basi3p01.png" ,
3014
+ "testfiles/pngsuite/basi3p02.png" , "testfiles/pngsuite/basi3p04.png" ,
3015
+ "testfiles/pngsuite/basi3p08.png" , "testfiles/pngsuite/basi4a08.png" ,
3016
+ "testfiles/pngsuite/basi6a08.png" , "testfiles/pngsuite/basn0g01.png" ,
3017
+ "testfiles/pngsuite/basn0g02.png" , "testfiles/pngsuite/basn0g04.png" ,
3018
+ "testfiles/pngsuite/basn0g08.png" , "testfiles/pngsuite/basn2c08.png" ,
3019
+ "testfiles/pngsuite/basn3p01.png" , "testfiles/pngsuite/basn3p02.png" ,
3020
+ "testfiles/pngsuite/basn3p04.png" , "testfiles/pngsuite/basn3p08.png" ,
3021
+ "testfiles/pngsuite/basn4a08.png" , "testfiles/pngsuite/basn6a08.png" ,
3022
+ "testfiles/pngsuite/exif2c08.png" , "testfiles/pngsuite/g03n2c08.png" ,
3023
+ "testfiles/pngsuite/g03n3p04.png" , "testfiles/pngsuite/g04n2c08.png" ,
3024
+ "testfiles/pngsuite/g04n3p04.png" , "testfiles/pngsuite/g05n2c08.png" ,
3025
+ "testfiles/pngsuite/g05n3p04.png" , "testfiles/pngsuite/g07n2c08.png" ,
3026
+ "testfiles/pngsuite/g07n3p04.png" , "testfiles/pngsuite/g10n2c08.png" ,
3027
+ "testfiles/pngsuite/g10n3p04.png" , "testfiles/pngsuite/g25n2c08.png" ,
3028
+ "testfiles/pngsuite/g25n3p04.png" , "testfiles/pngsuite/s02i3p01.png" ,
3029
+ "testfiles/pngsuite/s02n3p01.png" , "testfiles/pngsuite/s03i3p01.png" ,
3030
+ "testfiles/pngsuite/s03n3p01.png" , "testfiles/pngsuite/s04i3p01.png" ,
3031
+ "testfiles/pngsuite/s04n3p01.png" , "testfiles/pngsuite/s05i3p02.png" ,
3032
+ "testfiles/pngsuite/s05n3p02.png" , "testfiles/pngsuite/s06i3p02.png" ,
3033
+ "testfiles/pngsuite/s06n3p02.png" , "testfiles/pngsuite/s07i3p02.png" ,
3034
+ "testfiles/pngsuite/s07n3p02.png" , "testfiles/pngsuite/s08i3p02.png" ,
3035
+ "testfiles/pngsuite/s08n3p02.png" , "testfiles/pngsuite/s09i3p02.png" ,
3036
+ "testfiles/pngsuite/s09n3p02.png" , "testfiles/pngsuite/s32i3p04.png" ,
3037
+ "testfiles/pngsuite/s32n3p04.png" , "testfiles/pngsuite/s33i3p04.png" ,
3038
+ "testfiles/pngsuite/s33n3p04.png" , "testfiles/pngsuite/s34i3p04.png" ,
3039
+ "testfiles/pngsuite/s34n3p04.png" , "testfiles/pngsuite/s35i3p04.png" ,
3040
+ "testfiles/pngsuite/s35n3p04.png" , "testfiles/pngsuite/s36i3p04.png" ,
3041
+ "testfiles/pngsuite/s36n3p04.png" , "testfiles/pngsuite/s37i3p04.png" ,
3042
+ "testfiles/pngsuite/s37n3p04.png" , "testfiles/pngsuite/s38i3p04.png" ,
3043
+ "testfiles/pngsuite/s38n3p04.png" , "testfiles/pngsuite/s39i3p04.png" ,
3044
+ "testfiles/pngsuite/s39n3p04.png" , "testfiles/pngsuite/s40i3p04.png" ,
3045
+ "testfiles/pngsuite/s40n3p04.png" , "testfiles/pngsuite/tbbn0g04.png" ,
3046
+ "testfiles/pngsuite/tbbn3p08.png" , "testfiles/pngsuite/tbgn3p08.png" ,
3047
+ "testfiles/pngsuite/tbrn2c08.png" , "testfiles/pngsuite/tbwn3p08.png" ,
3048
+ "testfiles/pngsuite/tbyn3p08.png" , "testfiles/pngsuite/tm3n3p02.png" ,
3049
+ "testfiles/pngsuite/tp0n0g08.png" , "testfiles/pngsuite/tp0n2c08.png" ,
3050
+ "testfiles/pngsuite/tp0n3p08.png" , "testfiles/pngsuite/tp1n3p08.png"
3051
+ };
3052
+ static const char * const pngsuite_labels [80 ] =
3053
+ { // PngSuite test labels
3054
+ "basi0g01" , "basi0g02" , "basi0g04" , "basi0g08" , "basi2c08" , "basi3p01" ,
3055
+ "basi3p02" , "basi3p04" , "basi3p08" , "basi4a08" , "basi6a08" , "basn0g01" ,
3056
+ "basn0g02" , "basn0g04" , "basn0g08" , "basn2c08" , "basn3p01" , "basn3p02" ,
3057
+ "basn3p04" , "basn3p08" , "basn4a08" , "basn6a08" , "exif2c08" , "g03n2c08" ,
3058
+ "g03n3p04" , "g04n2c08" , "g04n3p04" , "g05n2c08" , "g05n3p04" , "g07n2c08" ,
3059
+ "g07n3p04" , "g10n2c08" , "g10n3p04" , "g25n2c08" , "g25n3p04" , "s02i3p01" ,
3060
+ "s02n3p01" , "s03i3p01" , "s03n3p01" , "s04i3p01" , "s04n3p01" , "s05i3p02" ,
3061
+ "s05n3p02" , "s06i3p02" , "s06n3p02" , "s07i3p02" , "s07n3p02" , "s08i3p02" ,
3062
+ "s08n3p02" , "s09i3p02" , "s09n3p02" , "s32i3p04" , "s32n3p04" , "s33i3p04" ,
3063
+ "s33n3p04" , "s34i3p04" , "s34n3p04" , "s35i3p04" , "s35n3p04" , "s36i3p04" ,
3064
+ "s36n3p04" , "s37i3p04" , "s37n3p04" , "s38i3p04" , "s38n3p04" , "s39i3p04" ,
3065
+ "s39n3p04" , "s40i3p04" , "s40n3p04" , "tbbn0g04" , "tbbn3p08" , "tbgn3p08" ,
3066
+ "tbrn2c08" , "tbwn3p08" , "tbyn3p08" , "tm3n3p02" , "tp0n0g08" , "tp0n2c08" ,
3067
+ "tp0n3p08" , "tp1n3p08"
3068
+ };
3069
+ #endif // HAVE_LIBPNG
3005
3070
3006
3071
3007
3072
// Import the PNG test images
@@ -3023,6 +3088,8 @@ write_png_test(pdfio_file_t *pdf, // I - PDF file
3023
3088
else
3024
3089
return (1 );
3025
3090
3091
+ #ifdef HAVE_LIBPNG
3092
+ ////// PDFio PNG image test page...
3026
3093
// Create the page dictionary, object, and stream...
3027
3094
fputs ("pdfioDictCreate: " , stdout );
3028
3095
if ((dict = pdfioDictCreate (pdf )) != NULL )
@@ -3168,6 +3235,108 @@ write_png_test(pdfio_file_t *pdf, // I - PDF file
3168
3235
else
3169
3236
return (1 );
3170
3237
3238
+ ////// PngSuite page
3239
+ // Create the image objects...
3240
+ for (i = 0 ; i < (sizeof (pngsuite_files ) / sizeof (pngsuite_files [0 ])); i ++ )
3241
+ {
3242
+ fprintf (stdout , "pdfioFileCreateImageObjFromFile(\"%s\"): " , pngsuite_files [i ]);
3243
+ if ((pngsuite [i ] = pdfioFileCreateImageObjFromFile (pdf , pngsuite_files [i ], false)) != NULL )
3244
+ puts ("PASS" );
3245
+ else
3246
+ return (1 );
3247
+ }
3248
+
3249
+ // Create the page dictionary, object, and stream...
3250
+ fputs ("pdfioDictCreate: " , stdout );
3251
+ if ((dict = pdfioDictCreate (pdf )) != NULL )
3252
+ puts ("PASS" );
3253
+ else
3254
+ return (1 );
3255
+
3256
+ for (i = 0 ; i < (sizeof (pngsuite_files ) / sizeof (pngsuite_files [0 ])); i ++ )
3257
+ {
3258
+ fprintf (stdout , "pdfioPageDictAddImage(\"%s\"): " , pngsuite_labels [i ]);
3259
+ snprintf (imgname , sizeof (imgname ), "IM%u" , (unsigned )(i + 1 ));
3260
+ if (pdfioPageDictAddImage (dict , pdfioStringCreate (pdf , imgname ), pngsuite [i ]))
3261
+ puts ("PASS" );
3262
+ else
3263
+ return (1 );
3264
+ }
3265
+
3266
+ fputs ("pdfioPageDictAddFont(F1): " , stdout );
3267
+ if (pdfioPageDictAddFont (dict , "F1" , font ))
3268
+ puts ("PASS" );
3269
+ else
3270
+ return (1 );
3271
+
3272
+ printf ("pdfioFileCreatePage(%d): " , number + 1 );
3273
+
3274
+ if ((st = pdfioFileCreatePage (pdf , dict )) != NULL )
3275
+ puts ("PASS" );
3276
+ else
3277
+ return (1 );
3278
+
3279
+ if (write_header_footer (st , "PngSuite Test Page" , number + 1 ))
3280
+ goto error ;
3281
+
3282
+ // Show content...
3283
+ fputs ("pdfioContentSetTextFont(\"F1\", 9.0): " , stdout );
3284
+ if (pdfioContentSetTextFont (st , "F1" , 8.0 ))
3285
+ puts ("PASS" );
3286
+ else
3287
+ goto error ;
3288
+
3289
+ for (i = 0 ; i < (sizeof (pngsuite_files ) / sizeof (pngsuite_files [0 ])); i ++ )
3290
+ {
3291
+ double x = (i % 8 ) * 69.0 + 36 ; // X position
3292
+ double y = 671 - (i / 8 ) * 64.0 ; // Y position
3293
+
3294
+ fputs ("pdfioContentTextBegin(): " , stdout );
3295
+ if (pdfioContentTextBegin (st ))
3296
+ puts ("PASS" );
3297
+ else
3298
+ goto error ;
3299
+
3300
+ printf ("pdfioContentTextMoveTo(%g, %g): " , x , y );
3301
+ if (pdfioContentTextMoveTo (st , x , y ))
3302
+ puts ("PASS" );
3303
+ else
3304
+ goto error ;
3305
+
3306
+ printf ("pdfioContentTextShow(\"%s\"): " , pngsuite_labels [i ]);
3307
+ if (pdfioContentTextShow (st , false, pngsuite_labels [i ]))
3308
+ puts ("PASS" );
3309
+ else
3310
+ goto error ;
3311
+
3312
+ fputs ("pdfioContentTextEnd(): " , stdout );
3313
+ if (pdfioContentTextEnd (st ))
3314
+ puts ("PASS" );
3315
+ else
3316
+ goto error ;
3317
+ }
3318
+
3319
+ for (i = 0 ; i < (sizeof (pngsuite_files ) / sizeof (pngsuite_files [0 ])); i ++ )
3320
+ {
3321
+ double x = (i % 8 ) * 69.0 + 36 ; // X position
3322
+ double y = 671 - (i / 8 ) * 64.0 ; // Y position
3323
+
3324
+ snprintf (imgname , sizeof (imgname ), "IM%u" , (unsigned )(i + 1 ));
3325
+ printf ("pdfioContentDrawImage(\"%s\"): " , imgname );
3326
+ if (pdfioContentDrawImage (st , imgname , x , y + 9 , 32 , 32 ))
3327
+ puts ("PASS" );
3328
+ else
3329
+ goto error ;
3330
+ }
3331
+
3332
+ // Close the object and stream...
3333
+ fputs ("pdfioStreamClose: " , stdout );
3334
+ if (pdfioStreamClose (st ))
3335
+ puts ("PASS" );
3336
+ else
3337
+ return (1 );
3338
+ #endif // HAVE_LIBPNG
3339
+
3171
3340
return (0 );
3172
3341
3173
3342
error :
@@ -3367,6 +3536,7 @@ write_unit_file(
3367
3536
* gray_jpg , // gray.jpg image
3368
3537
* helvetica , // Helvetica font
3369
3538
* page ; // Page from test PDF file
3539
+ int pagenum = 1 ; // Current page number
3370
3540
pdfio_dict_t * catalog ; // Catalog dictionary
3371
3541
3372
3542
@@ -3506,10 +3676,14 @@ write_unit_file(
3506
3676
else
3507
3677
return (1 );
3508
3678
3679
+ pagenum ++ ;
3680
+
3509
3681
// Write a page with a color image...
3510
- if (write_jpeg_test (outpdf , "Color JPEG Test" , 2 , helvetica , color_jpg ))
3682
+ if (write_jpeg_test (outpdf , "Color JPEG Test" , pagenum , helvetica , color_jpg ))
3511
3683
return (1 );
3512
3684
3685
+ pagenum ++ ;
3686
+
3513
3687
// Copy the third page from the test PDF file...
3514
3688
fputs ("pdfioFileGetPage(2): " , stdout );
3515
3689
if ((page = pdfioFileGetPage (inpdf , 2 )) != NULL )
@@ -3523,39 +3697,60 @@ write_unit_file(
3523
3697
else
3524
3698
return (1 );
3525
3699
3700
+ pagenum ++ ;
3701
+
3526
3702
// Write a page with a grayscale image...
3527
- if (write_jpeg_test (outpdf , "Grayscale JPEG Test" , 4 , helvetica , gray_jpg ))
3703
+ if (write_jpeg_test (outpdf , "Grayscale JPEG Test" , pagenum , helvetica , gray_jpg ))
3528
3704
return (1 );
3705
+ pagenum ++ ;
3529
3706
3530
3707
// Write a page with PNG images...
3531
- if (write_png_test (outpdf , 5 , helvetica ))
3708
+ if (write_png_tests (outpdf , pagenum , helvetica ))
3532
3709
return (1 );
3533
3710
3711
+ #ifdef HAVE_LIBPNG
3712
+ pagenum += 2 ;
3713
+ #else
3714
+ pagenum ++ ;
3715
+ #endif // HAVE_LIBPNG
3716
+
3534
3717
// Write a page that tests multiple color spaces...
3535
- if (write_color_test (outpdf , 6 , helvetica ))
3718
+ if (write_color_test (outpdf , pagenum , helvetica ))
3536
3719
return (1 );
3537
3720
3721
+ pagenum ++ ;
3722
+
3538
3723
// Write a page with test images...
3539
3724
* first_image = pdfioFileGetNumObjs (outpdf ) + 1 ;
3540
- if (write_images_test (outpdf , 7 , helvetica ))
3725
+ if (write_images_test (outpdf , pagenum , helvetica ))
3541
3726
return (1 );
3542
3727
3728
+ pagenum ++ ;
3729
+
3543
3730
// Write a page width alpha (soft masks)...
3544
- if (write_alpha_test (outpdf , 8 , helvetica ))
3731
+ if (write_alpha_test (outpdf , pagenum , helvetica ))
3545
3732
return (1 );
3546
3733
3734
+ pagenum ++ ;
3735
+
3547
3736
// Test TrueType fonts...
3548
- if (write_font_test (outpdf , 9 , helvetica , "testfiles/OpenSans-Regular.ttf" , false))
3737
+ if (write_font_test (outpdf , pagenum , helvetica , "testfiles/OpenSans-Regular.ttf" , false))
3549
3738
return (1 );
3550
3739
3551
- if (write_font_test (outpdf , 10 , helvetica , "testfiles/OpenSans-Regular.ttf" , true))
3740
+ pagenum ++ ;
3741
+
3742
+ if (write_font_test (outpdf , pagenum , helvetica , "testfiles/OpenSans-Regular.ttf" , true))
3552
3743
return (1 );
3553
3744
3554
- if (write_font_test (outpdf , 11 , helvetica , "testfiles/NotoSansJP-Regular.otf" , true))
3745
+ pagenum ++ ;
3746
+
3747
+ if (write_font_test (outpdf , pagenum , helvetica , "testfiles/NotoSansJP-Regular.otf" , true))
3555
3748
return (1 );
3556
3749
3750
+ pagenum ++ ;
3751
+
3557
3752
// Print this text file...
3558
- if (write_text_test (outpdf , 12 , helvetica , "README.md" ))
3753
+ if (write_text_test (outpdf , pagenum , helvetica , "README.md" ))
3559
3754
return (1 );
3560
3755
3561
3756
fputs ("pdfioFileGetNumPages: " , stdout );
0 commit comments