1 /* 2 * << Haru Free PDF Library >> -- hpdf_objects.c 3 * 4 * URL: http://libharu.org 5 * 6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> 7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org> 8 * 9 * Permission to use, copy, modify, distribute and sell this software 10 * and its documentation for any purpose is hereby granted without fee, 11 * provided that the above copyright notice appear in all copies and 12 * that both that copyright notice and this permission notice appear 13 * in supporting documentation. 14 * It is provided "as is" without express or implied warranty. 15 * 16 */ 17 18 #ifndef _HPDF_OBJECTS_H 19 #define _HPDF_OBJECTS_H 20 21 #include "hpdf_encoder.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 28 /* if HPDF_OTYPE_DIRECT bit is set, the object owned by other container 29 * object. if HPDF_OTYPE_INDIRECT bit is set, the object managed by xref. 30 */ 31 32 #define HPDF_OTYPE_NONE 0x00000000 33 #define HPDF_OTYPE_DIRECT 0x80000000 34 #define HPDF_OTYPE_INDIRECT 0x40000000 35 #define HPDF_OTYPE_ANY (HPDF_OTYPE_DIRECT | HPDF_OTYPE_INDIRECT) 36 #define HPDF_OTYPE_HIDDEN 0x10000000 37 38 #define HPDF_OCLASS_UNKNOWN 0x0001 39 #define HPDF_OCLASS_NULL 0x0002 40 #define HPDF_OCLASS_BOOLEAN 0x0003 41 #define HPDF_OCLASS_NUMBER 0x0004 42 #define HPDF_OCLASS_REAL 0x0005 43 #define HPDF_OCLASS_NAME 0x0006 44 #define HPDF_OCLASS_STRING 0x0007 45 #define HPDF_OCLASS_BINARY 0x0008 46 #define HPDF_OCLASS_ARRAY 0x0010 47 #define HPDF_OCLASS_DICT 0x0011 48 #define HPDF_OCLASS_PROXY 0x0012 49 #define HPDF_OCLASS_ANY 0x00FF 50 51 #define HPDF_OSUBCLASS_FONT 0x0100 52 #define HPDF_OSUBCLASS_CATALOG 0x0200 53 #define HPDF_OSUBCLASS_PAGES 0x0300 54 #define HPDF_OSUBCLASS_PAGE 0x0400 55 #define HPDF_OSUBCLASS_XOBJECT 0x0500 56 #define HPDF_OSUBCLASS_OUTLINE 0x0600 57 #define HPDF_OSUBCLASS_DESTINATION 0x0700 58 #define HPDF_OSUBCLASS_ANNOTATION 0x0800 59 #define HPDF_OSUBCLASS_ENCRYPT 0x0900 60 #define HPDF_OSUBCLASS_EXT_GSTATE 0x0A00 61 #define HPDF_OSUBCLASS_EXT_GSTATE_R 0x0B00 /* read only object */ 62 #define HPDF_OSUBCLASS_NAMEDICT 0x0C00 63 #define HPDF_OSUBCLASS_NAMETREE 0x0D00 64 65 66 67 /*----------------------------------------------------------------------------*/ 68 /*------ Values related xref -------------------------------------------------*/ 69 70 #define HPDF_FREE_ENTRY 'f' 71 #define HPDF_IN_USE_ENTRY 'n' 72 73 74 /* 75 * structure of Object-ID 76 * 77 * 1 direct-object 78 * 2 indirect-object 79 * 3 reserved 80 * 4 shadow-object 81 * 5-8 reserved 82 * 9-32 object-idi0-8388607j 83 * 84 * the real Object-ID is described "obj_id & 0x00FFFFFF" 85 */ 86 87 typedef struct _HPDF_Obj_Header { 88 HPDF_UINT32 obj_id; 89 HPDF_UINT16 gen_no; 90 HPDF_UINT16 obj_class; 91 } HPDF_Obj_Header; 92 93 94 95 HPDF_STATUS 96 HPDF_Obj_WriteValue (void *obj, 97 HPDF_Stream stream, 98 HPDF_Encrypt e); 99 100 101 HPDF_STATUS 102 HPDF_Obj_Write (void *obj, 103 HPDF_Stream stream, 104 HPDF_Encrypt e); 105 106 107 void 108 HPDF_Obj_Free (HPDF_MMgr mmgr, 109 void *obj); 110 111 112 void 113 HPDF_Obj_ForceFree (HPDF_MMgr mmgr, 114 void *obj); 115 116 117 /*---------------------------------------------------------------------------*/ 118 /*----- HPDF_Null -----------------------------------------------------------*/ 119 120 typedef struct _HPDF_Null_Rec *HPDF_Null; 121 122 typedef struct _HPDF_Null_Rec { 123 HPDF_Obj_Header header; 124 } HPDF_Null_Rec; 125 126 127 128 HPDF_Null 129 HPDF_Null_New (HPDF_MMgr mmgr); 130 131 132 /*---------------------------------------------------------------------------*/ 133 /*----- HPDF_Boolean --------------------------------------------------------*/ 134 135 typedef struct _HPDF_Boolean_Rec *HPDF_Boolean; 136 137 typedef struct _HPDF_Boolean_Rec { 138 HPDF_Obj_Header header; 139 HPDF_BOOL value; 140 } HPDF_Boolean_Rec; 141 142 143 144 HPDF_Boolean 145 HPDF_Boolean_New (HPDF_MMgr mmgr, 146 HPDF_BOOL value); 147 148 149 HPDF_STATUS 150 HPDF_Boolean_Write (HPDF_Boolean obj, 151 HPDF_Stream stream); 152 153 154 /*---------------------------------------------------------------------------*/ 155 /*----- HPDF_Number ---------------------------------------------------------*/ 156 157 typedef struct _HPDF_Number_Rec *HPDF_Number; 158 159 typedef struct _HPDF_Number_Rec { 160 HPDF_Obj_Header header; 161 HPDF_INT32 value; 162 } HPDF_Number_Rec; 163 164 165 166 HPDF_Number 167 HPDF_Number_New (HPDF_MMgr mmgr, 168 HPDF_INT32 value); 169 170 171 void 172 HPDF_Number_SetValue (HPDF_Number obj, 173 HPDF_INT32 value); 174 175 176 HPDF_STATUS 177 HPDF_Number_Write (HPDF_Number obj, 178 HPDF_Stream stream); 179 180 181 /*---------------------------------------------------------------------------*/ 182 /*----- HPDF_Real -----------------------------------------------------------*/ 183 184 typedef struct _HPDF_Real_Rec *HPDF_Real; 185 186 typedef struct _HPDF_Real_Rec { 187 HPDF_Obj_Header header; 188 HPDF_Error error; 189 HPDF_REAL value; 190 } HPDF_Real_Rec; 191 192 193 194 HPDF_Real 195 HPDF_Real_New (HPDF_MMgr mmgr, 196 HPDF_REAL value); 197 198 199 HPDF_STATUS 200 HPDF_Real_Write (HPDF_Real obj, 201 HPDF_Stream stream); 202 203 204 HPDF_STATUS 205 HPDF_Real_SetValue (HPDF_Real obj, 206 HPDF_REAL value); 207 208 209 /*---------------------------------------------------------------------------*/ 210 /*----- HPDF_Name -----------------------------------------------------------*/ 211 212 typedef struct _HPDF_Name_Rec *HPDF_Name; 213 214 typedef struct _HPDF_Name_Rec { 215 HPDF_Obj_Header header; 216 HPDF_Error error; 217 char value[HPDF_LIMIT_MAX_NAME_LEN + 1]; 218 } HPDF_Name_Rec; 219 220 221 222 HPDF_Name 223 HPDF_Name_New (HPDF_MMgr mmgr, 224 const char *value); 225 226 227 HPDF_STATUS 228 HPDF_Name_SetValue (HPDF_Name obj, 229 const char *value); 230 231 232 HPDF_STATUS 233 HPDF_Name_Write (HPDF_Name obj, 234 HPDF_Stream stream); 235 236 const char* 237 HPDF_Name_GetValue (HPDF_Name obj); 238 239 240 /*---------------------------------------------------------------------------*/ 241 /*----- HPDF_String ---------------------------------------------------------*/ 242 243 typedef struct _HPDF_String_Rec *HPDF_String; 244 245 typedef struct _HPDF_String_Rec { 246 HPDF_Obj_Header header; 247 HPDF_MMgr mmgr; 248 HPDF_Error error; 249 HPDF_Encoder encoder; 250 HPDF_BYTE *value; 251 HPDF_UINT len; 252 } HPDF_String_Rec; 253 254 255 256 HPDF_String 257 HPDF_String_New (HPDF_MMgr mmgr, 258 const char *value, 259 HPDF_Encoder encoder); 260 261 262 HPDF_STATUS 263 HPDF_String_SetValue (HPDF_String obj, 264 const char *value); 265 266 267 void 268 HPDF_String_Free (HPDF_String obj); 269 270 271 HPDF_STATUS 272 HPDF_String_Write (HPDF_String obj, 273 HPDF_Stream stream, 274 HPDF_Encrypt e); 275 276 HPDF_INT32 277 HPDF_String_Cmp (HPDF_String s1, 278 HPDF_String s2); 279 280 281 /*---------------------------------------------------------------------------*/ 282 /*----- HPDF_Binary ---------------------------------------------------------*/ 283 284 typedef struct _HPDF_Binary_Rec *HPDF_Binary; 285 286 typedef struct _HPDF_Binary_Rec { 287 HPDF_Obj_Header header; 288 HPDF_MMgr mmgr; 289 HPDF_Error error; 290 HPDF_BYTE *value; 291 HPDF_UINT len; 292 } HPDF_Binary_Rec; 293 294 295 296 HPDF_Binary 297 HPDF_Binary_New (HPDF_MMgr mmgr, 298 HPDF_BYTE *value, 299 HPDF_UINT len); 300 301 302 HPDF_STATUS 303 HPDF_Binary_SetValue (HPDF_Binary obj, 304 HPDF_BYTE *value, 305 HPDF_UINT len); 306 307 308 HPDF_BYTE* 309 HPDF_Binary_GetValue (HPDF_Binary obj); 310 311 312 void 313 HPDF_Binary_Free (HPDF_Binary obj); 314 315 316 HPDF_STATUS 317 HPDF_Binary_Write (HPDF_Binary obj, 318 HPDF_Stream stream, 319 HPDF_Encrypt e); 320 321 322 HPDF_UINT 323 HPDF_Binary_GetLen (HPDF_Binary obj); 324 325 326 /*---------------------------------------------------------------------------*/ 327 /*----- HPDF_Array ----------------------------------------------------------*/ 328 329 typedef struct _HPDF_Array_Rec *HPDF_Array; 330 331 typedef struct _HPDF_Array_Rec { 332 HPDF_Obj_Header header; 333 HPDF_MMgr mmgr; 334 HPDF_Error error; 335 HPDF_List list; 336 } HPDF_Array_Rec; 337 338 339 HPDF_Array 340 HPDF_Array_New (HPDF_MMgr mmgr); 341 342 343 HPDF_Array 344 HPDF_Box_Array_New (HPDF_MMgr mmgr, 345 HPDF_Box box); 346 347 348 void 349 HPDF_Array_Free (HPDF_Array array); 350 351 352 HPDF_STATUS 353 HPDF_Array_Write (HPDF_Array array, 354 HPDF_Stream stream, 355 HPDF_Encrypt e); 356 357 358 HPDF_STATUS 359 HPDF_Array_Add (HPDF_Array array, 360 void *obj); 361 362 363 HPDF_STATUS 364 HPDF_Array_Insert (HPDF_Array array, 365 void *target, 366 void *obj); 367 368 369 void* 370 HPDF_Array_GetItem (HPDF_Array array, 371 HPDF_UINT index, 372 HPDF_UINT16 obj_class); 373 374 375 HPDF_STATUS 376 HPDF_Array_AddNumber (HPDF_Array array, 377 HPDF_INT32 value); 378 379 380 HPDF_STATUS 381 HPDF_Array_AddReal (HPDF_Array array, 382 HPDF_REAL value); 383 384 385 HPDF_STATUS 386 HPDF_Array_AddName (HPDF_Array array, 387 const char *value); 388 389 void 390 HPDF_Array_Clear (HPDF_Array array); 391 392 393 HPDF_UINT 394 HPDF_Array_Items (HPDF_Array array); 395 396 397 /*---------------------------------------------------------------------------*/ 398 /*----- HPDF_Dict -----------------------------------------------------------*/ 399 400 typedef struct _HPDF_Xref_Rec *HPDF_Xref; 401 402 typedef struct _HPDF_Dict_Rec *HPDF_Dict; 403 404 typedef void 405 (*HPDF_Dict_FreeFunc) (HPDF_Dict obj); 406 407 typedef HPDF_STATUS 408 (*HPDF_Dict_BeforeWriteFunc) (HPDF_Dict obj); 409 410 typedef HPDF_STATUS 411 (*HPDF_Dict_AfterWriteFunc) (HPDF_Dict obj); 412 413 typedef HPDF_STATUS 414 (*HPDF_Dict_OnWriteFunc) (HPDF_Dict obj, 415 HPDF_Stream stream); 416 417 typedef struct _HPDF_Dict_Rec { 418 HPDF_Obj_Header header; 419 HPDF_MMgr mmgr; 420 HPDF_Error error; 421 HPDF_List list; 422 HPDF_Dict_BeforeWriteFunc before_write_fn; 423 HPDF_Dict_OnWriteFunc write_fn; 424 HPDF_Dict_AfterWriteFunc after_write_fn; 425 HPDF_Dict_FreeFunc free_fn; 426 HPDF_Stream stream; 427 HPDF_UINT filter; 428 HPDF_Dict filterParams; 429 void *attr; 430 } HPDF_Dict_Rec; 431 432 433 typedef struct _HPDF_DictElement_Rec *HPDF_DictElement; 434 435 typedef struct _HPDF_DictElement_Rec { 436 char key[HPDF_LIMIT_MAX_NAME_LEN + 1]; 437 void *value; 438 } HPDF_DictElement_Rec; 439 440 441 HPDF_Dict 442 HPDF_Dict_New (HPDF_MMgr mmgr); 443 444 445 HPDF_Dict 446 HPDF_DictStream_New (HPDF_MMgr mmgr, 447 HPDF_Xref xref); 448 449 450 void 451 HPDF_Dict_Free (HPDF_Dict dict); 452 453 454 HPDF_STATUS 455 HPDF_Dict_Write (HPDF_Dict dict, 456 HPDF_Stream stream, 457 HPDF_Encrypt e); 458 459 460 const char* 461 HPDF_Dict_GetKeyByObj (HPDF_Dict dict, 462 void *obj); 463 464 465 HPDF_STATUS 466 HPDF_Dict_Add (HPDF_Dict dict, 467 const char *key, 468 void *obj); 469 470 471 void* 472 HPDF_Dict_GetItem (HPDF_Dict dict, 473 const char *key, 474 HPDF_UINT16 obj_class); 475 476 477 HPDF_STATUS 478 HPDF_Dict_AddName (HPDF_Dict dict, 479 const char *key, 480 const char *value); 481 482 483 HPDF_STATUS 484 HPDF_Dict_AddNumber (HPDF_Dict dict, 485 const char *key, 486 HPDF_INT32 value); 487 488 489 HPDF_STATUS 490 HPDF_Dict_AddReal (HPDF_Dict dict, 491 const char *key, 492 HPDF_REAL value); 493 494 495 HPDF_STATUS 496 HPDF_Dict_AddBoolean (HPDF_Dict dict, 497 const char *key, 498 HPDF_BOOL value); 499 500 501 HPDF_STATUS 502 HPDF_Dict_RemoveElement (HPDF_Dict dict, 503 const char *key); 504 505 506 /*---------------------------------------------------------------------------*/ 507 /*----- HPDF_ProxyObject ----------------------------------------------------*/ 508 509 510 511 typedef struct _HPDF_Proxy_Rec *HPDF_Proxy; 512 513 typedef struct _HPDF_Proxy_Rec { 514 HPDF_Obj_Header header; 515 void *obj; 516 } HPDF_Proxy_Rec; 517 518 519 HPDF_Proxy 520 HPDF_Proxy_New (HPDF_MMgr mmgr, 521 void *obj); 522 523 524 525 /*---------------------------------------------------------------------------*/ 526 /*----- HPDF_Xref -----------------------------------------------------------*/ 527 528 typedef struct _HPDF_XrefEntry_Rec *HPDF_XrefEntry; 529 530 typedef struct _HPDF_XrefEntry_Rec { 531 char entry_typ; 532 HPDF_UINT byte_offset; 533 HPDF_UINT16 gen_no; 534 void* obj; 535 } HPDF_XrefEntry_Rec; 536 537 538 typedef struct _HPDF_Xref_Rec { 539 HPDF_MMgr mmgr; 540 HPDF_Error error; 541 HPDF_UINT32 start_offset; 542 HPDF_List entries; 543 HPDF_UINT addr; 544 HPDF_Xref prev; 545 HPDF_Dict trailer; 546 } HPDF_Xref_Rec; 547 548 549 HPDF_Xref 550 HPDF_Xref_New (HPDF_MMgr mmgr, 551 HPDF_UINT32 offset); 552 553 554 void 555 HPDF_Xref_Free (HPDF_Xref xref); 556 557 558 HPDF_STATUS 559 HPDF_Xref_Add (HPDF_Xref xref, 560 void *obj); 561 562 563 HPDF_XrefEntry 564 HPDF_Xref_GetEntry (HPDF_Xref xref, 565 HPDF_UINT index); 566 567 568 HPDF_STATUS 569 HPDF_Xref_WriteToStream (HPDF_Xref xref, 570 HPDF_Stream stream, 571 HPDF_Encrypt e); 572 573 574 HPDF_XrefEntry 575 HPDF_Xref_GetEntryByObjectId (HPDF_Xref xref, 576 HPDF_UINT obj_id); 577 578 579 580 typedef HPDF_Dict HPDF_EmbeddedFile; 581 typedef HPDF_Dict HPDF_NameDict; 582 typedef HPDF_Dict HPDF_NameTree; 583 typedef HPDF_Dict HPDF_Pages; 584 typedef HPDF_Dict HPDF_Page; 585 typedef HPDF_Dict HPDF_Annotation; 586 typedef HPDF_Dict HPDF_3DMeasure; 587 typedef HPDF_Dict HPDF_ExData; 588 typedef HPDF_Dict HPDF_XObject; 589 typedef HPDF_Dict HPDF_Image; 590 typedef HPDF_Dict HPDF_Outline; 591 typedef HPDF_Dict HPDF_EncryptDict; 592 typedef HPDF_Dict HPDF_Action; 593 typedef HPDF_Dict HPDF_ExtGState; 594 typedef HPDF_Array HPDF_Destination; 595 typedef HPDF_Dict HPDF_U3D; 596 typedef HPDF_Dict HPDF_OutputIntent; 597 typedef HPDF_Dict HPDF_JavaScript; 598 599 #ifdef __cplusplus 600 } 601 #endif /* __cplusplus */ 602 603 #endif /* _HPDF_OBJECTS_H */ 604