home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pdflb302.zip / pdf / pdflib-3.0.2 / pdflib / p_intern.h < prev    next >
C/C++ Source or Header  |  2000-09-08  |  30KB  |  774 lines

  1. /*---------------------------------------------------------------------------*
  2.  |        PDFlib - A library for dynamically generating PDF documents        |
  3.  +---------------------------------------------------------------------------+
  4.  |        Copyright (c) 1997-2000 Thomas Merz. All rights reserved.          |
  5.  +---------------------------------------------------------------------------+
  6.  |    This software is NOT in the public domain.  It can be used under two   |
  7.  |    substantially different licensing terms:                               |
  8.  |                                                                           |
  9.  |    The commercial license is available for a fee, and allows you to       |
  10.  |    - ship a commercial product based on PDFlib                            |
  11.  |    - implement commercial Web services with PDFlib                        |
  12.  |    - distribute (free or commercial) software when the source code is     |
  13.  |      not made available                                                   |
  14.  |    Details can be found in the file PDFlib-license.pdf.                   |
  15.  |                                                                           |
  16.  |    The "Aladdin Free Public License" doesn't require any license fee,     |
  17.  |    and allows you to                                                      |
  18.  |    - develop and distribute PDFlib-based software for which the complete  |
  19.  |      source code is made available                                        |
  20.  |    - redistribute PDFlib non-commercially under certain conditions        |
  21.  |    - redistribute PDFlib on digital media for a fee if the complete       |
  22.  |      contents of the media are freely redistributable                     |
  23.  |    Details can be found in the file aladdin-license.pdf.                  |
  24.  |                                                                           |
  25.  |    These conditions extend to ports to other programming languages.       |
  26.  |    PDFlib is distributed with no warranty of any kind. Commercial users,  |
  27.  |    however, will receive warranty and support statements in writing.      |
  28.  *---------------------------------------------------------------------------*/
  29.  
  30. /* p_intern.h
  31.  *
  32.  * PDFlib internal definitions
  33.  *
  34.  */
  35.  
  36. #ifndef P_INTERN_H
  37. #define P_INTERN_H
  38.  
  39. #include <stdio.h>
  40.  
  41. #include "pdflib.h"
  42. #include "p_config.h"
  43.  
  44. #ifdef HAVE_LIBTIFF
  45. #include <tiffio.h>
  46. #endif
  47.  
  48. #ifdef HAVE_LIBZ
  49. #include <zlib.h>
  50. #endif
  51.  
  52. #ifdef HAVE_LIBPNG
  53. #include <png.h>
  54. #endif
  55.  
  56. #define pdf_false       0
  57. #define pdf_true        1
  58. typedef int pdf_bool;
  59.  
  60. #define RESOURCEFILE            "PDFLIBRESOURCE"
  61. #define DEFAULTRESOURCEFILE     "pdflib.upr"
  62.  
  63. #define PDF_1_2                 12
  64. #define PDF_1_3                 13
  65.  
  66. /*
  67.  * Allocation chunk sizes. These don't affect the generated documents
  68.  * in any way. In order to save initial memory, however, you can lower
  69.  * the values. Increasing the values will bring some performance gain
  70.  * for large documents.
  71.  */
  72. #define PAGES_CHUNKSIZE         512             /* pages */
  73. #define ID_CHUNKSIZE            2048            /* object ids */
  74. #define CONTENTS_CHUNKSIZE      64              /* page content streams */
  75. #define FONTS_CHUNKSIZE         16              /* document fonts */
  76. #define XOBJECTS_CHUNKSIZE      128             /* document xobjects */
  77. #define IMAGES_CHUNKSIZE        128             /* document images */
  78. #define OUTLINE_CHUNKSIZE       256             /* document outlines */
  79. #define STREAM_CHUNKSIZE        65536           /* output buffer for in-core generation*/
  80.  
  81. /* The following shouldn't require any changes */
  82. #define ENC_MAX                 32              /* max number of encodings */
  83. #define PDF_MAX_SAVE_LEVEL      10              /* max number of save levels */
  84. #define FLOATBUFSIZE            20              /* buffer length for floats */
  85. #define PDF_FILENAMELEN         1024            /* maximum file name length */
  86. #define PDF_MAX_PARAMSTRING     128             /* image parameter string */
  87. #define PDF_DEFAULT_COMPRESSION 6               /* default zlib level */
  88.  
  89. /* configurable flush points */
  90. #define PDF_FLUSH_NONE          0               /* end of document */
  91. #define PDF_FLUSH_PAGE          (1<<0)          /* after page */
  92. #define PDF_FLUSH_CONTENT       (1<<1)          /* font, xobj, annots */
  93. #define PDF_FLUSH_RESERVED1     (1<<2)          /* reserved */
  94. #define PDF_FLUSH_RESERVED2     (1<<3)          /* reserved */
  95. #define PDF_FLUSH_HEAVY         (1<<4)          /* before realloc attempt */
  96.  
  97. /*
  98.  * An arbitrary number used as a sanity check for the PDF pointer.
  99.  * Actually, we use the hex representation of pi in order to avoid
  100.  * the more common patterns.
  101.  */
  102. #define PDF_MAGIC       ((unsigned long) 0x126960A1)
  103.  
  104. /*
  105.  * When there's no PDF pointer we don't have access to an error handler.
  106.  * Since the client completely screwed up, we refuse to do
  107.  * anything in the hope the client will recognize his trouble.
  108.  */
  109.  
  110. #define PDF_SANITY_CHECK_FAILED(p)      (p == NULL || p->magic != PDF_MAGIC)
  111.  
  112. /* Border styles for links */
  113. typedef enum {
  114.     border_solid, border_dashed, border_beveled,
  115.     border_inset, border_underlined
  116. } pdf_border_style;
  117.  
  118. /* Transition types for page transition effects */
  119. typedef enum {
  120.     trans_none, trans_split, trans_blinds, trans_box,
  121.     trans_wipe, trans_dissolve, trans_glitter, trans_replace
  122. } pdf_transition;
  123.  
  124. /* icons for file attachments and text annotations */
  125. typedef enum {
  126.     icon_file_graph, icon_file_paperclip,
  127.     icon_file_pushpin, icon_file_tag,
  128.  
  129.     icon_text_comment, icon_text_insert,
  130.     icon_text_note, icon_text_paragraph,
  131.     icon_text_newparagraph, icon_text_key,
  132.     icon_text_help
  133. } pdf_icon;
  134.  
  135. /*
  136.  * Symbolic names for predefined font encodings. 0 and above are used
  137.  * as indices in the pdf_encoding_vector array.
  138.  */
  139. typedef enum {
  140.     cid = -2, builtin = -1, winansi = 0, macroman = 1, ebcdic = 3
  141. } pdf_encoding;
  142.  
  143. typedef enum { ImageB = 1, ImageC = 2, ImageI = 4, Text = 8 } pdf_procset;
  144.  
  145. /* The color spaces are PDF standard except ImageMask, which we use
  146.  * internally.
  147.  */
  148. typedef enum {
  149.     DeviceGray, DeviceRGB, DeviceCMYK,
  150.     CalGray, CalRGB, Lab,
  151.     Indexed, PatternCS, Separation,
  152.     ImageMask
  153. } pdf_colorspace;
  154.  
  155. /* the different types of graphics object within a page description */
  156. typedef enum { c_none, c_page, c_path, c_text } pdf_content_type;
  157.  
  158. typedef long id;
  159.  
  160. typedef struct {
  161.     char *apiname;      /* PDFlib's name of the encoding at the API */
  162.     char *pdfname;      /* PDF's official name of the encoding */
  163.     char *chars[256];   /* the actual character names */
  164. } pdf_encodingvector;
  165.  
  166. typedef enum { none, lzw, runlength, ccitt, dct, flate } pdf_compression;
  167.  
  168. typedef unsigned char pdf_byte;
  169.  
  170. typedef pdf_byte pdf_colormap[256][3];
  171.  
  172. #define NEW_ID          0L
  173. #define BAD_ID          -1L
  174.  
  175. /* Note: pdf_begin_obj() is a function */
  176. #define pdf_end_obj(p)          pdf_puts(p, "endobj\n")
  177.  
  178. #define pdf_begin_dict(p)       pdf_puts(p, "<<")
  179. #define pdf_end_dict(p)         pdf_puts(p, ">>\n")
  180.  
  181. #define pdf_begin_stream(p)     pdf_puts(p, "stream\n")
  182. #define pdf_end_stream(p)       pdf_puts(p, "endstream\n")
  183.  
  184. /* some ASCII characters, deliberately defined as hex codes */
  185. #define PDF_NEWLINE             ((char) 0x0a)           /* ASCII '\n' */
  186. #define PDF_RETURN              ((char) 0x0d)           /* ASCII '\r' */
  187. #define PDF_SPACE               ((char) 0x20)           /* ASCII ' '  */
  188. #define PDF_BACKSLASH           ((char) 0x5c)           /* ASCII '\\' */
  189. #define PDF_PARENLEFT           ((char) 0x28)           /* ASCII '('  */
  190. #define PDF_PARENRIGHT          ((char) 0x29)           /* ASCII ')'  */
  191. #define PDF_EXCLAM              ((char) 0x21)           /* ASCII '!'  */
  192. #define PDF_COMMA               ((char) 0x2c)           /* ASCII ','  */
  193. #define PDF_SEMICOLON           ((char) 0x3b)           /* ASCII ';'  */
  194. #define PDF_n                   ((char) 0x6e)           /* ASCII 'n'  */
  195. #define PDF_r                   ((char) 0x72)           /* ASCII 'r'  */
  196. #define PDF_z                   ((char) 0x7a)           /* ASCII 'z'  */
  197.  
  198. #ifdef PDFLIB_EBCDIC
  199. #define pdf_make_ascii(s)       pdf_ebcdic2ascii(s)
  200. #else
  201. #define pdf_make_ascii(s)       (s)
  202. #endif
  203.  
  204. /* The Unicode byte order mark (BOM) signals Unicode strings */
  205. #define PDF_BOM0                0376            /* '\xFE' */
  206. #define PDF_BOM1                0377            /* '\xFF' */
  207.  
  208. /*
  209.  * check whether the string is plain C or unicode by looking for the BOM
  210.  * s must not be NULL.
  211.  */
  212. #define pdf_is_unicode(s) \
  213.         (((unsigned char *)(s))[0] != 0 &&              \
  214.          ((unsigned char *)(s))[0] == PDF_BOM0 &&       \
  215.          ((unsigned char *)(s))[1] == PDF_BOM1)
  216.  
  217. /* Document open modes */
  218. typedef enum {
  219.     open_auto, open_none, open_bookmarks, open_thumbnails, open_fullscreen
  220. } pdf_openmode;
  221.  
  222. /* Destination types for internal and external links */
  223. typedef enum { retain, fitpage, fitwidth, fitheight, fitbbox } pdf_desttype;
  224.  
  225. /* Destination structure for bookmarks and links */
  226. typedef struct {
  227.     pdf_desttype type;
  228.     int page;
  229. } pdf_dest;
  230.  
  231. typedef struct { float llx, lly, urx, ury; } PDF_rectangle;
  232.  
  233. /* A PDF xobject */
  234. typedef struct {
  235.     id          obj_id;                 /* object id of this xobject */
  236.     pdf_bool    used_on_current_page;   /* this xobject used on current page */
  237. } pdf_xobject;
  238.  
  239. typedef struct pdf_res_s pdf_res;
  240.  
  241. struct pdf_res_s {
  242.     char                *name;
  243.     char                *filename;
  244.     pdf_res             *next;
  245. };
  246.  
  247. typedef struct pdf_category_s pdf_category;
  248.  
  249. struct pdf_category_s {
  250.     char                *category;
  251.     pdf_res             *kids;
  252.     pdf_category        *next;
  253. };
  254.  
  255. typedef struct pdf_outline_s pdf_outline;
  256. struct pdf_outline_s {
  257.     id                  self;           /* id of this outline object */
  258.     id                  prev;           /* previous entry at this level */
  259.     id                  next;           /* next entry at this level */
  260.     int                 parent;         /* ancestor's index */
  261.     int                 first;          /* first sub-entry */
  262.     int                 last;           /* last sub-entry */
  263.     char                *text;          /* bookmark text */
  264.     int                 count;          /* number of open sub-entries */
  265.     int                 open;           /* whether or not to display children */
  266.     pdf_dest            dest;           /* destination */
  267. };
  268.  
  269. /* Internal PDFlib states for error checking */
  270. typedef enum {
  271.     pdf_state_null, pdf_state_open,
  272.     pdf_state_page_description, pdf_state_path, pdf_state_text
  273. } pdf_state;
  274.  
  275. typedef struct { float a, b, c, d, e, f; } pdf_matrix;
  276.  
  277. /* Annotation types */
  278. typedef enum {
  279.     ann_text, ann_locallink,
  280.     ann_pdflink, ann_weblink,
  281.     ann_launchlink, ann_attach
  282. } pdf_annot_type;
  283.  
  284. /* Fill rules */
  285. typedef enum {pdf_fill_winding, pdf_fill_evenodd} pdf_fillrule;
  286.  
  287. /* Annotations */
  288. typedef struct pdf_annot_s pdf_annot;
  289. struct pdf_annot_s {
  290.     pdf_annot_type      type;           /* used for all annotation types */
  291.     PDF_rectangle       rect;           /* used for all annotation types */
  292.     id                  obj_id;         /* used for all annotation types */
  293.     pdf_annot           *next;          /* used for all annotation types */
  294.  
  295.     pdf_icon            icon;           /* attach and text */
  296.     char                *filename;      /* attach, launchlink, pdflink,weblink*/
  297.     char                *contents;      /* text, attach, pdflink */
  298.     char                *mimetype;      /* attach */
  299.  
  300.     char                *title;         /* text */
  301.     int                 open;           /* text */
  302.     pdf_dest            dest;           /* locallink, pdflink */
  303.  
  304.     /* -------------- annotation border style and color -------------- */
  305.     pdf_border_style    border_style;
  306.     float               border_width;
  307.     float               border_red;
  308.     float               border_green;
  309.     float               border_blue;
  310.     float               border_dash1;
  311.     float               border_dash2;
  312. };
  313.  
  314. struct pdf_stream_s {
  315.     pdf_byte    *basepos;               /* start of this chunk */
  316.     pdf_byte    *curpos;                /* next write position */
  317.     pdf_byte    *maxpos;                /* maximum position of chunk */
  318.  
  319.     size_t      base_offset;            /* base offset of this chunk */
  320.  
  321.     int         flush;                  /* flushing strategy */
  322.  
  323.     pdf_bool    compress;               /* in compression state */
  324.  
  325. #ifdef HAVE_LIBZ
  326.     z_stream    z;                      /* zlib compression stream */
  327. #endif
  328. };
  329.  
  330. typedef struct pdf_image_s pdf_image;
  331. typedef struct pdf_font_s pdf_font;
  332. typedef struct pdf_stream_s pdf_stream;
  333.  
  334. /* -------------------- special graphics state -------------------- */
  335. typedef struct {
  336. #ifdef CTM_NYI
  337.     pdf_matrix  ctm;            /* current transformation matrix */
  338. #endif
  339.     float       x;              /* current x coordinate */
  340.     float       y;              /* current y coordinate */
  341.  
  342.     float       startx;         /* starting x point of the subpath */
  343.     float       starty;         /* starting y point of the subpath */
  344.  
  345.     /* other general gstate parameters nyi */
  346.  
  347. } pdf_gstate;
  348.  
  349. /* ------------------------ text state ---------------------------- */
  350. typedef struct {
  351.     float       c;              /* character spacing */
  352.     float       w;              /* word spacing */
  353.     float       h;              /* horizontal scaling */
  354.     float       l;              /* leading */
  355.     int         f;              /* slot number of the current font */
  356.     float       fs;             /* font size */
  357.     pdf_matrix  m;              /* text matrix */
  358.     int         mode;           /* text rendering mode */
  359.     float       rise;           /* text rise */
  360.     pdf_matrix  lm;             /* text line matrix */
  361. } pdf_tstate;
  362.  
  363. typedef struct {
  364.     pdf_colorspace      cs;
  365.     union {
  366.         float           gray;
  367.         struct {
  368.             float       r;
  369.             float       g;
  370.             float       b;
  371.         } rgb;
  372. #ifdef PDF_CMYK_SUPPORTED
  373.         struct {
  374.             float       c;
  375.             float       m;
  376.             float       y;
  377.             float       k;
  378.         } cmyk;
  379. #endif
  380.     } val;
  381. } pdf_color;
  382.  
  383. /* ----------------------- color state --------------------------- */
  384. typedef struct {
  385.     pdf_color   fill;
  386.     pdf_color   stroke;
  387. } pdf_cstate;
  388.  
  389. /*
  390.  * *************************************************************************
  391.  * The core PDF document descriptor
  392.  * *************************************************************************
  393.  */
  394.  
  395. struct PDF_s {
  396.     /* -------------------------- general stuff ------------------------ */
  397.     unsigned long       magic;          /* poor man's integrity check */
  398.  
  399.     char        *binding;               /* name of the language binding */
  400.     char        *prefix;                /* prefix for resource file names */
  401.     int         compatibility;          /* PDF version number * 10 */
  402.  
  403.     /* ------------------- PDF Info dictionary entries ----------------- */
  404.     char        *Keywords;
  405.     char        *Subject;
  406.     char        *Title;
  407.     char        *Creator;
  408.     char        *Author;
  409.     /* user-defined key and value */
  410.     char        *userkey;               /* ASCII string */
  411.     char        *userval;               /* Unicode string */
  412.  
  413.     /* ------------------------- PDF output ---------------------------- */
  414.     FILE        *fp;
  415.     char        *filename;
  416.     pdf_stream  stream;
  417.     /* writeproc == NULL means we're generating PDF in-core */
  418.     size_t      (*writeproc)(PDF *p, void *data, size_t size);
  419.  
  420.     /* -------------- error handling and memory management ------------- */
  421.     pdf_bool    in_error;               /* pdf_true if in error handler */
  422.     void        (*errorhandler)(PDF *p, int level, const char* msg);
  423.     void        *(*malloc)(PDF *p, size_t size, const char *caller);
  424.     void        *(*calloc)(PDF *p, size_t size, const char *caller);
  425.     void        *(*realloc)(PDF *p, void *mem, size_t size, const char *caller);
  426.     void         (*free)(PDF *p, void *mem);
  427.     void        *opaque;                /* user-specific, opaque data */
  428.  
  429.     /* ------------------------ resource stuff ------------------------- */
  430.     pdf_category *resources;            /* anchor for the resource list */
  431.     char        *resourcefilename;      /* name of the resource file */
  432.     pdf_bool    resourcefile_loaded;    /* already loaded the resource file */
  433.  
  434.     /* ------------------- object and id bookkeeping ------------------- */
  435.     id          root_id;
  436.     id          info_id;
  437.     id          pages_id;
  438.     pdf_openmode open_mode;             /* document open mode */
  439.     pdf_desttype open_action;           /* open action/first page display */
  440.     pdf_desttype bookmark_dest;         /* destination type for bookmarks */
  441.  
  442.     long        *file_offset;           /* the objects' file offsets */
  443.     int         file_offset_capacity;
  444.     id          currentobj;
  445.  
  446.     id          *pages;                 /* page ids */
  447.     int         pages_capacity;
  448.     int         current_page;           /* current page number (1-based) */
  449.  
  450.     /* ------------------- document resources ------------------- */
  451.     pdf_font    *fonts;                 /* all fonts in document */
  452.     int         fonts_capacity;         /* currently allocated size */
  453.     int         fonts_number;           /* next available font number */
  454.  
  455.     pdf_xobject *xobjects;              /* all xobjects in document */
  456.     int         xobjects_capacity;      /* currently allocated size */
  457.     int         xobjects_number;        /* next available xobject number */
  458.  
  459.     pdf_image  *images;                 /* all images in document */
  460.     int         images_capacity;        /* currently allocated size */
  461.  
  462.     /* ------------------- document outline tree ------------------- */
  463.     int         outline_capacity;       /* currently allocated size */
  464.     int         outline_count;          /* total number of outlines */
  465.     pdf_outline *outlines;              /* dynamic array of outlines */
  466.  
  467.     /* ------------------- page specific stuff ------------------- */
  468.     pdf_state   state;                  /* state within the library */
  469.     id          res_id;                 /* id of this page's res dict */
  470.     id          contents_length_id;     /* id of current cont section's length*/
  471.     id          *contents_ids;          /* content sections' chain */
  472.     int         contents_ids_capacity;  /* # of content sections */
  473.     id          next_content;           /* # of current content section */
  474.     pdf_content_type    contents;       /* type of current content section */
  475.     pdf_transition      transition;     /* type of page transition */
  476.     float       duration;               /* duration of page transition */
  477.  
  478.     pdf_annot   *annots;                /* annotation chain */
  479.  
  480.     int         procset;                /* procsets for this page */
  481.     long        start_contents_pos;     /* start offset of contents section */
  482.  
  483.     float       width;                  /* current page's width */
  484.     float       height;                 /* current page's height */
  485.     id          thumb_id;               /* id of this page's thumb, or BAD_ID */
  486.  
  487.     int         sl;                             /* current save level */
  488.     pdf_gstate  gstate[PDF_MAX_SAVE_LEVEL];     /* graphics state */
  489.     pdf_tstate  tstate[PDF_MAX_SAVE_LEVEL];     /* text state */
  490.     pdf_cstate  cstate[PDF_MAX_SAVE_LEVEL];     /* color state */
  491.  
  492.     /* ------------ other text and graphics-related stuff ------------ */
  493.     pdf_bool    leading_done;           /* leading value already set */
  494.     pdf_bool    underline;              /* underline text */
  495.     pdf_bool    overline;               /* overline text */
  496.     pdf_bool    strikeout;              /* strikeout text */
  497.  
  498.     pdf_fillrule        fillrule;       /* nonzero or evenodd fill rule */
  499.  
  500.     /* -------------- annotation border style and color -------------- */
  501.     pdf_border_style    border_style;
  502.     float               border_width;
  503.     float               border_red;
  504.     float               border_green;
  505.     float               border_blue;
  506.     float               border_dash1;
  507.     float               border_dash2;
  508.  
  509.     /* ------------------------ miscellaneous ------------------------ */
  510.     int         chars_on_this_line;
  511.     int         compress;               /* zlib compression level */
  512.     char        debug[128];             /* debug flags */
  513.  
  514.     /* the list of known encoding vectors */
  515.     pdf_encodingvector *encodings[ENC_MAX];
  516. };
  517.  
  518. /* Data source for images, compression, ASCII encoding, fonts, etc. */
  519. typedef struct PDF_data_source_s PDF_data_source;
  520. struct PDF_data_source_s {
  521.     pdf_byte            *next_byte;
  522.     size_t              bytes_available;
  523.     void                (*init)(PDF *, PDF_data_source *src);
  524.     int                 (*fill)(PDF *, PDF_data_source *src);
  525.     void                (*terminate)(PDF *, PDF_data_source *src);
  526.  
  527.     pdf_byte            *buffer_start;
  528.     size_t              buffer_length;
  529.     void                *private_data;
  530. };
  531.  
  532. /* JPEG specific image information */
  533. typedef struct pdf_jpeg_info_t {
  534.     long                startpos;       /* start of image data in file */
  535. } pdf_jpeg_info;
  536.  
  537. /* GIF specific image information */
  538. typedef struct pdf_gif_info_t {
  539.     int                 c_size;         /* current code size (9..12)    */
  540.     int                 t_size;         /* current table size (257...)  */
  541.     int                 i_buff;         /* input buffer                 */
  542.     int                 i_bits;         /* # of bits in i_buff          */
  543.     int                 o_buff;         /* output buffer                */
  544.     int                 o_bits;         /* # of bits in o_buff          */
  545. } pdf_gif_info;
  546.  
  547. #ifdef HAVE_LIBPNG
  548.  
  549. /* PNG specific image information */
  550. typedef struct pdf_png_info_t {
  551.         png_structp     png_ptr;
  552.         png_infop       info_ptr;
  553.         png_uint_32     rowbytes;
  554.         pdf_byte        *raster;
  555.         int             cur_line;
  556. } pdf_png_info;
  557.  
  558. #endif  /* HAVE_LIBPNG */
  559.  
  560. #ifdef HAVE_LIBTIFF
  561.  
  562. /* TIFF specific image information */
  563. typedef struct pdf_tiff_info_t {
  564.     TIFF                *tif;           /* pointer to TIFF data structure */
  565.     uint32              *raster;        /* frame buffer */
  566.     int                 cur_line;       /* current image row, or strip for multi-strip */
  567.     pdf_bool            use_raw;        /* use raw (compressed) image data */
  568. } pdf_tiff_info;
  569.  
  570. #endif  /* HAVE_LIBTIFF */
  571.  
  572. /* CCITT specific image information */
  573. typedef struct pdf_ccitt_info_t {
  574.     int                 BitReverse;     /* reverse all bits prior to use */
  575. } pdf_ccitt_info;
  576.  
  577. /* Type of image reference */
  578. typedef enum {pdf_ref_direct, pdf_ref_file, pdf_ref_url} pdf_ref_type;
  579.  
  580. /* The image descriptor */
  581. struct pdf_image_s {
  582.     FILE                *fp;            /* image file pointer */
  583.     char                *filename;      /* image file name or url */
  584.     pdf_ref_type        reference;      /* kind of image data reference */
  585.     int                 width;          /* image width in pixels */
  586.     int                 height;         /* image height in pixels */
  587.     int                 bpc;            /* bits per color component */
  588.     int                 components;     /* number of color components */
  589.     pdf_compression     compression;    /* image compression type */
  590.     pdf_colorspace      colorspace;     /* image color space */
  591.  
  592.     pdf_bool            invert;         /* invert: reverse black and white */
  593.     pdf_bool            transparent;    /* image is transparent */
  594.     pdf_byte            transval[4];    /* transparent color values */
  595.     int                 mask;           /* image number of image mask, or -1 */
  596.     int                 predictor;      /* predictor for lzw and flate compression */
  597.  
  598.     int                 palette_size;   /* # of entries (not bytes!) in color palette */
  599.     pdf_colormap        *colormap;      /* pointer to color palette */
  600.  
  601.     float               dpi_x;          /* horiz. resolution in dots per inch */
  602.     float               dpi_y;          /* vert. resolution in dots per inch */
  603.                                         /* dpi is 0 if unknown */
  604.  
  605.     pdf_bool            in_use;         /* image slot currently in use */
  606.  
  607.     char                *params;        /* K and BlackIs1 for TIFF and CCITT */
  608.     int                 strips;         /* number of strips in image */
  609.     int                 rowsperstrip;   /* number of rows per strip */
  610.     id                  colormap_id;    /* reuse colormap for multiple strips */
  611.  
  612.     /* image format specific information */
  613.     union {
  614.         pdf_jpeg_info   jpeg;
  615.  
  616.         pdf_gif_info    gif;
  617.  
  618. #ifdef HAVE_LIBPNG
  619.         pdf_png_info    png;
  620. #endif
  621.  
  622. #ifdef HAVE_LIBTIFF
  623.         pdf_tiff_info   tiff;
  624. #endif
  625.  
  626.         pdf_ccitt_info  ccitt;
  627.     } info;
  628.  
  629.     int                 no;             /* PDF image number */
  630.     PDF_data_source     src;
  631. };
  632.  
  633. /* ------ Private functions for library-internal use only --------- */
  634.  
  635. /* p_basic.c */
  636. void    pdf_begin_contents_section(PDF *p);
  637. void    pdf_end_contents_section(PDF *p);
  638. void    pdf_error(PDF *, int level, const char *fmt, ...);
  639. id      pdf_begin_obj(PDF *p, id obj_id);
  640. id      pdf_alloc_id(PDF *p);
  641. void    pdf_grow_pages(PDF *p);
  642.  
  643. /* p_color.c */
  644. void    pdf_init_cstate(PDF *p);
  645.  
  646. /* p_draw.c */
  647. void    pdf_end_path(PDF *p, pdf_bool force_endpath);
  648.  
  649. /* p_text.c */
  650. void    pdf_init_tstate(PDF *p);
  651. void    pdf_begin_text(PDF *p, pdf_bool setpos);
  652. void    pdf_end_text(PDF *p);
  653. void    pdf_quote_string(PDF *p, const char *string);
  654. void    pdf_set_leading(PDF *p, float leading);
  655. void    pdf_set_text_rise(PDF *p, float rise);
  656. void    pdf_set_horiz_scaling(PDF *p, float scale);
  657. void    pdf_set_text_rendering(PDF *p, int mode);
  658. void    pdf_set_char_spacing(PDF *p, float spacing);
  659. void    pdf_set_word_spacing(PDF *p, float spacing);
  660. const char *pdf_get_fontname(PDF *p);
  661. const char *pdf_get_fontencoding(PDF *p);
  662. float   pdf_get_fontsize(PDF *p);
  663. int     pdf_get_font(PDF *p);
  664.  
  665.  
  666. /* p_gstate.c */
  667. void    pdf_init_gstate(PDF *p);
  668. void    pdf_concat_raw(PDF *p, pdf_matrix m);
  669.  
  670. /* p_image.c */
  671. void    pdf_init_images(PDF *p);
  672. void    pdf_cleanup_images(PDF *p);
  673. void    pdf_init_xobjects(PDF *p);
  674. void    pdf_write_xobjects(PDF *p);
  675. void    pdf_grow_xobjects(PDF *p);
  676. void    pdf_cleanup_xobjects(PDF *p);
  677. void    pdf_put_image(PDF *p, int im, pdf_bool firststrip);
  678. void    pdf_grow_images(PDF *p);
  679.  
  680.  
  681. /* p_filter.c */
  682. void    pdf_ASCII85Encode(PDF *p, PDF_data_source *src);
  683. void    pdf_ASCIIHexEncode(PDF *p, PDF_data_source *src);
  684.  
  685. void    pdf_data_source_file_init(PDF *p, PDF_data_source *src);
  686. int     pdf_data_source_file_fill(PDF *p, PDF_data_source *src);
  687. void    pdf_data_source_file_terminate(PDF *p, PDF_data_source *src);
  688.  
  689. void    pdf_copy(PDF *p, PDF_data_source *src);
  690. void    pdf_compress(PDF *p, PDF_data_source *src);
  691.  
  692. /* p_font.c */
  693. void    pdf_init_fonts(PDF *p);
  694. void    pdf_init_font_struct(PDF *p, pdf_font *font);
  695. void    pdf_write_page_fonts(PDF *p);
  696. void    pdf_write_doc_fonts(PDF *p);
  697. void    pdf_cleanup_fonts(PDF *p);
  698. void    pdf_make_fontflags(PDF *p, pdf_font *font);
  699.  
  700. /* p_afm.c */
  701. pdf_bool        pdf_get_metrics_afm(PDF *p, pdf_font *font, const char *fontname, int enc, const char *filename);
  702. void    pdf_cleanup_font_struct(PDF *p, pdf_font *font);
  703.  
  704. /* p_pfm.c */
  705. pdf_bool pdf_get_metrics_pfm(PDF *p, pdf_font *font, const char *fontname, int enc, const char *filename);
  706.  
  707. /* p_annots.c */
  708. void    pdf_init_annots(PDF *p);
  709. void    pdf_init_page_annots(PDF *p);
  710. void    pdf_write_page_annots(PDF *p);
  711. void    pdf_cleanup_page_annots(PDF *p);
  712.  
  713. /* p_hyper.c */
  714. void    pdf_init_transition(PDF *p);
  715. void    pdf_init_outlines(PDF *p);
  716. void    pdf_write_outlines(PDF *p);
  717. void    pdf_cleanup_outlines(PDF *p);
  718.  
  719. void    pdf_init_info(PDF *p);
  720. void    pdf_write_info(PDF *p);
  721. void    pdf_cleanup_info(PDF *p);
  722.  
  723. void    pdf_set_transition(PDF *p, const char *type);
  724. void    pdf_set_duration(PDF *p, float t);
  725.  
  726. /* p_stream.c */
  727. long    pdf_tell(PDF *p);
  728. void    pdf_write(PDF *p, const void *data, size_t size);
  729. void    pdf_puts(PDF *p, const char *s);
  730. void    pdf_putc(PDF *p, char c);
  731. void    pdf_printf(PDF *p, const char *fmt, ...);
  732.  
  733. void    pdf_init_stream(PDF *p);
  734. void    pdf_flush_stream(PDF *p);
  735. void    pdf_close_stream(PDF *p);
  736.  
  737. #ifdef PDFLIB_EBCDIC
  738. void    pdf_ebcdic2ascii(char *s);
  739. #endif
  740.  
  741. #ifdef HAVE_LIBZ
  742. void    pdf_compress_init(PDF *p);
  743. void    pdf_compress_end(PDF *p);
  744. #endif
  745.  
  746. /* p_util.c */
  747. const char   *pdf_float(char *buf, float f);
  748. char   *pdf_strdup(PDF *p, const char *text);
  749. size_t  pdf_strlen(const char *text);
  750.  
  751. char   *pdf_find_resource(PDF *p, const char *category, const char *resourcename, pdf_bool loadupr);
  752. void    pdf_add_resource(PDF *p, const char *category, const char *resource,
  753.                 const char *filename, const char *prefix);
  754. void    pdf_cleanup_resources(PDF *p);
  755. int     pdf_load_encoding(PDF *p, const char *filename, const char *encoding);
  756.  
  757. #ifdef HAVE_LIBTIFF
  758. /* p_tiff.c */
  759. int pdf_open_TIFF_data(PDF *p, int imageslot, const char *filename, const char *stringparam, int intparam);
  760. #endif
  761.  
  762. /* p_gif.c */
  763. int pdf_open_GIF_data(PDF *p, int imageslot, const char *filename, const char *stringparam, int intparam);
  764.  
  765. /* p_jpeg.c */
  766. int pdf_open_JPEG_data(PDF *p, int imageslot, const char *filename, const char *stringparam, int intparam);
  767.  
  768. #ifdef HAVE_LIBPNG
  769. /* p_png.c */
  770. int pdf_open_PNG_data(PDF *p, int imageslot, const char *filename, const char *stringparam, int intparam);
  771. #endif
  772.  
  773. #endif  /* P_INTERN_H */
  774.