hpdf_objects.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * << Haru Free PDF Library >> -- hpdf_objects.c
  3. *
  4. * URL: http://libharu.org
  5. *
  6. * Copyright (c) 1999-2006 Takeshi Kanno <[email protected]>
  7. * Copyright (c) 2007-2009 Antony Dovgal <[email protected]>
  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. #ifndef _HPDF_OBJECTS_H
  18. #define _HPDF_OBJECTS_H
  19. #include "hpdf_encoder.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* if HPDF_OTYPE_DIRECT bit is set, the object owned by other container
  24. * object. if HPDF_OTYPE_INDIRECT bit is set, the object managed by xref.
  25. */
  26. #define HPDF_OTYPE_NONE 0x00000000
  27. #define HPDF_OTYPE_DIRECT 0x80000000
  28. #define HPDF_OTYPE_INDIRECT 0x40000000
  29. #define HPDF_OTYPE_ANY (HPDF_OTYPE_DIRECT | HPDF_OTYPE_INDIRECT)
  30. #define HPDF_OTYPE_HIDDEN 0x10000000
  31. #define HPDF_OCLASS_UNKNOWN 0x0001
  32. #define HPDF_OCLASS_NULL 0x0002
  33. #define HPDF_OCLASS_BOOLEAN 0x0003
  34. #define HPDF_OCLASS_NUMBER 0x0004
  35. #define HPDF_OCLASS_REAL 0x0005
  36. #define HPDF_OCLASS_NAME 0x0006
  37. #define HPDF_OCLASS_STRING 0x0007
  38. #define HPDF_OCLASS_BINARY 0x0008
  39. #define HPDF_OCLASS_ARRAY 0x0010
  40. #define HPDF_OCLASS_DICT 0x0011
  41. #define HPDF_OCLASS_PROXY 0x0012
  42. #define HPDF_OCLASS_ANY 0x00FF
  43. #define HPDF_OSUBCLASS_FONT 0x0100
  44. #define HPDF_OSUBCLASS_CATALOG 0x0200
  45. #define HPDF_OSUBCLASS_PAGES 0x0300
  46. #define HPDF_OSUBCLASS_PAGE 0x0400
  47. #define HPDF_OSUBCLASS_XOBJECT 0x0500
  48. #define HPDF_OSUBCLASS_OUTLINE 0x0600
  49. #define HPDF_OSUBCLASS_DESTINATION 0x0700
  50. #define HPDF_OSUBCLASS_ANNOTATION 0x0800
  51. #define HPDF_OSUBCLASS_ENCRYPT 0x0900
  52. #define HPDF_OSUBCLASS_EXT_GSTATE 0x0A00
  53. #define HPDF_OSUBCLASS_EXT_GSTATE_R 0x0B00 /* read only object */
  54. #define HPDF_OSUBCLASS_NAMEDICT 0x0C00
  55. #define HPDF_OSUBCLASS_NAMETREE 0x0D00
  56. /*----------------------------------------------------------------------------*/
  57. /*------ Values related xref -------------------------------------------------*/
  58. #define HPDF_FREE_ENTRY 'f'
  59. #define HPDF_IN_USE_ENTRY 'n'
  60. /*
  61. * structure of Object-ID
  62. *
  63. * 1 direct-object
  64. * 2 indirect-object
  65. * 3 reserved
  66. * 4 shadow-object
  67. * 5-8 reserved
  68. * 9-32 object-id�i0-8388607�j
  69. *
  70. * the real Object-ID is described "obj_id & 0x00FFFFFF"
  71. */
  72. typedef struct _HPDF_Obj_Header {
  73. HPDF_UINT32 obj_id;
  74. HPDF_UINT16 gen_no;
  75. HPDF_UINT16 obj_class;
  76. } HPDF_Obj_Header;
  77. HPDF_STATUS
  78. HPDF_Obj_WriteValue (void *obj,
  79. HPDF_Stream stream,
  80. HPDF_Encrypt e);
  81. HPDF_STATUS
  82. HPDF_Obj_Write (void *obj,
  83. HPDF_Stream stream,
  84. HPDF_Encrypt e);
  85. void
  86. HPDF_Obj_Free (HPDF_MMgr mmgr,
  87. void *obj);
  88. void
  89. HPDF_Obj_ForceFree (HPDF_MMgr mmgr,
  90. void *obj);
  91. /*---------------------------------------------------------------------------*/
  92. /*----- HPDF_Null -----------------------------------------------------------*/
  93. typedef struct _HPDF_Null_Rec *HPDF_Null;
  94. typedef struct _HPDF_Null_Rec {
  95. HPDF_Obj_Header header;
  96. } HPDF_Null_Rec;
  97. HPDF_Null
  98. HPDF_Null_New (HPDF_MMgr mmgr);
  99. /*---------------------------------------------------------------------------*/
  100. /*----- HPDF_Boolean --------------------------------------------------------*/
  101. typedef struct _HPDF_Boolean_Rec *HPDF_Boolean;
  102. typedef struct _HPDF_Boolean_Rec {
  103. HPDF_Obj_Header header;
  104. HPDF_BOOL value;
  105. } HPDF_Boolean_Rec;
  106. HPDF_Boolean
  107. HPDF_Boolean_New (HPDF_MMgr mmgr,
  108. HPDF_BOOL value);
  109. HPDF_STATUS
  110. HPDF_Boolean_Write (HPDF_Boolean obj,
  111. HPDF_Stream stream);
  112. /*---------------------------------------------------------------------------*/
  113. /*----- HPDF_Number ---------------------------------------------------------*/
  114. typedef struct _HPDF_Number_Rec *HPDF_Number;
  115. typedef struct _HPDF_Number_Rec {
  116. HPDF_Obj_Header header;
  117. HPDF_INT32 value;
  118. } HPDF_Number_Rec;
  119. HPDF_Number
  120. HPDF_Number_New (HPDF_MMgr mmgr,
  121. HPDF_INT32 value);
  122. void
  123. HPDF_Number_SetValue (HPDF_Number obj,
  124. HPDF_INT32 value);
  125. HPDF_STATUS
  126. HPDF_Number_Write (HPDF_Number obj,
  127. HPDF_Stream stream);
  128. /*---------------------------------------------------------------------------*/
  129. /*----- HPDF_Real -----------------------------------------------------------*/
  130. typedef struct _HPDF_Real_Rec *HPDF_Real;
  131. typedef struct _HPDF_Real_Rec {
  132. HPDF_Obj_Header header;
  133. HPDF_Error error;
  134. HPDF_REAL value;
  135. } HPDF_Real_Rec;
  136. HPDF_Real
  137. HPDF_Real_New (HPDF_MMgr mmgr,
  138. HPDF_REAL value);
  139. HPDF_STATUS
  140. HPDF_Real_Write (HPDF_Real obj,
  141. HPDF_Stream stream);
  142. HPDF_STATUS
  143. HPDF_Real_SetValue (HPDF_Real obj,
  144. HPDF_REAL value);
  145. /*---------------------------------------------------------------------------*/
  146. /*----- HPDF_Name -----------------------------------------------------------*/
  147. typedef struct _HPDF_Name_Rec *HPDF_Name;
  148. typedef struct _HPDF_Name_Rec {
  149. HPDF_Obj_Header header;
  150. HPDF_Error error;
  151. char value[HPDF_LIMIT_MAX_NAME_LEN + 1];
  152. } HPDF_Name_Rec;
  153. HPDF_Name
  154. HPDF_Name_New (HPDF_MMgr mmgr,
  155. const char *value);
  156. HPDF_STATUS
  157. HPDF_Name_SetValue (HPDF_Name obj,
  158. const char *value);
  159. HPDF_STATUS
  160. HPDF_Name_Write (HPDF_Name obj,
  161. HPDF_Stream stream);
  162. const char*
  163. HPDF_Name_GetValue (HPDF_Name obj);
  164. /*---------------------------------------------------------------------------*/
  165. /*----- HPDF_String ---------------------------------------------------------*/
  166. typedef struct _HPDF_String_Rec *HPDF_String;
  167. typedef struct _HPDF_String_Rec {
  168. HPDF_Obj_Header header;
  169. HPDF_MMgr mmgr;
  170. HPDF_Error error;
  171. HPDF_Encoder encoder;
  172. HPDF_BYTE *value;
  173. HPDF_UINT len;
  174. } HPDF_String_Rec;
  175. HPDF_String
  176. HPDF_String_New (HPDF_MMgr mmgr,
  177. const char *value,
  178. HPDF_Encoder encoder);
  179. HPDF_STATUS
  180. HPDF_String_SetValue (HPDF_String obj,
  181. const char *value);
  182. void
  183. HPDF_String_Free (HPDF_String obj);
  184. HPDF_STATUS
  185. HPDF_String_Write (HPDF_String obj,
  186. HPDF_Stream stream,
  187. HPDF_Encrypt e);
  188. HPDF_INT32
  189. HPDF_String_Cmp (HPDF_String s1,
  190. HPDF_String s2);
  191. /*---------------------------------------------------------------------------*/
  192. /*----- HPDF_Binary ---------------------------------------------------------*/
  193. typedef struct _HPDF_Binary_Rec *HPDF_Binary;
  194. typedef struct _HPDF_Binary_Rec {
  195. HPDF_Obj_Header header;
  196. HPDF_MMgr mmgr;
  197. HPDF_Error error;
  198. HPDF_BYTE *value;
  199. HPDF_UINT len;
  200. } HPDF_Binary_Rec;
  201. HPDF_Binary
  202. HPDF_Binary_New (HPDF_MMgr mmgr,
  203. HPDF_BYTE *value,
  204. HPDF_UINT len);
  205. HPDF_STATUS
  206. HPDF_Binary_SetValue (HPDF_Binary obj,
  207. HPDF_BYTE *value,
  208. HPDF_UINT len);
  209. HPDF_BYTE*
  210. HPDF_Binary_GetValue (HPDF_Binary obj);
  211. void
  212. HPDF_Binary_Free (HPDF_Binary obj);
  213. HPDF_STATUS
  214. HPDF_Binary_Write (HPDF_Binary obj,
  215. HPDF_Stream stream,
  216. HPDF_Encrypt e);
  217. HPDF_UINT
  218. HPDF_Binary_GetLen (HPDF_Binary obj);
  219. /*---------------------------------------------------------------------------*/
  220. /*----- HPDF_Array ----------------------------------------------------------*/
  221. typedef struct _HPDF_Array_Rec *HPDF_Array;
  222. typedef struct _HPDF_Array_Rec {
  223. HPDF_Obj_Header header;
  224. HPDF_MMgr mmgr;
  225. HPDF_Error error;
  226. HPDF_List list;
  227. } HPDF_Array_Rec;
  228. HPDF_Array
  229. HPDF_Array_New (HPDF_MMgr mmgr);
  230. HPDF_Array
  231. HPDF_Box_Array_New (HPDF_MMgr mmgr,
  232. HPDF_Box box);
  233. void
  234. HPDF_Array_Free (HPDF_Array array);
  235. HPDF_STATUS
  236. HPDF_Array_Write (HPDF_Array array,
  237. HPDF_Stream stream,
  238. HPDF_Encrypt e);
  239. HPDF_STATUS
  240. HPDF_Array_Add (HPDF_Array array,
  241. void *obj);
  242. HPDF_STATUS
  243. HPDF_Array_Insert (HPDF_Array array,
  244. void *target,
  245. void *obj);
  246. void*
  247. HPDF_Array_GetItem (HPDF_Array array,
  248. HPDF_UINT index,
  249. HPDF_UINT16 obj_class);
  250. HPDF_STATUS
  251. HPDF_Array_AddNumber (HPDF_Array array,
  252. HPDF_INT32 value);
  253. HPDF_STATUS
  254. HPDF_Array_AddReal (HPDF_Array array,
  255. HPDF_REAL value);
  256. HPDF_STATUS
  257. HPDF_Array_AddName (HPDF_Array array,
  258. const char *value);
  259. void
  260. HPDF_Array_Clear (HPDF_Array array);
  261. HPDF_UINT
  262. HPDF_Array_Items (HPDF_Array array);
  263. /*---------------------------------------------------------------------------*/
  264. /*----- HPDF_Dict -----------------------------------------------------------*/
  265. typedef struct _HPDF_Xref_Rec *HPDF_Xref;
  266. typedef struct _HPDF_Dict_Rec *HPDF_Dict;
  267. typedef void
  268. (*HPDF_Dict_FreeFunc) (HPDF_Dict obj);
  269. typedef HPDF_STATUS
  270. (*HPDF_Dict_BeforeWriteFunc) (HPDF_Dict obj);
  271. typedef HPDF_STATUS
  272. (*HPDF_Dict_AfterWriteFunc) (HPDF_Dict obj);
  273. typedef HPDF_STATUS
  274. (*HPDF_Dict_OnWriteFunc) (HPDF_Dict obj,
  275. HPDF_Stream stream);
  276. typedef struct _HPDF_Dict_Rec {
  277. HPDF_Obj_Header header;
  278. HPDF_MMgr mmgr;
  279. HPDF_Error error;
  280. HPDF_List list;
  281. HPDF_Dict_BeforeWriteFunc before_write_fn;
  282. HPDF_Dict_OnWriteFunc write_fn;
  283. HPDF_Dict_AfterWriteFunc after_write_fn;
  284. HPDF_Dict_FreeFunc free_fn;
  285. HPDF_Stream stream;
  286. HPDF_UINT filter;
  287. HPDF_Dict filterParams;
  288. void *attr;
  289. } HPDF_Dict_Rec;
  290. typedef struct _HPDF_DictElement_Rec *HPDF_DictElement;
  291. typedef struct _HPDF_DictElement_Rec {
  292. char key[HPDF_LIMIT_MAX_NAME_LEN + 1];
  293. void *value;
  294. } HPDF_DictElement_Rec;
  295. HPDF_Dict
  296. HPDF_Dict_New (HPDF_MMgr mmgr);
  297. HPDF_Dict
  298. HPDF_DictStream_New (HPDF_MMgr mmgr,
  299. HPDF_Xref xref);
  300. void
  301. HPDF_Dict_Free (HPDF_Dict dict);
  302. HPDF_STATUS
  303. HPDF_Dict_Write (HPDF_Dict dict,
  304. HPDF_Stream stream,
  305. HPDF_Encrypt e);
  306. const char*
  307. HPDF_Dict_GetKeyByObj (HPDF_Dict dict,
  308. void *obj);
  309. HPDF_STATUS
  310. HPDF_Dict_Add (HPDF_Dict dict,
  311. const char *key,
  312. void *obj);
  313. void*
  314. HPDF_Dict_GetItem (HPDF_Dict dict,
  315. const char *key,
  316. HPDF_UINT16 obj_class);
  317. HPDF_STATUS
  318. HPDF_Dict_AddName (HPDF_Dict dict,
  319. const char *key,
  320. const char *value);
  321. HPDF_STATUS
  322. HPDF_Dict_AddNumber (HPDF_Dict dict,
  323. const char *key,
  324. HPDF_INT32 value);
  325. HPDF_STATUS
  326. HPDF_Dict_AddReal (HPDF_Dict dict,
  327. const char *key,
  328. HPDF_REAL value);
  329. HPDF_STATUS
  330. HPDF_Dict_AddBoolean (HPDF_Dict dict,
  331. const char *key,
  332. HPDF_BOOL value);
  333. HPDF_STATUS
  334. HPDF_Dict_RemoveElement (HPDF_Dict dict,
  335. const char *key);
  336. /*---------------------------------------------------------------------------*/
  337. /*----- HPDF_ProxyObject ----------------------------------------------------*/
  338. typedef struct _HPDF_Proxy_Rec *HPDF_Proxy;
  339. typedef struct _HPDF_Proxy_Rec {
  340. HPDF_Obj_Header header;
  341. void *obj;
  342. } HPDF_Proxy_Rec;
  343. HPDF_Proxy
  344. HPDF_Proxy_New (HPDF_MMgr mmgr,
  345. void *obj);
  346. /*---------------------------------------------------------------------------*/
  347. /*----- HPDF_Xref -----------------------------------------------------------*/
  348. typedef struct _HPDF_XrefEntry_Rec *HPDF_XrefEntry;
  349. typedef struct _HPDF_XrefEntry_Rec {
  350. char entry_typ;
  351. HPDF_UINT byte_offset;
  352. HPDF_UINT16 gen_no;
  353. void* obj;
  354. } HPDF_XrefEntry_Rec;
  355. typedef struct _HPDF_Xref_Rec {
  356. HPDF_MMgr mmgr;
  357. HPDF_Error error;
  358. HPDF_UINT32 start_offset;
  359. HPDF_List entries;
  360. HPDF_UINT addr;
  361. HPDF_Xref prev;
  362. HPDF_Dict trailer;
  363. } HPDF_Xref_Rec;
  364. HPDF_Xref
  365. HPDF_Xref_New (HPDF_MMgr mmgr,
  366. HPDF_UINT32 offset);
  367. void
  368. HPDF_Xref_Free (HPDF_Xref xref);
  369. HPDF_STATUS
  370. HPDF_Xref_Add (HPDF_Xref xref,
  371. void *obj);
  372. HPDF_XrefEntry
  373. HPDF_Xref_GetEntry (HPDF_Xref xref,
  374. HPDF_UINT index);
  375. HPDF_STATUS
  376. HPDF_Xref_WriteToStream (HPDF_Xref xref,
  377. HPDF_Stream stream,
  378. HPDF_Encrypt e);
  379. HPDF_XrefEntry
  380. HPDF_Xref_GetEntryByObjectId (HPDF_Xref xref,
  381. HPDF_UINT obj_id);
  382. typedef HPDF_Dict HPDF_EmbeddedFile;
  383. typedef HPDF_Dict HPDF_NameDict;
  384. typedef HPDF_Dict HPDF_NameTree;
  385. typedef HPDF_Dict HPDF_Pages;
  386. typedef HPDF_Dict HPDF_Page;
  387. typedef HPDF_Dict HPDF_Annotation;
  388. typedef HPDF_Dict HPDF_3DMeasure;
  389. typedef HPDF_Dict HPDF_ExData;
  390. typedef HPDF_Dict HPDF_XObject;
  391. typedef HPDF_Dict HPDF_Image;
  392. typedef HPDF_Dict HPDF_Outline;
  393. typedef HPDF_Dict HPDF_EncryptDict;
  394. typedef HPDF_Dict HPDF_Action;
  395. typedef HPDF_Dict HPDF_ExtGState;
  396. typedef HPDF_Array HPDF_Destination;
  397. typedef HPDF_Dict HPDF_U3D;
  398. typedef HPDF_Dict HPDF_OutputIntent;
  399. typedef HPDF_Dict HPDF_JavaScript;
  400. #ifdef __cplusplus
  401. }
  402. #endif /* __cplusplus */
  403. #endif /* _HPDF_OBJECTS_H */