2021-04-10 14:00:52 +02:00
|
|
|
|
//
|
2021-05-30 13:10:44 +02:00
|
|
|
|
// Test program for PDFio.
|
2021-04-10 14:00:52 +02:00
|
|
|
|
//
|
|
|
|
|
// Copyright © 2021 by Michael R Sweet.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
2021-06-21 22:03:05 +02:00
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// ./testpdfio
|
|
|
|
|
//
|
|
|
|
|
// ./testpdfio FILENAME [OBJECT-NUMBER] [FILENAME [OBJECT-NUMBER]] ...
|
|
|
|
|
//
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Include necessary headers...
|
|
|
|
|
//
|
|
|
|
|
|
2021-05-05 03:31:58 +02:00
|
|
|
|
#include "pdfio-private.h"
|
2021-05-28 16:41:21 +02:00
|
|
|
|
#include "pdfio-content.h"
|
2021-05-31 15:31:00 +02:00
|
|
|
|
#include <math.h>
|
2021-07-26 17:58:20 +02:00
|
|
|
|
#ifndef M_PI
|
|
|
|
|
# define M_PI 3.14159265358979323846264338327950288
|
|
|
|
|
#endif // M_PI
|
2021-04-10 14:00:52 +02:00
|
|
|
|
|
|
|
|
|
|
2021-05-10 14:00:27 +02:00
|
|
|
|
//
|
|
|
|
|
// Local functions...
|
|
|
|
|
//
|
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
static int do_test_file(const char *filename, int objnum);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
static int do_unit_tests(void);
|
2021-06-01 23:10:36 +02:00
|
|
|
|
static int draw_image(pdfio_stream_t *st, const char *name, double x, double y, double w, double h, const char *label);
|
2021-05-10 14:40:52 +02:00
|
|
|
|
static bool error_cb(pdfio_file_t *pdf, const char *message, bool *error);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
static ssize_t token_consume_cb(const char **s, size_t bytes);
|
|
|
|
|
static ssize_t token_peek_cb(const char **s, char *buffer, size_t bytes);
|
2021-06-02 21:46:39 +02:00
|
|
|
|
static int verify_image(pdfio_file_t *pdf, size_t number);
|
2021-07-18 15:23:39 +02:00
|
|
|
|
static int write_alpha_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
2021-05-31 15:31:00 +02:00
|
|
|
|
static int write_color_patch(pdfio_stream_t *st, bool device);
|
2021-06-01 01:41:02 +02:00
|
|
|
|
static int write_color_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
2021-06-24 03:26:01 +02:00
|
|
|
|
static int write_font_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font, bool unicode);
|
2021-06-11 16:36:32 +02:00
|
|
|
|
static int write_header_footer(pdfio_stream_t *st, const char *title, int number);
|
2021-06-01 23:10:36 +02:00
|
|
|
|
static pdfio_obj_t *write_image_object(pdfio_file_t *pdf, _pdfio_predictor_t predictor);
|
2021-06-11 16:36:32 +02:00
|
|
|
|
static int write_images_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
|
|
|
|
static int write_jpeg_test(pdfio_file_t *pdf, const char *title, int number, pdfio_obj_t *font, pdfio_obj_t *image);
|
|
|
|
|
static int write_png_test(pdfio_file_t *pdf, int number, pdfio_obj_t *font);
|
|
|
|
|
static int write_text_test(pdfio_file_t *pdf, int first_page, pdfio_obj_t *font, const char *filename);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
|
|
|
|
|
2021-04-10 14:00:52 +02:00
|
|
|
|
//
|
|
|
|
|
// 'main()' - Main entry for test program.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - Exit status
|
|
|
|
|
main(int argc, // I - Number of command-line arguments
|
|
|
|
|
char *argv[]) // I - Command-line arguments
|
|
|
|
|
{
|
2021-05-01 17:50:17 +02:00
|
|
|
|
if (argc > 1)
|
|
|
|
|
{
|
2021-05-10 14:00:27 +02:00
|
|
|
|
int i; // Looping var
|
2021-05-01 17:50:17 +02:00
|
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i ++)
|
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if ((i + 1) < argc && isdigit(argv[i + 1][0] & 255))
|
|
|
|
|
{
|
|
|
|
|
// filename.pdf object-number
|
|
|
|
|
if (do_test_file(argv[i], atoi(argv[i + 1])))
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
|
}
|
|
|
|
|
else if (do_test_file(argv[i], 0))
|
2021-05-10 14:00:27 +02:00
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
do_unit_tests();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'do_test_file()' - Try loading a PDF file and listing pages and objects.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - Exit status
|
2021-06-21 22:03:05 +02:00
|
|
|
|
do_test_file(const char *filename, // I - PDF filename
|
|
|
|
|
int objnum) // I - Object number to dump, if any
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-05-10 14:40:52 +02:00
|
|
|
|
bool error = false; // Have we shown an error yet?
|
2021-05-10 14:00:27 +02:00
|
|
|
|
pdfio_file_t *pdf; // PDF file
|
|
|
|
|
size_t n, // Object/page index
|
|
|
|
|
num_objs, // Number of objects
|
|
|
|
|
num_pages; // Number of pages
|
|
|
|
|
pdfio_obj_t *obj; // Object
|
|
|
|
|
pdfio_dict_t *dict; // Object dictionary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try opening the file...
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if (!objnum)
|
|
|
|
|
printf("pdfioFileOpen(\"%s\", ...): ", filename);
|
|
|
|
|
|
2021-05-10 14:40:52 +02:00
|
|
|
|
if ((pdf = pdfioFileOpen(filename, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if (objnum)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
const char *filter; // Stream filter
|
|
|
|
|
pdfio_stream_t *st; // Stream
|
|
|
|
|
char buffer[8192]; // Read buffer
|
|
|
|
|
ssize_t bytes; // Bytes read
|
|
|
|
|
|
|
|
|
|
if ((obj = pdfioFileFindObj(pdf, (size_t)objnum)) == NULL)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
puts("Not found.");
|
|
|
|
|
return (1);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
}
|
2021-06-21 22:03:05 +02:00
|
|
|
|
|
|
|
|
|
if ((dict = pdfioObjGetDict(obj)) == NULL)
|
2021-05-01 17:50:17 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
puts("Not a stream.");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
filter = pdfioDictGetName(dict, "Filter");
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if ((st = pdfioObjOpenStream(obj, (filter && !strcmp(filter, "FlateDecode")) ? PDFIO_FILTER_FLATE : PDFIO_FILTER_NONE)) == NULL)
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
while ((bytes = pdfioStreamRead(st, buffer, sizeof(buffer))) > 0)
|
|
|
|
|
fwrite(buffer, 1, (size_t)bytes, stdout);
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
|
|
|
|
|
// Show basic stats...
|
|
|
|
|
num_objs = pdfioFileGetNumObjs(pdf);
|
|
|
|
|
num_pages = pdfioFileGetNumPages(pdf);
|
|
|
|
|
|
|
|
|
|
printf(" PDF %s, %d pages, %d objects.\n", pdfioFileGetVersion(pdf), (int)num_pages, (int)num_objs);
|
|
|
|
|
|
|
|
|
|
// Show a summary of each page...
|
|
|
|
|
for (n = 0; n < num_pages; n ++)
|
|
|
|
|
{
|
|
|
|
|
if ((obj = pdfioFileGetPage(pdf, n)) == NULL)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
printf("%s: Unable to get page #%d.\n", filename, (int)n + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pdfio_rect_t media_box; // MediaBox value
|
|
|
|
|
|
|
|
|
|
memset(&media_box, 0, sizeof(media_box));
|
|
|
|
|
dict = pdfioObjGetDict(obj);
|
|
|
|
|
|
|
|
|
|
if (!pdfioDictGetRect(dict, "MediaBox", &media_box))
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if ((obj = pdfioDictGetObj(dict, "Parent")) != NULL)
|
|
|
|
|
{
|
|
|
|
|
dict = pdfioObjGetDict(obj);
|
|
|
|
|
pdfioDictGetRect(dict, "MediaBox", &media_box);
|
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
printf(" Page #%d is %gx%g.\n", (int)n + 1, media_box.x2, media_box.y2);
|
|
|
|
|
}
|
2021-05-01 17:50:17 +02:00
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
// Show the associated value with each object...
|
|
|
|
|
for (n = 0; n < num_objs; n ++)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-06-21 22:03:05 +02:00
|
|
|
|
if ((obj = pdfioFileGetObj(pdf, n)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf(" Unable to get object #%d.\n", (int)n);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dict = pdfioObjGetDict(obj);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
2021-06-21 22:03:05 +02:00
|
|
|
|
printf(" %u %u obj dict=%p(%lu pairs)\n", (unsigned)pdfioObjGetNumber(obj), (unsigned)pdfioObjGetGeneration(obj), dict, dict ? (unsigned long)dict->num_pairs : 0UL);
|
|
|
|
|
fputs(" ", stdout);
|
|
|
|
|
_pdfioValueDebug(&obj->value, stdout);
|
|
|
|
|
putchar('\n');
|
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close the file and return success...
|
|
|
|
|
pdfioFileClose(pdf);
|
|
|
|
|
return (0);
|
2021-05-01 17:50:17 +02:00
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Error message will already be displayed so just indicate failure...
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'do_unit_tests()' - Do unit tests.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - Exit status
|
|
|
|
|
do_unit_tests(void)
|
|
|
|
|
{
|
2021-05-16 18:36:44 +02:00
|
|
|
|
int i; // Looping var
|
2021-05-30 02:00:48 +02:00
|
|
|
|
pdfio_file_t *pdf, // Test PDF file
|
|
|
|
|
*outpdf; // Output PDF file
|
2021-05-10 14:00:27 +02:00
|
|
|
|
bool error = false; // Error callback data
|
|
|
|
|
_pdfio_token_t tb; // Token buffer
|
|
|
|
|
const char *s; // String buffer
|
|
|
|
|
_pdfio_value_t value; // Value
|
2021-05-28 16:41:21 +02:00
|
|
|
|
pdfio_obj_t *color_jpg, // color.jpg image
|
2021-05-30 02:00:48 +02:00
|
|
|
|
*gray_jpg, // gray.jpg image
|
2021-06-01 01:41:02 +02:00
|
|
|
|
*helvetica, // Helvetica font
|
2021-05-30 02:00:48 +02:00
|
|
|
|
*page; // Page from test PDF file
|
2021-06-02 21:46:39 +02:00
|
|
|
|
size_t first_image, // First image object
|
|
|
|
|
num_pages; // Number of pages written
|
2021-05-10 14:00:27 +02:00
|
|
|
|
static const char *complex_dict = // Complex dictionary value
|
|
|
|
|
"<</Annots 5457 0 R/Contents 5469 0 R/CropBox[0 0 595.4 842]/Group 725 0 R"
|
|
|
|
|
"/MediaBox[0 0 595.4 842]/Parent 23513 0 R/Resources<</ColorSpace<<"
|
|
|
|
|
"/CS0 21381 0 R/CS1 21393 0 R>>/ExtGState<</GS0 21420 0 R>>/Font<<"
|
|
|
|
|
"/TT0 21384 0 R/TT1 21390 0 R/TT2 21423 0 R/TT3 21403 0 R/TT4 21397 0 R>>"
|
|
|
|
|
"/ProcSet[/PDF/Text/ImageC]/Properties<</MC0 5472 0 R/MC1 5473 0 R>>"
|
|
|
|
|
"/XObject<</E3Dp0QGN3h9EZL2X 23690 0 R/E6DU0TGl3s9NZT2C 23691 0 R"
|
|
|
|
|
"/ENDB06GH3u9tZT2N 21391 0 R/ENDD0NGM339cZe2F 23692 0 R"
|
|
|
|
|
"/ENDK00GK3c9DZN2n 23693 0 R/EPDB0NGN3Q9GZP2t 23695 0 R"
|
|
|
|
|
"/EpDA0kG03o9rZX21 23696 0 R/Im0 5475 0 R>>>>/Rotate 0/StructParents 2105"
|
|
|
|
|
"/Tabs/S/Type/Page>>";
|
|
|
|
|
|
|
|
|
|
|
2021-05-28 16:41:21 +02:00
|
|
|
|
setbuf(stdout, NULL);
|
|
|
|
|
|
2021-05-10 14:00:27 +02:00
|
|
|
|
// First open the test PDF file...
|
2021-05-28 15:31:42 +02:00
|
|
|
|
fputs("pdfioFileOpen(\"testfiles/testpdfio.pdf\"): ", stdout);
|
|
|
|
|
if ((pdf = pdfioFileOpen("testfiles/testpdfio.pdf", (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
2021-05-10 14:00:27 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
// TODO: Test for known values in this test file.
|
|
|
|
|
|
|
|
|
|
// Test the value parsers for edge cases...
|
|
|
|
|
fputs("_pdfioValueRead(complex_dict): ", stdout);
|
|
|
|
|
s = complex_dict;
|
2021-07-26 17:58:20 +02:00
|
|
|
|
_pdfioTokenInit(&tb, pdf, (_pdfio_tconsume_cb_t)token_consume_cb, (_pdfio_tpeek_cb_t)token_peek_cb, (void *)&s);
|
2021-05-10 14:00:27 +02:00
|
|
|
|
if (_pdfioValueRead(pdf, &tb, &value))
|
|
|
|
|
{
|
|
|
|
|
// TODO: Check value...
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-16 18:36:44 +02:00
|
|
|
|
// Create a new PDF file...
|
2021-05-28 16:41:21 +02:00
|
|
|
|
fputs("pdfioFileCreate(\"testpdfio-out.pdf\", ...): ", stdout);
|
2021-05-30 02:00:48 +02:00
|
|
|
|
if ((outpdf = pdfioFileCreate("testpdfio-out.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
2021-05-28 16:41:21 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-07-07 02:51:21 +02:00
|
|
|
|
// Set info values...
|
|
|
|
|
fputs("pdfioFileGet/SetAuthor: ", stdout);
|
|
|
|
|
pdfioFileSetAuthor(outpdf, "Michael R Sweet");
|
|
|
|
|
if ((s = pdfioFileGetAuthor(outpdf)) != NULL && !strcmp(s, "Michael R Sweet"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else if (s)
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got '%s', expected 'Michael R Sweet')\n", s);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL (got NULL, expected 'Michael R Sweet')");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioFileGet/SetCreator: ", stdout);
|
|
|
|
|
pdfioFileSetCreator(outpdf, "testpdfio");
|
|
|
|
|
if ((s = pdfioFileGetCreator(outpdf)) != NULL && !strcmp(s, "testpdfio"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else if (s)
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got '%s', expected 'testpdfio')\n", s);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL (got NULL, expected 'testpdfio')");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioFileGet/SetKeywords: ", stdout);
|
|
|
|
|
pdfioFileSetKeywords(outpdf, "one fish,two fish,red fish,blue fish");
|
|
|
|
|
if ((s = pdfioFileGetKeywords(outpdf)) != NULL && !strcmp(s, "one fish,two fish,red fish,blue fish"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else if (s)
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got '%s', expected 'one fish,two fish,red fish,blue fish')\n", s);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL (got NULL, expected 'one fish,two fish,red fish,blue fish')");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioFileGet/SetSubject: ", stdout);
|
|
|
|
|
pdfioFileSetSubject(outpdf, "Unit test document");
|
|
|
|
|
if ((s = pdfioFileGetSubject(outpdf)) != NULL && !strcmp(s, "Unit test document"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else if (s)
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got '%s', expected 'Unit test document')\n", s);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL (got NULL, expected 'Unit test document')");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioFileGet/SetTitle: ", stdout);
|
|
|
|
|
pdfioFileSetTitle(outpdf, "Test Document");
|
|
|
|
|
if ((s = pdfioFileGetTitle(outpdf)) != NULL && !strcmp(s, "Test Document"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else if (s)
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got '%s', expected 'Test Document')\n", s);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL (got NULL, expected 'Test Document')");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:41:21 +02:00
|
|
|
|
// Create some image objects...
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateImageObjFromFile(\"testfiles/color.jpg\"): ", stdout);
|
|
|
|
|
if ((color_jpg = pdfioFileCreateImageObjFromFile(outpdf, "testfiles/color.jpg", true)) != NULL)
|
2021-05-28 16:41:21 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateImageObjFromFile(\"testfiles/gray.jpg\"): ", stdout);
|
|
|
|
|
if ((gray_jpg = pdfioFileCreateImageObjFromFile(outpdf, "testfiles/gray.jpg", true)) != NULL)
|
2021-05-30 02:00:48 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-01 01:41:02 +02:00
|
|
|
|
// Create fonts...
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateFontObjFromBase(\"Helvetica\"): ", stdout);
|
|
|
|
|
if ((helvetica = pdfioFileCreateFontObjFromBase(outpdf, "Helvetica")) != NULL)
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-30 02:00:48 +02:00
|
|
|
|
// Copy the first page from the test PDF file...
|
|
|
|
|
fputs("pdfioFileGetPage(0): ", stdout);
|
|
|
|
|
if ((page = pdfioFileGetPage(pdf, 0)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageCopy(first page): ", stdout);
|
|
|
|
|
if (pdfioPageCopy(outpdf, page))
|
2021-05-16 18:36:44 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
// Write a page with a color image...
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_jpeg_test(outpdf, "Color JPEG Test", 2, helvetica, color_jpg))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
return (1);
|
2021-05-16 18:36:44 +02:00
|
|
|
|
|
2021-05-30 02:00:48 +02:00
|
|
|
|
// Copy the third page from the test PDF file...
|
|
|
|
|
fputs("pdfioFileGetPage(2): ", stdout);
|
|
|
|
|
if ((page = pdfioFileGetPage(pdf, 2)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageCopy(third page): ", stdout);
|
|
|
|
|
if (pdfioPageCopy(outpdf, page))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
// Write a page with a grayscale image...
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_jpeg_test(outpdf, "Grayscale JPEG Test", 4, helvetica, gray_jpg))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-06 06:27:33 +02:00
|
|
|
|
// Write a page with PNG images...
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_png_test(outpdf, 5, helvetica))
|
2021-06-06 06:27:33 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
// Write a page that tests multiple color spaces...
|
2021-06-06 06:27:33 +02:00
|
|
|
|
if (write_color_test(outpdf, 6, helvetica))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-01 23:10:36 +02:00
|
|
|
|
// Write a page with test images...
|
2021-06-10 16:58:07 +02:00
|
|
|
|
first_image = pdfioFileGetNumObjs(outpdf) + 1;
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_images_test(outpdf, 7, helvetica))
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-07-18 15:23:39 +02:00
|
|
|
|
// Write a page width alpha (soft masks)...
|
|
|
|
|
if (write_alpha_test(outpdf, 8, helvetica))
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Test TrueType fonts...
|
2021-07-18 15:23:39 +02:00
|
|
|
|
if (write_font_test(outpdf, 9, helvetica, false))
|
2021-06-24 03:26:01 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-07-18 15:23:39 +02:00
|
|
|
|
if (write_font_test(outpdf, 10, helvetica, true))
|
2021-06-01 23:10:36 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-01 02:51:37 +02:00
|
|
|
|
// Print this text file...
|
2021-07-18 15:23:39 +02:00
|
|
|
|
if (write_text_test(outpdf, 11, helvetica, "README.md"))
|
2021-06-01 02:51:37 +02:00
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-30 02:00:48 +02:00
|
|
|
|
// Close the test PDF file...
|
2021-06-02 21:46:39 +02:00
|
|
|
|
fputs("pdfioFileClose(\"testfiles/testpdfio.pdf\"): ", stdout);
|
2021-05-16 18:36:44 +02:00
|
|
|
|
if (pdfioFileClose(pdf))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-02 21:46:39 +02:00
|
|
|
|
fputs("pdfioFileGetNumPages: ", stdout);
|
|
|
|
|
if ((num_pages = pdfioFileGetNumPages(outpdf)) > 0)
|
|
|
|
|
{
|
|
|
|
|
printf("PASS (%lu)\n", (unsigned long)num_pages);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-30 02:00:48 +02:00
|
|
|
|
// Close the new PDF file...
|
2021-06-02 21:46:39 +02:00
|
|
|
|
fputs("pdfioFileClose(\"testpdfio-out.pdf\"): ", stdout);
|
2021-05-30 02:00:48 +02:00
|
|
|
|
if (pdfioFileClose(outpdf))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-02 21:46:39 +02:00
|
|
|
|
// Open the new PDF file to read it...
|
|
|
|
|
fputs("pdfioFileOpen(\"testpdfio-out.pdf\", ...): ", stdout);
|
|
|
|
|
if ((pdf = pdfioFileOpen("testpdfio-out.pdf", (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
// Verify the number of pages is the same...
|
|
|
|
|
fputs("pdfioFileGetNumPages: ", stdout);
|
|
|
|
|
if (num_pages == pdfioFileGetNumPages(pdf))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (%lu != %lu)\n", (unsigned long)num_pages, (unsigned long)pdfioFileGetNumPages(pdf));
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify the images
|
|
|
|
|
for (i = 0; i < 7; i ++)
|
2021-06-10 16:58:07 +02:00
|
|
|
|
{
|
|
|
|
|
if (verify_image(pdf, first_image + (size_t)i))
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
2021-06-02 21:46:39 +02:00
|
|
|
|
|
|
|
|
|
// Close the new PDF file...
|
|
|
|
|
fputs("pdfioFileClose(\"testpdfio-out.pdf\"): ", stdout);
|
|
|
|
|
if (pdfioFileClose(pdf))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-04-10 14:00:52 +02:00
|
|
|
|
return (0);
|
|
|
|
|
}
|
2021-05-10 14:00:27 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-01 23:10:36 +02:00
|
|
|
|
//
|
|
|
|
|
// 'draw_image()' - Draw an image with a label.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
draw_image(pdfio_stream_t *st,
|
|
|
|
|
const char *name, // I - Name
|
|
|
|
|
double x, // I - X offset
|
|
|
|
|
double y, // I - Y offset
|
|
|
|
|
double w, // I - Image width
|
|
|
|
|
double h, // I - Image height
|
|
|
|
|
const char *label) // I - Label
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioContentDrawImage(name=\"%s\", x=%g, y=%g, w=%g, h=%g): ", name, x, y, w, h);
|
|
|
|
|
if (pdfioContentDrawImage(st, name, x, y, w, h))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F1", 18.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentTextMoveTo(%g, %g): ", x, y + h + 9);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, x, y + h + 9))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentTextShow(\"%s\"): ", label);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, label))
|
2021-06-01 23:10:36 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-10 14:00:27 +02:00
|
|
|
|
//
|
|
|
|
|
// 'error_cb()' - Display an error message during a unit test.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static bool // O - `true` to stop, `false` to continue
|
2021-05-10 14:40:52 +02:00
|
|
|
|
error_cb(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
const char *message, // I - Error message
|
2021-06-10 16:58:07 +02:00
|
|
|
|
bool *error) // IO - Have we displayed an error?
|
2021-05-10 14:00:27 +02:00
|
|
|
|
{
|
2021-05-10 14:40:52 +02:00
|
|
|
|
(void)pdf;
|
|
|
|
|
|
2021-05-10 14:00:27 +02:00
|
|
|
|
if (!*error)
|
|
|
|
|
{
|
|
|
|
|
// First error, so show a "FAIL" indicator
|
|
|
|
|
*error = true;
|
|
|
|
|
|
2021-05-10 14:40:52 +02:00
|
|
|
|
puts("FAIL");
|
2021-05-10 14:00:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-10 14:40:52 +02:00
|
|
|
|
// Indent error messages...
|
|
|
|
|
printf(" %s\n", message);
|
|
|
|
|
|
2021-05-10 14:00:27 +02:00
|
|
|
|
// Continue to catch more errors...
|
|
|
|
|
return (false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'token_consume_cb()' - Consume bytes from a test string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static ssize_t // O - Number of bytes consumed
|
|
|
|
|
token_consume_cb(const char **s, // IO - Test string
|
|
|
|
|
size_t bytes) // I - Bytes to consume
|
|
|
|
|
{
|
|
|
|
|
size_t len = strlen(*s); // Number of bytes remaining
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// "Consume" bytes by incrementing the string pointer, limiting to the
|
|
|
|
|
// remaining length...
|
|
|
|
|
if (bytes > len)
|
|
|
|
|
bytes = len;
|
|
|
|
|
|
|
|
|
|
*s += bytes;
|
|
|
|
|
|
|
|
|
|
return ((ssize_t)bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'token_peek_cb()' - Peek bytes from a test string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static ssize_t // O - Number of bytes peeked
|
|
|
|
|
token_peek_cb(const char **s, // IO - Test string
|
|
|
|
|
char *buffer, // I - Buffer
|
|
|
|
|
size_t bytes) // I - Bytes to peek
|
|
|
|
|
{
|
|
|
|
|
size_t len = strlen(*s); // Number of bytes remaining
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy bytes from the test string as possible...
|
|
|
|
|
if (bytes > len)
|
|
|
|
|
bytes = len;
|
|
|
|
|
|
|
|
|
|
if (bytes > 0)
|
|
|
|
|
memcpy(buffer, *s, bytes);
|
|
|
|
|
|
|
|
|
|
return ((ssize_t)bytes);
|
|
|
|
|
}
|
2021-05-16 18:36:44 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-02 21:46:39 +02:00
|
|
|
|
//
|
|
|
|
|
// 'verify_image()' - Verify an image object.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
verify_image(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
size_t number) // I - Object number
|
|
|
|
|
{
|
|
|
|
|
pdfio_obj_t *obj; // Image object
|
|
|
|
|
const char *type, // Object type
|
|
|
|
|
*subtype; // Object subtype
|
|
|
|
|
double width, // Width of object
|
|
|
|
|
height; // Height of object
|
|
|
|
|
pdfio_stream_t *st; // Stream
|
|
|
|
|
int x, y; // Coordinates in image
|
|
|
|
|
unsigned char buffer[768], // Expected data
|
|
|
|
|
*bufptr, // Pointer into buffer
|
|
|
|
|
line[768]; // Line from file
|
|
|
|
|
ssize_t bytes; // Bytes read from stream
|
|
|
|
|
|
|
|
|
|
|
2021-06-07 14:34:30 +02:00
|
|
|
|
printf("pdfioFileFindObj(%lu): ", (unsigned long)number);
|
|
|
|
|
if ((obj = pdfioFileFindObj(pdf, number)) != NULL)
|
2021-06-02 21:46:39 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioObjGetType: ", stdout);
|
|
|
|
|
if ((type = pdfioObjGetType(obj)) != NULL && !strcmp(type, "XObject"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got %s, expected XObject)\n", type);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioObjGetSubtype: ", stdout);
|
|
|
|
|
if ((subtype = pdfioObjGetSubtype(obj)) != NULL && !strcmp(subtype, "Image"))
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got %s, expected Image)\n", subtype);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioImageGetWidth: ", stdout);
|
|
|
|
|
if ((width = pdfioImageGetWidth(obj)) == 256.0)
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got %g, expected 256)\n", width);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioImageGetHeight: ", stdout);
|
|
|
|
|
if ((height = pdfioImageGetHeight(obj)) == 256.0)
|
|
|
|
|
{
|
|
|
|
|
puts("PASS");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("FAIL (got %g, expected 256)\n", height);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the image stream, read the image, and verify it matches expectations...
|
|
|
|
|
fputs("pdfioObjOpenStream: ", stdout);
|
|
|
|
|
if ((st = pdfioObjOpenStream(obj, PDFIO_FILTER_FLATE)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < 256; y ++)
|
|
|
|
|
{
|
|
|
|
|
for (x = 0, bufptr = buffer; x < 256; x ++, bufptr += 3)
|
|
|
|
|
{
|
2021-06-07 14:34:30 +02:00
|
|
|
|
bufptr[0] = (unsigned char)y;
|
|
|
|
|
bufptr[1] = (unsigned char)(y + x);
|
|
|
|
|
bufptr[2] = (unsigned char)(y - x);
|
2021-06-02 21:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((bytes = pdfioStreamRead(st, line, sizeof(line))) != (ssize_t)sizeof(line))
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioStreamRead: FAIL (got %d for line %d, expected 768)\n", y, (int)bytes);
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (memcmp(buffer, line, sizeof(buffer)))
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioStreamRead: FAIL (line %d doesn't match expectations)\n", y);
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-18 15:23:39 +02:00
|
|
|
|
//
|
|
|
|
|
// 'write_alpha_test()' - Write a series of test images with alpha channels.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
write_alpha_test(
|
|
|
|
|
pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
int number, // I - Page number
|
|
|
|
|
pdfio_obj_t *font) // I - Text font
|
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
pdfio_stream_t *st; // Page stream
|
|
|
|
|
pdfio_obj_t *images[6]; // Images using PNG predictors
|
|
|
|
|
char iname[32]; // Image name
|
|
|
|
|
int i, // Image number
|
|
|
|
|
x, y; // Coordinates in image
|
|
|
|
|
unsigned char buffer[1280 * 256], // Buffer for image
|
|
|
|
|
*bufptr; // Pointer into buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the images...
|
|
|
|
|
for (i = 0; i < 6; i ++)
|
|
|
|
|
{
|
|
|
|
|
size_t num_colors = 0; // Number of colors
|
|
|
|
|
|
|
|
|
|
// Generate test image data...
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
case 0 : // Grayscale
|
|
|
|
|
case 3 : // Grayscale + alpha
|
|
|
|
|
num_colors = 1;
|
|
|
|
|
for (y = 0, bufptr = buffer; y < 256; y ++)
|
|
|
|
|
{
|
|
|
|
|
for (x = 0; x < 256; x ++)
|
|
|
|
|
{
|
|
|
|
|
unsigned char r = (unsigned char)y;
|
|
|
|
|
unsigned char g = (unsigned char)(y + x);
|
|
|
|
|
unsigned char b = (unsigned char)(y - x);
|
|
|
|
|
|
|
|
|
|
*bufptr++ = (unsigned char)((r * 30 + g * 59 + b * 11) / 100);
|
|
|
|
|
|
|
|
|
|
if (i > 2)
|
|
|
|
|
{
|
|
|
|
|
// Add alpha channel
|
2021-07-18 15:50:22 +02:00
|
|
|
|
if (x < 112 || x >= 144 || y < 112 || y >= 144)
|
|
|
|
|
*bufptr++ = (unsigned char)((x - 128) * (y - 128));
|
|
|
|
|
else
|
|
|
|
|
*bufptr++ = 0;
|
2021-07-18 15:23:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1 : // RGB
|
|
|
|
|
case 4 : // RGB + alpha
|
|
|
|
|
num_colors = 3;
|
|
|
|
|
for (y = 0, bufptr = buffer; y < 256; y ++)
|
|
|
|
|
{
|
|
|
|
|
for (x = 0; x < 256; x ++)
|
|
|
|
|
{
|
|
|
|
|
*bufptr++ = (unsigned char)y;
|
|
|
|
|
*bufptr++ = (unsigned char)(y + x);
|
|
|
|
|
*bufptr++ = (unsigned char)(y - x);
|
|
|
|
|
|
|
|
|
|
if (i > 2)
|
|
|
|
|
{
|
|
|
|
|
// Add alpha channel
|
2021-07-18 15:50:22 +02:00
|
|
|
|
if (x < 112 || x >= 144 || y < 112 || y >= 144)
|
|
|
|
|
*bufptr++ = (unsigned char)((x - 128) * (y - 128));
|
|
|
|
|
else
|
|
|
|
|
*bufptr++ = 0;
|
2021-07-18 15:23:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2 : // CMYK
|
|
|
|
|
case 5 : // CMYK + alpha
|
|
|
|
|
num_colors = 4;
|
|
|
|
|
for (y = 0, bufptr = buffer; y < 256; y ++)
|
|
|
|
|
{
|
|
|
|
|
for (x = 0; x < 256; x ++)
|
|
|
|
|
{
|
|
|
|
|
unsigned char cc = (unsigned char)y;
|
|
|
|
|
unsigned char mm = (unsigned char)(y + x);
|
|
|
|
|
unsigned char yy = (unsigned char)(y - x);
|
|
|
|
|
unsigned char kk = cc < mm ? cc < yy ? cc : yy : mm < yy ? mm : yy;
|
|
|
|
|
|
|
|
|
|
*bufptr++ = (unsigned char)(cc - kk);
|
|
|
|
|
*bufptr++ = (unsigned char)(mm - kk);
|
|
|
|
|
*bufptr++ = (unsigned char)(yy - kk);
|
|
|
|
|
*bufptr++ = (unsigned char)(kk);
|
|
|
|
|
|
|
|
|
|
if (i > 2)
|
|
|
|
|
{
|
|
|
|
|
// Add alpha channel
|
2021-07-18 15:50:22 +02:00
|
|
|
|
if (x < 112 || x >= 144 || y < 112 || y >= 144)
|
|
|
|
|
*bufptr++ = (unsigned char)((x - 128) * (y - 128));
|
|
|
|
|
else
|
|
|
|
|
*bufptr++ = 0;
|
2021-07-18 15:23:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write the image...
|
|
|
|
|
printf("pdfioFileCreateImageObjFromData(num_colors=%u, alpha=%s): ", (unsigned)num_colors, i > 2 ? "true" : "false");
|
|
|
|
|
if ((images[i] = pdfioFileCreateImageObjFromData(pdf, buffer, 256, 256, num_colors, NULL, i > 2, false)) != NULL)
|
|
|
|
|
{
|
2021-07-18 15:50:22 +02:00
|
|
|
|
printf("PASS (%u)\n", (unsigned)pdfioObjGetNumber(images[i]));
|
2021-07-18 15:23:39 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
puts("FAIL");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the page dictionary, object, and stream...
|
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i ++)
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioPageDictAddImage(%d): ", i + 1);
|
|
|
|
|
snprintf(iname, sizeof(iname), "IM%d", i + 1);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, pdfioStringCreate(pdf, iname), images[i]))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
if (write_header_footer(st, "Image Writing Test", number))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
// Draw images
|
|
|
|
|
for (i = 0; i < 6; i ++)
|
|
|
|
|
{
|
|
|
|
|
static const char *labels[] = {
|
|
|
|
|
"DeviceGray",
|
|
|
|
|
"DeviceRGB",
|
|
|
|
|
"DeviceCMYK",
|
2021-07-18 15:50:22 +02:00
|
|
|
|
"DevGray + Alpha",
|
|
|
|
|
"DevRGB + Alpha",
|
|
|
|
|
"DevCMYK + Alpha"
|
2021-07-18 15:23:39 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
snprintf(iname, sizeof(iname), "IM%d", i + 1);
|
|
|
|
|
|
|
|
|
|
if (draw_image(st, iname, 36 + 180 * (i % 3), 306 - 216 * (i / 3), 144, 144, labels[i]))
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrap up...
|
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
//
|
|
|
|
|
// 'write_color_patch()' - Write a color patch...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
write_color_patch(pdfio_stream_t *st, // I - Content stream
|
|
|
|
|
bool device)// I - Use device color?
|
|
|
|
|
{
|
|
|
|
|
int col, // Current column
|
|
|
|
|
row; // Current row
|
|
|
|
|
double x, y, // Relative position
|
|
|
|
|
r, // Radius
|
|
|
|
|
hue, // Hue angle
|
|
|
|
|
sat, // Saturation
|
|
|
|
|
cc, // Computed color
|
|
|
|
|
red, // Red value
|
|
|
|
|
green, // Green value
|
|
|
|
|
blue; // Blue value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw an 11x11 patch...
|
|
|
|
|
for (col = 0; col < 21; col ++)
|
|
|
|
|
{
|
|
|
|
|
for (row = 0; row < 21; row ++)
|
|
|
|
|
{
|
|
|
|
|
// Compute color in patch...
|
|
|
|
|
x = 0.1 * (col - 10);
|
|
|
|
|
y = 0.1 * (row - 10);
|
|
|
|
|
r = sqrt(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
if (r == 0.0)
|
|
|
|
|
{
|
|
|
|
|
red = green = blue = 1.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-01 02:51:37 +02:00
|
|
|
|
sat = pow(r, 1.5);
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
x /= r;
|
|
|
|
|
y /= r;
|
|
|
|
|
hue = 3.0 * atan2(y, x) / M_PI;
|
|
|
|
|
if (hue < 0.0)
|
|
|
|
|
hue += 6.0;
|
|
|
|
|
|
|
|
|
|
cc = sat * (1.0 - fabs(fmod(hue, 2.0) - 1.0)) + 1.0 - sat;
|
|
|
|
|
|
|
|
|
|
if (hue < 1.0)
|
|
|
|
|
{
|
|
|
|
|
red = 1.0;
|
|
|
|
|
green = cc;
|
|
|
|
|
blue = 1.0 - sat;
|
|
|
|
|
}
|
|
|
|
|
else if (hue < 2.0)
|
|
|
|
|
{
|
|
|
|
|
red = cc;
|
|
|
|
|
green = 1.0;
|
|
|
|
|
blue = 1.0 - sat;
|
|
|
|
|
}
|
|
|
|
|
else if (hue < 3.0)
|
|
|
|
|
{
|
|
|
|
|
red = 1.0 - sat;
|
|
|
|
|
green = 1.0;
|
|
|
|
|
blue = cc;
|
|
|
|
|
}
|
|
|
|
|
else if (hue < 4.0)
|
|
|
|
|
{
|
|
|
|
|
red = 1.0 - sat;
|
|
|
|
|
green = cc;
|
|
|
|
|
blue = 1.0;
|
|
|
|
|
}
|
|
|
|
|
else if (hue < 5.0)
|
|
|
|
|
{
|
|
|
|
|
red = cc;
|
|
|
|
|
green = 1.0 - sat;
|
|
|
|
|
blue = 1.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
red = 1.0;
|
|
|
|
|
green = 1.0 - sat;
|
|
|
|
|
blue = cc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw it...
|
|
|
|
|
if (device)
|
|
|
|
|
{
|
|
|
|
|
// Use device CMYK color instead of a calibrated RGB space...
|
|
|
|
|
double cyan = 1.0 - red; // Cyan color
|
|
|
|
|
double magenta = 1.0 - green; // Magenta color
|
|
|
|
|
double yellow = 1.0 - blue; // Yellow color
|
|
|
|
|
double black = cyan; // Black color
|
|
|
|
|
|
|
|
|
|
if (black > magenta)
|
|
|
|
|
black = magenta;
|
|
|
|
|
if (black > yellow)
|
|
|
|
|
black = yellow;
|
|
|
|
|
|
|
|
|
|
cyan -= black;
|
|
|
|
|
magenta -= black;
|
|
|
|
|
yellow -= black;
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentSetFillColorDeviceCMYK(c=%g, m=%g, y=%g, k=%g): ", cyan, magenta, yellow, black);
|
|
|
|
|
if (pdfioContentSetFillColorDeviceCMYK(st, cyan, magenta, yellow, black))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Use calibrate RGB space...
|
|
|
|
|
printf("pdfioContentSetFillColorRGB(r=%g, g=%g, b=%g): ", red, green, blue);
|
|
|
|
|
if (pdfioContentSetFillColorRGB(st, red, green, blue))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
printf("pdfioContentPathRect(x=%g, y=%g, w=%g, h=%g): ", col * 6.0, row * 6.0, 6.0, 6.0);
|
|
|
|
|
if (pdfioContentPathRect(st, col * 6.0, row * 6.0, 6.0, 6.0))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentFill(even_odd=false): ", stdout);
|
|
|
|
|
if (pdfioContentFill(st, false))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'write_color_test()' - Write a color test page...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
write_color_test(pdfio_file_t *pdf, // I - PDF file
|
2021-06-01 01:41:02 +02:00
|
|
|
|
int number, // I - Page number
|
|
|
|
|
pdfio_obj_t *font) // I - Text font
|
2021-05-31 15:31:00 +02:00
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
pdfio_stream_t *st; // Page contents stream
|
2021-06-05 17:28:32 +02:00
|
|
|
|
pdfio_array_t *cs; // Color space array
|
2021-06-10 18:40:06 +02:00
|
|
|
|
pdfio_obj_t *prophoto; // ProPhotoRGB ICC profile object
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateICCObjFromFile(ProPhotoRGB): ", stdout);
|
|
|
|
|
if ((prophoto = pdfioFileCreateICCObjFromFile(pdf, "testfiles/iso22028-2-romm-rgb.icc", 3)) != NULL)
|
2021-06-10 18:40:06 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-10 18:40:06 +02:00
|
|
|
|
fputs("pdfioArrayCreateColorFromMatrix(AdobeRGB): ", stdout);
|
|
|
|
|
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioAdobeRGBGamma, pdfioAdobeRGBMatrix, pdfioAdobeRGBWhitePoint)) != NULL)
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-05 17:28:32 +02:00
|
|
|
|
fputs("pdfioPageDictAddColorSpace(AdobeRGB): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddColorSpace(dict, "AdobeRGB", cs))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-10 18:40:06 +02:00
|
|
|
|
fputs("pdfioArrayCreateColorFromMatrix(DisplayP3): ", stdout);
|
|
|
|
|
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioDisplayP3Gamma, pdfioDisplayP3Matrix, pdfioDisplayP3WhitePoint)) != NULL)
|
2021-06-05 17:28:32 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddColorSpace(DisplayP3): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddColorSpace(dict, "DisplayP3", cs))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-10 18:40:06 +02:00
|
|
|
|
fputs("pdfioArrayCreateColorFromICCObj(ProPhotoRGB): ", stdout);
|
|
|
|
|
if ((cs = pdfioArrayCreateColorFromICCObj(pdf, prophoto)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddColorSpace(ProPhotoRGB): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddColorSpace(dict, "ProPhotoRGB", cs))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioArrayCreateColorFromMatrix(sRGB): ", stdout);
|
|
|
|
|
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioSRGBGamma, pdfioSRGBMatrix, pdfioSRGBWhitePoint)) != NULL)
|
2021-06-05 17:28:32 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddColorSpace(sRGB): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddColorSpace(dict, "sRGB", cs))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-01 01:41:02 +02:00
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_header_footer(st, "Color Space Test", number))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F1", 18.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
2021-06-10 18:40:06 +02:00
|
|
|
|
fputs("pdfioContentTextMoveTo(82, 234): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 82, 234))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextShow(\"AdobeRGB\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "AdobeRGB"))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(234, 0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 234, 0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextShow(\"DisplayP3\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "DisplayP3"))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentTextMoveTo(-234, 216): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, -234, 216))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextShow(\"sRGB\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "sRGB"))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(234, 0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 234, 0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
2021-06-10 18:40:06 +02:00
|
|
|
|
fputs("pdfioContentTextShow(\"ProPhotoRGB\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "ProPhotoRGB"))
|
2021-06-10 18:40:06 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentTextMoveTo(-234, 216): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, -234, 216))
|
2021-06-10 18:40:06 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-01 01:41:02 +02:00
|
|
|
|
fputs("pdfioContentTextShow(\"DeviceCMYK\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "DeviceCMYK"))
|
2021-06-01 01:41:02 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 01:41:02 +02:00
|
|
|
|
|
2021-05-31 15:31:00 +02:00
|
|
|
|
fputs("pdfioContentSave(): ", stdout);
|
|
|
|
|
if (pdfioContentSave(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetFillColorSpace(AdobeRGB): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorSpace(st, "AdobeRGB"))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentMatrixTranslate(82, 90): ", stdout);
|
|
|
|
|
if (pdfioContentMatrixTranslate(st, 82, 90))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
if (write_color_patch(st, false))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentRestore(): ", stdout);
|
|
|
|
|
if (pdfioContentRestore(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSave(): ", stdout);
|
|
|
|
|
if (pdfioContentSave(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetFillColorSpace(DisplayP3): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorSpace(st, "DisplayP3"))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentMatrixTranslate(316, 90): ", stdout);
|
|
|
|
|
if (pdfioContentMatrixTranslate(st, 316, 90))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
if (write_color_patch(st, false))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentRestore(): ", stdout);
|
|
|
|
|
if (pdfioContentRestore(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSave(): ", stdout);
|
|
|
|
|
if (pdfioContentSave(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetFillColorSpace(sRGB): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorSpace(st, "sRGB"))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentMatrixTranslate(82, 306): ", stdout);
|
|
|
|
|
if (pdfioContentMatrixTranslate(st, 82, 306))
|
2021-06-10 18:40:06 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
if (write_color_patch(st, false))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentRestore(): ", stdout);
|
|
|
|
|
if (pdfioContentRestore(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSave(): ", stdout);
|
|
|
|
|
if (pdfioContentSave(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetFillColorSpace(ProPhotoRGB): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorSpace(st, "ProPhotoRGB"))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentMatrixTranslate(316, 306): ", stdout);
|
|
|
|
|
if (pdfioContentMatrixTranslate(st, 316, 306))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
if (write_color_patch(st, false))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentRestore(): ", stdout);
|
|
|
|
|
if (pdfioContentRestore(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSave(): ", stdout);
|
|
|
|
|
if (pdfioContentSave(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentMatrixTranslate(82, 522): ", stdout);
|
|
|
|
|
if (pdfioContentMatrixTranslate(st, 82, 522))
|
2021-05-31 15:31:00 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
if (write_color_patch(st, true))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentRestore(): ", stdout);
|
|
|
|
|
if (pdfioContentRestore(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-31 15:31:00 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
2021-06-04 16:56:23 +02:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
2021-05-31 15:31:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
//
|
|
|
|
|
// 'write_font_test()' - Write a font test page.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
write_font_test(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
int number, // I - Page number
|
2021-06-24 03:26:01 +02:00
|
|
|
|
pdfio_obj_t *font, // I - Page number font
|
|
|
|
|
bool unicode) // I - Use Unicode font?
|
2021-06-11 16:36:32 +02:00
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
pdfio_stream_t *st; // Page contents stream
|
2021-06-11 17:22:08 +02:00
|
|
|
|
pdfio_obj_t *opensans; // OpenSans-Regular font
|
|
|
|
|
int i; // Looping var
|
|
|
|
|
static const char * const welcomes[] =// "Welcome" in many languages
|
|
|
|
|
{
|
|
|
|
|
"Welcome\n",
|
|
|
|
|
"Welkom\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"ḫaṣānu\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Mayad-ayad nga pad-abot\n",
|
|
|
|
|
"Mir se vjên\n",
|
|
|
|
|
"Mirë se vjen\n",
|
|
|
|
|
"Wellkumma\n",
|
|
|
|
|
"Bienveniu\n",
|
|
|
|
|
"Ghini vinit!\n",
|
|
|
|
|
"Bienveníu\n",
|
|
|
|
|
"Miro peicak\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Xoş gəlmişsiniz!\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Salamat datang\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Сәләм бирем!\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Menjuah-juah!\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Še das d' kemma bisd\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Mwaiseni\n",
|
|
|
|
|
"Maogmáng Pag-abót\n",
|
|
|
|
|
"Welkam\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Dobrodošli\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Degemer mat\n",
|
|
|
|
|
"Benvingut\n",
|
|
|
|
|
"Maayong pag-abot\n",
|
|
|
|
|
"Kopisanangan do kinorikatan\n",
|
|
|
|
|
"Bienvenida\n",
|
|
|
|
|
"Bien binidu\n",
|
|
|
|
|
"Bienbenidu\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Hóʔą\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Boolkhent!\n",
|
|
|
|
|
"Kopivosian do kinoikatan\n",
|
|
|
|
|
"Malipayeng Pag-abot!\n",
|
|
|
|
|
"Vítej\n",
|
|
|
|
|
"Velkommen\n",
|
|
|
|
|
"Salâm\n",
|
|
|
|
|
"Welkom\n",
|
|
|
|
|
"Emedi\n",
|
|
|
|
|
"Welkumin\n",
|
|
|
|
|
"Tere tulemast\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Woé zɔ\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Bienveníu\n",
|
|
|
|
|
"Vælkomin\n",
|
|
|
|
|
"Bula\n",
|
|
|
|
|
"Tervetuloa\n",
|
|
|
|
|
"Bienvenue\n",
|
|
|
|
|
"Wäljkiimen\n",
|
|
|
|
|
"Wäilkuumen\n",
|
|
|
|
|
"Wäilkuumen\n",
|
|
|
|
|
"Wolkom\n",
|
|
|
|
|
"Benvignût\n",
|
|
|
|
|
"Benvido\n",
|
|
|
|
|
"Willkommen\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Ἀσπάζομαι!\n",
|
|
|
|
|
"Καλώς Ήρθες\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Tikilluarit\n",
|
|
|
|
|
"Byen venu\n",
|
|
|
|
|
"Sannu da zuwa\n",
|
|
|
|
|
"Aloha\n",
|
|
|
|
|
"Wayakurua\n",
|
|
|
|
|
"Dayón\n",
|
|
|
|
|
"Zoo siab txais tos!\n",
|
|
|
|
|
"Üdvözlet\n",
|
|
|
|
|
"Selamat datai\n",
|
|
|
|
|
"Velkomin\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Nnọọ\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Selamat datang\n",
|
|
|
|
|
"Qaimarutin\n",
|
|
|
|
|
"Fáilte\n",
|
|
|
|
|
"Benvenuto\n",
|
|
|
|
|
"Voschata\n",
|
|
|
|
|
"Murakaza neza\n",
|
|
|
|
|
"Mauri\n",
|
|
|
|
|
"Tu be xér hatî ye!\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Taŋyáŋ yahí\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Salve\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Laipni lūdzam\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Wilkóm\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Sveiki atvykę\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Willkamen\n",
|
|
|
|
|
"Mu amuhezwi\n",
|
|
|
|
|
"Tukusanyukidde\n",
|
|
|
|
|
"Wëllkomm\n",
|
|
|
|
|
"Swagatam\n",
|
|
|
|
|
"Tonga soa\n",
|
|
|
|
|
"Selamat datang\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Merħba\n",
|
|
|
|
|
"B’a’ntulena\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Failt ort\n",
|
|
|
|
|
"Haere mai\n",
|
|
|
|
|
"mai\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Pjila’si\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Benvegnüu\n",
|
|
|
|
|
"Ne y kena\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Ximopanōltih\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Yá'át'ééh\n",
|
|
|
|
|
"Siyalemukela\n",
|
|
|
|
|
"Siyalemukela\n",
|
|
|
|
|
"Bures boahtin\n",
|
|
|
|
|
"Re a go amogela\n",
|
|
|
|
|
"Velkommen\n",
|
|
|
|
|
"Benvengut!\n",
|
|
|
|
|
"Bon bini\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Witam Cię\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Bem-vindo\n",
|
|
|
|
|
"Haykuykuy!\n",
|
|
|
|
|
"T'aves baxtalo\n",
|
|
|
|
|
"Bainvegni\n",
|
|
|
|
|
"Afio mai\n",
|
|
|
|
|
"Ennidos\n",
|
|
|
|
|
"Walcome\n",
|
|
|
|
|
"Fàilte\n",
|
|
|
|
|
"Mauya\n",
|
|
|
|
|
"Bon vinutu\n",
|
|
|
|
|
"Vitaj\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Dobrodošli\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Soo dhowow\n",
|
|
|
|
|
"Witaj\n",
|
|
|
|
|
"Bienvenido\n",
|
|
|
|
|
"Wilujeng sumping\n",
|
|
|
|
|
"Karibu\n",
|
|
|
|
|
"Wamukelekile\n",
|
|
|
|
|
"Välkommen\n",
|
|
|
|
|
"Wilkomme\n",
|
|
|
|
|
"Maligayang pagdating\n",
|
|
|
|
|
"Maeva\n",
|
|
|
|
|
"Räxim itegez\n",
|
|
|
|
|
"Ksolok Bodik Mai\n",
|
|
|
|
|
"Ulu tons mai\n",
|
|
|
|
|
"Welkam\n",
|
|
|
|
|
"Talitali fiefia\n",
|
|
|
|
|
"Lek oy li la tale\n",
|
|
|
|
|
"amogetswe\n",
|
|
|
|
|
"Tempokani\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Hoş geldin\n",
|
|
|
|
|
"Koş geldiniz\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Ulufale mai!\n",
|
|
|
|
|
"Xush kelibsiz\n",
|
|
|
|
|
"Benvignùo\n",
|
|
|
|
|
"Tervhen tuldes\n",
|
|
|
|
|
"Hoan nghênh\n",
|
|
|
|
|
"Tere tulõmast\n",
|
|
|
|
|
"Benvnuwe\n",
|
|
|
|
|
"Croeso\n",
|
|
|
|
|
"Merhbe\n",
|
|
|
|
|
"Wamkelekile\n",
|
2021-06-21 13:58:23 +02:00
|
|
|
|
"Märr-ŋamathirri\n",
|
|
|
|
|
"Ẹ ku abọ\n",
|
2021-06-11 17:22:08 +02:00
|
|
|
|
"Kíimak 'oolal\n",
|
|
|
|
|
"Ngiyakwemukela\n"
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-22 23:10:19 +02:00
|
|
|
|
|
2021-06-30 02:39:31 +02:00
|
|
|
|
#if 0
|
2021-06-24 15:07:03 +02:00
|
|
|
|
if (unicode)
|
|
|
|
|
{
|
|
|
|
|
fputs("pdfioFileCreateFontObjFromFile(NotoSansJP-Regular.otf): ", stdout);
|
|
|
|
|
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/NotoSansJP-Regular.otf", true)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
2021-06-22 23:10:19 +02:00
|
|
|
|
else
|
2021-06-30 02:39:31 +02:00
|
|
|
|
#endif // 0
|
2021-06-24 15:07:03 +02:00
|
|
|
|
{
|
|
|
|
|
fputs("pdfioFileCreateFontObjFromFile(OpenSans-Regular.ttf): ", stdout);
|
2021-06-30 02:39:31 +02:00
|
|
|
|
if ((opensans = pdfioFileCreateFontObjFromFile(pdf, "testfiles/OpenSans-Regular.ttf", unicode)) != NULL)
|
2021-06-24 15:07:03 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
2021-06-22 23:10:19 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 17:22:08 +02:00
|
|
|
|
fputs("pdfioPageDictAddFont(F2): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F2", opensans))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-24 03:26:01 +02:00
|
|
|
|
if (write_header_footer(st, unicode ? "Unicode TrueType Font Test" : "CP1252 TrueType Font Test", number))
|
2021-06-11 16:36:32 +02:00
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 17:22:08 +02:00
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F2", 10.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextLeading(12.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextLeading(st, 12.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(36.0, 702.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 36.0, 702.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < (int)(sizeof(welcomes) / sizeof(welcomes[0])); i ++)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0 && (i % 50) == 0)
|
|
|
|
|
{
|
|
|
|
|
fputs("pdfioContentTextMoveTo(200.0, 600.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 200.0, 600.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentTextShow(\"%s\"): ", welcomes[i]);
|
2021-06-22 23:10:19 +02:00
|
|
|
|
if (pdfioContentTextShow(st, unicode, welcomes[i]))
|
2021-06-11 17:22:08 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'write_header_footer()' - Write common header and footer text.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
|
|
|
|
write_header_footer(
|
|
|
|
|
pdfio_stream_t *st, // I - Page content stream
|
|
|
|
|
const char *title, // I - Title
|
|
|
|
|
int number) // I - Page number
|
|
|
|
|
{
|
|
|
|
|
fputs("pdfioContentSetFillColorDeviceGray(0.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorDeviceGray(st, 0.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F1", 18.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(36.0, 738.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 36.0, 738.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentTextShow(\"%s\"): ", title);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, title))
|
2021-06-11 16:36:32 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F1", 12.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(514.0, -702.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 514.0, -702.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioContentTextShowf(\"%d\"): ", number);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShowf(st, false, "%d", number))
|
2021-06-11 16:36:32 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-01 23:10:36 +02:00
|
|
|
|
//
|
|
|
|
|
// 'write_image_object()' - Write an image object using the specified predictor.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static pdfio_obj_t * // O - Image object
|
|
|
|
|
write_image_object(
|
|
|
|
|
pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
_pdfio_predictor_t predictor) // I - Predictor to use
|
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict, // Image dictionary
|
|
|
|
|
*decode; // Decode dictionary
|
|
|
|
|
pdfio_obj_t *obj; // Image object
|
|
|
|
|
pdfio_stream_t *st; // Image stream
|
|
|
|
|
int x, y; // Coordinates in image
|
|
|
|
|
unsigned char buffer[768], // Buffer for image
|
|
|
|
|
*bufptr; // Pointer into buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the image dictionary...
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
pdfioDictSetName(dict, "Type", "XObject");
|
|
|
|
|
pdfioDictSetName(dict, "Subtype", "Image");
|
|
|
|
|
pdfioDictSetNumber(dict, "Width", 256);
|
|
|
|
|
pdfioDictSetNumber(dict, "Height", 256);
|
|
|
|
|
pdfioDictSetNumber(dict, "BitsPerComponent", 8);
|
|
|
|
|
pdfioDictSetName(dict, "ColorSpace", "DeviceRGB");
|
|
|
|
|
pdfioDictSetName(dict, "Filter", "FlateDecode");
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// DecodeParms dictionary...
|
2021-06-01 23:10:36 +02:00
|
|
|
|
if ((decode = pdfioDictCreate(pdf)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
pdfioDictSetNumber(decode, "BitsPerComponent", 8);
|
|
|
|
|
pdfioDictSetNumber(decode, "Colors", 3);
|
|
|
|
|
pdfioDictSetNumber(decode, "Columns", 256);
|
|
|
|
|
pdfioDictSetNumber(decode, "Predictor", predictor);
|
|
|
|
|
pdfioDictSetDict(dict, "DecodeParms", decode);
|
|
|
|
|
|
|
|
|
|
// Create the image object...
|
2021-06-07 14:34:30 +02:00
|
|
|
|
if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL)
|
2021-06-01 23:10:36 +02:00
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the image stream and write the image...
|
|
|
|
|
if ((st = pdfioObjCreateStream(obj, PDFIO_FILTER_FLATE)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// This creates a useful criss-cross image that highlights predictor errors...
|
2021-06-01 23:10:36 +02:00
|
|
|
|
for (y = 0; y < 256; y ++)
|
|
|
|
|
{
|
|
|
|
|
for (x = 0, bufptr = buffer; x < 256; x ++, bufptr += 3)
|
|
|
|
|
{
|
2021-06-07 14:34:30 +02:00
|
|
|
|
bufptr[0] = (unsigned char)y;
|
|
|
|
|
bufptr[1] = (unsigned char)(y + x);
|
|
|
|
|
bufptr[2] = (unsigned char)(y - x);
|
2021-06-01 23:10:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pdfioStreamWrite(st, buffer, sizeof(buffer)))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
{
|
|
|
|
|
pdfioStreamClose(st);
|
2021-06-01 23:10:36 +02:00
|
|
|
|
return (NULL);
|
2021-06-04 16:56:23 +02:00
|
|
|
|
}
|
2021-06-01 23:10:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Close the object and stream...
|
2021-06-01 23:10:36 +02:00
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
|
|
|
|
|
return (obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// 'write_images_test()' - Write a series of test images.
|
2021-06-01 23:10:36 +02:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
2021-07-18 15:23:39 +02:00
|
|
|
|
write_images_test(
|
|
|
|
|
pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
int number, // I - Page number
|
|
|
|
|
pdfio_obj_t *font) // I - Text font
|
2021-06-01 23:10:36 +02:00
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
pdfio_stream_t *st; // Page stream
|
|
|
|
|
_pdfio_predictor_t p; // Current predictor
|
|
|
|
|
pdfio_obj_t *noimage, // No predictor
|
|
|
|
|
*pimages[6]; // Images using PNG predictors
|
|
|
|
|
char pname[32], // Image name
|
|
|
|
|
plabel[32]; // Image label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the images...
|
|
|
|
|
fputs("Create Image (Predictor 1): ", stdout);
|
|
|
|
|
if ((noimage = write_image_object(pdf, _PDFIO_PREDICTOR_NONE)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++)
|
|
|
|
|
{
|
|
|
|
|
printf("Create Image (Predictor %d): ", p);
|
|
|
|
|
if ((pimages[p - _PDFIO_PREDICTOR_PNG_NONE] = write_image_object(pdf, p)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the page dictionary, object, and stream...
|
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddImage(1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, "IM1", noimage))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++)
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioPageDictAddImage(%d): ", p);
|
|
|
|
|
snprintf(pname, sizeof(pname), "IM%d", p);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, pdfioStringCreate(pdf, pname), pimages[p - _PDFIO_PREDICTOR_PNG_NONE]))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_header_footer(st, "Image Predictor Test", number))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 23:10:36 +02:00
|
|
|
|
|
|
|
|
|
// Draw images
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (draw_image(st, "IM1", 36, 522, 144, 144, "No Predictor"))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 23:10:36 +02:00
|
|
|
|
|
|
|
|
|
for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++)
|
|
|
|
|
{
|
2021-06-07 14:34:30 +02:00
|
|
|
|
int i = (int)p - _PDFIO_PREDICTOR_PNG_NONE;
|
2021-06-01 23:10:36 +02:00
|
|
|
|
|
|
|
|
|
snprintf(pname, sizeof(pname), "IM%d", p);
|
|
|
|
|
snprintf(plabel, sizeof(plabel), "PNG Predictor %d", p);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (draw_image(st, pname, 36 + 180 * (i % 3), 306 - 216 * (i / 3), 144, 144, plabel))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 23:10:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrap up...
|
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
2021-06-04 16:56:23 +02:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
2021-06-01 23:10:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-16 18:36:44 +02:00
|
|
|
|
//
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// 'write_jpeg_test()' - Write a page with a JPEG image to a PDF file.
|
2021-05-16 18:36:44 +02:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 1 on failure, 0 on success
|
2021-06-11 16:36:32 +02:00
|
|
|
|
write_jpeg_test(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
const char *title, // I - Page title
|
|
|
|
|
int number, // I - Page number
|
|
|
|
|
pdfio_obj_t *font, // I - Text font
|
|
|
|
|
pdfio_obj_t *image) // I - Image to draw
|
2021-05-16 18:36:44 +02:00
|
|
|
|
{
|
2021-05-28 16:41:21 +02:00
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
2021-05-16 18:36:44 +02:00
|
|
|
|
pdfio_stream_t *st; // Page contents stream
|
2021-05-30 03:16:21 +02:00
|
|
|
|
double width, // Width of image
|
2021-05-29 04:05:44 +02:00
|
|
|
|
height; // Height of image
|
2021-05-30 03:16:21 +02:00
|
|
|
|
double swidth, // Scaled width
|
2021-05-29 04:05:44 +02:00
|
|
|
|
sheight, // Scaled height
|
|
|
|
|
tx, // X offset
|
|
|
|
|
ty; // Y offset
|
2021-05-16 18:36:44 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-01 23:10:36 +02:00
|
|
|
|
// Create the page dictionary, object, and stream...
|
2021-05-28 16:41:21 +02:00
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddImage: ", stdout);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, "IM1", image))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-01 01:41:02 +02:00
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-05-16 18:36:44 +02:00
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
2021-05-28 16:41:21 +02:00
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
2021-05-16 18:36:44 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_header_footer(st, title, number))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-28 16:41:21 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Calculate the scaled size of the image...
|
2021-05-29 04:05:44 +02:00
|
|
|
|
fputs("pdfioImageGetWidth(): ", stdout);
|
2021-05-30 03:16:21 +02:00
|
|
|
|
if ((width = pdfioImageGetWidth(image)) > 0.0)
|
2021-05-28 16:41:21 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-28 16:41:21 +02:00
|
|
|
|
|
2021-05-29 04:05:44 +02:00
|
|
|
|
fputs("pdfioImageGetHeight(): ", stdout);
|
2021-05-30 03:16:21 +02:00
|
|
|
|
if ((height = pdfioImageGetHeight(image)) > 0.0)
|
2021-05-29 04:05:44 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-29 04:05:44 +02:00
|
|
|
|
|
2021-05-30 03:16:21 +02:00
|
|
|
|
swidth = 400.0;
|
2021-05-29 04:05:44 +02:00
|
|
|
|
sheight = swidth * height / width;
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (sheight > 500.0)
|
2021-05-29 04:05:44 +02:00
|
|
|
|
{
|
2021-06-11 16:36:32 +02:00
|
|
|
|
sheight = 500.0;
|
2021-05-29 04:05:44 +02:00
|
|
|
|
swidth = sheight * width / height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tx = 0.5 * (595.28 - swidth);
|
|
|
|
|
ty = 0.5 * (792 - sheight);
|
2021-05-28 16:41:21 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Show "raw" content (a bordered box for the image...)
|
|
|
|
|
fputs("pdfioStreamPrintf(...): ", stdout);
|
|
|
|
|
if (pdfioStreamPrintf(st,
|
|
|
|
|
"1 0 0 RG 0 g 5 w\n"
|
|
|
|
|
"%g %g %g %g re %g %g %g %g re B*\n", tx - 36, ty - 36, swidth + 72, sheight + 72, tx - 1, ty - 1, swidth + 2, sheight + 2))
|
2021-05-28 16:41:21 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-28 16:41:21 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Draw the image inside the border box...
|
|
|
|
|
printf("pdfioContentDrawImage(\"IM1\", x=%g, y=%g, w=%g, h=%g): ", tx, ty, swidth, sheight);
|
|
|
|
|
if (pdfioContentDrawImage(st, "IM1", tx, ty, swidth, sheight))
|
2021-05-28 16:41:21 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-05-28 16:41:21 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Close the page stream/object...
|
2021-05-16 18:36:44 +02:00
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
2021-06-04 16:56:23 +02:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
2021-05-16 18:36:44 +02:00
|
|
|
|
}
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
|
2021-06-06 06:27:33 +02:00
|
|
|
|
//
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// 'write_png_test()' - Write a page of PNG test images.
|
2021-06-06 06:27:33 +02:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 0 on success, 1 on failure
|
2021-06-11 16:36:32 +02:00
|
|
|
|
write_png_test(pdfio_file_t *pdf, // I - PDF file
|
2021-06-06 06:27:33 +02:00
|
|
|
|
int number, // I - Page number
|
|
|
|
|
pdfio_obj_t *font) // I - Page number font
|
|
|
|
|
{
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
pdfio_stream_t *st; // Page contents stream
|
|
|
|
|
pdfio_obj_t *color, // pdfio-color.png
|
|
|
|
|
*gray, // pdfio-gray.png
|
|
|
|
|
*indexed; // pdfio-indexed.png
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Import the PNG test images
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-color.png\"): ", stdout);
|
|
|
|
|
if ((color = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-color.png", false)) != NULL)
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-gray.png\"): ", stdout);
|
|
|
|
|
if ((gray = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-gray.png", false)) != NULL)
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-indexed.png\"): ", stdout);
|
|
|
|
|
if ((indexed = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-indexed.png", false)) != NULL)
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
// Create the page dictionary, object, and stream...
|
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddImage(color): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, "IM1", color))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddImage(gray): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, "IM2", gray))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddImage(indexed): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddImage(dict, "IM3", indexed))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
printf("pdfioFileCreatePage(%d): ", number);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_header_footer(st, "PNG Image Test Page", number))
|
2021-06-06 06:27:33 +02:00
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Show content...
|
2021-06-06 06:27:33 +02:00
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F1", 18.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(36.0, 342.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 36.0, 342.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-10 17:18:51 +02:00
|
|
|
|
fputs("pdfioContentTextShow(\"PNG RGB Color\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "PNG RGB Color"))
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(288.0, 0.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 288.0, 0.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextShow(\"PNG Gray\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "PNG Gray"))
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextMoveTo(-288.0, 288.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, -288.0, 288.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextShow(\"PNG Indexed\"): ", stdout);
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (pdfioContentTextShow(st, false, "PNG Indexed"))
|
2021-06-06 06:27:33 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentDrawImage(\"IM1\"): ", stdout);
|
|
|
|
|
if (pdfioContentDrawImage(st, "IM1", 36, 108, 216, 216))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentDrawImage(\"IM2\"): ", stdout);
|
|
|
|
|
if (pdfioContentDrawImage(st, "IM2", 324, 108, 216, 216))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentDrawImage(\"IM3\"): ", stdout);
|
|
|
|
|
if (pdfioContentDrawImage(st, "IM3", 36, 396, 216, 216))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-10 17:18:51 +02:00
|
|
|
|
fputs("pdfioContentSetFillColorDeviceRGB(0, 1, 1): ", stdout);
|
|
|
|
|
if (pdfioContentSetFillColorDeviceRGB(st, 0.0, 1.0, 1.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentPathRect(315, 387, 234, 234): ", stdout);
|
|
|
|
|
if (pdfioContentPathRect(st, 315, 387, 234, 234))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentFill(false): ", stdout);
|
|
|
|
|
if (pdfioContentFill(st, false))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentDrawImage(\"IM3\"): ", stdout);
|
|
|
|
|
if (pdfioContentDrawImage(st, "IM3", 324, 396, 216, 216))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// Close the object and stream...
|
2021-06-06 06:27:33 +02:00
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-01 02:51:37 +02:00
|
|
|
|
//
|
2021-06-11 16:36:32 +02:00
|
|
|
|
// 'write_text_test()' - Print a plain text file.
|
2021-06-01 02:51:37 +02:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static int // O - 0 on success, 1 on failure
|
2021-06-11 16:36:32 +02:00
|
|
|
|
write_text_test(pdfio_file_t *pdf, // I - PDF file
|
2021-06-01 02:51:37 +02:00
|
|
|
|
int first_page, // I - First page number
|
|
|
|
|
pdfio_obj_t *font, // I - Page number font
|
|
|
|
|
const char *filename) // I - File to print
|
|
|
|
|
{
|
|
|
|
|
pdfio_obj_t *courier; // Courier font
|
|
|
|
|
pdfio_dict_t *dict; // Page dictionary
|
|
|
|
|
FILE *fp; // Print file
|
|
|
|
|
char line[1024]; // Line from file
|
|
|
|
|
int page, // Current page number
|
|
|
|
|
plinenum, // Current line number on page
|
|
|
|
|
flinenum; // Current line number in file
|
|
|
|
|
pdfio_stream_t *st = NULL; // Page contents stream
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create text font...
|
2021-06-11 01:41:39 +02:00
|
|
|
|
fputs("pdfioFileCreateFontObjFromBase(\"Courier\"): ", stdout);
|
|
|
|
|
if ((courier = pdfioFileCreateFontObjFromBase(pdf, "Courier")) != NULL)
|
2021-06-01 02:51:37 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
// Create the page dictionary...
|
|
|
|
|
fputs("pdfioDictCreate: ", stdout);
|
|
|
|
|
if ((dict = pdfioDictCreate(pdf)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F1): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F1", font))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
fputs("pdfioPageDictAddFont(F2): ", stdout);
|
|
|
|
|
if (pdfioPageDictAddFont(dict, "F2", courier))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
|
|
// Open the print file...
|
|
|
|
|
if ((fp = fopen(filename, "r")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Unable to open \"%s\": %s\n", filename, strerror(errno));
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page = first_page;
|
|
|
|
|
plinenum = 0;
|
|
|
|
|
flinenum = 0;
|
|
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), fp))
|
|
|
|
|
{
|
|
|
|
|
flinenum ++;
|
|
|
|
|
|
|
|
|
|
if (plinenum == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("pdfioFileCreatePage(%d): ", page);
|
|
|
|
|
|
|
|
|
|
if ((st = pdfioFileCreatePage(pdf, dict)) != NULL)
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 17:09:34 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (write_header_footer(st, "README.md", page))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
page ++;
|
|
|
|
|
plinenum ++;
|
|
|
|
|
|
|
|
|
|
fputs("pdfioContentTextBegin(): ", stdout);
|
|
|
|
|
if (pdfioContentTextBegin(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextFont(st, "F2", 10.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioContentSetTextLeading(12.0): ", stdout);
|
|
|
|
|
if (pdfioContentSetTextLeading(st, 12.0))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
2021-06-11 16:36:32 +02:00
|
|
|
|
fputs("pdfioContentTextMoveTo(36.0, 708.0): ", stdout);
|
|
|
|
|
if (pdfioContentTextMoveTo(st, 36.0, 708.0))
|
2021-06-01 02:51:37 +02:00
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 16:56:23 +02:00
|
|
|
|
if (!pdfioContentSetFillColorDeviceGray(st, 0.75))
|
|
|
|
|
goto error;
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (!pdfioContentTextShowf(st, false, "%3d ", flinenum))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
|
|
|
|
if (!pdfioContentSetFillColorDeviceGray(st, 0.0))
|
|
|
|
|
goto error;
|
2021-06-11 17:33:41 +02:00
|
|
|
|
if (strlen(line) > 81)
|
|
|
|
|
{
|
|
|
|
|
char temp[82]; // Temporary string
|
|
|
|
|
|
|
|
|
|
memcpy(temp, line, 80);
|
|
|
|
|
temp[80] = '\n';
|
|
|
|
|
temp[81] = '\0';
|
|
|
|
|
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (!pdfioContentTextShow(st, false, temp))
|
2021-06-11 17:33:41 +02:00
|
|
|
|
goto error;
|
|
|
|
|
|
2021-06-21 13:58:23 +02:00
|
|
|
|
if (!pdfioContentTextShowf(st, false, " %s", line + 80))
|
2021-06-11 17:33:41 +02:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
plinenum ++;
|
|
|
|
|
}
|
2021-06-21 13:58:23 +02:00
|
|
|
|
else if (!pdfioContentTextShow(st, false, line))
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
plinenum ++;
|
2021-06-11 16:36:32 +02:00
|
|
|
|
if (plinenum >= 56)
|
2021-06-01 02:51:37 +02:00
|
|
|
|
{
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
st = NULL;
|
|
|
|
|
plinenum = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plinenum > 0)
|
|
|
|
|
{
|
|
|
|
|
fputs("pdfioContentTextEnd(): ", stdout);
|
|
|
|
|
if (pdfioContentTextEnd(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
2021-06-04 16:56:23 +02:00
|
|
|
|
goto error;
|
2021-06-01 02:51:37 +02:00
|
|
|
|
|
|
|
|
|
fputs("pdfioStreamClose: ", stdout);
|
|
|
|
|
if (pdfioStreamClose(st))
|
|
|
|
|
puts("PASS");
|
|
|
|
|
else
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 17:07:27 +02:00
|
|
|
|
fclose(fp);
|
|
|
|
|
|
2021-06-01 02:51:37 +02:00
|
|
|
|
return (0);
|
2021-06-04 16:56:23 +02:00
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
pdfioStreamClose(st);
|
|
|
|
|
return (1);
|
2021-06-01 02:51:37 +02:00
|
|
|
|
}
|