diff --git a/doc/pdfio.3 b/doc/pdfio.3 index a60835c..237898b 100644 --- a/doc/pdfio.3 +++ b/doc/pdfio.3 @@ -1,4 +1,4 @@ -.TH pdfio 3 "pdf read/write library" "2021-05-30" "pdf read/write library" +.TH pdfio 3 "pdf read/write library" "2021-06-07" "pdf read/write library" .SH NAME pdfio \- pdf read/write library .SH Introduction @@ -29,6 +29,191 @@ Provide access to objects used for each page PDFio is .I not concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it. +.PP +PDFio is Copyright \[co] 2021 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information. +.SS Requirements +.PP +PDFio requires the following to build the software: +.IP \(bu 5 +.PP +A C99 compiler such as Clang, GCC, or MS Visual C + +.IP \(bu 5 +.PP +A POSIX\-compliant make program + +.IP \(bu 5 +.PP +ZLIB (https://www.zlib.net) 1.0 or higher + + +.PP +IDE files for Xcode (macOS/iOS) and Visual Studio (Windows) are also provided. +.SS Installing pdfio +.PP +PDFio comes with a portable makefile that will work on any POSIX\-compliant system with ZLIB installed. To make it, run: +.nf + + make all +.fi +.PP +To test it, run: +.nf + + make test +.fi +.PP +To install it, run: +.nf + + make install +.fi +.PP +If you want a shared library, run: +.nf + + make all\-shared + make install\-shared +.fi +.PP +The default installation location is "/usr/local". Pass the prefix variable to make to install it to another location: +.nf + + make install prefix=/some/other/directory +.fi +.PP +The makefile installs the pdfio header to "${prefix}/include", the library to "${prefix}/lib", the pkg\-config file to "${prefix}/lib/pkgconfig", the man page to "${prefix}/share/man/man3", and the documentation to "${prefix}/share/doc/pdfio". +.PP +The makefile supports the following variables that can be specified in the make command or as environment variables: +.IP \(bu 5 +.PP +AR: the library archiver (default "ar") + +.IP \(bu 5 +.PP +ARFLAGS: options for the library archiver (default "cr") + +.IP \(bu 5 +.PP +CC: the C compiler (default "cc") + +.IP \(bu 5 +.PP +CFLAGS: options for the C compiler (default "") + +.IP \(bu 5 +.PP +CODESIGN_IDENTITY: the identity to use when code signing the shared library on macOS (default "Developer ID") + +.IP \(bu 5 +.PP +COMMONFLAGS: options for the C compiler and linker (typically architecture and optimization options, default is "\-Os \-g") + +.IP \(bu 5 +.PP +CPPFLAGS: options for the C preprocessor (default "") + +.IP \(bu 5 +.PP +DESTDIR" and "DSTROOT: specifies a root directory when installing (default is "", specify only one) + +.IP \(bu 5 +.PP +DSOFLAGS: options for the C compiler when linking the shared library (default "") + +.IP \(bu 5 +.PP +LDFLAGS: options for the C compiler when linking the test programs (default "") + +.IP \(bu 5 +.PP +LIBS: library options when linking the test programs (default "\-lz") + +.IP \(bu 5 +.PP +RANLIB: program that generates a table\-of\-contents in a library (default "ranlib") + +.IP \(bu 5 +.PP +prefix: specifies the installation directory (default "/usr/local") + + +.SS Visual Studio Project +.PP +Note: I haven't yet added this... + +.PP +The Visual Studio solution ("pdfio.sln") is provided for Windows developers generates both a static library and DLL. +.SS Xcode Project +.PP +There is also an Xcode project ("pdfio.xcodeproj") you can use on macOS which generates a static library that will be installed under "/usr/local" with: +.nf + + sudo xcodebuild install +.fi +.PP +You can reproduce this with the makefile using: +.nf + + sudo make 'COMMONFLAGS="\-Os \-mmacosx\-version\-min=10.14 \-arch x86_64 \-arch arm64"' install +.fi +.SS Detecting PDFio +.PP +PDFio can be detected using the pkg\-config command, for example: +.nf + + if pkg\-config \-\-exists pdfio; then + ... + fi +.fi +.PP +In a makefile you can add the necessary compiler and linker options with: +.nf + + CFLAGS += `pkg\-config \-\-cflags pdfio` + LIBS += `pkg\-config \-\-libs pdfio` +.fi +.SS Header Files +.PP +PDFio provides a primary header file that is always used: +.nf + + #include +.fi +.PP +PDFio also provides content helper functions that are defined in a separate header file: +.nf + + #include +.fi +.SH API Overview +.PP +PDFio exposes several types: +.IP \(bu 5 +.PP +pdfio_file_t: A PDF file (for reading or writing) + +.IP \(bu 5 +.PP +pdfio_array_t: An array of values + +.IP \(bu 5 +.PP +pdfio_dict_t: A dictionary of key/value pairs in a PDF file, object, etc. + +.IP \(bu 5 +.PP +pdfio_obj_t: An object in a PDF file + +.IP \(bu 5 +.PP +pdfio_stream_t: An object stream + + +.SS PDF Files +.SS PDF Values +.SS PDF Objects +.SS PDF Streams .SH ENUMERATIONS .SS pdfio_filter_e @@ -139,7 +324,7 @@ Add a binary string value to an array. .nf bool pdfioArrayAppendBinary ( pdfio_array_t *a, - unsigned char *value, + const unsigned char *value, size_t valuelen ); .fi @@ -179,11 +364,11 @@ bool pdfioArrayAppendNumber ( double value ); .fi -.SS pdfioArrayAppendObject +.SS pdfioArrayAppendObj Add an indirect object reference to an array. .PP .nf -bool pdfioArrayAppendObject ( +bool pdfioArrayAppendObj ( pdfio_array_t *a, pdfio_obj_t *value ); @@ -214,6 +399,55 @@ pdfio_array_t * pdfioArrayCreate ( pdfio_file_t *pdf ); .fi +.SS pdfioArrayCreateCalibratedColorFromMatrix +Create a calibrated color space array using a CIE XYZ transform matrix. +.PP +.nf +pdfio_array_t * pdfioArrayCreateCalibratedColorFromMatrix ( + pdfio_file_t *pdf, + size_t num_colors, + double gamma, + const double matrix[3][3], + const double white_point[3] +); +.fi +.SS pdfioArrayCreateCalibratedColorFromPrimaries +Create a calibrated color sapce array using CIE xy primary chromacities. +.PP +.nf +pdfio_array_t * pdfioArrayCreateCalibratedColorFromPrimaries ( + pdfio_file_t *pdf, + size_t num_colors, + double gamma, + double wx, + double wy, + double rx, + double ry, + double gx, + double gy, + double bx, + double by +); +.fi +.SS pdfioArrayCreateICCBasedColor +Create an ICC-based color space array. +.PP +.nf +pdfio_array_t * pdfioArrayCreateICCBasedColor ( + pdfio_file_t *pdf, + pdfio_obj_t *icc_object +); +.fi +.SS pdfioArrayCreateIndexedColor +Create an indexed color space array. +.PP +.nf +pdfio_array_t * pdfioArrayCreateIndexedColor ( + pdfio_file_t *pdf, + size_t num_colors, + const unsigned char *colors +); +.fi .SS pdfioArrayGetArray Get an array value from an array. .PP @@ -269,11 +503,11 @@ double pdfioArrayGetNumber ( size_t n ); .fi -.SS pdfioArrayGetObject +.SS pdfioArrayGetObj Get an indirect object reference from an array. .PP .nf -pdfio_obj_t * pdfioArrayGetObject ( +pdfio_obj_t * pdfioArrayGetObj ( pdfio_array_t *a, size_t n ); @@ -304,14 +538,6 @@ pdfio_valtype_t pdfioArrayGetType ( size_t n ); .fi -.SS pdfioContentBeginText -Begin a text block. -.PP -.nf -bool pdfioContentBeginText ( - pdfio_stream_t *st -); -.fi .SS pdfioContentClip Clip output to the current path. .PP @@ -330,21 +556,13 @@ bool pdfioContentDrawImage ( const char *name, double x, double y, - double w, - double h + double width, + double height ); .fi .PP The object name must be part of the page dictionary resources, typically using the \fIpdfioPageDictAddImage\fR function. -.SS pdfioContentEndText -End a text block. -.PP -.nf -bool pdfioContentEndText ( - pdfio_stream_t *st -); -.fi .SS pdfioContentFill Fill the current path. .PP @@ -474,7 +692,10 @@ Add a rectangle to the current path. .nf bool pdfioContentPathRect ( pdfio_stream_t *st, - pdfio_rect_t *rect + double x, + double y, + double width, + double height ); .fi .SS pdfioContentRestore @@ -752,6 +973,22 @@ bool pdfioContentStroke ( pdfio_stream_t *st ); .fi +.SS pdfioContentTextBegin +Begin a text block. +.PP +.nf +bool pdfioContentTextBegin ( + pdfio_stream_t *st +); +.fi +.SS pdfioContentTextEnd +End a text block. +.PP +.nf +bool pdfioContentTextEnd ( + pdfio_stream_t *st +); +.fi .SS pdfioContentTextMoveLine Move to the next line and offset. .PP @@ -786,8 +1023,7 @@ Show text. .nf bool pdfioContentTextShow ( pdfio_stream_t *st, - const char *s, - bool new_line + const char *s ); .fi .SS pdfioContentTextShowJustified @@ -801,6 +1037,16 @@ bool pdfioContentTextShowJustified ( const char *const *fragments ); .fi +.SS pdfioContentTextShowf + +.PP +.nf +bool pdfioContentTextShowf ( + pdfio_stream_t *st, + const char *format, + ... +); +.fi .SS pdfioDictCopy Copy a dictionary to a PDF file. .PP @@ -873,11 +1119,11 @@ double pdfioDictGetNumber ( const char *key ); .fi -.SS pdfioDictGetObject +.SS pdfioDictGetObj Get a key indirect object value from a dictionary. .PP .nf -pdfio_obj_t * pdfioDictGetObject ( +pdfio_obj_t * pdfioDictGetObj ( pdfio_dict_t *dict, const char *key ); @@ -927,7 +1173,7 @@ Set a key binary string in a dictionary. bool pdfioDictSetBinary ( pdfio_dict_t *dict, const char *key, - unsigned char *value, + const unsigned char *value, size_t valuelen ); .fi @@ -980,11 +1226,11 @@ bool pdfioDictSetNumber ( double value ); .fi -.SS pdfioDictSetObject +.SS pdfioDictSetObj Set a key indirect object reference in a dictionary. .PP .nf -bool pdfioDictSetObject ( +bool pdfioDictSetObj ( pdfio_dict_t *dict, const char *key, pdfio_obj_t *value @@ -1042,29 +1288,72 @@ pdfio_file_t * pdfioFileCreate ( void *error_data ); .fi -.SS pdfioFileCreateFontObject +.SS pdfioFileCreateBaseFontObj +Create one of the base 14 PDF fonts. +.PP +.nf +pdfio_obj_t * pdfioFileCreateBaseFontObj ( + pdfio_file_t *pdf, + const char *name +); +.fi +.PP +This function creates one of the base 14 PDF fonts. The "name" parameter +specifies the font nane: +.PP +.IP \(bu 5 +\fBCourier\fR +.IP \(bu 5 +\fBCourier-Bold\fR +.IP \(bu 5 +\fBCourier-BoldItalic\fR +.IP \(bu 5 +\fBCourier-Italic\fR +.IP \(bu 5 +\fBHelvetica\fR +.IP \(bu 5 +\fBHelvetica-Bold\fR +.IP \(bu 5 +\fBHelvetica-BoldOblique\fR +.IP \(bu 5 +\fBHelvetica-Oblique\fR +.IP \(bu 5 +\fBSymbol\fR +.IP \(bu 5 +\fBTimes-Bold\fR +.IP \(bu 5 +\fBTimes-BoldItalic\fR +.IP \(bu 5 +\fBTimes-Italic\fR +.IP \(bu 5 +\fBTimes-Roman\fR +.IP \(bu 5 +\fBZapfDingbats\fR + +.SS pdfioFileCreateFontObj Add a font object to a PDF file. .PP .nf -pdfio_obj_t * pdfioFileCreateFontObject ( +pdfio_obj_t * pdfioFileCreateFontObj ( pdfio_file_t *pdf, - const char *filename + const char *filename, + bool unicode ); .fi -.SS pdfioFileCreateICCProfileObject +.SS pdfioFileCreateICCProfileObj Add an ICC profile object to a PDF file. .PP .nf -pdfio_obj_t * pdfioFileCreateICCProfileObject ( +pdfio_obj_t * pdfioFileCreateICCProfileObj ( pdfio_file_t *pdf, const char *filename ); .fi -.SS pdfioFileCreateImageObject +.SS pdfioFileCreateImageObj Add an image object to a PDF file. .PP .nf -pdfio_obj_t * pdfioFileCreateImageObject ( +pdfio_obj_t * pdfioFileCreateImageObj ( pdfio_file_t *pdf, const char *filename, bool interpolate @@ -1072,11 +1361,11 @@ pdfio_obj_t * pdfioFileCreateImageObject ( .fi .PP Currently only GIF, JPEG, and PNG files are supported. -.SS pdfioFileCreateObject +.SS pdfioFileCreateObj Create a new object in a PDF file. .PP .nf -pdfio_obj_t * pdfioFileCreateObject ( +pdfio_obj_t * pdfioFileCreateObj ( pdfio_file_t *pdf, pdfio_dict_t *dict ); @@ -1090,17 +1379,17 @@ pdfio_stream_t * pdfioFileCreatePage ( pdfio_dict_t *dict ); .fi -.SS pdfioFileFindObject +.SS pdfioFileFindObj Find an object using its object number. .PP .nf -pdfio_obj_t * pdfioFileFindObject ( +pdfio_obj_t * pdfioFileFindObj ( pdfio_file_t *pdf, size_t number ); .fi .PP -This differs from \fIpdfioFileGetObject\fR which takes an index into the +This differs from \fIpdfioFileGetObj\fR which takes an index into the list of objects while this function takes the object number. .SS pdfioFileGetID Get the PDF file's ID strings. @@ -1118,11 +1407,11 @@ const char * pdfioFileGetName ( pdfio_file_t *pdf ); .fi -.SS pdfioFileGetNumObjects +.SS pdfioFileGetNumObjs Get the number of objects in a PDF file. .PP .nf -size_t pdfioFileGetNumObjects ( +size_t pdfioFileGetNumObjs ( pdfio_file_t *pdf ); .fi @@ -1134,11 +1423,11 @@ size_t pdfioFileGetNumPages ( pdfio_file_t *pdf ); .fi -.SS pdfioFileGetObject +.SS pdfioFileGetObj Get an object from a PDF file. .PP .nf -pdfio_obj_t * pdfioFileGetObject ( +pdfio_obj_t * pdfioFileGetObj ( pdfio_file_t *pdf, size_t n ); @@ -1170,6 +1459,14 @@ pdfio_file_t * pdfioFileOpen ( void *error_data ); .fi +.SS pdfioImageGetBytesPerLine +Get the number of bytes to read for each line. +.PP +.nf +size_t pdfioImageGetBytesPerLine ( + pdfio_obj_t *obj +); +.fi .SS pdfioImageGetHeight Get the height of an image object. .PP @@ -1253,6 +1550,14 @@ size_t pdfioObjGetNumber ( pdfio_obj_t *obj ); .fi +.SS pdfioObjGetSubtype +Get an object's subtype. +.PP +.nf +const char * pdfioObjGetSubtype ( + pdfio_obj_t *obj +); +.fi .SS pdfioObjGetType Get an object's type. .PP @@ -1279,19 +1584,28 @@ bool pdfioPageCopy ( pdfio_obj_t *srcpage ); .fi -.SS pdfioPageDictAddCalibratedColorSpace -Add a calibrated color space to -the page dictionary. +.SS pdfioPageDictAddColorSpace +Add a color space to the page dictionary. .PP .nf -bool pdfioPageDictAddCalibratedColorSpace ( +bool pdfioPageDictAddColorSpace ( pdfio_dict_t *dict, const char *name, - size_t num_colors, - const double *white_point, - double gamma + pdfio_array_t *data ); .fi +.PP +This function adds a named color space to the page dictionary. +.PP +The names "DefaultCMYK", "DefaultGray", and "DefaultRGB" specify the default +device color space used for the page. +.PP +The "data" array contains a calibrated, indexed, or ICC-based color space +array that was created using the +\fIpdfioArrayCreateCalibratedColorFromMatrix\fR, +\fIpdfioArrayCreateCalibratedColorFromPrimaries\fR, +\fIpdfioArrayCreateICCBasedColor\fR, or +\fIpdfioArrayCreateIndexedColor\fR functions. .SS pdfioPageDictAddFont Add a font object to the page dictionary. .PP @@ -1302,17 +1616,6 @@ bool pdfioPageDictAddFont ( pdfio_obj_t *obj ); .fi -.SS pdfioPageDictAddICCColorSpace -Add an ICC color space to the page -dictionary. -.PP -.nf -bool pdfioPageDictAddICCColorSpace ( - pdfio_dict_t *dict, - const char *name, - pdfio_obj_t *obj -); -.fi .SS pdfioPageDictAddImage Add an image object to the page dictionary. .PP @@ -1389,6 +1692,11 @@ ssize_t pdfioStreamRead ( size_t bytes ); .fi +.PP +This function reads data from a stream. When reading decoded image data +from a stream, you \fImust\fR read whole scanlines. The +\fIpdfioImageGetBytesPerLine\fR function can be used to determine the +proper read length. .SS pdfioStreamWrite Write data to a stream. .PP diff --git a/doc/pdfio.html b/doc/pdfio.html index 776e7ea..9724306 100644 --- a/doc/pdfio.html +++ b/doc/pdfio.html @@ -252,7 +252,20 @@ span.string {

Contents

    -
  • Introduction
  • +
  • Introduction
  • +
  • API Overview
  • Functions

    PDFio is not concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it.

    +

    PDFio is Copyright © 2021 by Michael R Sweet and is licensed under the Apache License Version 2.0 with an (optional) exception to allow linking against GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information.

    +

    Requirements

    +

    PDFio requires the following to build the software:

    +
      +
    • A C99 compiler such as Clang, GCC, or MS Visual C

      +
    • +
    • A POSIX-compliant make program

      +
    • +
    • ZLIB (https://www.zlib.net) 1.0 or higher

      +
    • +
    +

    IDE files for Xcode (macOS/iOS) and Visual Studio (Windows) are also provided.

    +

    Installing pdfio

    +

    PDFio comes with a portable makefile that will work on any POSIX-compliant system with ZLIB installed. To make it, run:

    +
    make all
    +
    +

    To test it, run:

    +
    make test
    +
    +

    To install it, run:

    +
    make install
    +
    +

    If you want a shared library, run:

    +
    make all-shared
    +make install-shared
    +
    +

    The default installation location is "/usr/local". Pass the prefix variable to make to install it to another location:

    +
    make install prefix=/some/other/directory
    +
    +

    The makefile installs the pdfio header to "${prefix}/include", the library to "${prefix}/lib", the pkg-config file to "${prefix}/lib/pkgconfig", the man page to "${prefix}/share/man/man3", and the documentation to "${prefix}/share/doc/pdfio".

    +

    The makefile supports the following variables that can be specified in the make command or as environment variables:

    +
      +
    • AR: the library archiver (default "ar")

      +
    • +
    • ARFLAGS: options for the library archiver (default "cr")

      +
    • +
    • CC: the C compiler (default "cc")

      +
    • +
    • CFLAGS: options for the C compiler (default "")

      +
    • +
    • CODESIGN_IDENTITY: the identity to use when code signing the shared library on macOS (default "Developer ID")

      +
    • +
    • COMMONFLAGS: options for the C compiler and linker (typically architecture and optimization options, default is "-Os -g")

      +
    • +
    • CPPFLAGS: options for the C preprocessor (default "")

      +
    • +
    • DESTDIR" and "DSTROOT: specifies a root directory when installing (default is "", specify only one)

      +
    • +
    • DSOFLAGS: options for the C compiler when linking the shared library (default "")

      +
    • +
    • LDFLAGS: options for the C compiler when linking the test programs (default "")

      +
    • +
    • LIBS: library options when linking the test programs (default "-lz")

      +
    • +
    • RANLIB: program that generates a table-of-contents in a library (default "ranlib")

      +
    • +
    • prefix: specifies the installation directory (default "/usr/local")

      +
    • +
    +

    Visual Studio Project

    +
    +

    Note: I haven't yet added this...

    +
    +

    The Visual Studio solution ("pdfio.sln") is provided for Windows developers generates both a static library and DLL.

    +

    Xcode Project

    +

    There is also an Xcode project ("pdfio.xcodeproj") you can use on macOS which generates a static library that will be installed under "/usr/local" with:

    +
    sudo xcodebuild install
    +
    +

    You can reproduce this with the makefile using:

    +
    sudo make 'COMMONFLAGS="-Os -mmacosx-version-min=10.14 -arch x86_64 -arch arm64"' install
    +
    +

    Detecting PDFio

    +

    PDFio can be detected using the pkg-config command, for example:

    +
    if pkg-config --exists pdfio; then
    +    ... 
    +fi
    +
    +

    In a makefile you can add the necessary compiler and linker options with:

    +
    CFLAGS  +=      `pkg-config --cflags pdfio`
    +LIBS    +=      `pkg-config --libs pdfio`
    +
    +

    Header Files

    +

    PDFio provides a primary header file that is always used:

    +
    #include <pdfio.h>
    +
    +

    PDFio also provides content helper functions that are defined in a separate header file:

    +
    #include <pdfio-content.h>
    +
    +

    API Overview

    +

    PDFio exposes several types:

    +
      +
    • pdfio_file_t: A PDF file (for reading or writing)

      +
    • +
    • pdfio_array_t: An array of values

      +
    • +
    • pdfio_dict_t: A dictionary of key/value pairs in a PDF file, object, etc.

      +
    • +
    • pdfio_obj_t: An object in a PDF file

      +
    • +
    • pdfio_stream_t: An object stream

      +
    • +
    +

    PDF Files

    +

    PDF Values

    +

    PDF Objects

    +

    PDF Streams

    Functions

    pdfioArrayAppendArray

    Add an array value to an array.

    @@ -446,7 +572,7 @@ bool pdfioArrayAppendArray(pdfio_array_t *a, pdfioArrayAppendBinary

    Add a binary string value to an array.

    -bool pdfioArrayAppendBinary(pdfio_array_t *a, unsigned char *value, size_t valuelen);

    +bool pdfioArrayAppendBinary(pdfio_array_t *a, const unsigned char *value, size_t valuelen);

    Parameters

    @@ -510,10 +636,10 @@ bool pdfioArrayAppendNumber(pdfio_array_t *a, doubl
    a

    Return Value

    true on success, false on failure

    -

    pdfioArrayAppendObject

    +

    pdfioArrayAppendObj

    Add an indirect object reference to an array.

    -bool pdfioArrayAppendObject(pdfio_array_t *a, pdfio_obj_t *value);

    +bool pdfioArrayAppendObj(pdfio_array_t *a, pdfio_obj_t *value);

    Parameters

    @@ -560,6 +686,84 @@ bool pdfioArrayAppendString(pdfio_array_t *a, const
    a

    Return Value

    New array or NULL on error

    +

    pdfioArrayCreateCalibratedColorFromMatrix

    +

    Create a calibrated color space array using a CIE XYZ transform matrix.

    +

    +pdfio_array_t *pdfioArrayCreateCalibratedColorFromMatrix(pdfio_file_t *pdf, size_t num_colors, double gamma, const double matrix[3][3], const double white_point[3]);

    +

    Parameters

    + + + + + + + + + + + +
    pdfPDF file
    num_colorsNumber of colors (1 or 3)
    gammaGamma value
    matrix[3][3]XYZ transform
    white_point[3]White point
    +

    Return Value

    +

    Color space array

    +

    pdfioArrayCreateCalibratedColorFromPrimaries

    +

    Create a calibrated color sapce array using CIE xy primary chromacities.

    +

    +pdfio_array_t *pdfioArrayCreateCalibratedColorFromPrimaries(pdfio_file_t *pdf, size_t num_colors, double gamma, double wx, double wy, double rx, double ry, double gx, double gy, double bx, double by);

    +

    Parameters

    + + + + + + + + + + + + + + + + + + + + + + + +
    pdfPDF file
    num_colorsNumber of colors (1 or 3)
    gammaGama value
    wxWhite point X chromacity
    wyWhite point Y chromacity
    rxRed X chromacity
    ryRed Y chromacity
    gxGreen X chromacity
    gyGreen Y chromacity
    bxBlue X chromacity
    byBlue Y chromacity
    +

    Return Value

    +

    Color space array

    +

    pdfioArrayCreateICCBasedColor

    +

    Create an ICC-based color space array.

    +

    +pdfio_array_t *pdfioArrayCreateICCBasedColor(pdfio_file_t *pdf, pdfio_obj_t *icc_object);

    +

    Parameters

    + + + + + +
    pdfPDF file
    icc_objectICC profile object
    +

    Return Value

    +

    Color array

    +

    pdfioArrayCreateIndexedColor

    +

    Create an indexed color space array.

    +

    +pdfio_array_t *pdfioArrayCreateIndexedColor(pdfio_file_t *pdf, size_t num_colors, const unsigned char *colors);

    +

    Parameters

    + + + + + + + +
    pdfPDF file
    num_colorsNumber of colors
    colorsRGB values for colors
    +

    Return Value

    +

    Color array

    pdfioArrayGetArray

    Get an array value from an array.

    @@ -640,10 +844,10 @@ double pdfioArrayGetNumber(pdfio_array_t *a, size_t

    Return Value

    Value

    -

    pdfioArrayGetObject

    +

    pdfioArrayGetObj

    Get an indirect object reference from an array.

    -pdfio_obj_t *pdfioArrayGetObject(pdfio_array_t *a, size_t n);

    +pdfio_obj_t *pdfioArrayGetObj(pdfio_array_t *a, size_t n);

    Parameters

    @@ -690,17 +894,6 @@ const char *pdfioArrayGetString(pdfio_array_t *a, s
    a

    Return Value

    Value type

    -

    pdfioContentBeginText

    -

    Begin a text block.

    -

    -bool pdfioContentBeginText(pdfio_stream_t *st);

    -

    Parameters

    - - - -
    stStream
    -

    Return Value

    -

    true on success, false on failure

    pdfioContentClip

    Clip output to the current path.

    @@ -717,7 +910,7 @@ bool pdfioContentClip(pdfio_stream_t *st, bool eve

    pdfioContentDrawImage

    Draw an image object.

    -bool pdfioContentDrawImage(pdfio_stream_t *st, const char *name, double x, double y, double w, double h);

    +bool pdfioContentDrawImage(pdfio_stream_t *st, const char *name, double x, double y, double width, double height);

    Parameters

    @@ -728,9 +921,9 @@ bool pdfioContentDrawImage(pdfio_stream_t *st, con - + - +
    stX offset of image
    y Y offset of image
    w
    width Width of image
    h
    height Height of image

    Return Value

    @@ -738,17 +931,6 @@ bool pdfioContentDrawImage(pdfio_stream_t *st, con

    Discussion

    The object name must be part of the page dictionary resources, typically using the pdfioPageDictAddImage function.

    -

    pdfioContentEndText

    -

    End a text block.

    -

    -bool pdfioContentEndText(pdfio_stream_t *st);

    -

    Parameters

    - - - -
    stStream
    -

    Return Value

    -

    true on success, false on failure

    pdfioContentFill

    Fill the current path.

    @@ -937,13 +1119,19 @@ bool pdfioContentPathMoveTo(pdfio_stream_t *st, do

    pdfioContentPathRect

    Add a rectangle to the current path.

    -bool pdfioContentPathRect(pdfio_stream_t *st, pdfio_rect_t *rect);

    +bool pdfioContentPathRect(pdfio_stream_t *st, double x, double y, double width, double height);

    Parameters

    - - + + + + + + + +
    st Stream
    rectRectangle
    xX offset
    yY offset
    widthWidth
    heightHeight

    Return Value

    true on success, false on failure

    @@ -1352,6 +1540,28 @@ bool pdfioContentStroke(pdfio_stream_t *st);

    Return Value

    true on success, false on failure

    +

    pdfioContentTextBegin

    +

    Begin a text block.

    +

    +bool pdfioContentTextBegin(pdfio_stream_t *st);

    +

    Parameters

    + + + +
    stStream
    +

    Return Value

    +

    true on success, false on failure

    +

    pdfioContentTextEnd

    +

    End a text block.

    +

    +bool pdfioContentTextEnd(pdfio_stream_t *st);

    +

    Parameters

    + + + +
    stStream
    +

    Return Value

    +

    true on success, false on failure

    pdfioContentTextMoveLine

    Move to the next line and offset.

    @@ -1396,15 +1606,13 @@ bool pdfioContentTextNextLine(pdfio_stream_t *st);

    pdfioContentTextShow

    Show text.

    -bool pdfioContentTextShow(pdfio_stream_t *st, const char *s, bool new_line);

    +bool pdfioContentTextShow(pdfio_stream_t *st, const char *s);

    Parameters

    - -
    st Stream
    s String to show
    new_lineAdvance to the next line afterwards

    Return Value

    true on success, false on failure

    @@ -1425,6 +1633,21 @@ bool pdfioContentTextShowJustified(pdfio_stream_t

    Return Value

    true on success, false on failure

    +

    pdfioContentTextShowf

    +

    +

    +bool pdfioContentTextShowf(pdfio_stream_t *st, const char *format, ...);

    +

    Parameters

    + + + + + + + +
    stStream
    formatprintf-style format string
    ...Additional arguments as needed
    +

    Return Value

    +

    Show formatted text.

    pdfioDictCopy

    Copy a dictionary to a PDF file.

    @@ -1529,10 +1752,10 @@ double pdfioDictGetNumber(pdfio_dict_t *dict, const

    Return Value

    Value

    -

    pdfioDictGetObject

    +

    pdfioDictGetObj

    Get a key indirect object value from a dictionary.

    -pdfio_obj_t *pdfioDictGetObject(pdfio_dict_t *dict, const char *key);

    +pdfio_obj_t *pdfioDictGetObj(pdfio_dict_t *dict, const char *key);

    Parameters

    @@ -1601,7 +1824,7 @@ bool pdfioDictSetArray(pdfio_dict_t *dict, const cha

    pdfioDictSetBinary

    Set a key binary string in a dictionary.

    -bool pdfioDictSetBinary(pdfio_dict_t *dict, const char *key, unsigned char *value, size_t valuelen);

    +bool pdfioDictSetBinary(pdfio_dict_t *dict, const char *key, const unsigned char *value, size_t valuelen);

    Parameters

    dict
    @@ -1688,10 +1911,10 @@ bool pdfioDictSetNumber(pdfio_dict_t *dict, const ch
    dict

    Return Value

    true on success, false on failure

    -

    pdfioDictSetObject

    +

    pdfioDictSetObj

    Set a key indirect object reference in a dictionary.

    -bool pdfioDictSetObject(pdfio_dict_t *dict, const char *key, pdfio_obj_t *value);

    +bool pdfioDictSetObj(pdfio_dict_t *dict, const char *key, pdfio_obj_t *value);

    Parameters

    @@ -1782,23 +2005,71 @@ bool pdfioFileClose(pdfio_file_t *pdf);

    dict

    Return Value

    PDF file or NULL on error

    -

    pdfioFileCreateFontObject

    +

    pdfioFileCreateBaseFontObj

    +

    Create one of the base 14 PDF fonts.

    +

    +pdfio_obj_t *pdfioFileCreateBaseFontObj(pdfio_file_t *pdf, const char *name);

    +

    Parameters

    + + + + + +
    pdfPDF file
    nameFont name
    +

    Return Value

    +

    Font object

    +

    Discussion

    +

    This function creates one of the base 14 PDF fonts. The "name" parameter +specifies the font nane: + +

      +
    • Courier +
    • +
    • Courier-Bold +
    • +
    • Courier-BoldItalic +
    • +
    • Courier-Italic +
    • +
    • Helvetica +
    • +
    • Helvetica-Bold +
    • +
    • Helvetica-BoldOblique +
    • +
    • Helvetica-Oblique +
    • +
    • Symbol +
    • +
    • Times-Bold +
    • +
    • Times-BoldItalic +
    • +
    • Times-Italic +
    • +
    • Times-Roman +
    • +
    • ZapfDingbats
    • +
    +

    pdfioFileCreateFontObj

    Add a font object to a PDF file.

    -pdfio_obj_t *pdfioFileCreateFontObject(pdfio_file_t *pdf, const char *filename);

    +pdfio_obj_t *pdfioFileCreateFontObj(pdfio_file_t *pdf, const char *filename, bool unicode);

    Parameters

    + +
    pdf PDF file
    filename Filename
    unicodeUnicode font?

    Return Value

    -

    Object

    -

    pdfioFileCreateICCProfileObject

    +

    Font object

    +

    pdfioFileCreateICCProfileObj

    Add an ICC profile object to a PDF file.

    -pdfio_obj_t *pdfioFileCreateICCProfileObject(pdfio_file_t *pdf, const char *filename);

    +pdfio_obj_t *pdfioFileCreateICCProfileObj(pdfio_file_t *pdf, const char *filename);

    Parameters

    @@ -1808,10 +2079,10 @@ bool pdfioFileClose(pdfio_file_t *pdf);

    pdf

    Return Value

    Object

    -

    pdfioFileCreateImageObject

    +

    pdfioFileCreateImageObj

    Add an image object to a PDF file.

    -pdfio_obj_t *pdfioFileCreateImageObject(pdfio_file_t *pdf, const char *filename, bool interpolate);

    +pdfio_obj_t *pdfioFileCreateImageObj(pdfio_file_t *pdf, const char *filename, bool interpolate);

    Parameters

    @@ -1825,10 +2096,10 @@ bool pdfioFileClose(pdfio_file_t *pdf);

    Object

    Discussion

    Currently only GIF, JPEG, and PNG files are supported.

    -

    pdfioFileCreateObject

    +

    pdfioFileCreateObj

    Create a new object in a PDF file.

    -pdfio_obj_t *pdfioFileCreateObject(pdfio_file_t *pdf, pdfio_dict_t *dict);

    +pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict);

    Parameters

    pdf
    @@ -1851,10 +2122,10 @@ bool pdfioFileClose(pdfio_file_t *pdf);

    pdf

    Return Value

    Contents stream

    -

    pdfioFileFindObject

    +

    pdfioFileFindObj

    Find an object using its object number.

    -pdfio_obj_t *pdfioFileFindObject(pdfio_file_t *pdf, size_t number);

    +pdfio_obj_t *pdfioFileFindObj(pdfio_file_t *pdf, size_t number);

    Parameters

    @@ -1865,7 +2136,7 @@ bool pdfioFileClose(pdfio_file_t *pdf);

    Return Value

    Object or NULL if not found

    Discussion

    -

    This differs from pdfioFileGetObject which takes an index into the +

    This differs from pdfioFileGetObj which takes an index into the list of objects while this function takes the object number.

    pdfioFileGetID

    Get the PDF file's ID strings.

    @@ -1889,10 +2160,10 @@ const char *pdfioFileGetName(pdfio_file_t *pdf);

    pdf

    Return Value

    Filename

    -

    pdfioFileGetNumObjects

    +

    pdfioFileGetNumObjs

    Get the number of objects in a PDF file.

    -size_t pdfioFileGetNumObjects(pdfio_file_t *pdf);

    +size_t pdfioFileGetNumObjs(pdfio_file_t *pdf);

    Parameters

    @@ -1911,10 +2182,10 @@ size_t pdfioFileGetNumPages(pdfio_file_t *pdf);

    pdf

    Return Value

    Number of pages

    -

    pdfioFileGetObject

    +

    pdfioFileGetObj

    Get an object from a PDF file.

    -pdfio_obj_t *pdfioFileGetObject(pdfio_file_t *pdf, size_t n);

    +pdfio_obj_t *pdfioFileGetObj(pdfio_file_t *pdf, size_t n);

    Parameters

    @@ -1963,6 +2234,17 @@ const char *pdfioFileGetVersion(pdfio_file_t *pdf);<
    pdf

    Return Value

    PDF file

    +

    pdfioImageGetBytesPerLine

    +

    Get the number of bytes to read for each line.

    +

    +size_t pdfioImageGetBytesPerLine(pdfio_obj_t *obj);

    +

    Parameters

    + + + +
    objImage object
    +

    Return Value

    +

    Number of bytes per line

    pdfioImageGetHeight

    Get the height of an image object.

    @@ -2078,6 +2360,17 @@ size_t pdfioObjGetNumber(pdfio_obj_t *obj);

    Return Value

    Object number (1 to 9999999999)

    +

    pdfioObjGetSubtype

    +

    Get an object's subtype.

    +

    +const char *pdfioObjGetSubtype(pdfio_obj_t *obj);

    +

    Parameters

    + + + +
    objObject
    +

    Return Value

    +

    Object subtype

    pdfioObjGetType

    Get an object's type.

    @@ -2115,26 +2408,33 @@ bool pdfioPageCopy(pdfio_file_t *pdf, Return Value

    true on success, false on failure

    -

    pdfioPageDictAddCalibratedColorSpace

    -

    Add a calibrated color space to -the page dictionary.

    +

    pdfioPageDictAddColorSpace

    +

    Add a color space to the page dictionary.

    -bool pdfioPageDictAddCalibratedColorSpace(pdfio_dict_t *dict, const char *name, size_t num_colors, const double *white_point, double gamma);

    +bool pdfioPageDictAddColorSpace(pdfio_dict_t *dict, const char *name, pdfio_array_t *data);

    Parameters

    - - - - - - + +
    dict Page dictionary
    name Color space name
    num_colorsNumber of color components
    white_pointCIE XYZ white point
    gammaGamma value
    dataColor space array

    Return Value

    true on success, false on failure

    +

    Discussion

    +

    This function adds a named color space to the page dictionary.
    +
    +The names "DefaultCMYK", "DefaultGray", and "DefaultRGB" specify the default +device color space used for the page.
    +
    +The "data" array contains a calibrated, indexed, or ICC-based color space +array that was created using the +pdfioArrayCreateCalibratedColorFromMatrix, +pdfioArrayCreateCalibratedColorFromPrimaries, +pdfioArrayCreateICCBasedColor, or +pdfioArrayCreateIndexedColor functions.

    pdfioPageDictAddFont

    Add a font object to the page dictionary.

    @@ -2150,22 +2450,6 @@ bool pdfioPageDictAddFont(pdfio_dict_t *dict, const

    Return Value

    true on success, false on failure

    -

    pdfioPageDictAddICCColorSpace

    -

    Add an ICC color space to the page -dictionary.

    -

    -bool pdfioPageDictAddICCColorSpace(pdfio_dict_t *dict, const char *name, pdfio_obj_t *obj);

    -

    Parameters

    - - - - - - - -
    dictPage dictionary
    nameColor space name
    objICC profile object
    -

    Return Value

    -

    true on success, false on failure

    pdfioPageDictAddImage

    Add an image object to the page dictionary.

    @@ -2278,6 +2562,11 @@ ssize_t pdfioStreamRead(pdfio_stream_t *st, void *

    Return Value

    Number of bytes read or -1 on error

    +

    Discussion

    +

    This function reads data from a stream. When reading decoded image data +from a stream, you must read whole scanlines. The +pdfioImageGetBytesPerLine function can be used to determine the +proper read length.

    pdfioStreamWrite

    Write data to a stream.

    diff --git a/doc/pdfio.md b/doc/pdfio.md index 8c3c503..6e9c54f 100644 --- a/doc/pdfio.md +++ b/doc/pdfio.md @@ -13,3 +13,158 @@ goals of pdfio are: PDFio is *not* concerned with rendering or viewing a PDF file, although a PDF RIP or viewer could be written using it. + +PDFio is Copyright © 2021 by Michael R Sweet and is licensed under the Apache +License Version 2.0 with an (optional) exception to allow linking against +GPL2/LGPL2 software. See the files "LICENSE" and "NOTICE" for more information. + + +Requirements +------------ + +PDFio requires the following to build the software: + +- A C99 compiler such as Clang, GCC, or MS Visual C +- A POSIX-compliant `make` program +- ZLIB () 1.0 or higher + +IDE files for Xcode (macOS/iOS) and Visual Studio (Windows) are also provided. + + +Installing pdfio +---------------- + +PDFio comes with a portable makefile that will work on any POSIX-compliant +system with ZLIB installed. To make it, run: + + make all + +To test it, run: + + make test + +To install it, run: + + make install + +If you want a shared library, run: + + make all-shared + make install-shared + +The default installation location is "/usr/local". Pass the `prefix` variable +to make to install it to another location: + + make install prefix=/some/other/directory + +The makefile installs the pdfio header to "${prefix}/include", the library to +"${prefix}/lib", the `pkg-config` file to "${prefix}/lib/pkgconfig", the man +page to "${prefix}/share/man/man3", and the documentation to +"${prefix}/share/doc/pdfio". + +The makefile supports the following variables that can be specified in the make +command or as environment variables: + +- `AR`: the library archiver (default "ar") +- `ARFLAGS`: options for the library archiver (default "cr") +- `CC`: the C compiler (default "cc") +- `CFLAGS`: options for the C compiler (default "") +- `CODESIGN_IDENTITY`: the identity to use when code signing the shared library + on macOS (default "Developer ID") +- `COMMONFLAGS`: options for the C compiler and linker (typically architecture + and optimization options, default is "-Os -g") +- `CPPFLAGS`: options for the C preprocessor (default "") +- `DESTDIR" and "DSTROOT`: specifies a root directory when installing + (default is "", specify only one) +- `DSOFLAGS`: options for the C compiler when linking the shared library + (default "") +- `LDFLAGS`: options for the C compiler when linking the test programs + (default "") +- `LIBS`: library options when linking the test programs (default "-lz") +- `RANLIB`: program that generates a table-of-contents in a library + (default "ranlib") +- `prefix`: specifies the installation directory (default "/usr/local") + + +Visual Studio Project +--------------------- + +> Note: I haven't yet added this... + +The Visual Studio solution ("pdfio.sln") is provided for Windows developers +generates both a static library and DLL. + + +Xcode Project +------------- + +There is also an Xcode project ("pdfio.xcodeproj") you can use on macOS which +generates a static library that will be installed under "/usr/local" with: + + sudo xcodebuild install + +You can reproduce this with the makefile using: + + sudo make 'COMMONFLAGS="-Os -mmacosx-version-min=10.14 -arch x86_64 -arch arm64"' install + + +Detecting PDFio +--------------- + +PDFio can be detected using the `pkg-config` command, for example: + + if pkg-config --exists pdfio; then + ... + fi + +In a makefile you can add the necessary compiler and linker options with: + +```make +CFLAGS += `pkg-config --cflags pdfio` +LIBS += `pkg-config --libs pdfio` +``` + + +Header Files +------------ + +PDFio provides a primary header file that is always used: + +```c +#include +``` + +PDFio also provides content helper functions that are defined in a separate +header file: + +```c +#include +``` + + +API Overview +============ + +PDFio exposes several types: + +- `pdfio_file_t`: A PDF file (for reading or writing) +- `pdfio_array_t`: An array of values +- `pdfio_dict_t`: A dictionary of key/value pairs in a PDF file, object, etc. +- `pdfio_obj_t`: An object in a PDF file +- `pdfio_stream_t`: An object stream + + +PDF Files +--------- + + +PDF Values +---------- + + +PDF Objects +----------- + + +PDF Streams +----------- diff --git a/pdfio-array.c b/pdfio-array.c index bd3bc8e..94f87d9 100644 --- a/pdfio-array.c +++ b/pdfio-array.c @@ -180,11 +180,11 @@ pdfioArrayAppendNumber( // -// 'pdfioArrayAppendObject()' - Add an indirect object reference to an array. +// 'pdfioArrayAppendObj()' - Add an indirect object reference to an array. // bool // O - `true` on success, `false` on failure -pdfioArrayAppendObject( +pdfioArrayAppendObj( pdfio_array_t *a, // I - Array pdfio_obj_t *value) // I - Value { @@ -445,13 +445,13 @@ pdfioArrayGetNumber(pdfio_array_t *a, // I - Array // pdfio_obj_t * // O - Value -pdfioArrayGetObject(pdfio_array_t *a, // I - Array - size_t n) // I - Index +pdfioArrayGetObj(pdfio_array_t *a, // I - Array + size_t n) // I - Index { if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_INDIRECT) return (NULL); else - return (pdfioFileFindObject(a->pdf, a->values[n].value.indirect.number)); + return (pdfioFileFindObj(a->pdf, a->values[n].value.indirect.number)); } diff --git a/pdfio-content.c b/pdfio-content.c index 30ec28a..51371e0 100644 --- a/pdfio-content.c +++ b/pdfio-content.c @@ -299,7 +299,7 @@ pdfioArrayCreateICCBasedColor( return (NULL); pdfioArrayAppendName(icc_color, "ICCBased"); - pdfioArrayAppendObject(icc_color, icc_object); + pdfioArrayAppendObj(icc_color, icc_object); return (icc_color); } @@ -1104,7 +1104,7 @@ pdfioContentTextShowJustified( // -// 'pdfioFileCreateBaseFontObject()' - Create one of the base 14 PDF fonts. +// 'pdfioFileCreateBaseFontObj()' - Create one of the base 14 PDF fonts. // // This function creates one of the base 14 PDF fonts. The "name" parameter // specifies the font nane: @@ -1126,7 +1126,7 @@ pdfioContentTextShowJustified( // pdfio_obj_t * // O - Font object -pdfioFileCreateBaseFontObject( +pdfioFileCreateBaseFontObj( pdfio_file_t *pdf, // I - PDF file const char *name) // I - Font name { @@ -1142,7 +1142,7 @@ pdfioFileCreateBaseFontObject( pdfioDictSetName(dict, "BaseFont", pdfioStringCreate(pdf, name)); pdfioDictSetName(dict, "Encoding", "WinAnsiEncoding"); - if ((obj = pdfioFileCreateObject(dict->pdf, dict)) != NULL) + if ((obj = pdfioFileCreateObj(dict->pdf, dict)) != NULL) pdfioObjClose(obj); return (obj); @@ -1150,11 +1150,11 @@ pdfioFileCreateBaseFontObject( // -// 'pdfioFileCreateFontObject()' - Add a font object to a PDF file. +// 'pdfioFileCreateFontObj()' - Add a font object to a PDF file. // pdfio_obj_t * // O - Font object -pdfioFileCreateFontObject( +pdfioFileCreateFontObj( pdfio_file_t *pdf, // I - PDF file const char *filename, // I - Filename bool unicode) // I - Unicode font? @@ -1177,11 +1177,11 @@ pdfioFileCreateFontObject( // -// 'pdfioFileCreateICCProfileObject()' - Add an ICC profile object to a PDF file. +// 'pdfioFileCreateICCProfileObj()' - Add an ICC profile object to a PDF file. // pdfio_obj_t * // O - Object -pdfioFileCreateICCProfileObject( +pdfioFileCreateICCProfileObj( pdfio_file_t *pdf, // I - PDF file const char *filename) // I - Filename { @@ -1193,13 +1193,13 @@ pdfioFileCreateICCProfileObject( // -// 'pdfioFileCreateImageObject()' - Add an image object to a PDF file. +// 'pdfioFileCreateImageObj()' - Add an image object to a PDF file. // // Currently only GIF, JPEG, and PNG files are supported. // pdfio_obj_t * // O - Object -pdfioFileCreateImageObject( +pdfioFileCreateImageObj( pdfio_file_t *pdf, // I - PDF file const char *filename, // I - Filename bool interpolate) // I - Interpolate image data? @@ -1445,7 +1445,7 @@ pdfioPageDictAddFont( } // Now set the image reference in the Font resource dictionary and return... - return (pdfioDictSetObject(font, name, obj)); + return (pdfioDictSetObj(font, name, obj)); } @@ -1488,7 +1488,7 @@ pdfioPageDictAddImage( } // Now set the image reference in the XObject resource dictionary and return... - return (pdfioDictSetObject(xobject, name, obj)); + return (pdfioDictSetObj(xobject, name, obj)); } @@ -1606,7 +1606,7 @@ copy_jpeg(pdfio_dict_t *dict, // I - Dictionary pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateCalibratedColorFromMatrix(dict->pdf, num_colors, pdfioSRGBGamma, pdfioSRGBMatrix, pdfioSRGBWhitePoint)); pdfioDictSetName(dict, "Filter", "DCTDecode"); - obj = pdfioFileCreateObject(dict->pdf, dict); + obj = pdfioFileCreateObj(dict->pdf, dict); st = pdfioObjCreateStream(obj, PDFIO_FILTER_NONE); // Copy the file to a stream... @@ -1671,7 +1671,7 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary if (!st) { - obj = pdfioFileCreateObject(dict->pdf, dict); + obj = pdfioFileCreateObj(dict->pdf, dict); if ((st = pdfioObjCreateStream(obj, PDFIO_FILTER_NONE)) == NULL) { diff --git a/pdfio-content.h b/pdfio-content.h index c9956f0..30365fb 100644 --- a/pdfio-content.h +++ b/pdfio-content.h @@ -144,10 +144,10 @@ extern bool pdfioContentTextShowf(pdfio_stream_t *st, const char *format, ...) extern bool pdfioContentTextShowJustified(pdfio_stream_t *st, size_t num_fragments, const double *offsets, const char * const *fragments) PDFIO_PUBLIC; // Resource helpers... -extern pdfio_obj_t *pdfioFileCreateBaseFontObject(pdfio_file_t *pdf, const char *name) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileCreateFontObject(pdfio_file_t *pdf, const char *filename, bool unicode) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileCreateICCProfileObject(pdfio_file_t *pdf, const char *filename) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileCreateImageObject(pdfio_file_t *pdf, const char *filename, bool interpolate) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateBaseFontObj(pdfio_file_t *pdf, const char *name) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateFontObj(pdfio_file_t *pdf, const char *filename, bool unicode) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateICCProfileObj(pdfio_file_t *pdf, const char *filename) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateImageObj(pdfio_file_t *pdf, const char *filename, bool interpolate) PDFIO_PUBLIC; // Image object helpers... extern size_t pdfioImageGetBytesPerLine(pdfio_obj_t *obj) PDFIO_PUBLIC; diff --git a/pdfio-dict.c b/pdfio-dict.c index 2303ae0..5adfa3c 100644 --- a/pdfio-dict.c +++ b/pdfio-dict.c @@ -54,7 +54,7 @@ pdfioDictCopy(pdfio_file_t *pdf, // I - PDF file if (!strcmp(p->key, "Length") && p->value.type == PDFIO_VALTYPE_INDIRECT && dict->pdf != pdf) { // Don't use indirect stream lengths for copied objects... - pdfio_obj_t *lenobj = pdfioFileFindObject(dict->pdf, p->value.value.indirect.number); + pdfio_obj_t *lenobj = pdfioFileFindObj(dict->pdf, p->value.value.indirect.number); // Length object v.type = PDFIO_VALTYPE_NUMBER; @@ -273,17 +273,17 @@ pdfioDictGetNumber(pdfio_dict_t *dict, // I - Dictionary // -// 'pdfioDictGetObject()' - Get a key indirect object value from a dictionary. +// 'pdfioDictGetObj()' - Get a key indirect object value from a dictionary. // pdfio_obj_t * // O - Value -pdfioDictGetObject(pdfio_dict_t *dict, // I - Dictionary - const char *key) // I - Key +pdfioDictGetObj(pdfio_dict_t *dict, // I - Dictionary + const char *key) // I - Key { _pdfio_value_t *value = _pdfioDictGetValue(dict, key); if (value && value->type == PDFIO_VALTYPE_INDIRECT) - return (pdfioFileFindObject(dict->pdf, value->value.indirect.number)); + return (pdfioFileFindObj(dict->pdf, value->value.indirect.number)); else return (NULL); } @@ -618,13 +618,13 @@ pdfioDictSetNumber(pdfio_dict_t *dict, // I - Dictionary // -// 'pdfioDictSetObject()' - Set a key indirect object reference in a dictionary. +// 'pdfioDictSetObj()' - Set a key indirect object reference in a dictionary. // bool // O - `true` on success, `false` on failure -pdfioDictSetObject(pdfio_dict_t *dict, // I - Dictionary - const char *key, // I - Key - pdfio_obj_t *value)// I - Value +pdfioDictSetObj(pdfio_dict_t *dict, // I - Dictionary + const char *key, // I - Key + pdfio_obj_t *value) // I - Value { _pdfio_value_t temp; // New value diff --git a/pdfio-file.c b/pdfio-file.c index 96ae188..3bc324d 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -33,11 +33,11 @@ static bool write_trailer(pdfio_file_t *pdf); // -// '_pdfioFileAddMappedObject()' - Add a mapped object. +// '_pdfioFileAddMappedObj()' - Add a mapped object. // bool // O - `true` on success, `false` on failure -_pdfioFileAddMappedObject( +_pdfioFileAddMappedObj( pdfio_file_t *pdf, // I - Destination PDF file pdfio_obj_t *dst_obj, // I - Destination object pdfio_obj_t *src_obj) // I - Source object @@ -262,7 +262,7 @@ pdfioFileCreate( pdfioDictSetName(dict, "Type", "Pages"); - if ((pdf->pages_root = pdfioFileCreateObject(pdf, dict)) == NULL) + if ((pdf->pages_root = pdfioFileCreateObj(pdf, dict)) == NULL) { pdfioFileClose(pdf); unlink(filename); @@ -274,11 +274,11 @@ pdfioFileCreate( // -// 'pdfioFileCreateObject()' - Create a new object in a PDF file. +// 'pdfioFileCreateObj()' - Create a new object in a PDF file. // pdfio_obj_t * // O - New object -pdfioFileCreateObject( +pdfioFileCreateObj( pdfio_file_t *pdf, // I - PDF file pdfio_dict_t *dict) // I - Object dictionary { @@ -288,16 +288,16 @@ pdfioFileCreateObject( value.type = PDFIO_VALTYPE_DICT; value.value.dict = dict; - return (_pdfioFileCreateObject(pdf, dict->pdf, &value)); + return (_pdfioFileCreateObj(pdf, dict->pdf, &value)); } // -// '_pdfioFileCreateObject()' - Create a new object in a PDF file with a value. +// '_pdfioFileCreateObj()' - Create a new object in a PDF file with a value. // pdfio_obj_t * // O - New object -_pdfioFileCreateObject( +_pdfioFileCreateObj( pdfio_file_t *pdf, // I - PDF file pdfio_file_t *srcpdf, // I - Source PDF file, if any _pdfio_value_t *value) // I - Object dictionary @@ -379,7 +379,7 @@ pdfioFileCreatePage(pdfio_file_t *pdf, // I - PDF file if (!_pdfioDictGetValue(dict, "MediaBox")) pdfioDictSetRect(dict, "MediaBox", &pdf->media_box); - pdfioDictSetObject(dict, "Parent", pdf->pages_root); + pdfioDictSetObj(dict, "Parent", pdf->pages_root); if (!_pdfioDictGetValue(dict, "Resources")) pdfioDictSetDict(dict, "Resources", pdfioDictCreate(pdf)); @@ -388,7 +388,7 @@ pdfioFileCreatePage(pdfio_file_t *pdf, // I - PDF file pdfioDictSetName(dict, "Type", "Page"); // Create the page object... - page = pdfioFileCreateObject(pdf, dict); + page = pdfioFileCreateObj(pdf, dict); // Create a contents object to hold the contents of the page... contents_dict = pdfioDictCreate(pdf); @@ -396,10 +396,10 @@ pdfioFileCreatePage(pdfio_file_t *pdf, // I - PDF file pdfioDictSetName(contents_dict, "Filter", "FlateDecode"); #endif // !DEBUG - contents = pdfioFileCreateObject(pdf, contents_dict); + contents = pdfioFileCreateObj(pdf, contents_dict); // Add the contents stream to the pages object and write it... - pdfioDictSetObject(dict, "Contents", contents); + pdfioDictSetObj(dict, "Contents", contents); if (!pdfioObjClose(page)) return (NULL); @@ -416,11 +416,11 @@ pdfioFileCreatePage(pdfio_file_t *pdf, // I - PDF file // -// '_pdfioFileFindMappedObject()' - Find a mapped object. +// '_pdfioFileFindMappedObj()' - Find a mapped object. // pdfio_obj_t * // O - Match object or `NULL` if none -_pdfioFileFindMappedObject( +_pdfioFileFindMappedObj( pdfio_file_t *pdf, // I - Destination PDF file pdfio_file_t *src_pdf, // I - Source PDF file size_t src_number) // I - Source object number @@ -445,14 +445,14 @@ _pdfioFileFindMappedObject( // -// 'pdfioFileFindObject()' - Find an object using its object number. +// 'pdfioFileFindObj()' - Find an object using its object number. // -// This differs from @link pdfioFileGetObject@ which takes an index into the +// This differs from @link pdfioFileGetObj@ which takes an index into the // list of objects while this function takes the object number. // pdfio_obj_t * // O - Object or `NULL` if not found -pdfioFileFindObject( +pdfioFileFindObj( pdfio_file_t *pdf, // I - PDF file size_t number) // I - Object number (1 to N) { @@ -497,11 +497,11 @@ pdfioFileGetName(pdfio_file_t *pdf) // I - PDF file // -// 'pdfioFileGetNumObjects()' - Get the number of objects in a PDF file. +// 'pdfioFileGetNumObjs()' - Get the number of objects in a PDF file. // size_t // O - Number of objects -pdfioFileGetNumObjects( +pdfioFileGetNumObjs( pdfio_file_t *pdf) // I - PDF file { return (pdf ? pdf->num_objs : 0); @@ -520,12 +520,12 @@ pdfioFileGetNumPages(pdfio_file_t *pdf) // I - PDF file // -// 'pdfioFileGetObject()' - Get an object from a PDF file. +// 'pdfioFileGetObj()' - Get an object from a PDF file. // pdfio_obj_t * // O - Object -pdfioFileGetObject(pdfio_file_t *pdf, // I - PDF file - size_t n) // I - Object index (starting at 0) +pdfioFileGetObj(pdfio_file_t *pdf, // I - PDF file + size_t n) // I - Object index (starting at 0) { if (!pdf || n >= pdf->num_objs) return (NULL); @@ -876,7 +876,7 @@ load_pages(pdfio_file_t *pdf, // I - PDF file for (i = 0, num_kids = pdfioArrayGetSize(kids); i < num_kids; i ++) { - if (!load_pages(pdf, pdfioArrayGetObject(kids, i))) + if (!load_pages(pdf, pdfioArrayGetObj(kids, i))) return (false); } } @@ -1080,7 +1080,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file } // Create a placeholder for the object in memory... - if (pdfioFileFindObject(pdf, (size_t)number)) + if (pdfioFileFindObj(pdf, (size_t)number)) { number ++; continue; // Don't replace newer object... @@ -1089,7 +1089,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file if (w[0] > 0 && buffer[0] == 2) { // Object streams need to be loaded into memory... - if ((obj = pdfioFileFindObject(pdf, (size_t)offset)) != NULL) + if ((obj = pdfioFileFindObj(pdf, (size_t)offset)) != NULL) { // Load it now... if (!load_obj_stream(obj)) @@ -1121,7 +1121,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file for (i = 0; i < num_sobjs; i ++) { - if ((obj = pdfioFileFindObject(pdf, sobjs[i])) != NULL) + if ((obj = pdfioFileFindObj(pdf, sobjs[i])) != NULL) { PDFIO_DEBUG("load_xref: Loading compressed object stream %lu (pdf=%p, obj->pdf=%p).\n", (unsigned long)sobjs[i], pdf, obj->pdf); @@ -1195,7 +1195,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file continue; // Don't care about free objects... // Create a placeholder for the object in memory... - if (pdfioFileFindObject(pdf, (size_t)number)) + if (pdfioFileFindObj(pdf, (size_t)number)) continue; // Don't replace newer object... if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset)) @@ -1248,7 +1248,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file // Once we have all of the xref tables loaded, get the important objects and // build the pages array... - if ((pdf->root = pdfioDictGetObject(pdf->trailer, "Root")) == NULL) + if ((pdf->root = pdfioDictGetObj(pdf->trailer, "Root")) == NULL) { _pdfioFileError(pdf, "Missing Root object."); return (false); @@ -1256,11 +1256,11 @@ load_xref(pdfio_file_t *pdf, // I - PDF file PDFIO_DEBUG("load_xref: Root=%p(%lu)\n", pdf->root, (unsigned long)pdf->root->number); - pdf->info = pdfioDictGetObject(pdf->trailer, "Info"); - pdf->encrypt = pdfioDictGetObject(pdf->trailer, "Encrypt"); + pdf->info = pdfioDictGetObj(pdf->trailer, "Info"); + pdf->encrypt = pdfioDictGetObj(pdf->trailer, "Encrypt"); pdf->id_array = pdfioDictGetArray(pdf->trailer, "ID"); - return (load_pages(pdf, pdfioDictGetObject(pdfioObjGetDict(pdf->root), "Pages"))); + return (load_pages(pdf, pdfioDictGetObj(pdfioObjGetDict(pdf->root), "Pages"))); } @@ -1278,10 +1278,10 @@ write_catalog(pdfio_file_t *pdf) // I - PDF file return (false); pdfioDictSetName(dict, "Type", "Catalog"); - pdfioDictSetObject(dict, "Pages", pdf->pages_root); + pdfioDictSetObj(dict, "Pages", pdf->pages_root); // TODO: Add support for all of the root object dictionary keys - if ((pdf->root = pdfioFileCreateObject(pdf, dict)) == NULL) + if ((pdf->root = pdfioFileCreateObj(pdf, dict)) == NULL) return (false); else return (pdfioObjClose(pdf->root)); @@ -1304,7 +1304,7 @@ write_pages(pdfio_file_t *pdf) // I - PDF file return (false); for (i = 0; i < pdf->num_pages; i ++) - pdfioArrayAppendObject(kids, pdf->pages[i]); + pdfioArrayAppendObj(kids, pdf->pages[i]); pdfioDictSetNumber(pdf->pages_root->value.value.dict, "Count", pdf->num_pages); pdfioDictSetArray(pdf->pages_root->value.value.dict, "Kids", kids); @@ -1374,11 +1374,11 @@ write_trailer(pdfio_file_t *pdf) // I - PDF file pdf->trailer = pdfioDictCreate(pdf); if (pdf->encrypt) - pdfioDictSetObject(pdf->trailer, "Encrypt", pdf->encrypt); + pdfioDictSetObj(pdf->trailer, "Encrypt", pdf->encrypt); if (pdf->id_array) pdfioDictSetArray(pdf->trailer, "ID", pdf->id_array); - pdfioDictSetObject(pdf->trailer, "Info", pdf->info); - pdfioDictSetObject(pdf->trailer, "Root", pdf->root); + pdfioDictSetObj(pdf->trailer, "Info", pdf->info); + pdfioDictSetObj(pdf->trailer, "Root", pdf->root); pdfioDictSetNumber(pdf->trailer, "Size", pdf->num_objs + 1); if (!_pdfioDictWrite(pdf->trailer, NULL)) diff --git a/pdfio-object.c b/pdfio-object.c index d044f06..8ce8210 100644 --- a/pdfio-object.c +++ b/pdfio-object.c @@ -85,11 +85,11 @@ pdfioObjCopy(pdfio_file_t *pdf, // I - PDF file _pdfioObjLoad(srcobj); // Create the new object... - if ((dstobj = _pdfioFileCreateObject(pdf, srcobj->pdf, NULL)) == NULL) + if ((dstobj = _pdfioFileCreateObj(pdf, srcobj->pdf, NULL)) == NULL) return (NULL); // Add new object to the cache of copied objects... - if (!_pdfioFileAddMappedObject(pdf, dstobj, srcobj)) + if (!_pdfioFileAddMappedObj(pdf, dstobj, srcobj)) return (NULL); // Copy the object's value... @@ -267,7 +267,7 @@ pdfioObjGetLength(pdfio_obj_t *obj) // I - Object return (length); } - if ((lenobj = pdfioDictGetObject(obj->value.value.dict, "Length")) == NULL) + if ((lenobj = pdfioDictGetObj(obj->value.value.dict, "Length")) == NULL) { _pdfioFileError(obj->pdf, "Unable to get length of stream."); return (0); diff --git a/pdfio-private.h b/pdfio-private.h index 986fe71..f2022e0 100644 --- a/pdfio-private.h +++ b/pdfio-private.h @@ -287,13 +287,13 @@ extern pdfio_dict_t *_pdfioDictRead(pdfio_file_t *pdf, _pdfio_token_t *ts) PDFIO extern bool _pdfioDictSetValue(pdfio_dict_t *dict, const char *key, _pdfio_value_t *value) PDFIO_INTERNAL; extern bool _pdfioDictWrite(pdfio_dict_t *dict, off_t *length) PDFIO_INTERNAL; -extern bool _pdfioFileAddMappedObject(pdfio_file_t *pdf, pdfio_obj_t *dst_obj, pdfio_obj_t *src_obj) PDFIO_INTERNAL; +extern bool _pdfioFileAddMappedObj(pdfio_file_t *pdf, pdfio_obj_t *dst_obj, pdfio_obj_t *src_obj) PDFIO_INTERNAL; extern bool _pdfioFileAddPage(pdfio_file_t *pdf, pdfio_obj_t *obj) PDFIO_INTERNAL; extern bool _pdfioFileConsume(pdfio_file_t *pdf, size_t bytes) PDFIO_INTERNAL; -extern pdfio_obj_t *_pdfioFileCreateObject(pdfio_file_t *pdf, pdfio_file_t *srcpdf, _pdfio_value_t *value) PDFIO_INTERNAL; +extern pdfio_obj_t *_pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_file_t *srcpdf, _pdfio_value_t *value) PDFIO_INTERNAL; extern bool _pdfioFileDefaultError(pdfio_file_t *pdf, const char *message, void *data) PDFIO_INTERNAL; extern bool _pdfioFileError(pdfio_file_t *pdf, const char *format, ...) PDFIO_FORMAT(2,3) PDFIO_INTERNAL; -extern pdfio_obj_t *_pdfioFileFindMappedObject(pdfio_file_t *pdf, pdfio_file_t *src_pdf, size_t src_number) PDFIO_INTERNAL; +extern pdfio_obj_t *_pdfioFileFindMappedObj(pdfio_file_t *pdf, pdfio_file_t *src_pdf, size_t src_number) PDFIO_INTERNAL; extern bool _pdfioFileFlush(pdfio_file_t *pdf) PDFIO_INTERNAL; extern int _pdfioFileGetChar(pdfio_file_t *pdf) PDFIO_INTERNAL; extern bool _pdfioFileGets(pdfio_file_t *pdf, char *buffer, size_t bufsize) PDFIO_INTERNAL; diff --git a/pdfio-value.c b/pdfio-value.c index 06b6d89..0183804 100644 --- a/pdfio-value.c +++ b/pdfio-value.c @@ -57,9 +57,9 @@ _pdfioValueCopy(pdfio_file_t *pdfdst, // I - Destination PDF file switch (vsrc->type) { case PDFIO_VALTYPE_INDIRECT : - if ((obj = _pdfioFileFindMappedObject(pdfdst, pdfsrc, vsrc->value.indirect.number)) == NULL) + if ((obj = _pdfioFileFindMappedObj(pdfdst, pdfsrc, vsrc->value.indirect.number)) == NULL) { - obj = pdfioObjCopy(pdfdst, pdfioFileFindObject(pdfsrc, vsrc->value.indirect.number)); + obj = pdfioObjCopy(pdfdst, pdfioFileFindObj(pdfsrc, vsrc->value.indirect.number)); } if (!obj) diff --git a/pdfio.h b/pdfio.h index e1ecca4..6f1dc44 100644 --- a/pdfio.h +++ b/pdfio.h @@ -107,7 +107,7 @@ extern bool pdfioArrayAppendBoolean(pdfio_array_t *a, bool value) PDFIO_PUBLIC; extern bool pdfioArrayAppendDict(pdfio_array_t *a, pdfio_dict_t *value) PDFIO_PUBLIC; extern bool pdfioArrayAppendName(pdfio_array_t *a, const char *value) PDFIO_PUBLIC; extern bool pdfioArrayAppendNumber(pdfio_array_t *a, double value) PDFIO_PUBLIC; -extern bool pdfioArrayAppendObject(pdfio_array_t *a, pdfio_obj_t *value) PDFIO_PUBLIC; +extern bool pdfioArrayAppendObj(pdfio_array_t *a, pdfio_obj_t *value) PDFIO_PUBLIC; extern bool pdfioArrayAppendString(pdfio_array_t *a, const char *value) PDFIO_PUBLIC; extern pdfio_array_t *pdfioArrayCopy(pdfio_file_t *pdf, pdfio_array_t *a) PDFIO_PUBLIC; extern pdfio_array_t *pdfioArrayCreate(pdfio_file_t *pdf) PDFIO_PUBLIC; @@ -117,7 +117,7 @@ extern bool pdfioArrayGetBoolean(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; extern pdfio_dict_t *pdfioArrayGetDict(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; extern const char *pdfioArrayGetName(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; extern double pdfioArrayGetNumber(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioArrayGetObject(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioArrayGetObj(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; extern size_t pdfioArrayGetSize(pdfio_array_t *a) PDFIO_PUBLIC; extern const char *pdfioArrayGetString(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; extern pdfio_valtype_t pdfioArrayGetType(pdfio_array_t *a, size_t n) PDFIO_PUBLIC; @@ -130,7 +130,7 @@ extern bool pdfioDictGetBoolean(pdfio_dict_t *dict, const char *key) PDFIO_PUBL extern pdfio_dict_t *pdfioDictGetDict(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; extern const char *pdfioDictGetName(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; extern double pdfioDictGetNumber(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioDictGetObject(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioDictGetObj(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; extern pdfio_rect_t *pdfioDictGetRect(pdfio_dict_t *dict, const char *key, pdfio_rect_t *rect) PDFIO_PUBLIC; extern const char *pdfioDictGetString(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; extern pdfio_valtype_t pdfioDictGetType(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; @@ -141,22 +141,22 @@ extern bool pdfioDictSetDict(pdfio_dict_t *dict, const char *key, pdfio_dict_t extern bool pdfioDictSetName(pdfio_dict_t *dict, const char *key, const char *value) PDFIO_PUBLIC; extern bool pdfioDictSetNull(pdfio_dict_t *dict, const char *key) PDFIO_PUBLIC; extern bool pdfioDictSetNumber(pdfio_dict_t *dict, const char *key, double value) PDFIO_PUBLIC; -extern bool pdfioDictSetObject(pdfio_dict_t *dict, const char *key, pdfio_obj_t *value) PDFIO_PUBLIC; +extern bool pdfioDictSetObj(pdfio_dict_t *dict, const char *key, pdfio_obj_t *value) PDFIO_PUBLIC; extern bool pdfioDictSetRect(pdfio_dict_t *dict, const char *key, pdfio_rect_t *value) PDFIO_PUBLIC; extern bool pdfioDictSetString(pdfio_dict_t *dict, const char *key, const char *value) PDFIO_PUBLIC; extern bool pdfioDictSetStringf(pdfio_dict_t *dict, const char *key, const char *format, ...) PDFIO_PUBLIC PDFIO_FORMAT(3,4); extern bool pdfioFileClose(pdfio_file_t *pdf) PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileCreate(const char *filename, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileCreateObject(pdfio_file_t *pdf, pdfio_dict_t *dict) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) PDFIO_PUBLIC; // TODO: Add number, array, string, etc. versions of pdfioFileCreateObject? extern pdfio_stream_t *pdfioFileCreatePage(pdfio_file_t *pdf, pdfio_dict_t *dict) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileFindObject(pdfio_file_t *pdf, size_t number) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileFindObj(pdfio_file_t *pdf, size_t number) PDFIO_PUBLIC; extern pdfio_array_t *pdfioFileGetID(pdfio_file_t *pdf) PDFIO_PUBLIC; extern const char *pdfioFileGetName(pdfio_file_t *pdf) PDFIO_PUBLIC; -extern size_t pdfioFileGetNumObjects(pdfio_file_t *pdf) PDFIO_PUBLIC; +extern size_t pdfioFileGetNumObjs(pdfio_file_t *pdf) PDFIO_PUBLIC; extern size_t pdfioFileGetNumPages(pdfio_file_t *pdf) PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileGetObject(pdfio_file_t *pdf, size_t n) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileGetObj(pdfio_file_t *pdf, size_t n) PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileGetPage(pdfio_file_t *pdf, size_t n) PDFIO_PUBLIC; extern const char *pdfioFileGetVersion(pdfio_file_t *pdf) PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileOpen(const char *filename, pdfio_error_cb_t error_cb, void *error_data) PDFIO_PUBLIC; diff --git a/testpdfio.c b/testpdfio.c index 1df38c2..f72e057 100644 --- a/testpdfio.c +++ b/testpdfio.c @@ -77,7 +77,6 @@ do_test_file(const char *filename) // I - PDF filename num_pages; // Number of pages pdfio_obj_t *obj; // Object pdfio_dict_t *dict; // Object dictionary - const char *type; // Object type // Try opening the file... @@ -87,7 +86,7 @@ do_test_file(const char *filename) // I - PDF filename puts("PASS"); // Show basic stats... - num_objs = pdfioFileGetNumObjects(pdf); + num_objs = pdfioFileGetNumObjs(pdf); num_pages = pdfioFileGetNumPages(pdf); printf(" PDF %s, %d pages, %d objects.\n", pdfioFileGetVersion(pdf), (int)num_pages, (int)num_objs); @@ -108,7 +107,7 @@ do_test_file(const char *filename) // I - PDF filename if (!pdfioDictGetRect(dict, "MediaBox", &media_box)) { - if ((obj = pdfioDictGetObject(dict, "Parent")) != NULL) + if ((obj = pdfioDictGetObj(dict, "Parent")) != NULL) { dict = pdfioObjGetDict(obj); pdfioDictGetRect(dict, "MediaBox", &media_box); @@ -122,7 +121,7 @@ do_test_file(const char *filename) // I - PDF filename // Show the associated value with each object... for (n = 0; n < num_objs; n ++) { - if ((obj = pdfioFileGetObject(pdf, n)) == NULL) + if ((obj = pdfioFileGetObj(pdf, n)) == NULL) { printf(" Unable to get object #%d.\n", (int)n); } @@ -157,7 +156,6 @@ static int // O - Exit status do_unit_tests(void) { int i; // Looping var - char filename[256]; // PDF filename pdfio_file_t *pdf, // Test PDF file *outpdf; // Output PDF file bool error = false; // Error callback data @@ -214,21 +212,21 @@ do_unit_tests(void) return (1); // Create some image objects... - fputs("pdfioFileCreateImageObject(\"testfiles/color.jpg\"): ", stdout); - if ((color_jpg = pdfioFileCreateImageObject(outpdf, "testfiles/color.jpg", true)) != NULL) + fputs("pdfioFileCreateImageObj(\"testfiles/color.jpg\"): ", stdout); + if ((color_jpg = pdfioFileCreateImageObj(outpdf, "testfiles/color.jpg", true)) != NULL) puts("PASS"); else return (1); - fputs("pdfioFileCreateImageObject(\"testfiles/gray.jpg\"): ", stdout); - if ((gray_jpg = pdfioFileCreateImageObject(outpdf, "testfiles/gray.jpg", true)) != NULL) + fputs("pdfioFileCreateImageObj(\"testfiles/gray.jpg\"): ", stdout); + if ((gray_jpg = pdfioFileCreateImageObj(outpdf, "testfiles/gray.jpg", true)) != NULL) puts("PASS"); else return (1); // Create fonts... - fputs("pdfioFileCreateBaseFontObject(\"Helvetica\"): ", stdout); - if ((helvetica = pdfioFileCreateBaseFontObject(outpdf, "Helvetica")) != NULL) + fputs("pdfioFileCreateBaseFontObj(\"Helvetica\"): ", stdout); + if ((helvetica = pdfioFileCreateBaseFontObj(outpdf, "Helvetica")) != NULL) puts("PASS"); else return (1); @@ -276,7 +274,7 @@ do_unit_tests(void) return (1); // Write a page with test images... - first_image = pdfioFileGetNumObjects(outpdf); + first_image = pdfioFileGetNumObjs(outpdf); if (write_images(outpdf, 7, helvetica)) return (1); @@ -330,7 +328,7 @@ do_unit_tests(void) // Verify the images for (i = 0; i < 7; i ++) - verify_image(pdf, (size_t)(first_image + i)); + verify_image(pdf, first_image + (size_t)i); // Close the new PDF file... fputs("pdfioFileClose(\"testpdfio-out.pdf\"): ", stdout); @@ -489,8 +487,8 @@ verify_image(pdfio_file_t *pdf, // I - PDF file ssize_t bytes; // Bytes read from stream - printf("pdfioFileFindObject(%lu): ", (unsigned long)number); - if ((obj = pdfioFileFindObject(pdf, number)) != NULL) + printf("pdfioFileFindObj(%lu): ", (unsigned long)number); + if ((obj = pdfioFileFindObj(pdf, number)) != NULL) puts("PASS"); else return (1); @@ -550,9 +548,9 @@ verify_image(pdfio_file_t *pdf, // I - PDF file { for (x = 0, bufptr = buffer; x < 256; x ++, bufptr += 3) { - bufptr[0] = y; - bufptr[1] = y + x; - bufptr[2] = y - x; + bufptr[0] = (unsigned char)y; + bufptr[1] = (unsigned char)(y + x); + bufptr[2] = (unsigned char)(y - x); } if ((bytes = pdfioStreamRead(st, line, sizeof(line))) != (ssize_t)sizeof(line)) @@ -1040,7 +1038,7 @@ write_image_object( pdfioDictSetDict(dict, "DecodeParms", decode); // Create the image object... - if ((obj = pdfioFileCreateObject(pdf, dict)) == NULL) + if ((obj = pdfioFileCreateObj(pdf, dict)) == NULL) return (NULL); // Create the image stream and write the image... @@ -1051,9 +1049,9 @@ write_image_object( { for (x = 0, bufptr = buffer; x < 256; x ++, bufptr += 3) { - bufptr[0] = y; - bufptr[1] = y + x; - bufptr[2] = y - x; + bufptr[0] = (unsigned char)y; + bufptr[1] = (unsigned char)(y + x); + bufptr[2] = (unsigned char)(y - x); } if (!pdfioStreamWrite(st, buffer, sizeof(buffer))) @@ -1182,7 +1180,7 @@ write_images(pdfio_file_t *pdf, // I - PDF file for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++) { - int i = p - _PDFIO_PREDICTOR_PNG_NONE; + int i = (int)p - _PDFIO_PREDICTOR_PNG_NONE; snprintf(pname, sizeof(pname), "IM%d", p); snprintf(plabel, sizeof(plabel), "PNG Predictor %d", p); @@ -1371,20 +1369,20 @@ write_png(pdfio_file_t *pdf, // I - PDF file // Import the PNG test images - fputs("pdfioFileCreateImageObject(\"testfiles/pdfio-color.png\"): ", stdout); - if ((color = pdfioFileCreateImageObject(pdf, "testfiles/pdfio-color.png", false)) != NULL) + fputs("pdfioFileCreateImageObj(\"testfiles/pdfio-color.png\"): ", stdout); + if ((color = pdfioFileCreateImageObj(pdf, "testfiles/pdfio-color.png", false)) != NULL) puts("PASS"); else return (1); - fputs("pdfioFileCreateImageObject(\"testfiles/pdfio-gray.png\"): ", stdout); - if ((gray = pdfioFileCreateImageObject(pdf, "testfiles/pdfio-gray.png", false)) != NULL) + fputs("pdfioFileCreateImageObj(\"testfiles/pdfio-gray.png\"): ", stdout); + if ((gray = pdfioFileCreateImageObj(pdf, "testfiles/pdfio-gray.png", false)) != NULL) puts("PASS"); else return (1); - fputs("pdfioFileCreateImageObject(\"testfiles/pdfio-indexed.png\"): ", stdout); - if ((indexed = pdfioFileCreateImageObject(pdf, "testfiles/pdfio-indexed.png", false)) != NULL) + fputs("pdfioFileCreateImageObj(\"testfiles/pdfio-indexed.png\"): ", stdout); + if ((indexed = pdfioFileCreateImageObj(pdf, "testfiles/pdfio-indexed.png", false)) != NULL) puts("PASS"); else return (1); @@ -1572,8 +1570,8 @@ write_text(pdfio_file_t *pdf, // I - PDF file // Create text font... - fputs("pdfioFileCreateBaseFontObject(\"Courier\"): ", stdout); - if ((courier = pdfioFileCreateBaseFontObject(pdf, "Courier")) != NULL) + fputs("pdfioFileCreateBaseFontObj(\"Courier\"): ", stdout); + if ((courier = pdfioFileCreateBaseFontObj(pdf, "Courier")) != NULL) puts("PASS"); else return (1);