1 /*
2  * << H a r u -- Free PDF Library >> -- libharu.h
3  *
4  * Copyright (c) 1999-2003 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.
11  * It is provided "as is" without express or implied warranty.
12  *
13  */
14 
15 #ifndef _LIB_HARU_H
16 #define _LIB_HARU_H
17 
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 // Peter Beerli added
22 #include "../conf.h"
23 
24 #ifdef __cplusplus
25 #include <exception>
26 
27 #ifdef _BCC32
28 #include <exceptio.h>
29 #endif /* _BCC32 */
30 #endif /* __cplusplus */
31 
32 /*----------------------------------------------------------------------------*/
33 /*------ typedef elements which depending on platform ------------------------*/
34 
35 typedef int             PdfOID;
36 typedef char            PdfEntryType;
37 typedef unsigned char   pdf_uint8;
38 typedef unsigned short  pdf_uint16;
39 typedef unsigned long   pdf_uint32;
40 
41 #ifndef FLT_MIN
42 #define PDF_PARAM_NODEF 1.17549435e-38F
43 #else
44 #define PDF_PARAM_NODEF FLT_MIN
45 #endif /* FLT_MIN */
46 
47 #ifndef INT_MIN
48 #define PDF_INT_MIN     -2147483647
49 #else
50 #define PDF_INT_MIN     INT_MIN
51 #endif /* INT_MIN */
52 
53 /*----------------------------------------------------------------------------*/
54 /*---- Using external libraries or not. --------------------------------------*/
55 
56 #ifdef NOZLIB
57 #define PDF_ZLIB_MODE           0
58 #else
59 #define PDF_ZLIB_MODE           1
60 #include <zlib.h>
61 #endif /* NOZLIB */
62 
63 #ifndef NOPNG
64 #include <png.h>
65 #endif /* NOPNG */
66 
67 #ifndef NOJPEG
68 #ifdef __cplusplus
69 extern "C" {
70 #endif /* __cplusplus */
71 #include <jpeglib.h>
72 #ifdef __cplusplus
73 }
74 #endif /* __cplusplus */
75 #endif
76 
77 /*----------------------------------------------------------------------------*/
78 /*---- error number definition -----------------------------------------------*/
79 
80 #define PDF_ERR_MALLOC                  -1
81 #define PDF_ERR_NEW_OBJECT              -2
82 #define PDF_ERR_FILE_OPEN               -3
83 #define PDF_ERR_INVALID_RANGE           -4
84 #define PDF_RUNTIME_ERROR               -5
85 #define PDF_ERR_OUT_OF_RANGE            -6
86 #define PDF_INTERNAL_ERROR              -7
87 #define PDF_DEFLATEER_ERROR             -8
88 #define PDF_INVALID_PARAMETER           -9
89 #define PDF_ERR_LIST_ADD                -10
90 #define PDF_ERR_INVALID_OBJECT          -11
91 #define PDF_ERR_INVALID_FONT_WIDTHS     -12
92 #define PDF_ERR_INVALID_OPERATION       -13
93 #define PDF_ERR_INVALID_GRAPHIC_MODE    -14
94 #define PDF_ERR_INVALID_WMF_FILE        -15
95 #define PDF_ERR_INVALID_CMAP_OBJECT     -16
96 #define PDF_ERR_NOT_SUPPORTED_FUNCTION  -17
97 #define PDF_UNKNOWN_ERROR           PDF_INT_MIN
98 
99 /*----------------------------------------------------------------------------*/
100 /*------ PreDefined page size ------------------------------------------------*/
101 
102 #define PDF_PAGE_WIDTH_A4       596
103 #define PDF_PAGE_HEIGHT_A4      842
104 #define PDF_PAGE_WIDTH_LETTER   612
105 #define PDF_PAGE_HEIGHT_LETTER  792
106 
107 #ifdef A4PAPER
108 #define PDF_DEFAULT_PAGE_WIDTH  PDF_PAGE_WIDTH_A4
109 #define PDF_DEFAULT_PAGE_HEIGHT PDF_PAGE_HEIGHT_A4
110 #else
111 #define PDF_DEFAULT_PAGE_WIDTH  PDF_PAGE_WIDTH_LETTER
112 #define PDF_DEFAULT_PAGE_HEIGHT PDF_PAGE_HEIGHT_LETTER
113 #endif
114 /*----------------------------------------------------------------------------*/
115 /*------ default values ------------------------------------------------------*/
116 
117 #define PDF_DEF_BUF_SIZE        1024
118 #define PDF_DEFLATOR_BUF_SIZE   8192
119 
120 /*----------------------------------------------------------------------------*/
121 /*------ collection of flags defining various characteristics of the font. ---*/
122 
123 #define PDF_FONT_FIXED_WIDTH    1
124 #define PDF_FONT_SERIF          2
125 #define PDF_FONT_SYMBOLIC       4
126 #define PDF_FONT_SCRIPT         8
127   /* Reserved                   16 */
128 #define PDF_FONT_STD_CHARSET    32
129 #define PDF_FONT_ITALIC         64
130   /* Reserved                   128
131      Reserved                   256
132      Reserved                   512
133      Reserved                   1024
134      Reserved                   2048
135      Reserved                   4096
136      Reserved                   8192
137      Reserved                   16384
138      Reserved                   32768 */
139 #define PDF_FONT_ALL_CAP        65536
140 #define PDF_FONT_SMALL_CAP      131072
141 #define PDF_FONT_FOURCE_BOLD    262144
142 
143 /*----------------------------------------------------------------------------*/
144 /*------ limitation of object implementation ---------------------------------*/
145 
146 #define PDF_LIMIT_MAX_ARRAY         8191
147 #define PDF_LIMIT_MAX_DICT_ELEMENT  4095
148 #define PDF_LIMIT_STRING_MAX        65535
149 #define PDF_LIMIT_MAX_NAME          127
150 #define PDF_LIMIT_MAX_XREF          250000
151 #define PDF_LIMIT_MAX_REAL          32767
152 #define PDF_LIMIT_MIN_REAL          -32767
153 
154 /*----------------------------------------------------------------------------*/
155 /*------ limitation of various properties ------------------------------------*/
156 
157 #define PDF_MIN_HORIZONTALSCALING   10
158 #define PDF_MAX_HORIZONTALSCALING   300
159 #define PDF_MIN_WORDSPACE           -30
160 #define PDF_MAX_WORDSPACE           300
161 #define PDF_MIN_CHARSPACE           -30
162 #define PDF_MAX_CHARSPACE           300
163 #define PDF_MAX_FONTSIZE            300
164 #define PDF_MAX_ZOOMSIZE            10
165 #define PDF_MAX_LEADING             300
166 #define PDF_MAX_LINEWIDTH           100
167 
168 /*----------------------------------------------------------------------------*/
169 /*------ default values ------------------------------------------------------*/
170 
171 #define PDF_DEF_FONT_SIZE           10
172 #define PDF_DEF_FONT                "Hervetica"
173 #define PDF_DEF_PAGE_LAYOUT         PDF_SINGLE_PAGE
174 #define PDF_DEF_PAGE_MODE           PDF_USE_NONE
175 #define PDF_DEF_WORDSPACE           0
176 #define PDF_DEF_CHARSPACE           0
177 #define PDF_DEF_FONTSIZE            10
178 #define PDF_DEF_HSCALING            100
179 #define PDF_DEF_LEADING             0
180 #define PDF_DEF_RENDERING_MODE      PDF_FILL
181 #define PDF_DEF_RAISE               0
182 #define PDF_DEF_LINEWIDTH           1
183 #define PDF_DEF_LINECAP             PDF_BUTT_END
184 #define PDF_DEF_LINEJOIN            PDF_MITER_JOIN
185 #define PDF_DEF_MITERLIMIT          10
186 #define PDF_DEF_PAGE_NUM            1
187 
188 #define LIB_HARU_VERSION_TXT        "HARU Free PDF Library Version 1.2.0 Beta5"
189 #define PDF_ERROR_MSG_MAX           512
190 #define PDF_DEFAULT_ITEMS_PER_BLOCK 20
191 #define PDF_UNICODE_HEADER_LEN      2
192 
193 /*----------------------------------------------------------------------------*/
194 /*------ The pagemode determines. --------------------------------------------*/
195 
196 enum pdf_page_mode_enum {
197     PDF_USE_NONE = 0,
198     PDF_USE_OUTLINES,
199     PDF_USE_THUMBS,
200     PDF_FULL_SCREEN
201 };
202 typedef enum pdf_page_mode_enum pdf_page_mode;
203 
204 /*----------------------------------------------------------------------------*/
205 /*------ The line cap style --------------------------------------------------*/
206 
207 enum pdf_line_cap_style_enum {
208     PDF_BUTT_END,
209     PDF_ROUND_END,
210     PDF_PROJECTING_SCUARE_END
211 };
212 typedef enum pdf_line_cap_style_enum pdf_line_cap_style;
213 
214 /*----------------------------------------------------------------------------*/
215 /*------ The line join style -------------------------------------------------*/
216 
217 enum pdf_line_join_style_enum {
218     PDF_MITER_JOIN = 0,
219     PDF_ROUND_JOIN,
220     PDF_BEVEL_JOIN
221 };
222 typedef enum pdf_line_join_style_enum pdf_line_join_style;
223 
224 /*----------------------------------------------------------------------------*/
225 /*------ The text rendering mode ---------------------------------------------*/
226 
227 enum pdf_text_rendering_mode_enum {
228     PDF_FILL = 0,
229     PDF_STROKE,
230     PDF_FILL_THEN_STROKE,
231     PDF_INVISIBLE,
232     PDF_FILL_CLIPPING,
233     PDF_STROKE_CLIPPING,
234     PDF_FILL_STROKE_CLIPPING,
235     PDF_CLIPPING,
236     PDF_RENDERING_MODE_EOF
237 };
238 typedef enum pdf_text_rendering_mode_enum pdf_text_rendering_mode;
239 
240 /*----------------------------------------------------------------------------*/
241 /*------ border stype --------------------------------------------------------*/
242 
243 enum pdf_bs_subtype_enum {
244     PDF_BS_SOLID,
245     PDF_BS_DASHED,
246     PDF_BS_BEVELED,
247     PDF_BS_INSET,
248     PDF_BS_UNDERLINED
249 };
250 typedef enum pdf_bs_subtype_enum pdf_bs_subtype;
251 
252 /*----------------------------------------------------------------------------*/
253 /*------ The annotation types ------------------------------------------------*/
254 
255 enum pdf_annot_type_enum {
256     PDF_ANNOT_TEXT_NOTES,
257     PDF_ANNOT_LINK,
258     PDF_ANNOT_SOUND,
259     PDF_ANNOT_FREE_TEXT,
260     PDF_ANNOT_STAMP,
261     PDF_ANNOT_SQUARE,
262     PDF_ANNOT_CIRCLE,
263     PDF_ANNOT_STRIKE_OUT,
264     PDF_ANNOT_HIGHTLIGHT,
265     PDF_ANNOT_UNDERLINE,
266     PDF_ANNOT_INK,
267     PDF_ANNOT_FILE_ATTACHMENT,
268     PDF_ANNOT_POPUP
269 };
270 typedef enum pdf_annot_type_enum pdf_annot_type;
271 
272 enum pdf_annot_flgs_enum {
273     PDF_ANNOT_INVISIBLE,
274     PDF_ANNOT_HIDDEN,
275     PDF_ANNOT_PRINT,
276     PDF_ANNOT_NOZOOM,
277     PDF_ANNOT_NOROTATE,
278     PDF_ANNOT_NOVIEW,
279     PDF_ANNOT_READONLY
280 };
281 typedef enum pdf_annot_flgs_enum pdf_annot_flgs;
282 
283 enum pdf_annot_hl_mode_enum {
284     PDF_ANNOT_NO_HIGHTLIGHT,
285     PDF_ANNOT_INVERT_BOX,
286     PDF_ANNOT_INVERT_BORDER,
287     PDF_ANNOT_DOWN_APPEARANCE,
288     PDF_ANNOT_HL_EOF
289 };
290 typedef enum pdf_annot_hl_mode_enum pdf_annot_hl_mode;
291 
292 enum pdf_annot_icon_names_enum {
293     PDF_ANNOT_ICON_COMMENT,
294     PDF_ANNOT_ICON_KEY,
295     PDF_ANNOT_ICON_NOTE,
296     PDF_ANNOT_ICON_HELP,
297     PDF_ANNOT_ICON_NEW_PARAGRAPH,
298     PDF_ANNOT_ICON_PARAGRAPH,
299     PDF_ANNOT_ICON_INSERT,
300     PDF_ANNOT_ICON_EOF
301 };
302 typedef enum pdf_annot_icon_names_enum pdf_annot_icon_names;
303 
304 /*----------------------------------------------------------------------------*/
305 /*------ pdf_destination_type ------------------------------------------------*/
306 
307 enum pdf_destination_type_enum {
308     PDF_XYZ = 0,
309     PDF_FIT,
310     PDF_FIT_H,
311     PDF_FIT_V,
312     PDF_FIT_R,
313     PDF_FIT_B,
314     PDF_FIT_BH,
315     PDF_FIT_BV,
316     PDF_DST_EOF
317 };
318 typedef enum pdf_destination_type_enum pdf_destination_type;
319 
320 /*----------------------------------------------------------------------------*/
321 /*------ pdf_page_layout -----------------------------------------------------*/
322 
323 enum pdf_page_layout_enum {
324     PDF_SINGLE_PAGE,
325     PDF_ONE_COLUMN,
326     PDF_TWO_COLUMN_LEFT,
327     PDF_TWO_COLUMN_RIGHT
328 };
329 typedef enum pdf_page_layout_enum pdf_page_layout;
330 
331 /*----------------------------------------------------------------------------*/
332 /*------ viewer preferences definitions --------------------------------------*/
333 
334 #define PDF_HIDE_TOOLBAR    1
335 #define PDF_HIDE_MENUBAR    2
336 #define PDF_HIDE_WINDOW_UI  4
337 #define PDF_FIT_WINDOW      8
338 #define PDF_CENTER_WINDOW   16
339 
340 /*----------------------------------------------------------------------------*/
341 /*------ pdf_page_num_style definition ---------------------------------------*/
342 
343 enum pdf_page_num_style_enum {
344     PDF_PAGE_NUM_DECIMAL = 0,
345     PDF_PAGE_NUM_UPPER_ROMAN,
346     PDF_PAGE_NUM_LOWER_ROMAN,
347     PDF_PAGE_NUM_UPPER_LETTERS,
348     PDF_PAGE_NUM_LOWER_LETTERS
349 };
350 typedef enum pdf_page_num_style_enum pdf_page_num_style;
351 
352 /*----------------------------------------------------------------------------*/
353 /*------ pdf_color_space definition ------------------------------------------*/
354 
355 enum pdf_color_space_enum {
356     PDF_CS_DEVICE_GRAY = 0,
357     PDF_CS_DEVICE_RGB,
358     PDF_CS_DEVICE_CMYK,
359     PDF_CS_CAL_GRAY,
360     PDF_CS_CAL_RGB,
361     PDF_CS_LAB,
362     PDF_CS_ICC_BASED,
363     PDF_CS_SEPARATION,
364     PDF_CS_DEVICE_N,
365     PDF_CS_INDEXED,
366     PDF_CS_PATTERN,
367     PDF_CS_EOF
368 };
369 typedef enum pdf_color_space_enum pdf_color_space;
370 
371 /*----------------------------------------------------------------------------*/
372 /*------ bits-per-component definition ---------------------------------------*/
373 
374 #define PDF_BITS_1      1
375 #define PDF_BITS_2      2
376 #define PDF_BITS_4      4
377 #define PDF_BITS_8      8
378 
379 /*----------------------------------------------------------------------------*/
380 /*------ predefined font encoding --------------------------------------------*/
381 
382 enum pdf_encoding_enum {
383     PDF_STANDARD_ENCODING = 0,
384     PDF_MAC_ROMAN_ENCODING,
385     PDF_WIN_ANSI_ENCODING,
386     PDF_FONT_SPECIFIC,
387     PDF_ENCODING_EOF
388 };
389 typedef enum pdf_encoding_enum pdf_encoding;
390 
391 /*----------------------------------------------------------------------------*/
392 /*----- Writing Mode ---------------------------------------------------------*/
393 
394 enum pdf_writing_mode_enum {
395     PDF_WMODE_HORIZONTAL = 0,
396     PDF_WMODE_VERTICAL
397 };
398 typedef enum pdf_writing_mode_enum pdf_writing_mode;
399 
400 /*----------------------------------------------------------------------------*/
401 /*----- Graphics Mode --------------------------------------------------------*/
402 
403 enum pdf_graphics_mode_enum {
404     PDF_GMODE_PAGE_DESCRIPTION = 0,
405     PDF_GMODE_PATH_OBJECT,
406     PDF_GMODE_TEXT_OBJECT,
407     PDF_GMODE_CLIPPING_PATH,
408     PDF_GMODE_SHADING,
409     PDF_GMODE_INLINE_IMAGE,
410     PDF_GMODE_EXTERNAL_OBJECT,
411     PDF_GMODE_EOF
412 };
413 typedef enum pdf_graphics_mode_enum pdf_graphics_mode;
414 
415 /*----------------------------------------------------------------------------*/
416 /*----- filter type definition -----------------------------------------------*/
417 
418 #define PDF_FILTER_NONE         0
419 #define PDF_FILTER_DEFLATE      2
420 #define PDF_FILTER_DCT_DECODE   8
421 
422 typedef unsigned int      pdf_filter;
423 
424 /*----------------------------------------------------------------------------*/
425 /*----- proc set element definition ------------------------------------------*/
426 
427 #define PDF_PROCSET_PDF         2
428 #define PDF_PROCSET_TEXT        4
429 #define PDF_PROCSET_IMAGEB      8
430 #define PDF_PROCSET_IMAGEC      16
431 #define PDF_PROCSET_IMAGEI      32
432 
433 /*----------------------------------------------------------------------------*/
434 /*----- pdf_point struct -----------------------------------------------------*/
435 
436 struct pdf_point_struct {
437         double x;
438         double y;
439 };
440 typedef struct pdf_point_struct pdf_point;
441 
442 /*----------------------------------------------------------------------------*/
443 /*----- pdf_rect struct ------------------------------------------------------*/
444 
445 struct pdf_rect_struct {
446         double left;
447         double bottom;
448         double right;
449         double top;
450 };
451 typedef struct pdf_rect_struct pdf_rect;
452 
453 /*----------------------------------------------------------------------------*/
454 /*----- pdf_box struct -------------------------------------------------------*/
455 
456 struct pdf_box_struct {
457         int left;
458         int bottom;
459         int right;
460         int top;
461 };
462 typedef struct pdf_box_struct pdf_box;
463 
464 /*----------------------------------------------------------------------------*/
465 /*----- pdf_text_matrix struct -----------------------------------------------*/
466 
467 struct pdf_text_matrix_struct {
468         double a;
469         double b;
470         double c;
471         double d;
472         double x;
473         double y;
474 };
475 typedef struct pdf_text_matrix_struct pdf_text_matrix;
476 
477 /*----------------------------------------------------------------------------*/
478 /*----- pdf_text_width struct ------------------------------------------------*/
479 
480 struct pdf_text_width_struct {
481         int numchars;
482         int numwords;
483         int width;
484 };
485 typedef struct pdf_text_width_struct pdf_text_width;
486 
487 /*----------------------------------------------------------------------------*/
488 /*----- pdf_date struct ------------------------------------------------------*/
489 
490 struct pdf_date_struct {
491         int year;
492         int month;
493         int day;
494         int hour;
495         int minutes;
496         int seconds;
497         char ind;
498         int off_hour;
499         int off_minutes;
500 };
501 typedef struct pdf_date_struct pdf_date;
502 
503 /*----------------------------------------------------------------------------*/
504 /*----- pdf_rgb_color struct -------------------------------------------------*/
505 
506 struct pdf_pal_color_struct {
507         unsigned char red;
508         unsigned char green;
509         unsigned char blue;
510 };
511 typedef struct pdf_pal_color_struct pdf_pal_color;
512 
513 struct pdf_rgb_color_struct {
514         double red;
515         double green;
516         double blue;
517 };
518 typedef struct pdf_rgb_color_struct pdf_rgb_color;
519 
520 /*---------------------------------------------------------------------------*/
521 /*----- definition for multibyte fonts --------------------------------------*/
522 
523 typedef unsigned short pdf_cid;
524 
525 typedef struct pdf_cid_range_struct {
526     unsigned short from;
527     unsigned short to;
528     pdf_cid cid;
529 } pdf_cid_range;
530 
531 typedef struct pdf_mb_unicode_struct1 {
532     unsigned short mbchar;
533     unsigned short unicode;
534 } pdf_mb_unicode_map1;
535 
536 typedef struct pdf_mb_unicode_struct2 {
537     unsigned short from;
538     unsigned short to;
539     unsigned short unicode;
540 } pdf_mb_unicode_map2;
541 
542 typedef enum pdf_cid_widths_type_enum {
543     PDF_CID_W_TYPE_FROM_TO = 0,
544     PDF_CID_W_TYPE_FROM_ARRAY
545 } pdf_cid_widths_type;
546 
547 typedef struct pdf_cid_width_struct {
548     pdf_cid_widths_type type;
549     pdf_cid from_cid;
550     pdf_cid to_cid;
551     unsigned int* widths;
552 } pdf_cid_width;
553 
554 typedef enum pdf_byte_type_enum {
555     PDF_BYTE_TYPE_SINGLE = 0,
556     PDF_BYTE_TYPE_LEAD,
557     PDF_BYTE_TYPE_TRIAL
558 } pdf_byte_type;
559 
560 /*----------------------------------------------------------------------------*/
561 /*----- definition for font encoding -----------------------------------------*/
562 
563 #define PDF_CHAR_NOTDEF ".notdef"
564 
565 /*----------------------------------------------------------------------------*/
566 /*----- country code definition ----------------------------------------------*/
567 
568 #define PDF_COUNTRY_AF  "AF"    /* AFGHANISTAN */
569 #define PDF_COUNTRY_AL  "AL"    /* ALBANIA */
570 #define PDF_COUNTRY_DZ  "DZ"    /* ALGERIA */
571 #define PDF_COUNTRY_AS  "AS"    /* AMERICAN SAMOA */
572 #define PDF_COUNTRY_AD  "AD"    /* ANDORRA */
573 #define PDF_COUNTRY_AO  "AO"    /* ANGOLA */
574 #define PDF_COUNTRY_AI  "AI"    /* ANGUILLA */
575 #define PDF_COUNTRY_AQ  "AQ"    /* ANTARCTICA */
576 #define PDF_COUNTRY_AG  "AG"    /* ANTIGUA AND BARBUDA */
577 #define PDF_COUNTRY_AR  "AR"    /* ARGENTINA */
578 #define PDF_COUNTRY_AM  "AM"    /* ARMENIA */
579 #define PDF_COUNTRY_AW  "AW"    /* ARUBA */
580 #define PDF_COUNTRY_AU  "AU"    /* AUSTRALIA */
581 #define PDF_COUNTRY_AT  "AT"    /* AUSTRIA */
582 #define PDF_COUNTRY_AZ  "AZ"    /* AZERBAIJAN */
583 #define PDF_COUNTRY_BS  "BS"    /* BAHAMAS */
584 #define PDF_COUNTRY_BH  "BH"    /* BAHRAIN */
585 #define PDF_COUNTRY_BD  "BD"    /* BANGLADESH */
586 #define PDF_COUNTRY_BB  "BB"    /* BARBADOS */
587 #define PDF_COUNTRY_BY  "BY"    /* BELARUS */
588 #define PDF_COUNTRY_BE  "BE"    /* BELGIUM */
589 #define PDF_COUNTRY_BZ  "BZ"    /* BELIZE */
590 #define PDF_COUNTRY_BJ  "BJ"    /* BENIN */
591 #define PDF_COUNTRY_BM  "BM"    /* BERMUDA */
592 #define PDF_COUNTRY_BT  "BT"    /* BHUTAN */
593 #define PDF_COUNTRY_BO  "BO"    /* BOLIVIA */
594 #define PDF_COUNTRY_BA  "BA"    /* BOSNIA AND HERZEGOWINA */
595 #define PDF_COUNTRY_BW  "BW"    /* BOTSWANA */
596 #define PDF_COUNTRY_BV  "BV"    /* BOUVET ISLAND */
597 #define PDF_COUNTRY_BR  "BR"    /* BRAZIL */
598 #define PDF_COUNTRY_IO  "IO"    /* BRITISH INDIAN OCEAN TERRITORY */
599 #define PDF_COUNTRY_BN  "BN"    /* BRUNEI DARUSSALAM */
600 #define PDF_COUNTRY_BG  "BG"    /* BULGARIA */
601 #define PDF_COUNTRY_BF  "BF"    /* BURKINA FASO */
602 #define PDF_COUNTRY_BI  "BI"    /* BURUNDI */
603 #define PDF_COUNTRY_KH  "KH"    /* CAMBODIA */
604 #define PDF_COUNTRY_CM  "CM"    /* CAMEROON */
605 #define PDF_COUNTRY_CA  "CA"    /* CANADA */
606 #define PDF_COUNTRY_CV  "CV"    /* CAPE VERDE */
607 #define PDF_COUNTRY_KY  "KY"    /* CAYMAN ISLANDS */
608 #define PDF_COUNTRY_CF  "CF"    /* CENTRAL AFRICAN REPUBLIC */
609 #define PDF_COUNTRY_TD  "TD"    /* CHAD */
610 #define PDF_COUNTRY_CL  "CL"    /* CHILE */
611 #define PDF_COUNTRY_CN  "CN"    /* CHINA */
612 #define PDF_COUNTRY_CX  "CX"    /* CHRISTMAS ISLAND */
613 #define PDF_COUNTRY_CC  "CC"    /* COCOS (KEELING) ISLANDS */
614 #define PDF_COUNTRY_CO  "CO"    /* COLOMBIA */
615 #define PDF_COUNTRY_KM  "KM"    /* COMOROS */
616 #define PDF_COUNTRY_CG  "CG"    /* CONGO */
617 #define PDF_COUNTRY_CK  "CK"    /* COOK ISLANDS */
618 #define PDF_COUNTRY_CR  "CR"    /* COSTA RICA */
619 #define PDF_COUNTRY_CI  "CI"    /* COTE D'IVOIRE */
620 #define PDF_COUNTRY_HR  "HR"    /* CROATIA (local name: Hrvatska) */
621 #define PDF_COUNTRY_CU  "CU"    /* CUBA */
622 #define PDF_COUNTRY_CY  "CY"    /* CYPRUS */
623 #define PDF_COUNTRY_CZ  "CZ"    /* CZECH REPUBLIC */
624 #define PDF_COUNTRY_DK  "DK"    /* DENMARK */
625 #define PDF_COUNTRY_DJ  "DJ"    /* DJIBOUTI */
626 #define PDF_COUNTRY_DM  "DM"    /* DOMINICA */
627 #define PDF_COUNTRY_DO  "DO"    /* DOMINICAN REPUBLIC */
628 #define PDF_COUNTRY_TP  "TP"    /* EAST TIMOR */
629 #define PDF_COUNTRY_EC  "EC"    /* ECUADOR */
630 #define PDF_COUNTRY_EG  "EG"    /* EGYPT */
631 #define PDF_COUNTRY_SV  "SV"    /* EL SALVADOR */
632 #define PDF_COUNTRY_GQ  "GQ"    /* EQUATORIAL GUINEA */
633 #define PDF_COUNTRY_ER  "ER"    /* ERITREA */
634 #define PDF_COUNTRY_EE  "EE"    /* ESTONIA */
635 #define PDF_COUNTRY_ET  "ET"    /* ETHIOPIA */
636 #define PDF_COUNTRY_FK  "FK"   /* FALKLAND ISLANDS (MALVINAS) */
637 #define PDF_COUNTRY_FO  "FO"    /* FAROE ISLANDS */
638 #define PDF_COUNTRY_FJ  "FJ"    /* FIJI */
639 #define PDF_COUNTRY_FI  "FI"    /* FINLAND */
640 #define PDF_COUNTRY_FR  "FR"    /* FRANCE */
641 #define PDF_COUNTRY_FX  "FX"    /* FRANCE, METROPOLITAN */
642 #define PDF_COUNTRY_GF  "GF"    /* FRENCH GUIANA */
643 #define PDF_COUNTRY_PF  "PF"    /* FRENCH POLYNESIA */
644 #define PDF_COUNTRY_TF  "TF"    /* FRENCH SOUTHERN TERRITORIES */
645 #define PDF_COUNTRY_GA  "GA"    /* GABON */
646 #define PDF_COUNTRY_GM  "GM"    /* GAMBIA */
647 #define PDF_COUNTRY_GE  "GE"    /* GEORGIA */
648 #define PDF_COUNTRY_DE  "DE"    /* GERMANY */
649 #define PDF_COUNTRY_GH  "GH"    /* GHANA */
650 #define PDF_COUNTRY_GI  "GI"    /* GIBRALTAR */
651 #define PDF_COUNTRY_GR  "GR"    /* GREECE */
652 #define PDF_COUNTRY_GL  "GL"    /* GREENLAND */
653 #define PDF_COUNTRY_GD  "GD"    /* GRENADA */
654 #define PDF_COUNTRY_GP  "GP"    /* GUADELOUPE */
655 #define PDF_COUNTRY_GU  "GU"    /* GUAM */
656 #define PDF_COUNTRY_GT  "GT"    /* GUATEMALA */
657 #define PDF_COUNTRY_GN  "GN"    /* GUINEA */
658 #define PDF_COUNTRY_GW  "GW"    /* GUINEA-BISSAU */
659 #define PDF_COUNTRY_GY  "GY"    /* GUYANA */
660 #define PDF_COUNTRY_HT  "HT"    /* HAITI */
661 #define PDF_COUNTRY_HM  "HM"    /* HEARD AND MC DONALD ISLANDS */
662 #define PDF_COUNTRY_HN  "HN"    /* HONDURAS */
663 #define PDF_COUNTRY_HK  "HK"    /* HONG KONG */
664 #define PDF_COUNTRY_HU  "HU"    /* HUNGARY */
665 #define PDF_COUNTRY_IS  "IS"    /* ICELAND */
666 #define PDF_COUNTRY_IN  "IN"    /* INDIA */
667 #define PDF_COUNTRY_ID  "ID"    /* INDONESIA */
668 #define PDF_COUNTRY_IR  "IR"    /* IRAN (ISLAMIC REPUBLIC OF) */
669 #define PDF_COUNTRY_IQ  "IQ"    /* IRAQ */
670 #define PDF_COUNTRY_IE  "IE"    /* IRELAND */
671 #define PDF_COUNTRY_IL  "IL"    /* ISRAEL */
672 #define PDF_COUNTRY_IT  "IT"    /* ITALY */
673 #define PDF_COUNTRY_JM  "JM"    /* JAMAICA */
674 #define PDF_COUNTRY_JP  "JP"    /* JAPAN */
675 #define PDF_COUNTRY_JO  "JO"    /* JORDAN */
676 #define PDF_COUNTRY_KZ  "KZ"    /* KAZAKHSTAN */
677 #define PDF_COUNTRY_KE  "KE"    /* KENYA */
678 #define PDF_COUNTRY_KI  "KI"    /* KIRIBATI */
679 #define PDF_COUNTRY_KP  "KP"    /* KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF */
680 #define PDF_COUNTRY_KR  "KR"    /* KOREA, REPUBLIC OF */
681 #define PDF_COUNTRY_KW  "KW"    /* KUWAIT */
682 #define PDF_COUNTRY_KG  "KG"    /* KYRGYZSTAN */
683 #define PDF_COUNTRY_LA  "LA"    /* LAO PEOPLE'S DEMOCRATIC REPUBLIC */
684 #define PDF_COUNTRY_LV  "LV"    /* LATVIA */
685 #define PDF_COUNTRY_LB  "LB"    /* LEBANON */
686 #define PDF_COUNTRY_LS  "LS"    /* LESOTHO */
687 #define PDF_COUNTRY_LR  "LR"    /* LIBERIA */
688 #define PDF_COUNTRY_LY  "LY"    /* LIBYAN ARAB JAMAHIRIYA */
689 #define PDF_COUNTRY_LI  "LI"    /* LIECHTENSTEIN */
690 #define PDF_COUNTRY_LT  "LT"    /* LITHUANIA */
691 #define PDF_COUNTRY_LU  "LU"    /* LUXEMBOURG */
692 #define PDF_COUNTRY_MO  "MO"    /* MACAU */
693 #define PDF_COUNTRY_MK  "MK"   /* MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF */
694 #define PDF_COUNTRY_MG  "MG"    /* MADAGASCAR */
695 #define PDF_COUNTRY_MW  "MW"    /* MALAWI */
696 #define PDF_COUNTRY_MY  "MY"    /* MALAYSIA */
697 #define PDF_COUNTRY_MV  "MV"    /* MALDIVES */
698 #define PDF_COUNTRY_ML  "ML"    /* MALI */
699 #define PDF_COUNTRY_MT  "MT"    /* MALTA */
700 #define PDF_COUNTRY_MH  "MH"    /* MARSHALL ISLANDS */
701 #define PDF_COUNTRY_MQ  "MQ"    /* MARTINIQUE */
702 #define PDF_COUNTRY_MR  "MR"    /* MAURITANIA */
703 #define PDF_COUNTRY_MU  "MU"    /* MAURITIUS */
704 #define PDF_COUNTRY_YT  "YT"    /* MAYOTTE */
705 #define PDF_COUNTRY_MX  "MX"    /* MEXICO */
706 #define PDF_COUNTRY_FM  "FM"    /* MICRONESIA, FEDERATED STATES OF */
707 #define PDF_COUNTRY_MD  "MD"    /* MOLDOVA, REPUBLIC OF */
708 #define PDF_COUNTRY_MC  "MC"    /* MONACO */
709 #define PDF_COUNTRY_MN  "MN"    /* MONGOLIA */
710 #define PDF_COUNTRY_MS  "MS"    /* MONTSERRAT */
711 #define PDF_COUNTRY_MA  "MA"    /* MOROCCO */
712 #define PDF_COUNTRY_MZ  "MZ"    /* MOZAMBIQUE */
713 #define PDF_COUNTRY_MM  "MM"    /* MYANMAR */
714 #define PDF_COUNTRY_NA  "NA"    /* NAMIBIA */
715 #define PDF_COUNTRY_NR  "NR"    /* NAURU */
716 #define PDF_COUNTRY_NP  "NP"    /* NEPAL */
717 #define PDF_COUNTRY_NL  "NL"    /* NETHERLANDS */
718 #define PDF_COUNTRY_AN  "AN"    /* NETHERLANDS ANTILLES */
719 #define PDF_COUNTRY_NC  "NC"    /* NEW CALEDONIA */
720 #define PDF_COUNTRY_NZ  "NZ"    /* NEW ZEALAND */
721 #define PDF_COUNTRY_NI  "NI"    /* NICARAGUA */
722 #define PDF_COUNTRY_NE  "NE"    /* NIGER */
723 #define PDF_COUNTRY_NG  "NG"    /* NIGERIA */
724 #define PDF_COUNTRY_NU  "NU"    /* NIUE */
725 #define PDF_COUNTRY_NF  "NF"    /* NORFOLK ISLAND */
726 #define PDF_COUNTRY_MP  "MP"    /* NORTHERN MARIANA ISLANDS */
727 #define PDF_COUNTRY_NO  "NO"    /* NORWAY */
728 #define PDF_COUNTRY_OM  "OM"    /* OMAN */
729 #define PDF_COUNTRY_PK  "PK"    /* PAKISTAN */
730 #define PDF_COUNTRY_PW  "PW"    /* PALAU */
731 #define PDF_COUNTRY_PA  "PA"    /* PANAMA */
732 #define PDF_COUNTRY_PG  "PG"    /* PAPUA NEW GUINEA */
733 #define PDF_COUNTRY_PY  "PY"    /* PARAGUAY */
734 #define PDF_COUNTRY_PE  "PE"    /* PERU */
735 #define PDF_COUNTRY_PH  "PH"    /* PHILIPPINES */
736 #define PDF_COUNTRY_PN  "PN"    /* PITCAIRN */
737 #define PDF_COUNTRY_PL  "PL"    /* POLAND */
738 #define PDF_COUNTRY_PT  "PT"    /* PORTUGAL */
739 #define PDF_COUNTRY_PR  "PR"    /* PUERTO RICO */
740 #define PDF_COUNTRY_QA  "QA"    /* QATAR */
741 #define PDF_COUNTRY_RE  "RE"    /* REUNION */
742 #define PDF_COUNTRY_RO  "RO"    /* ROMANIA */
743 #define PDF_COUNTRY_RU  "RU"    /* RUSSIAN FEDERATION */
744 #define PDF_COUNTRY_RW  "RW"    /* RWANDA */
745 #define PDF_COUNTRY_KN  "KN"    /* SAINT KITTS AND NEVIS */
746 #define PDF_COUNTRY_LC  "LC"    /* SAINT LUCIA */
747 #define PDF_COUNTRY_VC  "VC"    /* SAINT VINCENT AND THE GRENADINES */
748 #define PDF_COUNTRY_WS  "WS"    /* SAMOA */
749 #define PDF_COUNTRY_SM  "SM"    /* SAN MARINO */
750 #define PDF_COUNTRY_ST  "ST"    /* SAO TOME AND PRINCIPE */
751 #define PDF_COUNTRY_SA  "SA"    /* SAUDI ARABIA */
752 #define PDF_COUNTRY_SN  "SN"    /* SENEGAL */
753 #define PDF_COUNTRY_SC  "SC"    /* SEYCHELLES */
754 #define PDF_COUNTRY_SL  "SL"    /* SIERRA LEONE */
755 #define PDF_COUNTRY_SG  "SG"    /* SINGAPORE */
756 #define PDF_COUNTRY_SK  "SK"    /* SLOVAKIA (Slovak Republic) */
757 #define PDF_COUNTRY_SI  "SI"    /* SLOVENIA */
758 #define PDF_COUNTRY_SB  "SB"    /* SOLOMON ISLANDS */
759 #define PDF_COUNTRY_SO  "SO"    /* SOMALIA */
760 #define PDF_COUNTRY_ZA  "ZA"    /* SOUTH AFRICA */
761 #define PDF_COUNTRY_ES  "ES"    /* SPAIN */
762 #define PDF_COUNTRY_LK  "LK"    /* SRI LANKA */
763 #define PDF_COUNTRY_SH  "SH"    /* ST. HELENA */
764 #define PDF_COUNTRY_PM  "PM"    /* ST. PIERRE AND MIQUELON */
765 #define PDF_COUNTRY_SD  "SD"    /* SUDAN */
766 #define PDF_COUNTRY_SR  "SR"    /* SURINAME */
767 #define PDF_COUNTRY_SJ  "SJ"    /* SVALBARD AND JAN MAYEN ISLANDS */
768 #define PDF_COUNTRY_SZ  "SZ"    /* SWAZILAND */
769 #define PDF_COUNTRY_SE  "SE"    /* SWEDEN */
770 #define PDF_COUNTRY_CH  "CH"    /* SWITZERLAND */
771 #define PDF_COUNTRY_SY  "SY"    /* SYRIAN ARAB REPUBLIC */
772 #define PDF_COUNTRY_TW  "TW"    /* TAIWAN, PROVINCE OF CHINA */
773 #define PDF_COUNTRY_TJ  "TJ"    /* TAJIKISTAN */
774 #define PDF_COUNTRY_TZ  "TZ"    /* TANZANIA, UNITED REPUBLIC OF */
775 #define PDF_COUNTRY_TH  "TH"    /* THAILAND */
776 #define PDF_COUNTRY_TG  "TG"    /* TOGO */
777 #define PDF_COUNTRY_TK  "TK"    /* TOKELAU */
778 #define PDF_COUNTRY_TO  "TO"    /* TONGA */
779 #define PDF_COUNTRY_TT  "TT"    /* TRINIDAD AND TOBAGO */
780 #define PDF_COUNTRY_TN  "TN"    /* TUNISIA */
781 #define PDF_COUNTRY_TR  "TR"    /* TURKEY */
782 #define PDF_COUNTRY_TM  "TM"    /* TURKMENISTAN */
783 #define PDF_COUNTRY_TC  "TC"    /* TURKS AND CAICOS ISLANDS */
784 #define PDF_COUNTRY_TV  "TV"    /* TUVALU */
785 #define PDF_COUNTRY_UG  "UG"    /* UGANDA */
786 #define PDF_COUNTRY_UA  "UA"    /* UKRAINE */
787 #define PDF_COUNTRY_AE  "AE"    /* UNITED ARAB EMIRATES */
788 #define PDF_COUNTRY_GB  "GB"    /* UNITED KINGDOM */
789 #define PDF_COUNTRY_US  "US"    /* UNITED STATES */
790 #define PDF_COUNTRY_UM  "UM"    /* UNITED STATES MINOR OUTLYING ISLANDS */
791 #define PDF_COUNTRY_UY  "UY"    /* URUGUAY */
792 #define PDF_COUNTRY_UZ  "UZ"    /* UZBEKISTAN */
793 #define PDF_COUNTRY_VU  "VU"    /* VANUATU */
794 #define PDF_COUNTRY_VA  "VA"    /* VATICAN CITY STATE (HOLY SEE) */
795 #define PDF_COUNTRY_VE  "VE"    /* VENEZUELA */
796 #define PDF_COUNTRY_VN  "VN"    /* VIET NAM */
797 #define PDF_COUNTRY_VG  "VG"    /* VIRGIN ISLANDS (BRITISH) */
798 #define PDF_COUNTRY_VI  "VI"    /* VIRGIN ISLANDS (U.S.) */
799 #define PDF_COUNTRY_WF  "WF"    /* WALLIS AND FUTUNA ISLANDS */
800 #define PDF_COUNTRY_EH  "EH"    /* WESTERN SAHARA */
801 #define PDF_COUNTRY_YE  "YE"    /* YEMEN */
802 #define PDF_COUNTRY_YU  "YU"    /* YUGOSLAVIA */
803 #define PDF_COUNTRY_ZR  "ZR"    /* ZAIRE */
804 #define PDF_COUNTRY_ZM  "ZM"    /* ZAMBIA */
805 #define PDF_COUNTRY_ZW  "ZW"    /* ZIMBABWE */
806 
807 /*----------------------------------------------------------------------------*/
808 /*----- lang code definition -------------------------------------------------*/
809 
810 #define PDF_LANG_AA    "aa"     /* Afar */
811 #define PDF_LANG_AB    "ab"     /* Abkhazian */
812 #define PDF_LANG_AF    "af"     /* Afrikaans */
813 #define PDF_LANG_AM    "am"     /* Amharic */
814 #define PDF_LANG_AR    "ar"     /* Arabic */
815 #define PDF_LANG_AS    "as"     /* Assamese */
816 #define PDF_LANG_AY    "ay"     /* Aymara */
817 #define PDF_LANG_AZ    "az"     /* Azerbaijani */
818 #define PDF_LANG_BA    "ba"     /* Bashkir */
819 #define PDF_LANG_BE    "be"     /* Byelorussian */
820 #define PDF_LANG_BG    "bg"     /* Bulgarian */
821 #define PDF_LANG_BH    "bh"     /* Bihari */
822 #define PDF_LANG_BI    "bi"     /* Bislama */
823 #define PDF_LANG_BN    "bn"     /* Bengali Bangla */
824 #define PDF_LANG_BO    "bo"     /* Tibetan */
825 #define PDF_LANG_BR    "br"     /* Breton */
826 #define PDF_LANG_CA    "ca"     /* Catalan */
827 #define PDF_LANG_CO    "co"     /* Corsican */
828 #define PDF_LANG_CS    "cs"     /* Czech */
829 #define PDF_LANG_CY    "cy"     /* Welsh */
830 #define PDF_LANG_DA    "da"     /* Danish */
831 #define PDF_LANG_DE    "de"     /* German */
832 #define PDF_LANG_DZ    "dz"     /* Bhutani */
833 #define PDF_LANG_EL    "el"     /* Greek */
834 #define PDF_LANG_EN    "en"     /* English */
835 #define PDF_LANG_EO    "eo"     /* Esperanto */
836 #define PDF_LANG_ES    "es"     /* Spanish */
837 #define PDF_LANG_ET    "et"     /* Estonian */
838 #define PDF_LANG_EU    "eu"     /* Basque */
839 #define PDF_LANG_FA    "fa"     /* Persian */
840 #define PDF_LANG_FI    "fi"     /* Finnish */
841 #define PDF_LANG_FJ    "fj"     /* Fiji */
842 #define PDF_LANG_FO    "fo"     /* Faeroese */
843 #define PDF_LANG_FR    "fr"     /* French */
844 #define PDF_LANG_FY    "fy"     /* Frisian */
845 #define PDF_LANG_GA    "ga"     /* Irish */
846 #define PDF_LANG_GD    "gd"     /* Scots Gaelic */
847 #define PDF_LANG_GL    "gl"     /* Galician */
848 #define PDF_LANG_GN    "gn"     /* Guarani */
849 #define PDF_LANG_GU    "gu"     /* Gujarati */
850 #define PDF_LANG_HA    "ha"     /* Hausa */
851 #define PDF_LANG_HI    "hi"     /* Hindi */
852 #define PDF_LANG_HR    "hr"     /* Croatian */
853 #define PDF_LANG_HU    "hu"     /* Hungarian */
854 #define PDF_LANG_HY    "hy"     /* Armenian */
855 #define PDF_LANG_IA    "ia"     /* Interlingua */
856 #define PDF_LANG_IE    "ie"     /* Interlingue */
857 #define PDF_LANG_IK    "ik"     /* Inupiak */
858 #define PDF_LANG_IN    "in"     /* Indonesian */
859 #define PDF_LANG_IS    "is"     /* Icelandic */
860 #define PDF_LANG_IT    "it"     /* Italian */
861 #define PDF_LANG_IW    "iw"     /* Hebrew */
862 #define PDF_LANG_JA    "ja"     /* Japanese */
863 #define PDF_LANG_JI    "ji"     /* Yiddish */
864 #define PDF_LANG_JW    "jw"     /* Javanese */
865 #define PDF_LANG_KA    "ka"     /* Georgian */
866 #define PDF_LANG_KK    "kk"     /* Kazakh */
867 #define PDF_LANG_KL    "kl"     /* Greenlandic */
868 #define PDF_LANG_KM    "km"     /* Cambodian */
869 #define PDF_LANG_KN    "kn"     /* Kannada */
870 #define PDF_LANG_KO    "ko"     /* Korean */
871 #define PDF_LANG_KS    "ks"     /* Kashmiri */
872 #define PDF_LANG_KU    "ku"     /* Kurdish */
873 #define PDF_LANG_KY    "ky"     /* Kirghiz */
874 #define PDF_LANG_LA    "la"     /* Latin */
875 #define PDF_LANG_LN    "ln"     /* Lingala */
876 #define PDF_LANG_LO    "lo"     /* Laothian */
877 #define PDF_LANG_LT    "lt"     /* Lithuanian */
878 #define PDF_LANG_LV    "lv"     /* Latvian,Lettish */
879 #define PDF_LANG_MG    "mg"     /* Malagasy */
880 #define PDF_LANG_MI    "mi"     /* Maori */
881 #define PDF_LANG_MK    "mk"     /* Macedonian */
882 #define PDF_LANG_ML    "ml"     /* Malayalam */
883 #define PDF_LANG_MN    "mn"     /* Mongolian */
884 #define PDF_LANG_MO    "mo"     /* Moldavian */
885 #define PDF_LANG_MR    "mr"     /* Marathi */
886 #define PDF_LANG_MS    "ms"     /* Malay */
887 #define PDF_LANG_MT    "mt"     /* Maltese */
888 #define PDF_LANG_MY    "my"     /* Burmese */
889 #define PDF_LANG_NA    "na"     /* Nauru */
890 #define PDF_LANG_NE    "ne"     /* Nepali */
891 #define PDF_LANG_NL    "nl"     /* Dutch */
892 #define PDF_LANG_NO    "no"     /* Norwegian */
893 #define PDF_LANG_OC    "oc"     /* Occitan */
894 #define PDF_LANG_OM    "om"     /* (Afan)Oromo */
895 #define PDF_LANG_OR    "or"     /* Oriya */
896 #define PDF_LANG_PA    "pa"     /* Punjabi */
897 #define PDF_LANG_PL    "pl"     /* Polish */
898 #define PDF_LANG_PS    "ps"     /* Pashto,Pushto */
899 #define PDF_LANG_PT    "pt"     /* Portuguese  */
900 #define PDF_LANG_QU    "qu"     /* Quechua */
901 #define PDF_LANG_RM    "rm"     /* Rhaeto-Romance */
902 #define PDF_LANG_RN    "rn"     /* Kirundi */
903 #define PDF_LANG_RO    "ro"     /* Romanian */
904 #define PDF_LANG_RU    "ru"     /* Russian */
905 #define PDF_LANG_RW    "rw"     /* Kinyarwanda */
906 #define PDF_LANG_SA    "sa"     /* Sanskrit */
907 #define PDF_LANG_SD    "sd"     /* Sindhi */
908 #define PDF_LANG_SG    "sg"     /* Sangro */
909 #define PDF_LANG_SH    "sh"     /* Serbo-Croatian */
910 #define PDF_LANG_SI    "si"     /* Singhalese */
911 #define PDF_LANG_SK    "sk"     /* Slovak */
912 #define PDF_LANG_SL    "sl"     /* Slovenian */
913 #define PDF_LANG_SM    "sm"     /* Samoan */
914 #define PDF_LANG_SN    "sn"     /* Shona */
915 #define PDF_LANG_SO    "so"     /* Somali */
916 #define PDF_LANG_SQ    "sq"     /* Albanian */
917 #define PDF_LANG_SR    "sr"     /* Serbian */
918 #define PDF_LANG_SS    "ss"     /* Siswati */
919 #define PDF_LANG_ST    "st"     /* Sesotho */
920 #define PDF_LANG_SU    "su"     /* Sundanese */
921 #define PDF_LANG_SV    "sv"     /* Swedish */
922 #define PDF_LANG_SW    "sw"     /* Swahili */
923 #define PDF_LANG_TA    "ta"     /* Tamil */
924 #define PDF_LANG_TE    "te"     /* Tegulu */
925 #define PDF_LANG_TG    "tg"     /* Tajik */
926 #define PDF_LANG_TH    "th"     /* Thai */
927 #define PDF_LANG_TI    "ti"     /* Tigrinya */
928 #define PDF_LANG_TK    "tk"     /* Turkmen */
929 #define PDF_LANG_TL    "tl"     /* Tagalog */
930 #define PDF_LANG_TN    "tn"     /* Setswanato Tonga */
931 #define PDF_LANG_TR    "tr"     /* Turkish */
932 #define PDF_LANG_TS    "ts"     /* Tsonga */
933 #define PDF_LANG_TT    "tt"     /* Tatar */
934 #define PDF_LANG_TW    "tw"     /* Twi */
935 #define PDF_LANG_UK    "uk"     /* Ukrainian */
936 #define PDF_LANG_UR    "ur"     /* Urdu */
937 #define PDF_LANG_UZ    "uz"     /* Uzbek */
938 #define PDF_LANG_VI    "vi"     /* Vietnamese */
939 #define PDF_LANG_VO    "vo"     /* Volapuk */
940 #define PDF_LANG_WO    "wo"     /* Wolof */
941 #define PDF_LANG_XH    "xh"     /* Xhosa */
942 #define PDF_LANG_YO    "yo"     /* Yoruba */
943 #define PDF_LANG_ZH    "zh"     /* Chinese */
944 #define PDF_LANG_ZU    "zu"     /* Zulu */
945 
946 /*----------------------------------------------------------------------------*/
947 /*----- permission flags (only Revision 2 is supported)-----------------------*/
948 
949 #define PDF_ENABLE_READ         0
950 #define PDF_ENABLE_PRINT        4
951 #define PDF_ENABLE_EDIT_ALL     8
952 #define PDF_ENABLE_COPY         16
953 #define PDF_ENABLE_EDIT         32
954 
955 /*----------------------------------------------------------------------------*/
956 /*----- default values for encrypt -------------------------------------------*/
957 
958 #define PDF_ID_LEN              16
959 #define PDF_PASSWD_LEN          32
960 #define PDF_ENCRYPT_KEY_LEN     5
961 #define PDF_MD5_KEY_LEN         16
962 #define PDF_PERMISSION_PAD      0xFFFFFFC0
963 
964 /*----------------------------------------------------------------------------*/
965 /*----- check macros ---------------------------------------------------------*/
966 
967 #define PDF_CHECK_RECT(RECT) \
968     (RECT.left < RECT.right && RECT.bottom < RECT.top)
969 
970 /*----------------------------------------------------------------------------*/
971 /*----- DEBUG macros ---------------------------------------------------------*/
972 
973 #ifdef DEBUG
974 #define PDF_DEBUG_PRINT(ARGS) printf ARGS
975 #else /* DEBUG == 0 */
976 #define PDF_DEBUG_PRINT(ARGS) void(0)
977 #endif
978 
979 void pdf_print_binary(const unsigned char* buf, int len, char* caption);
980 
981 #ifdef DEBUG
982 #define PDF_PRINT_BINARY(BUF, LEN, CAPTION) pdf_print_binary(BUF, LEN, CAPTION)
983 #else
984 #define PDF_PRINT_BINARY(BUF, LEN, CAPTION) void(0)
985 #endif
986 
987 /*----------------------------------------------------------------------------*/
988 
989 #ifdef __cplusplus
990 
991 #ifdef _NOT_SUPPORT_STD
992 
993 #define PDF_STD_EXCEPTION   exception
994 #define ALLOC_ERROR     exception
995 
996 int throw_new_handler(size_t size);
997 void throw_new_handler();
998 
999 #else /* _NOT_SUPPORT_STD */
1000 
1001 #define ALLOC_ERROR         std::bad_alloc
1002 #define PDF_STD_EXCEPTION   std::exception
1003 
1004 #endif /* _NOT_SUPPORT_STD */
1005 
1006 /*----------------------------------------------------------------------------*/
1007 /*----- auto-ptr object-id ---------------------------------------------------*/
1008 
1009 typedef enum pdf_auto_ptr_object_type_enum {
1010     PDF_OBJECT_UNKNOWN = 0,
1011     PDF_OBJECT_FONT_DEF,
1012     PDF_OBJECT_ENCODING_DEF,
1013     PDF_OBJECT_CMAP,
1014 } pdf_auto_ptr_object_type;
1015 
1016 /*----------------------------------------------------------------------------*/
1017 /*----- PdfException class ---------------------------------------------------*/
1018 
1019 class PdfException : public PDF_STD_EXCEPTION
1020 {
1021 public:
1022                     PdfException(int code, const char* fmt, ...);
1023 #ifdef _NO_EXCEPT_LIST
~PdfException()1024                     ~PdfException() {};
1025         const char* what() const;
1026 #else
throw()1027                     ~PdfException() throw() {};
1028         const char* what() const throw();
1029 #endif
GetCode()1030         int         GetCode()       { return fCode; }
1031 private:
1032         char        fErrorBuf[512];
1033         int         fCode;
1034 };
1035 
1036 /*----------------------------------------------------------------------------*/
1037 /*----- PdfList class --------------------------------------------------------*/
1038 
1039 class PdfList {
1040 
1041 public:
1042                     PdfList(int itemsPerBlock = PDF_DEFAULT_ITEMS_PER_BLOCK);
1043                     ~PdfList();
1044 
1045         bool        AddItem(void* item);
1046         bool        AddItem(void* item, int atIndex);
RemoveItem(const void * item)1047         bool        RemoveItem(const void* item)
1048                             { return (RemoveItem(IndexOf(item)) != NULL); }
1049         void*       RemoveItem(int index);
Clear()1050         void        Clear()             { fCount = 0; }
1051 
ItemAt(int index)1052         void*       ItemAt(int index)
1053                        { return (fCount <= index || index < 0) ? NULL :
1054                            fObjectList[index]; }
HasItem(const void * item)1055         bool        HasItem(const void* item)
1056                                         { return (IndexOf(item) > 0); }
1057         int         IndexOf(const void* item);
CountItems()1058         int         CountItems()        { return fCount; }
IsEmpty()1059         bool        IsEmpty()           { return (fCount != 0); }
1060 
1061 private:
1062         int         fBlockSize;
1063         int         fItemsPerBlock;
1064         int         fCount;
1065         void**      fObjectList;
1066 
1067         bool        Resize(int count);
1068 };
1069 
1070 /*----------------------------------------------------------------------------*/
1071 /*----- PdfStreamBase --------------------------------------------------------*/
1072 
1073 class PdfStreamBase
1074 {
1075 public:
1076                             PdfStreamBase();
1077 virtual                     ~PdfStreamBase();
GetPos()1078         unsigned int        GetPos() { return fNumBytes; }
1079 virtual int                 Write(const void* ptr, int count) = 0;
1080         PdfStreamBase&      operator<<(const char c)
1081                                 { Write(&c, 1); return *this; }
1082         PdfStreamBase&      operator<<(unsigned char c)
1083                                 { return (*this) << (char)c; }
1084         PdfStreamBase&      operator<<(const char* s);
1085         PdfStreamBase&      operator<<(unsigned int i);
1086         PdfStreamBase&      operator<<(int i);
1087         PdfStreamBase&      operator<<(float f)
1088                                 { return (*this) << (double)f; }
1089         PdfStreamBase&      operator<<(double d);
1090 protected:
1091         unsigned int        fNumBytes;
1092         char                fDecimalPoint;
1093 };
1094 
1095 /*----------------------------------------------------------------------------*/
1096 /*----- PdfFileStream class --------------------------------------------------*/
1097 
1098 class PdfFileStream : public PdfStreamBase
1099 {
1100 public:
1101                             PdfFileStream(FILE *file, bool closefile = false);
1102                             PdfFileStream(const char *filename);
1103 virtual                     ~PdfFileStream();
1104 virtual int                 Write(const void* ptr, int count);
1105 private:
1106         FILE*               fFile;
1107         bool                fCloseFile;
1108         int                 fErrorNo;
1109 };
1110 
1111 /*----------------------------------------------------------------------------*/
1112 /*----- PdfEncryptor class ---------------------------------------------------*/
1113 
1114 #ifdef USE_ENCRYPTION
1115 class PdfEncryptor
1116 {
1117 public:
1118                         PdfEncryptor(const unsigned char* key);
1119                         ~PdfEncryptor();
1120         void            Init(PdfOID id, unsigned int gen_no);
1121         void            Reset();
1122         void            CryptBuf(const unsigned char* src,
1123                             unsigned char* dst, unsigned int len);
1124 private:
1125         unsigned char   fKey[PDF_ENCRYPT_KEY_LEN + 5];
1126         unsigned char   fDigest[PDF_MD5_KEY_LEN];
1127         unsigned char*  fARC4Key;
1128 };
1129 #else
1130 typedef void PdfEncryptor;
1131 #endif
1132 
1133 /*----------------------------------------------------------------------------*/
1134 /*----- PdfMemStream class ---------------------------------------------------*/
1135 
1136 class PdfMemStream : public PdfStreamBase
1137 {
1138 public:
1139                         PdfMemStream(const int bufSize = PDF_DEF_BUF_SIZE);
1140 virtual                 ~PdfMemStream();
1141 virtual int             Write(const void* ptr, int count);
GetSize()1142         size_t          GetSize() {
1143                             return (fBuf == NULL) ? 0 :
1144                                 (fBuf->CountItems() - 1) * fBufSize +
1145                                 fCurrentPos;
1146                         }
1147         size_t          WriteToStream(PdfStreamBase* out,
1148                             PdfEncryptor* eobj = NULL);
1149         size_t          WriteToStreamDeflate(PdfStreamBase* out,
1150                             PdfEncryptor* eobj = NULL);
1151         void            FreeData();
BufSize()1152         unsigned int    BufSize()    { return fBufSize; }
1153         const void*     GetBuf(int index, unsigned int* size);
GetBufCount()1154         int             GetBufCount() {
1155                             return (fBuf == NULL) ? 0 : (fBuf->CountItems());
1156                         }
1157 		PdfMemStream*   Duplicate() const;
1158 private:
1159         void            InternalWrite(unsigned char** ptr, int *count);
1160         void            InitStream();
1161         PdfList*        fBuf;
1162         unsigned int    fBufSize;
1163         unsigned int    fCurrentPos;
1164         unsigned char*  fCurrentPtr;
1165 };
1166 
1167 /*----------------------------------------------------------------------------*/
1168 
1169 typedef enum pdf_object_type_enum
1170 {
1171     PDF_OBJ_TYPE_DIRECT,
1172     PDF_OBJ_TYPE_INDIRECT,
1173     PDF_OBJ_TYPE_VIRTUAL
1174 } pdf_object_type;
1175 
1176 typedef enum pdf_object_class_enum
1177 {
1178     ocUnknown,
1179     ocBoolean,
1180     ocNumber,
1181     ocReal,
1182     ocText,
1183     ocBinary,
1184     ocName,
1185     ocArray,
1186     ocDictionary,
1187     ocStream,
1188     ocUnicodeText,
1189     ocNull
1190 } pdf_object_class;
1191 
1192 /*----------------------------------------------------------------------------*/
1193 /*----- PdfObject class ------------------------------------------------------*/
1194 
1195 class PdfObject
1196 {
1197 public:
1198                             PdfObject();
1199                             PdfObject(PdfOID objectID);
1200 virtual                     ~PdfObject();
GetObjectType()1201 virtual pdf_object_type     GetObjectType()     { return (fObjectID > 0 ?
1202                                 PDF_OBJ_TYPE_INDIRECT : PDF_OBJ_TYPE_DIRECT); }
GetClass()1203 virtual pdf_object_class    GetClass()          { return ocUnknown; }
GetObjectID()1204         PdfOID              GetObjectID()       { return fObjectID; }
GetGenerationNo()1205         unsigned int        GetGenerationNo()   { return fGenerationNo; }
IsLockedObject()1206 virtual bool                IsLockedObject()    { return fObjectID < 0; }
1207         void                SetObjectID(PdfOID value);
WriteToStream(PdfStreamBase * out,PdfEncryptor * e)1208         void                WriteToStream(PdfStreamBase* out,
1209                                 PdfEncryptor* e)
1210                                 { InternalWriteStream(out, e); }
1211         void                WriteValueToStream(PdfStreamBase* out,
1212                                 PdfEncryptor* e);
1213         size_t              WriteEscapeName(PdfStreamBase* stream,
1214                                 const char* text);
1215         size_t              WriteEscapeText(PdfStreamBase* stream,
1216                                 const char* text);
1217 protected:
1218         void                WriteBinary(PdfStreamBase* out, unsigned char* buf,
1219                                 unsigned int len, PdfEncryptor* e);
1220 virtual void                InternalWriteStream(PdfStreamBase* out,
1221                                 PdfEncryptor* e) = 0;
1222 private:
1223         PdfOID              fObjectID;
1224         unsigned int        fGenerationNo;
1225 };
1226 
1227 /*----------------------------------------------------------------------------*/
1228 /*----- PdfVirtualObject class -----------------------------------------------*/
1229 
1230 class PdfVirtualObject : public PdfObject
1231 {
1232 public:
PdfVirtualObject(PdfOID objectID)1233                         PdfVirtualObject(PdfOID objectID) :
1234                             PdfObject(objectID) {}
GetObjectType()1235     pdf_object_type     GetObjectType()     { return PDF_OBJ_TYPE_VIRTUAL; }
IsLockedObject()1236     bool                IsLockedObject()    { return true; }
1237 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1238     void                InternalWriteStream(PdfStreamBase* out,
1239                             PdfEncryptor* e) {
1240                             *out << GetObjectID()
1241                                  << " "
1242                                  << GetGenerationNo()
1243                                  << " R";
1244                         }
1245 };
1246 
1247 /*----------------------------------------------------------------------------*/
1248 /*----- PdfNullObject class --------------------------------------------------*/
1249 
1250 class PdfNullObject : public PdfObject
1251 {
1252 public:
PdfNullObject()1253                             PdfNullObject() : PdfObject() {}
PdfNullObject(PdfOID objectID)1254                             PdfNullObject(PdfOID objectID) :
1255                                 PdfObject(objectID) {}
GetClass()1256         pdf_object_class    GetClass()          { return ocNull; }
1257 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1258         void                InternalWriteStream(PdfStreamBase* out,
1259                                 PdfEncryptor* e)    { *out << "null"; }
1260 };
1261 
1262 /*----------------------------------------------------------------------------*/
1263 /*----- PdfBoolean class -----------------------------------------------------*/
1264 
1265 class PdfBoolean : public PdfObject
1266 {
1267 public:
PdfBoolean()1268                             PdfBoolean() : PdfObject()  { fValue = false; }
PdfBoolean(PdfOID objectID,bool value)1269                             PdfBoolean(PdfOID objectID, bool value)
1270                                 : PdfObject(objectID)       { fValue = value; }
PdfBoolean(bool value)1271                             PdfBoolean(bool value) : PdfObject()
1272                                 { fValue = value; }
GetClass()1273         pdf_object_class    GetClass()              { return ocBoolean; }
GetValue()1274         bool                GetValue()              { return fValue; }
SetValue(bool value)1275         void                SetValue(bool value)    { fValue = value; }
1276 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1277         void                InternalWriteStream(PdfStreamBase* out,
1278                                 PdfEncryptor* e)
1279                                 { fValue ? *out << "true" : *out << "false"; }
1280 private:
1281         bool                fValue;
1282 };
1283 
1284 /*----------------------------------------------------------------------------*/
1285 /*----- PdfNumber class ------------------------------------------------------*/
1286 
1287 class PdfNumber : public PdfObject
1288 {
1289 public:
PdfNumber()1290                             PdfNumber() : PdfObject()       { fValue = 0; }
PdfNumber(PdfOID objectID,int value)1291                             PdfNumber(PdfOID objectID, int value)
1292                                 : PdfObject(objectID)       { fValue = value; }
PdfNumber(int value)1293                             PdfNumber(int value)
1294                                 : PdfObject()       { fValue = value; }
GetClass()1295         pdf_object_class    GetClass()              { return ocNumber; }
GetValue()1296         int                 GetValue()              { return fValue; }
SetValue(int value)1297         void                SetValue(int value)           { fValue = value; }
1298 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1299         void                InternalWriteStream(PdfStreamBase* out,
1300                                 PdfEncryptor* e)
1301                                 { *out << fValue; }
1302 private:
1303         int                 fValue;
1304 };
1305 
1306 /*----------------------------------------------------------------------------*/
1307 /*----- PdfReal class --------------------------------------------------------*/
1308 
1309 class PdfReal : public PdfObject
1310 {
1311 public:
PdfReal()1312                             PdfReal() : PdfObject()         { fValue = 0; }
PdfReal(PdfOID objectID,double value)1313                             PdfReal(PdfOID objectID, double value)
1314                                 : PdfObject(objectID)       { fValue = value; }
PdfReal(double value)1315                             PdfReal(double value)
1316                                 : PdfObject()       { fValue = value; }
GetClass()1317         pdf_object_class    GetClass()              { return(ocReal); }
GetValue()1318         double              GetValue()              { return(fValue); }
SetValue(double value)1319         void                SetValue(double value)  { fValue = value; }
1320 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1321         void                InternalWriteStream(PdfStreamBase* out,
1322                                 PdfEncryptor* e)
1323                                 { *out << fValue; }
1324 private:
1325         double              fValue;
1326 };
1327 
1328 /*----------------------------------------------------------------------------*/
1329 /*----- PdfName class --------------------------------------------------------*/
1330 
1331 class PdfName : public PdfObject
1332 {
1333 public:
PdfName()1334                             PdfName() : PdfObject()     { fValue[0] = 0x00; }
1335                             PdfName(PdfOID objectID, const char* value);
1336                             PdfName(const char* value);
GetClass()1337         pdf_object_class    GetClass()          { return(ocName); }
GetValue()1338 const   char*               GetValue()          { return fValue; }
1339         void                SetValue(const char* value);
EqualTo(const char * value)1340         bool                EqualTo(const char* value)
1341                                 { return (strcmp(fValue, value) == 0); }
1342 protected:
InternalWriteStream(PdfStreamBase * out,PdfEncryptor * e)1343         void                InternalWriteStream(PdfStreamBase* out,
1344                                 PdfEncryptor* e)
1345                                 { WriteEscapeName(out, fValue); }
1346 private:
1347         char                fValue[PDF_LIMIT_MAX_NAME + 1];
1348 };
1349 
1350 /*----------------------------------------------------------------------------*/
1351 /*----- PdfText class --------------------------------------------------------*/
1352 
1353 class PdfText : public PdfObject
1354 {
1355 public:
PdfText()1356                             PdfText() : PdfObject()     { fValue = NULL; }
1357                             PdfText(PdfOID objectID, const char* value);
1358                             PdfText(const char* value);
1359                             ~PdfText();
GetClass()1360         pdf_object_class    GetClass()           { return(ocText); }
GetValue()1361 const   char*               GetValue()           { return fValue; }
1362         void                SetValue(const char* value);
1363 protected:
1364         void                InternalWriteStream(PdfStreamBase* out,
1365                                 PdfEncryptor* e);
1366 private:
1367         char*               fValue;
1368 };
1369 
1370 /*----------------------------------------------------------------------------*/
1371 /*----- PdfBinary class ------------------------------------------------------*/
1372 
1373 class PdfBinary : public PdfObject
1374 {
1375 public:
PdfBinary()1376                             PdfBinary() : PdfObject() { fData = NULL; }
PdfBinary(PdfOID objectID)1377                             PdfBinary(PdfOID objectID)
1378                                 : PdfObject(objectID) { fData = NULL; };
GetClass()1379         pdf_object_class    GetClass()          { return ocBinary; }
1380         void                SetData(const void* data, unsigned int length,
1381                                 bool encryptable = true);
1382 protected:
1383         void                InternalWriteStream(PdfStreamBase* out,
1384                                 PdfEncryptor* e);
1385 private:
1386         const void*         fData;
1387         unsigned int        fLength;
1388         bool                fEncryptable;
1389 };
1390 
1391 /*----------------------------------------------------------------------------*/
1392 /*----- PdfXrefEntry class ---------------------------------------------------*/
1393 
1394 class PdfXrefEntry
1395 {
1396 public:
1397                     PdfXrefEntry(PdfObject *object);
1398                     ~PdfXrefEntry();
GetEntryType()1399     PdfEntryType    GetEntryType()      { return fEntryType; };
GetByteOffset()1400     int             GetByteOffset()     { return fByteOffset; };
GetGenerationNo()1401     unsigned int    GetGenerationNo()   { return fGenerationNo; };
SetByteOffset(int byteOffset)1402     void            SetByteOffset(int byteOffset) { fByteOffset = byteOffset; };
SetGenerationNo(unsigned int generationNo)1403     void            SetGenerationNo(unsigned int generationNo)
1404                         { fGenerationNo = generationNo; };
SetEntryType(PdfEntryType entryType)1405     void            SetEntryType(PdfEntryType entryType)
1406                         { fEntryType = entryType; };
1407     void            SetObject(PdfObject* object);
HasObject()1408     bool            HasObject()         { return (fObject != NULL); };
GetObject()1409     PdfObject*      GetObject()         { return fObject; };
1410 private:
1411     PdfEntryType    fEntryType;
1412     int             fByteOffset;
1413     unsigned int    fGenerationNo;
1414     PdfObject*      fObject;
1415 };
1416 
1417 /*----------------------------------------------------------------------------*/
1418 /*----- PdfXref class --------------------------------------------------------*/
1419 
1420 class PdfDoc;
1421 
1422 class PdfXref
1423 {
1424 public:
1425                     PdfXref(PdfDoc* doc);
1426                     ~PdfXref();
1427     void            Clear();
GetCount()1428     int             GetCount()      { return fEntries->CountItems(); };
1429     PdfObject*      GetObject(PdfOID objectID);
1430     PdfOID          AddObject(PdfObject* object);
1431     void            WriteToStream(PdfStreamBase* out, PdfEncryptor* e);
GetAddr()1432     int             GetAddr()       { return fAddr; };
GetDoc()1433     PdfDoc*         GetDoc()        { return fDoc; };
1434     void            SetError(int err);
1435 protected:
GetEntry(int index)1436     PdfXrefEntry*   GetEntry(int index) {
1437                         return (fEntries == NULL) ? NULL :
1438                             (PdfXrefEntry*)fEntries->ItemAt(index);
1439                     };
1440 private:
1441     void            Init();
1442     PdfList*        fEntries;
1443     int             fAddr;
1444     PdfDoc*         fDoc;
1445 };
1446 
1447 /*----------------------------------------------------------------------------*/
1448 /*----- PdfArray class -------------------------------------------------------*/
1449 
1450 class PdfArray : public PdfObject
1451 {
1452 public:
1453                             PdfArray(PdfXref* xref);
1454                             PdfArray(PdfOID objectID, PdfXref* xref);
1455                             ~PdfArray();
GetClass()1456         pdf_object_class    GetClass()          { return(ocArray); }
GetCount()1457         int                 GetCount()  {
1458                                 return (fItems == NULL) ? 0 :
1459                                 fItems->CountItems();
1460                             }
1461         PdfObject*          GetItem(int index);
1462         int                 GetAsInteger(int index);
1463         double              GetAsReal(int index);
1464         void                Add(PdfObject* value);
1465         void                Add(const pdf_box value);
1466         void                Add(const pdf_rect value);
1467         void                Insert(PdfObject* value, int index);
IndexOf(PdfObject * value)1468         int                 IndexOf(PdfObject* value) {
1469                                 return (fItems == NULL) ? 0 :
1470                                 fItems->IndexOf(value);
1471                             }
GetXref()1472         PdfXref*            GetXref()      { return(fXref); }
1473         void                Clear();
1474 protected:
1475         void                InternalWriteStream(PdfStreamBase* out,
1476                                 PdfEncryptor* e);
1477 private:
CheckList()1478         void                CheckList() {
1479                                 if (fItems == NULL)
1480                                     fItems = new PdfList();
1481                             }
1482         PdfList*            fItems;
1483         PdfXref*            fXref;
1484 };
1485 
1486 /*----------------------------------------------------------------------------*/
1487 /*----- PdfDictElement class -------------------------------------------------*/
1488 
1489 class PdfDictElement
1490 {
1491 public:
1492                     PdfDictElement();
1493                     PdfDictElement(PdfName* key, PdfObject* value);
1494                     PdfDictElement(const char* key, PdfObject* value);
1495                     ~PdfDictElement();
1496     void            SetValue(PdfObject* value);
GetValue()1497     PdfObject*      GetValue()              { return(fValue); }
GetKey()1498     PdfName*        GetKey()                { return(fKey); }
1499 private:
1500     PdfName*        fKey;
1501     PdfObject*      fValue;
1502 };
1503 
1504 /*----------------------------------------------------------------------------*/
1505 /*----- PdfDictionary class --------------------------------------------------*/
1506 
1507 class PdfDictionary : public PdfObject
1508 {
1509 public:
1510                             PdfDictionary(PdfXref* xref);
1511                             PdfDictionary(PdfOID objectID, PdfXref* xref);
1512                             ~PdfDictionary();
GetClass()1513         pdf_object_class    GetClass()          { return(ocDictionary); }
1514         int                 GetCount();
1515         PdfObject*          GetValue(const char* key);
1516 const   char*               GetKeyValue(unsigned int index);
1517         void                AddElement(const char* key, PdfObject* value);
1518         void                RemoveElement(const char* key);
1519         void                RemoveElement(unsigned int index);
GetXref()1520         PdfXref*            GetXref()      { return(fXref); }
1521         bool                IsTypeOf(const char* type);
1522 const   char*               GetTextValue(const char* key);
1523 const   char*               GetNameValue(const char* key);
1524         void                SetError(int err);
1525 protected:
1526         void                InternalWriteStream(PdfStreamBase* out,
1527                                 PdfEncryptor* e);
SetType(const char * type)1528         void                SetType(const char* type) {
1529                                 AddElement("Type", new PdfName(type));
1530                             }
1531 private:
CheckList()1532         void                CheckList() {
1533                                 if (fElements == NULL)
1534                                     fElements = new PdfList();
1535                             }
GetElementAt(int idx)1536         PdfDictElement*     GetElementAt(int idx) {
1537                                 return (PdfDictElement*)fElements->ItemAt(idx);
1538                             }
1539         PdfDictElement*     GetElement(const char* key);
1540         PdfList*            fElements;
1541         PdfXref*            fXref;
1542 };
1543 
1544 /*----------------------------------------------------------------------------*/
1545 /*----- PdfStream class ------------------------------------------------------*/
1546 
1547 class PdfStream : public PdfDictionary
1548 {
1549 public:
1550                             PdfStream(PdfXref* xref);
1551                             PdfStream(PdfOID objectID, PdfXref* xref);
1552                             ~PdfStream();
1553         void                AddFilter(pdf_filter filter);
1554         void                RemoveFilter(pdf_filter filter);
GetClass()1555         pdf_object_class    GetClass()          { return ocStream; }
1556         PdfMemStream*       GetStream();
1557 protected:
1558         void                InternalWriteStream(PdfStreamBase* out,
1559                                 PdfEncryptor* e);
1560 private:
1561         PdfMemStream*       fStream;
1562         int                 fFilter;
1563 };
1564 
1565 /*----------------------------------------------------------------------------*/
1566 /*----- pdf_char_data struct -------------------------------------------------*/
1567 
1568 struct pdf_char_data_struct {
1569     int char_cd;
1570     char* char_name;
1571     int width;
1572 };
1573 typedef pdf_char_data_struct pdf_char_data;
1574 
1575 /* read only data */
1576 struct pdf_char_data_struct_ro {
1577     int char_cd;
1578     const char* char_name;
1579     int width;
1580 };
1581 typedef pdf_char_data_struct_ro pdf_char_data_ro;
1582 
1583 /*----------------------------------------------------------------------------*/
1584 /*----- PdfAutoPtrObject class -----------------------------------------------*/
1585 
1586 class PdfAutoPtrMgr;
1587 
1588 class PdfAutoPtrObject
1589 {
1590 friend class PdfAutoPtrMgr;
1591 public:
1592                         PdfAutoPtrObject();
1593 virtual                 ~PdfAutoPtrObject();
1594 virtual pdf_auto_ptr_object_type
GetType()1595                         GetType()   { return PDF_OBJECT_UNKNOWN; }
IsValid()1596         bool            IsValid()   { return fMgr != NULL; }
1597 protected:
Init()1598 virtual void            Init()  {};
1599 
1600 private:
1601         PdfAutoPtrMgr*  fMgr;
1602 };
1603 
1604 class PdfAutoPtrMgr
1605 {
1606 public:
1607                         PdfAutoPtrMgr();
1608                         ~PdfAutoPtrMgr();
1609         void            RegisterObject(PdfAutoPtrObject* obj);
1610         void            UnRegisterObject(PdfAutoPtrObject* obj);
CountObjects()1611         unsigned int    CountObjects()  { return fList->CountItems(); }
1612 private:
1613         PdfList*        fList;
1614 };
1615 
1616 /*----------------------------------------------------------------------------*/
1617 /*----- PdfType1FontDef class ------------------------------------------------*/
1618 
1619 class PdfType1FontDef : public PdfAutoPtrObject
1620 {
1621 public:
1622                         	PdfType1FontDef();
1623                         	PdfType1FontDef(const char* basefont);
1624 virtual                 	~PdfType1FontDef();
1625         unsigned int    	Widths(const char* char_name);
1626         unsigned int    	Widths(unsigned char c);
1627 
1628         /* font-specific encording only. */
FirstChar()1629         int             	FirstChar()             { return fFirstChar; }
LastChar()1630         int             	LastChar()              { return fLastChar; }
1631 
BaseFont()1632         const char*     	BaseFont()              { return fBaseFont; }
Ascent()1633         int             	Ascent()                { return fAscent; }
Descent()1634         int             	Descent()               { return fDescent; }
Flags()1635         unsigned int    	Flags()                 { return fFlags; }
FontName()1636         const char*     	FontName()              { return fFontName; }
FontBBox()1637         pdf_box         	FontBBox()              { return fFontBBox; }
ItalicAngle()1638         int             	ItalicAngle()           { return fItalicAngle; }
StemV()1639         unsigned int    	StemV()                 { return fStemV; }
AvgWidth()1640         int             	AvgWidth()              { return fAvgWidth; }
Leading()1641         int             	Leading()               { return fLeading; }
MaxWidth()1642         int             	MaxWidth()              { return fMaxWidth; }
MissingWidth()1643         int             	MissingWidth()          { return fMissingWidth; }
StemH()1644         int             	StemH()                 { return fStemH; }
XHeight()1645         int             	XHeight()               { return fXHeight; }
CapHeight()1646         int             	CapHeight()             { return fCapHeight; }
CharSet()1647         const char*     	CharSet()               { return fCharSet; }
IsBase14Font()1648         bool            	IsBase14Font()          { return fIsBase14Font; }
Length1()1649         unsigned int    	Length1()               { return fLength1; }
Length2()1650         unsigned int    	Length2()               { return fLength2; }
Length3()1651         unsigned int    	Length3()               { return fLength3; }
FontData()1652         PdfMemStream*   	FontData()              { return fFontData; }
Descriptor()1653         PdfDictionary*  	Descriptor()            { return fDescriptor; }
SetDescriptor(PdfDictionary * desc)1654         void            	SetDescriptor(PdfDictionary* desc)
1655                             	        { fDescriptor = desc; }
DefaultEncoding()1656         pdf_encoding    	DefaultEncoding()
1657                             	        { return fDefaultEncoding; }
1658         void            	Clear();
1659         void            	LoadFromFile(const char* afmfile,
1660 								const char* fontfile);
1661 		PdfType1FontDef* 	Duplicate() const;
1662 protected:
1663         void            SetWidths(const pdf_char_data_ro* array);
1664         void            FreeWidths();
1665         char            fBaseFont[PDF_LIMIT_MAX_NAME + 1];
1666         pdf_char_data*  fWidths;
1667         int             fWidthsCount;
1668         int             fFirstChar;
1669         int             fLastChar;
1670         int             fAscent;
1671         int             fDescent;
1672         unsigned int    fFlags;
1673         char            fFontName[PDF_LIMIT_MAX_NAME + 1];
1674         pdf_box         fFontBBox;
1675         int             fItalicAngle;
1676         unsigned int    fStemV;
1677         int             fAvgWidth;
1678         int             fLeading;
1679         int             fMaxWidth;
1680         int             fMissingWidth;
1681         int             fStemH;
1682         int             fXHeight;
1683         int             fCapHeight;
1684         char            fCharSet[PDF_LIMIT_MAX_NAME + 1];
1685         unsigned int    fLength1;
1686         unsigned int    fLength2;
1687         unsigned int    fLength3;
1688         bool            fIsBase14Font;
1689         pdf_encoding    fDefaultEncoding;
1690         PdfMemStream*   fFontData;
1691         PdfDictionary*  fDescriptor;
1692 private:
1693         void            InitAttributes();
1694         void            SetParam(char* param, const char* text);
1695         void            LoadFontFile(const char* filename);
1696         void            LoadAfmFile(const char* filename);
1697         char*           GetStrParam(char* str, char* param, int len);
1698         char*           GetIntParam(char* str, int* param);
1699         int             FindBuf(const char* findbuf, const char* srcbuf,
1700                             int len);
1701 };
1702 
1703 /*----------------------------------------------------------------------------*/
1704 /*----- Helvetica Font -------------------------------------------------------*/
1705 
1706 class PdfHelveticaFontDef : public PdfType1FontDef
1707 {
1708 public:
1709                     PdfHelveticaFontDef();
1710 };
1711 
1712 class PdfHelveticaBoldFontDef : public PdfType1FontDef
1713 {
1714 public:
1715                     PdfHelveticaBoldFontDef();
1716 };
1717 
1718 class PdfHelveticaObliqueFontDef : public PdfType1FontDef
1719 {
1720 public:
1721                     PdfHelveticaObliqueFontDef();
1722 };
1723 
1724 class PdfHelveticaBoldObliqueFontDef : public PdfType1FontDef
1725 {
1726 public:
1727                     PdfHelveticaBoldObliqueFontDef();
1728 };
1729 
1730 /*----------------------------------------------------------------------------*/
1731 /*----- Times Font -----------------------------------------------------------*/
1732 
1733 class PdfTimesRomanFontDef : public PdfType1FontDef
1734 {
1735 public:
1736                     PdfTimesRomanFontDef();
1737 };
1738 
1739 class PdfTimesBoldFontDef : public PdfType1FontDef
1740 {
1741 public:
1742                     PdfTimesBoldFontDef();
1743 };
1744 
1745 class PdfTimesItalicFontDef : public PdfType1FontDef
1746 {
1747 public:
1748                     PdfTimesItalicFontDef();
1749 };
1750 
1751 class PdfTimesBoldItalicFontDef : public PdfType1FontDef
1752 {
1753 public:
1754                     PdfTimesBoldItalicFontDef();
1755 };
1756 
1757 /*----------------------------------------------------------------------------*/
1758 /*----- Courier Font ---------------------------------------------------------*/
1759 
1760 class PdfCourierFontDef : public PdfType1FontDef
1761 {
1762 public:
1763                     PdfCourierFontDef();
1764 };
1765 
1766 class PdfCourierBoldFontDef : public PdfType1FontDef
1767 {
1768 public:
1769                     PdfCourierBoldFontDef();
1770 };
1771 
1772 class PdfCourierObliqueFontDef : public PdfType1FontDef
1773 {
1774 public:
1775                     PdfCourierObliqueFontDef();
1776 };
1777 
1778 class PdfCourierBoldObliqueFontDef : public PdfType1FontDef
1779 {
1780 public:
1781                     PdfCourierBoldObliqueFontDef();
1782 };
1783 
1784 /*----------------------------------------------------------------------------*/
1785 /*----- Symbol Font ----------------------------------------------------------*/
1786 
1787 class PdfSymbolFontDef : public PdfType1FontDef
1788 {
1789 public:
1790                     PdfSymbolFontDef();
1791 };
1792 
1793 /*----------------------------------------------------------------------------*/
1794 /*----- ZapfDingbats Font ----------------------------------------------------*/
1795 
1796 class PdfZapfDingbatsFontDef : public PdfType1FontDef
1797 {
1798 public:
1799                     PdfZapfDingbatsFontDef();
1800 };
1801 
1802 /*----------------------------------------------------------------------------*/
1803 /*------ PdfEncodingDef class ------------------------------------------------*/
1804 
1805 struct pdf_differences_element {
1806     unsigned int code;
1807     const char* char_name;
1808 };
1809 
1810 class PdfEncodingDef : public PdfAutoPtrObject
1811 {
1812 public:
1813                         PdfEncodingDef();
1814 virtual                 ~PdfEncodingDef();
1815         int             GetCharCode(unsigned short unicode);
1816         int             GetCharCode(const char* char_name);
1817         const char*     GetCharName(unsigned int code);
1818         unsigned short  GetUnicode(unsigned int code);
BaseEncoding()1819         pdf_encoding    BaseEncoding()      { return fBaseEncoding; }
1820 virtual PdfObject*      GetEncoding(PdfXref* xref);
FirstChar()1821         unsigned int    FirstChar()         { return fFirstChar; }
LastChar()1822         unsigned int    LastChar()          { return fLastChar; }
1823         void            OverrideUnicodeArray(const unsigned short* array);
1824         int             ToUnicode(const char* src, unsigned char* dst,
1825                             int* len);
1826 static  pdf_encoding    StringToPdfEncoding(const char* encoding);
1827 protected:
1828         void            AddDifference(unsigned int code, const char* char_name);
1829         void            SetUnicodeArray(unsigned int first_char,
1830                             unsigned int last_char,
1831                             const unsigned short* array);
1832         const char*     PdfEncodingToString(pdf_encoding encoding);
1833         const char*     UnicodeToGryphName(unsigned short unicode);
1834         unsigned short  GryphNameToUnicode(const char* gryph_name);
1835         unsigned int    fFirstChar;
1836         unsigned int    fLastChar;
1837         pdf_encoding    fBaseEncoding;
1838 private:
1839         void            ClearDefferences();
1840         PdfList*        fDifferences;
1841         unsigned short  fUnicodeArray[255];
1842 };
1843 
1844 /*----------------------------------------------------------------------------*/
1845 /*------ predefined encoding -------------------------------------------------*/
1846 
1847 class PdfStandardEncoding : public PdfEncodingDef
1848 {
1849 public:
1850                         PdfStandardEncoding();
1851 };
1852 
1853 class PdfWinAnsiEncoding : public PdfEncodingDef
1854 {
1855 public:
1856                         PdfWinAnsiEncoding();
1857 };
1858 
1859 class PdfMacRomanEncoding : public PdfEncodingDef
1860 {
1861 public:
1862                         PdfMacRomanEncoding();
1863 };
1864 
1865 class PdfSymbolFontEncoding : public PdfEncodingDef
1866 {
1867 public:
1868                         PdfSymbolFontEncoding();
GetEncoding(PdfXref * xref)1869         PdfObject*      GetEncoding(PdfXref* xref)      { return NULL; }
1870 };
1871 
1872 class PdfZapfDingbatsFontEncoding : public PdfEncodingDef
1873 {
1874 public:
1875                         PdfZapfDingbatsFontEncoding();
GetEncoding(PdfXref * xref)1876         PdfObject*      GetEncoding(PdfXref* xref)      { return NULL; }
1877 };
1878 
1879 
1880 /*----------------------------------------------------------------------------*/
1881 /*----- PdfFontBase class ----------------------------------------------------*/
1882 
1883 class PdfFontBase : public PdfStream
1884 {
1885 public:
1886                             PdfFontBase(PdfXref* xref);
1887                             ~PdfFontBase();
Name()1888         const char*         Name()    { return fName; }
1889 virtual pdf_text_width      TextWidth(const char* text);
1890 virtual pdf_text_width      TextWidths(const char* text,
1891                                 unsigned int* widths);
1892 virtual unsigned int        MeasureText(const char* text, double width,
1893                                 double fontsize, double charspace,
1894                                 double wordspace, double* realwdth = NULL);
WritingMode()1895 virtual pdf_writing_mode    WritingMode()   { return fWritingMode; }
1896 virtual int                 Ascent() = 0;
1897 virtual int                 Descent() = 0;
1898 protected:
SetWritingMode(pdf_writing_mode mode)1899         void                SetWritingMode(pdf_writing_mode mode)
1900                                 { fWritingMode = mode; }
1901         char*               fName;
1902         pdf_writing_mode    fWritingMode;
1903 private:
1904 };
1905 
1906 typedef PdfFontBase PdfFont;
1907 
1908 /*----------------------------------------------------------------------------*/
1909 /*----- PdfFontMgr class -----------------------------------------------------*/
1910 
1911 class PdfFontMgr
1912 {
1913 public:
1914                         PdfFontMgr(PdfXref *xref);
1915                         ~PdfFontMgr();
1916         int             RegisterFont(PdfFont* font);
1917         PdfFont*        GetFont(const char* name);
GetFont(unsigned int index)1918         PdfFont*        GetFont(unsigned int index)
1919                             { return (PdfFont*)fList->ItemAt(index); }
CountFonts()1920         unsigned int    CountFonts()  { return fList->CountItems(); }
1921 private:
1922         PdfList*        fList;
1923         PdfXref*        fXref;
1924 };
1925 
1926 /*----------------------------------------------------------------------------*/
1927 /*----- PdfType1Font class ---------------------------------------------------*/
1928 
1929 class PdfType1Font : public PdfFont
1930 {
1931 public:
1932                             PdfType1Font(PdfXref* xref);
1933                             ~PdfType1Font();
1934         pdf_text_width      TextWidth(const char* text);
1935         pdf_text_width      TextWidths(const char* text, unsigned int* widths);
1936         unsigned int        MeasureText(const char* text, double width,
1937                                 double fontsize, double charspace,
1938                                 double wordspace, double* realwidth = NULL);
CharWidth(const unsigned char c)1939         unsigned int        CharWidth(const unsigned char c)  {
1940                                 return (fFirstChar <= c && c <= fLastChar) ?
1941                                     fWidths[c - fFirstChar] : fMissingWidth; }
Encording()1942         PdfEncodingDef*     Encording()     { return fEncoding; }
FontDef()1943         PdfType1FontDef*    FontDef()       { return fFontDef; }
IsBase14Font()1944         bool                IsBase14Font()  { return fFontDef->IsBase14Font(); }
GetValid()1945         bool                GetValid()      { return fValid; }
1946         void                SetAttributes(const char* name,
1947                                 PdfType1FontDef* fontdef,
1948                                 PdfEncodingDef* encoding);
1949         int                 Ascent();
1950         int                 Descent();
1951 protected:
1952         bool                CreateDescriptor();
1953         bool                fValid;
1954 private:
1955         PdfDictionary*      fDescriptor;
1956         PdfEncodingDef*     fEncoding;
1957         PdfType1FontDef*    fFontDef;
1958         int                 fFirstChar;
1959         int                 fLastChar;
1960         int                 fMissingWidth;
1961         int*                fWidths;
1962 		int					fFlags;
1963 };
1964 
1965 /*---------------------------------------------------------------------------*/
1966 /*----- PdfCMap -------------------------------------------------------------*/
1967 
1968 class PdfCIDType2FontDef;
1969 typedef PdfCIDType2FontDef PdfCIDFontDef;
1970 
1971 class PdfCIDType2Font;
1972 typedef PdfCIDType2Font PdfCIDFont;
1973 
1974 class PdfCMap : public PdfAutoPtrObject
1975 {
1976 public:
1977                             PdfCMap();
1978 virtual                     ~PdfCMap();
1979         pdf_cid             GetCID(unsigned int code);
1980         unsigned int        GetUnicode(unsigned int code);
1981 virtual const char*         GetCMapName() = 0;
1982 virtual void                ParseText(const char* text,
1983                                 pdf_byte_type* btype) = 0;
1984         int                 ToUnicode(const char* src, unsigned char* dst,
1985                                 int* len);
1986         void                AddCIDSystemInfo(PdfCIDFont* font);
GetWritingMode()1987 virtual pdf_writing_mode    GetWritingMode()
1988                                 { return PDF_WMODE_HORIZONTAL; }
1989 protected:
1990         void                AddCMap(const pdf_cid_range* range);
1991         void                SetCIDSystemInfo(const char* registry,
1992                                 const char* ordering, unsigned int supplement);
1993         void                SetUnicodeArray(const pdf_mb_unicode_map1* array1,
1994                                 const pdf_mb_unicode_map2* array2);
1995 private:
1996     unsigned short          fUnicodeArray[256][256];
1997     pdf_cid                 fCMapArray[256][256];
1998     char*                   fRegistry;
1999     char*                   fOrdering;
2000     unsigned int            fSupplement;
2001 };
2002 
2003 /*----------------------------------------------------------------------------*/
2004 /*----- PdfUnicodeText -------------------------------------------------------*/
2005 
2006 class PdfUnicodeText : public PdfBinary
2007 {
2008 public:
2009                             PdfUnicodeText();
2010                             PdfUnicodeText(PdfCMap* cmap);
2011                             PdfUnicodeText(PdfEncodingDef* def);
2012                             ~PdfUnicodeText();
GetClass()2013         pdf_object_class    GetClass()           { return(ocUnicodeText); }
2014         void                SetText(const char* text);
2015         const char*         GetText();
2016 private:
2017         unsigned char*      fValue;
2018         PdfCMap*            fCMap;
2019         PdfEncodingDef*     fDef;
2020 };
2021 
2022 /*---------------------------------------------------------------------------*/
2023 /*----- PdfType0Font --------------------------------------------------------*/
2024 
2025 class PdfType0Font : public PdfFont
2026 {
2027 public:
2028                             PdfType0Font(PdfXref* xref);
2029                             ~PdfType0Font();
TextWidth(const char * text)2030         pdf_text_width      TextWidth(const char* text) {
2031                                 return TextWidths(text, NULL);
2032                             }
2033         pdf_text_width      TextWidths(const char* text, unsigned int* widths);
2034         unsigned int        MeasureText(const char* text, double width,
2035                                 double fontsize, double charspace,
2036                                 double wordspace, double* realwidth = NULL);
DescendantFont()2037         PdfCIDType2Font*    DescendantFont()    { return fDescendantFont; }
2038         void                SetAttributes(const char* name, PdfCIDFont* font,
2039                                 PdfCMap* cmap);
GetValid()2040         bool                GetValid()      { return fValid; }
2041         int                 Ascent();
2042         int                 Descent();
2043 private:
2044         PdfCIDType2Font*    fDescendantFont;
2045         PdfCMap*            fCMap;
2046         bool                fValid;
2047 };
2048 
2049 /*---------------------------------------------------------------------------*/
2050 /*----- PdfCIDType2FontDef --------------------------------------------------*/
2051 
2052 class PdfCIDType2FontDef : public PdfAutoPtrObject
2053 {
2054 friend class PdfCIDType2Font;
2055 public:
2056                             PdfCIDType2FontDef();
2057 virtual                     ~PdfCIDType2FontDef();
2058         unsigned int        CIDWidth(pdf_cid cid);
BaseFont()2059         const char*         BaseFont()              { return fBaseFont; }
Ascent()2060         int                 Ascent()                { return fAscent; }
Descent()2061         int                 Descent()               { return fDescent; }
CapHeight()2062         int                 CapHeight()             { return fCapHeight; }
Flags()2063         unsigned int        Flags()                 { return fFlags; }
FontBBox()2064         pdf_box             FontBBox()              { return fFontBBox; }
ItalicAngle()2065         int                 ItalicAngle()           { return fItalicAngle; }
StemV()2066         unsigned int        StemV()                 { return fStemV; }
DW()2067         int                 DW()                    { return fDW; }
DW2()2068         int*                DW2()                   { return fDW2; }
MissingWidth()2069         int                 MissingWidth()          { return fMissingWidth; }
GetWidths(int index)2070         pdf_cid_width*      GetWidths(int index) {
2071                                 return (fWidths == NULL) ? 0 :
2072                                     (pdf_cid_width*)fWidths->ItemAt(index);
2073                             }
2074         int                 NumWidths();
2075 protected:
2076         void                AddWidths1(pdf_cid fromcid, pdf_cid tocid,
2077                                 unsigned int width);
2078         void                AddWidths2(pdf_cid fromcid, pdf_cid tocid,
2079                                 const unsigned int* widths);
SetBaseFont(const char * value)2080         void                SetBaseFont(const char* value)
2081                                 { SetParam(&fBaseFont, value); }
2082 virtual void                Init() = 0;
2083         int                 fAscent;
2084         int                 fDescent;
2085         int                 fCapHeight;
2086         unsigned int        fFlags;
2087         pdf_box             fFontBBox;
2088         int                 fItalicAngle;
2089         unsigned int        fStemV;
2090         int                 fAvgWidth;
2091         int                 fLeading;
2092         int                 fMaxWidth;
2093         int                 fMissingWidth;
2094         int                 fStemH;
2095         int                 fDW;
2096         int                 fDW2[2];
2097 private:
2098         void                SetParam(char** dst, const char* src);
2099         PdfList*            fWidths;
2100         char*               fBaseFont;
2101 };
2102 
2103 /*---------------------------------------------------------------------------*/
2104 /*----- PdfCIDType2Font -----------------------------------------------------*/
2105 
2106 class PdfCIDType2Font : public PdfFont
2107 {
2108 public:
2109                             PdfCIDType2Font(PdfXref* xref);
2110                             ~PdfCIDType2Font();
FontDef()2111         PdfCIDFontDef*      FontDef()               { return fFontDef; }
BaseFont()2112         const char*         BaseFont() {
2113                                 return fValid ? fFontDef->BaseFont() : NULL;
2114                             }
GetValid()2115         bool                GetValid()              { return fValid; }
CIDWidth(pdf_cid cid)2116         unsigned int        CIDWidth(pdf_cid cid) {
2117                                 return fValid ? fFontDef->CIDWidth(cid) : 0;
2118                             }
2119         void                SetAttributes(PdfCIDFontDef* fontdef);
2120         int                 Ascent();
2121         int                 Descent();
2122 private:
2123         void                CreateDescriptor();
2124         bool                fValid;
2125         PdfCIDFontDef*      fFontDef;
2126         PdfDictionary*      fDescriptor;
2127 };
2128 
2129 /*----------------------------------------------------------------------------*/
2130 /*----- PdfPageBase class ----------------------------------------------------*/
2131 
2132 enum pdf_pages_type {
2133     ptHasNoKids = 0,
2134     ptHasPages,
2135     ptHasPage
2136 };
2137 
2138 class PdfPages;
2139 class PdfPage;
2140 class PdfXObjectBase;
2141 typedef PdfXObjectBase PdfXObject;
2142 
2143 class PdfPageBase : public PdfDictionary
2144 {
2145     friend class PdfPages;
2146 public:
2147                         PdfPageBase(PdfXref* xref);
2148                         ~PdfPageBase();
2149 virtual void            Init();
2150         pdf_box         MediaBox();
2151         pdf_box         CropBox();
2152         PdfDictionary*  Resources();
2153         int             Rotate();
Parent()2154         PdfPages*       Parent()        { return fParent; }
2155         PdfDictionary*  GetResource(const char* element_name);
2156         void            SetMediaBox(pdf_box rect);
2157         void            SetCropBox(pdf_box rect);
2158         void            SetResources(PdfDictionary* res);
2159         void            SetRotate(int rotate);
2160         int             CountFonts();
2161         bool            AddFont(PdfFont* font, const char* fontname);
2162         const char*     GetFontName(PdfFont* font);
2163         bool            AddXObject(PdfXObject* xobject, const char* name);
2164         const char*     GetXObjectName(PdfXObject* xobject);
2165         int             GetIndex();
2166         void            SetSize(int width, int height);
AddProcSet(int procset)2167         void            AddProcSet(int procset) {
2168                             if ((fProcSet & procset) != procset)
2169                                 InternalAddProcSet(procset);
2170                         }
2171 protected:
2172         PdfObject*      FindElement(const char* name);
2173         pdf_box         GetElementRect(const char* name);
2174         void            SetElementRect(const char* name, pdf_box rect);
2175 virtual unsigned int    GetPageCount() = 0;
2176         PdfPages*       fParent;
2177 private:
2178         void            InternalAddProcSet(int procset);
2179         int             fProcSet;
2180 };
2181 
2182 /*----------------------------------------------------------------------------*/
2183 /*----- PdfPages class -------------------------------------------------------*/
2184 
2185 class PdfXObjectMgr;
2186 
2187 class PdfPages : public PdfPageBase
2188 {
2189 public:
2190                         PdfPages(PdfXref *xref, PdfFontMgr* fmgr = NULL,
2191                             PdfXObjectMgr* omgr = NULL);
2192         void            Init();
FontMgr()2193         PdfFontMgr*     FontMgr()       { return fFontMgr; }
XObjectMgr()2194         PdfXObjectMgr*  XObjectMgr()    { return fXObjectMgr; }
2195         PdfPage*        AddPage(int index = -1);
2196         PdfPages*       AddPages(int index = -1);
2197         unsigned int    GetKidsCount();
2198         int             IndexOf(PdfPageBase* page);
2199 protected:
2200         void            InternalWriteStream(PdfStreamBase* out,
2201                             PdfEncryptor* e);
2202 private:
2203         void            SetParent(PdfPages *parent);
Kids()2204         PdfArray*       Kids()      { return (PdfArray*)GetValue("Kids"); }
2205         bool            AddKids(PdfPageBase* page);
2206         bool            InsertKids(PdfPageBase* page, int index);
2207         unsigned int    GetPageCount();
2208         PdfFontMgr*     fFontMgr;
2209         PdfXObjectMgr*  fXObjectMgr;
2210         pdf_pages_type  fPagesType;
2211 };
2212 
2213 /*----------------------------------------------------------------------------*/
2214 /*----- PdfPage class --------------------------------------------------------*/
2215 
2216 class PdfContents;
2217 class PdfAnnotation;
2218 class PdfLinkAnnot;
2219 class PdfTextAnnot;
2220 class PdfDestination;
2221 
2222 class PdfPage : public PdfPageBase
2223 {
2224     friend class PdfPages;
2225 public:
PdfPage(PdfXref * xref)2226                     PdfPage(PdfXref* xref)
2227                         : PdfPageBase(xref)  { fCanvas = NULL; }
2228     PdfContents*    Canvas();
FontMgr()2229     PdfFontMgr*     FontMgr()       { return ((PdfPages*)fParent)->FontMgr(); }
XObjectMgr()2230     PdfXObjectMgr*  XObjectMgr()    {
2231                          return ((PdfPages*)fParent)->XObjectMgr();
2232                     }
Width()2233     int             Width()         { return MediaBox().right; }
Height()2234     int             Height()        { return MediaBox().top; }
2235     PdfLinkAnnot*   AddLink(pdf_rect rect, PdfDestination* dest,
2236                         pdf_annot_hl_mode mode = PDF_ANNOT_HL_EOF);
2237     PdfTextAnnot*   AddTextAnnot(pdf_rect rect);
2238 protected:
2239     void            AddAnnotation(PdfAnnotation* annot);
2240 private:
2241     void            SetParent(PdfPages *parent);
GetPageCount()2242     unsigned int    GetPageCount()  { return 1; }
2243     PdfContents*    fCanvas;
2244 };
2245 
2246 /*----------------------------------------------------------------------------*/
2247 /*----- PdfDestination class -------------------------------------------------*/
2248 
2249 class PdfDestination : public PdfArray
2250 {
2251 public:
2252                             PdfDestination(PdfPage* page,
2253                                     bool create_as_shared = true);
Page()2254     PdfPage*                Page()  { return fPage; }
2255     pdf_destination_type    Type();
2256     void                    SetXYZ(double left, double top, double zoom);
2257     void                    SetFit();
2258     void                    SetFitH(double top);
2259     void                    SetFitV(double left);
2260     void                    SetFitR(double left, double bottom, double right,
2261                                 double top);
2262     void                    SetFitB();
2263     void                    SetFitBH(double top);
2264     void                    SetFitBV(double left);
2265     double                   GetParam(int index);
2266     bool                    CheckValid();
IsShared()2267     bool                    IsShared()  { return fShared; }
2268 private:
2269     void                    CheckShared();
2270     PdfPage*                fPage;
2271     bool                    fShared;
2272 };
2273 
2274 /*---------------------------------------------------------------------------*/
2275 /*----- PdfBorderStyle ------------------------------------------------------*/
2276 
2277 class PdfBorderStyle : public PdfDictionary
2278 {
2279 public:
2280                             PdfBorderStyle(PdfXref *xref);
Subtype()2281         pdf_bs_subtype      Subtype()   { return fSubtype; }
SetSubtype(pdf_bs_subtype type)2282         void                SetSubtype(pdf_bs_subtype type)
2283                                 { fSubtype = type; }
Width()2284         double               Width()     { return fWidth; }
SetWidth(double width)2285         void                SetWidth(double width)
2286                                 { (width >= 0) ? fWidth = width: fWidth = 0; }
2287         void                SetDash(unsigned int on, unsigned int off,
2288                                 unsigned int phase);
2289 protected:
2290         void                InternalWriteStream(PdfStreamBase* out,
2291                                 PdfEncryptor* e);
2292 private:
2293         pdf_bs_subtype      fSubtype;
2294         double               fWidth;
2295         unsigned int        fDashOn;
2296         unsigned int        fDashOff;
2297         unsigned int        fPhase;
2298 };
2299 
2300 /*---------------------------------------------------------------------------*/
2301 /*----- PdfAnnotation -------------------------------------------------------*/
2302 
2303 class PdfAnnotation : public PdfDictionary
2304 {
2305 public:
2306                             PdfAnnotation(PdfXref *xref, pdf_annot_type type);
Subtype()2307         pdf_annot_type      Subtype()   { return fSubtype; }
Rect()2308         pdf_rect            Rect()      { return fRect; }
2309         void                SetRect(pdf_rect rect);
2310         const char*         SubtypeText(pdf_annot_type type);
2311         void                SetBorder(double horiz, double vert, double width);
2312         void                GetBorder(double* horiz, double* vert,
2313                                 double* width);
2314         PdfBorderStyle*     GetBorderStyle();
2315 protected:
2316         void                InternalWriteStream(PdfStreamBase* out,
2317                                 PdfEncryptor* e);
2318 private:
2319         pdf_annot_type      fSubtype;
2320         pdf_rect            fRect;
2321         double              fBorder[3];
2322 };
2323 
2324 /*----------------------------------------------------------------------------*/
2325 /*----- PdfLinkAnnot ---------------------------------------------------------*/
2326 
2327 class PdfLinkAnnot : public PdfAnnotation
2328 {
2329 public:
PdfLinkAnnot(PdfXref * xref)2330                         PdfLinkAnnot(PdfXref* xref)
2331                             : PdfAnnotation(xref, PDF_ANNOT_LINK) {}
2332     pdf_annot_hl_mode   HightlightMode();
2333     PdfDestination*     Dest();
2334     void                SetDest(PdfDestination* dest);
2335     void                SetHightlightMode(pdf_annot_hl_mode mode);
2336 };
2337 
2338 /*----------------------------------------------------------------------------*/
2339 /*----- PdfTextAnnot ---------------------------------------------------------*/
2340 
2341 class PdfTextAnnot : public PdfAnnotation
2342 {
2343 public:
2344                             PdfTextAnnot(PdfXref* xref);
2345     const char*             GetContents();
2346     void                    SetContents(const char* text,
2347                                 PdfEncodingDef* encoding = NULL);
2348     void                    SetContentsMb(const char* text, PdfCMap* cmap);
GetOpened()2349     bool                    GetOpened()             { return fOpened; }
SetOpened(bool value)2350     void                    SetOpened(bool value)   { fOpened = value; }
SetIcon(pdf_annot_icon_names icon)2351     void                    SetIcon(pdf_annot_icon_names icon)
2352                                 { fIcon = icon; }
GetIcon()2353     pdf_annot_icon_names    GetIcon()   { return fIcon; }
2354 protected:
2355     void                    InternalWriteStream(PdfStreamBase* out,
2356                                     PdfEncryptor* e);
2357 private:
2358     PdfObject*              fContents;
2359     bool                    fOpened;
2360     pdf_annot_icon_names    fIcon;
2361 };
2362 
2363 /*----------------------------------------------------------------------------*/
2364 /*----- operator type --------------------------------------------------------*/
2365 
2366 typedef enum pdf_ope_type_enum {
2367     otUnknown = 0,
2368     otGeneralGState,
2369     otSpecialGState,
2370     otPathConstruction,
2371     otColor,
2372     otTextState,
2373     otTextShowing,
2374     otTextPositioning,
2375     otMarkdContent,
2376     otID
2377 } pdf_ope_type;
2378 
2379 /*----------------------------------------------------------------------------*/
2380 /*----- PdfContents class ----------------------------------------------------*/
2381 
2382 class PdfContents : public PdfStream
2383 {
2384 public:
2385                         PdfContents(PdfPage *page);
2386     void                Init();
Page()2387     PdfPage*            Page()              { return fPage; }
Width()2388     int                 Width()             { return fPage->Width(); }
Height()2389     int                 Height()            { return fPage->Height(); }
CurPoint()2390     pdf_point           CurPoint()          { return fCurPoint; }
TextPos()2391     pdf_point           TextPos()           { return fTextPoint; }
TextLeading()2392     double              TextLeading()       { return fTextLeading; }
FontSize()2393     double              FontSize()          { return fFontSize; }
FontName()2394     const char*         FontName()
2395                             { return ((fFont != NULL) ? fFont->Name() : NULL); }
Font()2396     PdfFont*            Font()              { return fFont; }
CharSpace()2397     double              CharSpace()         { return fCharSpace; }
WordSpace()2398     double              WordSpace()         { return fWordSpace; }
2399     double              TextWidth(const char* text, int* numchars = NULL,
2400                             int* numwords = NULL);
2401     void                CharWidths(const char* chars, double* widths);
2402     unsigned int        MeasureText(const char* text, double width,
2403                             double* realwidth = NULL);
2404     void                TextRect(const char* text, pdf_rect rect,
2405                             int max_len = PDF_DEF_BUF_SIZE);
2406     void                TextOut(double x, double y, const char* text);
RGBFill()2407     pdf_rgb_color       RGBFill()           { return fRGBFill; }
RGBStroke()2408     pdf_rgb_color       RGBStroke()         { return fRGBStroke; }
GrayFill()2409     double              GrayFill()          { return fGrayFill; }
GrayStroke()2410     double              GrayStroke()        { return fGrayStroke; }
GMode()2411     pdf_graphics_mode   GMode()             { return fGMode; }
2412 
2413     /*--- General graphics state ---------------------------------------------*/
2414 
2415     void        SetLineWidth(double linewidth);                          /* w */
2416     void        SetLineCap(pdf_line_cap_style linecap);                  /* J */
2417     void        SetLineJoin(pdf_line_join_style linejoin);               /* j */
2418     void        SetMiterLimit(double miterlimit);                        /* M */
2419     void        SetDash(unsigned int on, unsigned int off,
2420                     unsigned int phase);                                 /* d */
2421                                                   /* ri --not implemented yet */
2422     void        SetFlat(unsigned int flatness);                          /* i */
2423                                                   /* gs --not implemented yet */
2424 
2425     /*--- Special graphic state ----------------------------------------------*/
2426 
2427     void        GSave();                                                 /* q */
2428     void        GRestore();                                              /* Q */
2429     void        Concat(double a, double b, double c,
2430                        double d, double e, double f);                   /* cm */
2431 
2432     /*--- Path construction --------------------------------------------------*/
2433 
2434     void        MoveTo(double x, double y);                              /* m */
2435     void        LineTo(double x, double y);                              /* l */
2436     void        CurveTo(double x1, double y1, double x2,
2437                     double y2, double x3, double y3);                    /* c */
2438     void        CurveTo2(double x2, double y2, double x3, double y3);    /* v */
2439     void        CurveTo3(double x1, double y1, double x3, double y3);    /* y */
2440     void        ClosePath();                                             /* h */
2441     void        Rectangle(double x, double y,
2442                     double width, double height);                       /* re */
2443 
2444     /*--- Path painting ------------------------------------------------------*/
2445 
2446     void        Stroke();                                                /* S */
2447     void        ClosePathStroke();                                       /* s */
2448     void        Fill();                                                  /* f */
2449     void        Eofill();                                               /* f* */
2450     void        FillStroke();                                            /* B */
2451     void        EofillStroke();                                         /* B* */
2452     void        ClosePathFillStroke();                                   /* b */
2453     void        ClosePathEofillStroke();                                /* b* */
2454     void        EndPath();                                               /* n */
2455 
2456     /*--- Clipping paths -----------------------------------------------------*/
2457 
2458     void        Clip();                                                  /* W */
2459     void        EoClip();                                               /* W* */
2460 
2461     /*--- Text object --------------------------------------------------------*/
2462 
2463     void        BeginText();                                            /* BT */
2464     void        EndText();                                              /* ET */
2465 
2466     /*--- Text state ---------------------------------------------------------*/
2467 
2468     void        SetCharSpace(double value);                             /* Tc */
2469     void        SetWordSpace(double value);                             /* Tw */
2470     void        SetHorizontalScalling(double value);                    /* Tz */
2471     void        SetTextLeading(double value);                           /* TL */
2472     void        SetFontAndSize(const char* fontname, double size);      /* Tf */
2473     void        SetFontAndSize(PdfFont* font, double size);
2474     void        SetTextRenderingMode(pdf_text_rendering_mode mode);     /* Tr */
2475     void        SetTextRaise(double value);                             /* Ts */
2476 
2477     /*--- Text positioning ---------------------------------------------------*/
2478 
2479     void        MoveTextPos(double tx, double ty);                      /* Td */
2480     void        MoveTextPos2(double tx, double ty);                     /* TD */
2481     void        SetTextMatrix(double a, double b, double c,
2482                     double d, double x, double y);                      /* Tm */
2483     void        MoveToNextLine();                                       /* T* */
2484 
2485     /*--- Text showing -------------------------------------------------------*/
2486 
2487     void        ShowText(const char* text);                             /* Tj */
2488                                                                         /* TJ */
2489     void        ShowTextNextLine(const char* text);                      /* ' */
2490     void        ShowTextNextLine(double aw, double ac,
2491                     const char* text);                                   /* " */
2492 
2493     /*--- Color showing ------------------------------------------------------*/
2494 
2495                                                   /* cs --not implemented yet */
2496                                                   /* CS --not implemented yet */
2497                                                   /* sc --not implemented yet */
2498                                                  /* scn --not implemented yet */
2499                                                   /* SC --not implemented yet */
2500                                                  /* SCN --not implemented yet */
2501     void        SetGrayFill(double gray);                                /* g */
2502     void        SetGrayStroke(double gray);                              /* G */
2503     void        SetRGBFill(double r, double g, double b);               /* rg */
2504     void        SetRGBFill(int r, int g, int b);
SetRGBFill(pdf_rgb_color c)2505     void        SetRGBFill(pdf_rgb_color c)
2506                     { SetRGBFill(c.red, c.green, c.blue); }
2507     void        SetRGBStroke(double r, double g, double b);             /* RG */
SetRGBStroke(pdf_rgb_color c)2508     void        SetRGBStroke(pdf_rgb_color c)
2509                     { SetRGBStroke(c.red, c.green, c.blue); }
2510     void        SetRGBStroke(int r, int g, int b);
2511     void        SetCMYKFill(double c, double m, double y, double k);     /* k */
2512     void        SetCMYKStroke(double c, double m, double y, double k);   /* K */
2513 
2514     /*--- Shading patterns ---------------------------------------------------*/
2515 
2516                                                   /* sh --not implemented yet */
2517 
2518     /*--- In-line images -----------------------------------------------------*/
2519 
2520                                                   /* BI --not implemented yet */
2521                                                   /* ID --not implemented yet */
2522                                                   /* EI --not implemented yet */
2523 
2524     /*--- XObjects -----------------------------------------------------------*/
2525 
2526     void        ExecuteXObject(const char* name);                       /* Do */
2527     void        ExecuteXObject(PdfXObject* xobject);
2528 
2529     /*--- Marked content -----------------------------------------------------*/
2530 
2531                                                  /* BMC --not implemented yet */
2532                                                  /* BDC --not implemented yet */
2533                                                  /* EMC --not implemented yet */
2534                                                   /* MP --not implemented yet */
2535                                                   /* DP --not implemented yet */
2536 
2537     /*--- Compatibility ------------------------------------------------------*/
2538 
2539                                                   /* BX --not implemented yet */
2540                                                   /* EX --not implemented yet */
2541 protected:
2542 private:
2543     PdfPage*                fPage;
2544     PdfFontMgr*             fFontMgr;
2545     PdfXObjectMgr*          fXObjectMgr;
2546 
2547     double                  fCharSpace;
2548     double                  fWordSpace;
2549     double                  fFontSize;
2550     PdfFont*                fFont;
2551     double                  fHScalling;
2552     double                  fTextLeading;
2553     pdf_text_rendering_mode fRenderingMode;
2554     double                  fTextRaise;
2555 
2556     double                  fLineWidth;
2557     pdf_line_cap_style      fLineCap;
2558     pdf_line_join_style     fLineJoin;
2559     double                  fMiterLimit;
2560     unsigned int            fDashOn;
2561     unsigned int            fDashOff;
2562     unsigned int            fDashPhase;
2563     unsigned int            fFlatness;
2564 
2565     pdf_point               fStartPoint;
2566     pdf_point               fCurPoint;
2567     pdf_point               fTextPoint;
2568     pdf_text_matrix         fMatrix;
2569     pdf_graphics_mode       fGMode;
2570 
2571     pdf_rgb_color           fRGBFill;
2572     pdf_rgb_color           fRGBStroke;
2573     double                  fGrayFill;
2574     double                  fGrayStroke;
2575 };
2576 
2577 /*----------------------------------------------------------------------------*/
2578 /*----- PdfCatalog class -----------------------------------------------------*/
2579 
2580 class PdfOutlineRoot;
2581 class PdfPageLabel;
2582 
2583 class PdfCatalog : public PdfDictionary
2584 {
2585 public:
2586                     PdfCatalog(PdfXref *xref);
2587                     PdfCatalog(int objectID, PdfXref *xref);
2588     void            Init();
OpenAction()2589     PdfDestination* OpenAction()            { return fOpenAction; }
2590     PdfOutlineRoot* Outlines();
PageLayout()2591     pdf_page_layout PageLayout()            { return fPageLayout; }
PageMode()2592     pdf_page_mode   PageMode()              { return fPageMode; }
NonFullScreenPageMode()2593     pdf_page_mode   NonFullScreenPageMode() { return fNonFullScreenPageMode; }
ViewerPreferences()2594     int             ViewerPreferences()     { return fViewerPreferences; }
IsSetViewerPreference(int preferences)2595     bool            IsSetViewerPreference(int preferences)  { return
2596                         ((fViewerPreferences & preferences) == preferences); }
2597     PdfPages*       Pages();
SetPageLayout(pdf_page_layout layout)2598     void            SetPageLayout(pdf_page_layout layout)
2599                             { fPageLayout = layout; }
SetPageMode(pdf_page_mode mode)2600     void            SetPageMode(pdf_page_mode mode)
2601                             { fPageMode = mode; }
SetNonFullScreenPageMode(pdf_page_mode mode)2602     void            SetNonFullScreenPageMode(pdf_page_mode mode)
2603                             { fNonFullScreenPageMode = mode; }
SetViewerPreferences(int viewerPreferences)2604     void            SetViewerPreferences(int viewerPreferences)
2605                             { fViewerPreferences = viewerPreferences; }
2606     void            SetOpenAction(PdfDestination* action);
2607     void            AddPageLabel(unsigned int pagenum, pdf_page_num_style style,
2608                         unsigned int firstpage = 1, const char* prefix = NULL);
2609     void            ClearPageLabel();
2610 protected:
2611     void            InternalAddPageLabel(unsigned int pagenum,
2612                         PdfPageLabel* label);
2613     void            InternalWriteStream(PdfStreamBase* out,
2614                         PdfEncryptor* e);
2615 private:
2616     pdf_page_layout fPageLayout;
2617     pdf_page_mode   fPageMode;
2618     pdf_page_mode   fNonFullScreenPageMode;
2619     PdfDestination* fOpenAction;
2620     int             fViewerPreferences;
2621 };
2622 
2623 /*---------------------------------------------------------------------------*/
2624 /*----- PdfPageLabel --------------------------------------------------------*/
2625 
2626 class  PdfPageLabel : public PdfDictionary
2627 {
2628 public:
2629                             PdfPageLabel(PdfXref *xref);
2630                             ~PdfPageLabel();
NumberingStyle()2631         pdf_page_num_style  NumberingStyle()    { return fNumberingStyle; }
LabelPrefix()2632         const char*         LabelPrefix()       { return fLabelPrefix; }
FirstPage()2633         unsigned int        FirstPage()         { return fFirstPage; }
SetNumberingStyle(pdf_page_num_style value)2634         void                SetNumberingStyle(pdf_page_num_style value)
2635                                                 { fNumberingStyle = value; }
2636         void                SetLabelPrefix(const char* value);
SetFirstPage(unsigned int page)2637         void                SetFirstPage(unsigned int page)
2638                                                 { fFirstPage = page; }
2639 protected:
2640         void                InternalWriteStream(PdfStreamBase* out,
2641                                 PdfEncryptor* e);
2642 private:
2643         pdf_page_num_style  fNumberingStyle;
2644         char*               fLabelPrefix;
2645         unsigned int        fFirstPage;
2646 };
2647 
2648 /*----------------------------------------------------------------------------*/
2649 /*------ PdfInfo -------------------------------------------------------------*/
2650 
2651 class PdfInfo : public PdfDictionary
2652 {
2653 public:
2654                     PdfInfo(PdfXref* xref);
2655                     PdfInfo(int objectID, PdfXref* xref);
2656     void            Init();
2657     pdf_date        CreationDate();
2658     pdf_date        ModDate();
Author()2659     const char*     Author()            { return GetTextValue("Author"); }
Creator()2660     const char*     Creator()           { return GetTextValue("Creator"); }
Producer()2661     const char*     Producer()          { return GetTextValue("Producer"); }
Title()2662     const char*     Title()             { return GetTextValue("Title"); }
Subject()2663     const char*     Subject()           { return GetTextValue("Subject"); }
Keywords()2664     const char*     Keywords()          { return GetTextValue("Keywords"); }
2665     void            SetCreationDate(pdf_date value);
2666     void            SetModDate(pdf_date value);
2667     void            SetAuthor(const char* value,
2668                         PdfEncodingDef* encoding = NULL);
2669     void            SetCreator(const char* value,
2670                         PdfEncodingDef* encoding = NULL);
2671     void            SetProducer(const char* value,
2672                         PdfEncodingDef* encoding = NULL);
2673     void            SetTitle(const char* value,
2674                         PdfEncodingDef* encoding = NULL);
2675     void            SetSubject(const char* value,
2676                         PdfEncodingDef* encoding = NULL);
2677     void            SetKeywords(const char* value,
2678                         PdfEncodingDef* encoding = NULL);
SetAuthorMb(const char * value,PdfCMap * cmap)2679     void            SetAuthorMb(const char* value, PdfCMap* cmap)
2680                                 { SetMbText("Author", value, cmap); }
SetCreatorMb(const char * value,PdfCMap * cmap)2681     void            SetCreatorMb(const char* value, PdfCMap* cmap)
2682                                 { SetMbText("Creator", value, cmap); }
SetProducerMb(const char * value,PdfCMap * cmap)2683     void            SetProducerMb(const char* value, PdfCMap* cmap)
2684                                 { SetMbText("Producer", value, cmap); }
SetTitleMb(const char * value,PdfCMap * cmap)2685     void            SetTitleMb(const char* value, PdfCMap* cmap)
2686                                 { SetMbText("Title", value, cmap); }
SetSubjectMb(const char * value,PdfCMap * cmap)2687     void            SetSubjectMb(const char* value, PdfCMap* cmap)
2688                                 { SetMbText("Subject", value, cmap); }
SetKeywordsMb(const char * value,PdfCMap * cmap)2689     void            SetKeywordsMb(const char* value, PdfCMap* cmap)
2690                                 { SetMbText("Keywords", value, cmap); }
2691 protected:
2692 private:
2693     pdf_date        StrToPdfDate(const char* value);
2694     bool            PdfDateToStr(const pdf_date date, char* value, int length);
2695     void            SetTextAsUnicode(const char* key, const char* value,
2696                         PdfEncodingDef* encoding);
2697     void            SetMbText(const char* key, const char* value,
2698                         PdfCMap* cmap);
2699 };
2700 
2701 /*----------------------------------------------------------------------------*/
2702 /*----- PdfEncryptDict class -------------------------------------------------*/
2703 
2704 #ifdef USE_ENCRYPTION
2705 class PdfEncryptDict : public PdfDictionary
2706 {
2707 public:
2708                     PdfEncryptDict(PdfXref* xref, PdfInfo* info = NULL);
2709     void            Init();
2710     void            SetPassword(const char* owner_passwd,
2711                         const char* user_passwd);
SetPermission(int value)2712     void            SetPermission(int value)
2713                         { fPermission = value | PDF_PERMISSION_PAD; }
2714     void            EncryptPassword();
Permission()2715     int             Permission()    { return fPermission; }
2716     const unsigned char*
ID()2717                     ID()    { return fID; }
2718     const unsigned char*
FileKey()2719                     FileKey()       { return fFileKey; }
2720 private:
2721     void            CreateID();
2722     void            CreateUserKey();
2723     void            CreateOwnerKey();
2724     void            CreateFileKey();
2725     void            PadOrTruncatePasswd(const char* passwd, unsigned char* out);
2726     unsigned char   fOwnerPasswdValue[PDF_PASSWD_LEN];
2727     unsigned char   fUserPasswdValue[PDF_PASSWD_LEN];
2728     unsigned char   fOwnerPasswd[PDF_PASSWD_LEN];
2729     unsigned char   fUserPasswd[PDF_PASSWD_LEN];
2730     unsigned char   fFileKey[PDF_MD5_KEY_LEN];
2731     unsigned char   fID[PDF_ID_LEN];
2732     PdfInfo*        fInfo;
2733     int             fPermission;
2734 };
2735 #else
2736 typedef void PdfEncryptDict;
2737 #endif
2738 
2739 /*----------------------------------------------------------------------------*/
2740 /*----- PdfOutlineBase class -------------------------------------------------*/
2741 
2742 class PdfOutlineItem;
2743 
2744 class PdfOutlineBase : public PdfDictionary
2745 {
2746     friend class PdfOutlineItem;
2747 public:
2748                         PdfOutlineBase(PdfXref *xref);
First()2749         PdfOutlineItem* First()
2750                         { return (PdfOutlineItem*)GetValue("First"); }
Last()2751         PdfOutlineItem* Last()
2752                         { return (PdfOutlineItem*)GetValue("Last"); }
HasChild()2753         bool            HasChild()    { return ChildCount() > 0; }
2754 virtual int             ChildCount();
Opened()2755         bool            Opened()      { return fOpened; }
SetOpened(bool value)2756         void            SetOpened(bool value)   { fOpened = value; }
2757 protected:
2758         void            AddChild(PdfOutlineItem* item);
2759         void            InternalWriteStream(PdfStreamBase* out,
2760                             PdfEncryptor* e);
2761         bool            fOpened;
2762 };
2763 
2764 typedef PdfOutlineBase  PdfOutline;
2765 
2766 /*----------------------------------------------------------------------------*/
2767 /*----- PdfOutlineRoot class -------------------------------------------------*/
2768 
2769 class PdfOutlineRoot : public PdfOutline
2770 {
2771 public:
2772                         PdfOutlineRoot(PdfXref *xref);
2773 };
2774 
2775 /*----------------------------------------------------------------------------*/
2776 /*----- PdfOutlineItem class -------------------------------------------------*/
2777 
2778 class PdfOutlineItem : public PdfOutline
2779 {
2780 public:
2781                         PdfOutlineItem(PdfOutline *parent);
2782         const char*     Title();
2783         void            SetTitle(const char* title,
2784                             PdfEncodingDef* encoding = NULL);
2785         void            SetTitleMb(const char* title, PdfCMap* cmap);
2786         void            SetDestination(PdfDestination* dst);
Prev()2787         PdfOutlineItem* Prev()
2788                         { return (PdfOutlineItem*)GetValue("Prev"); }
Next()2789         PdfOutlineItem* Next()
2790                         { return (PdfOutlineItem*)GetValue("Next"); }
Parent()2791         PdfOutline*     Parent()
2792                         { return (PdfOutline*)GetValue("Parent"); }
2793 private:
2794         PdfText*        fTitle;
2795 };
2796 
2797 /*----------------------------------------------------------------------------*/
2798 /*----- PdfXObjectBase class -------------------------------------------------*/
2799 
2800 class PdfXObjectBase : public PdfStream
2801 {
2802     friend class PdfXObjectMgr;
2803 public:
2804                         PdfXObjectBase(PdfDoc* doc);
2805                         ~PdfXObjectBase();
Name()2806         const char*     Name()    { return fName; }
2807 virtual bool            IsValidObject() = 0;
2808 protected:
2809         void            SetName(const char* name);
2810 private:
2811         char            fName[PDF_LIMIT_MAX_NAME + 1];
2812         bool            fValid;
2813 };
2814 
2815 /*----------------------------------------------------------------------------*/
2816 /*----- PdfXObjectMgr class --------------------------------------------------*/
2817 
2818 class PdfXObjectMgr
2819 {
2820 public:
2821                         PdfXObjectMgr(PdfXref* xref);
2822                         ~PdfXObjectMgr();
2823         void            RegisterXObject(PdfXObject* xobject, const char* name);
2824         PdfXObject*     GetXObject(const char* name);
GetXObject(unsigned int index)2825         PdfXObject*     GetXObject(unsigned int index)
2826                             { return (PdfXObject*)fList->ItemAt(index); }
CountXObjects()2827         unsigned int    CountXObjects()  { return fList->CountItems(); }
2828 private:
2829         PdfList*        fList;
2830         PdfXref*        fXref;
2831 };
2832 
2833 /*----------------------------------------------------------------------------*/
2834 /*----- PdfImage class -------------------------------------------------------*/
2835 
2836 class PdfImage : public PdfXObject
2837 {
2838 public:
2839                         PdfImage(PdfDoc* doc);
Width()2840         double           Width()              { return fWidth; }
Height()2841         double           Height()             { return fHeight; }
ColorSpace()2842         pdf_color_space ColorSpace()         { return fColorSpace; }
BitsPerComponent()2843         unsigned int    BitsPerComponent()   { return fBitsPerComponent; }
2844 protected:
2845         void            InternalWriteStream(PdfStreamBase* out,
2846                             PdfEncryptor* e);
2847         unsigned int    fWidth;
2848         unsigned int    fHeight;
2849         unsigned int    fBitsPerComponent;
2850         pdf_color_space fColorSpace;
2851 };
2852 
2853 /*----------------------------------------------------------------------------*/
2854 /*------ utilities -----------------------------------------------------------*/
2855 
2856 const char* PdfGetColorSpaceName(pdf_color_space cs);
2857 
2858 /*----------------------------------------------------------------------------*/
2859 /*----- PdfHeader class ------------------------------------------------------*/
2860 
2861 class PdfHeader
2862 {
2863     friend class    PdfDoc;
2864 protected:
2865     void            WriteToStream(PdfStreamBase* out);
2866 private:
2867 };
2868 
2869 /*----------------------------------------------------------------------------*/
2870 /*----- PdfTrailer class -----------------------------------------------------*/
2871 
2872 class PdfTrailer
2873 {
2874     friend class    PdfDoc;
2875 public:
2876                     PdfTrailer(PdfXref *xref);
2877                     ~PdfTrailer();
2878     void            SetEncryptDict(PdfEncryptDict* encrypt);
2879 protected:
2880     void            WriteToStream(PdfStreamBase* out);
2881     void            SetXrefAddr(unsigned int addr);
2882     void            SetXrefSize(unsigned int size);
2883     void            SetRoot(PdfCatalog* root);
2884     void            SetInfo(PdfInfo* info);
2885 private:
2886     void            SetID(const unsigned char* id);
2887     PdfDictionary*  fAttributes;
2888     PdfEncryptDict* fEncryptDict;
2889     unsigned int    fXrefAddr;
2890     PdfXref*        fXref;
2891     unsigned char   fID1[PDF_ID_LEN];
2892     unsigned char   fID2[PDF_ID_LEN];
2893 };
2894 
2895 /*----------------------------------------------------------------------------*/
2896 /*----- PdfDoc class ---------------------------------------------------------*/
2897 
2898 class PdfDoc
2899 {
2900     friend class PdfPages;
2901 public:
2902                         PdfDoc();
2903                         ~PdfDoc();
2904         void            NewDoc();
2905         void            FreeDoc(bool free_all_objects = true);
2906         void            WriteToStream(PdfStreamBase* out);
2907         void            WriteToFile(const char* filename);
2908         void            AddType1Font(PdfType1FontDef* fontdef,
2909                             const char* name = NULL,
2910                             PdfEncodingDef* encoding = NULL);
2911 
2912         void            AddType0Font(PdfCIDFontDef* fontdef,
2913                             const char* name = NULL,
2914                             PdfCMap* cmap = NULL);
2915 
2916         void            AddXObject(PdfXObject* xobject,
2917                             const char* name = NULL);
2918         void            RegisterObject(PdfAutoPtrObject* obj);
2919         PdfPage*        AddPage();
Catalog()2920         PdfCatalog*     Catalog()           { return fCatalog; }
2921         PdfInfo*        Info();
2922         void            SetPassword(const char* owner_passwd,
2923                             const char* user_passwd);
2924         void            SetPermission(int permission);
Xref()2925         PdfXref*        Xref()              { return fXref; }
Outlines()2926         PdfOutlineRoot* Outlines()          { return Catalog()->Outlines(); }
RootPages()2927         PdfPages*       RootPages()         { return fRootPages; }
CurrentPages()2928         PdfPages*       CurrentPages()      { return fCurrentPages; }
CurrentPage()2929         PdfPage*        CurrentPage()       { return fCurrentPage; }
XObjectMgr()2930         PdfXObjectMgr*  XObjectMgr()        { return fXObjectMgr; }
FontMgr()2931         PdfFontMgr*     FontMgr()           { return fFontMgr; }
HasDoc()2932         bool            HasDoc()            { return fHasDoc; }
LastError()2933         int             LastError()         { return fError; }
2934         void            SetError(int err);
2935 private:
2936         void            Init();
SetCurrentPages(PdfPages * pages)2937         void            SetCurrentPages(PdfPages* pages)
2938                                             { fCurrentPages = pages; }
SetCurrentPage(PdfPage * page)2939         void            SetCurrentPage(PdfPage* page)
2940                                             { fCurrentPage = page; }
GetEncryptDict()2941         PdfEncryptDict* GetEncryptDict()
2942                             { return fTrailer->fEncryptDict; }
IsEncrypted()2943         bool            IsEncrypted()
2944                             { return (GetEncryptDict() != NULL); }
2945         PdfXref*        fXref;
2946         PdfHeader*      fHeader;
2947         PdfTrailer*     fTrailer;
2948         PdfCatalog*     fCatalog;
2949         PdfInfo*        fInfo;
2950         PdfFontMgr*     fFontMgr;
2951         PdfXObjectMgr*  fXObjectMgr;
2952         PdfAutoPtrMgr*  fAutoPtrMgr;
2953         PdfPages*       fRootPages;
2954         PdfPages*       fCurrentPages;
2955         PdfPage*        fCurrentPage;
2956         bool            fHasDoc;
2957         int             fError;
2958 };
2959 
2960 /*----------------------------------------------------------------------------*/
2961 /*----- PdfPngImage class ----------------------------------------------------*/
2962 
2963 #ifndef NOPNG
2964 
2965 class PdfPngImage : public PdfImage
2966 {
2967 public:
2968                         PdfPngImage(PdfDoc* doc);
2969                         ~PdfPngImage();
2970         void            LoadFromFile(const char* filename);
2971         void            FreeImage();
IsValidObject()2972         bool            IsValidObject()    { return fHasImage; }
2973 private:
2974         FILE*           OpenImageFile(const char* filename);
2975         void            CreatePallet(png_structp png_ptr, png_infop info_ptr);
2976         bool            fHasImage;
2977         unsigned char*  fPallet;
2978         unsigned int    fNumPallet;
2979 };
2980 
2981 #endif /* NOPNG */
2982 
2983 /*----------------------------------------------------------------------------*/
2984 /*----- PdfJpegImage class ---------------------------------------------------*/
2985 
2986 #ifndef NOJPEG
2987 
2988 class PdfJpegImage : public PdfImage
2989 {
2990 public:
2991                         PdfJpegImage(PdfDoc* doc);
2992                         ~PdfJpegImage();
2993         void            LoadFromFile(const char* filename);
2994         void            FreeImage();
IsValidObject()2995         bool            IsValidObject()    { return fHasImage; }
2996 private:
2997         bool            fHasImage;
2998 };
2999 
3000 void
3001 PdfJpegErrorExit(j_common_ptr cinfo);
3002 
3003 #endif /* NOJPEG */
3004 
3005 
3006 /*---------------------------------------------------------------------------*/
3007 /*----- Utility routines ----------------------------------------------------*/
3008 
3009 extern "C" {
3010 #endif /* __cplusplus */
3011 
3012 pdf_rgb_color PdfRGBColor(double r, double g, double b);
3013 
3014 pdf_point PdfPoint(double x, double y);
3015 
3016 pdf_rect PdfRect(double left, double bottom, double right, double top);
3017 
3018 pdf_box PdfBox(int left, int bottom, int right, int top);
3019 
3020 pdf_text_matrix PdfTextMatrix(double a, double b, double c, double d,
3021         double x, double y);
3022 
3023 #ifdef __cplusplus
3024 }
3025 #endif
3026 
3027 #endif /* _LIB_HARU_H */
3028 
3029