hpdf 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/History +57 -0
  2. data/License +25 -0
  3. data/README +165 -0
  4. data/examples/arc_demo.rb +82 -0
  5. data/examples/demo.rb +92 -0
  6. data/examples/encryption.rb +41 -0
  7. data/examples/ext_gstater_demo.rb +171 -0
  8. data/examples/font_demo.rb +67 -0
  9. data/examples/jpfont_demo.rb +122 -0
  10. data/examples/line_demo.rb +301 -0
  11. data/examples/slide_show_demo.rb +139 -0
  12. data/examples/text_demo2.rb +189 -0
  13. data/examples/ttfont_demo.rb +106 -0
  14. data/ext/extconf.rb +6 -0
  15. data/ext/hpdf.c +3779 -0
  16. data/ext/hpdf_annotation.c +415 -0
  17. data/ext/hpdf_array.c +344 -0
  18. data/ext/hpdf_binary.c +117 -0
  19. data/ext/hpdf_boolean.c +47 -0
  20. data/ext/hpdf_catalog.c +354 -0
  21. data/ext/hpdf_destination.c +339 -0
  22. data/ext/hpdf_dict.c +488 -0
  23. data/ext/hpdf_doc.c +2020 -0
  24. data/ext/hpdf_doc_png.c +137 -0
  25. data/ext/hpdf_encoder.c +2991 -0
  26. data/ext/hpdf_encoder_cns.c +36359 -0
  27. data/ext/hpdf_encoder_cnt.c +15307 -0
  28. data/ext/hpdf_encoder_jp.c +16125 -0
  29. data/ext/hpdf_encoder_kr.c +27978 -0
  30. data/ext/hpdf_encrypt.c +632 -0
  31. data/ext/hpdf_encryptdict.c +240 -0
  32. data/ext/hpdf_error.c +114 -0
  33. data/ext/hpdf_ext_gstate.c +150 -0
  34. data/ext/hpdf_font.c +229 -0
  35. data/ext/hpdf_font_cid.c +1030 -0
  36. data/ext/hpdf_font_tt.c +406 -0
  37. data/ext/hpdf_font_type1.c +391 -0
  38. data/ext/hpdf_fontdef.c +56 -0
  39. data/ext/hpdf_fontdef_base14.c +4506 -0
  40. data/ext/hpdf_fontdef_cid.c +194 -0
  41. data/ext/hpdf_fontdef_cns.c +471 -0
  42. data/ext/hpdf_fontdef_cnt.c +250 -0
  43. data/ext/hpdf_fontdef_jp.c +1904 -0
  44. data/ext/hpdf_fontdef_kr.c +1572 -0
  45. data/ext/hpdf_fontdef_tt.c +2230 -0
  46. data/ext/hpdf_fontdef_type1.c +524 -0
  47. data/ext/hpdf_gstate.c +119 -0
  48. data/ext/hpdf_image.c +568 -0
  49. data/ext/hpdf_image_png.c +424 -0
  50. data/ext/hpdf_info.c +164 -0
  51. data/ext/hpdf_list.c +333 -0
  52. data/ext/hpdf_mmgr.c +243 -0
  53. data/ext/hpdf_name.c +71 -0
  54. data/ext/hpdf_null.c +31 -0
  55. data/ext/hpdf_number.c +49 -0
  56. data/ext/hpdf_objects.c +172 -0
  57. data/ext/hpdf_outline.c +329 -0
  58. data/ext/hpdf_page_label.c +74 -0
  59. data/ext/hpdf_page_operator.c +2764 -0
  60. data/ext/hpdf_pages.c +1508 -0
  61. data/ext/hpdf_real.c +61 -0
  62. data/ext/hpdf_streams.c +1435 -0
  63. data/ext/hpdf_string.c +189 -0
  64. data/ext/hpdf_utils.c +438 -0
  65. data/ext/hpdf_xref.c +348 -0
  66. data/ext/include/hpdf.h +1227 -0
  67. data/ext/include/hpdf_annotation.h +74 -0
  68. data/ext/include/hpdf_catalog.h +81 -0
  69. data/ext/include/hpdf_conf.h +76 -0
  70. data/ext/include/hpdf_consts.h +549 -0
  71. data/ext/include/hpdf_destination.h +41 -0
  72. data/ext/include/hpdf_doc.h +159 -0
  73. data/ext/include/hpdf_encoder.h +311 -0
  74. data/ext/include/hpdf_encrypt.h +156 -0
  75. data/ext/include/hpdf_encryptdict.h +66 -0
  76. data/ext/include/hpdf_error.h +201 -0
  77. data/ext/include/hpdf_ext_gstate.h +38 -0
  78. data/ext/include/hpdf_font.h +112 -0
  79. data/ext/include/hpdf_fontdef.h +403 -0
  80. data/ext/include/hpdf_gstate.h +80 -0
  81. data/ext/include/hpdf_image.h +72 -0
  82. data/ext/include/hpdf_info.h +48 -0
  83. data/ext/include/hpdf_list.h +85 -0
  84. data/ext/include/hpdf_mmgr.h +82 -0
  85. data/ext/include/hpdf_objects.h +587 -0
  86. data/ext/include/hpdf_outline.h +74 -0
  87. data/ext/include/hpdf_page_label.h +35 -0
  88. data/ext/include/hpdf_pages.h +128 -0
  89. data/ext/include/hpdf_streams.h +276 -0
  90. data/ext/include/hpdf_types.h +488 -0
  91. data/ext/include/hpdf_utils.h +161 -0
  92. data/tests/arc_demo.rb +82 -0
  93. data/tests/demo.rb +91 -0
  94. data/tests/encryption.rb +41 -0
  95. data/tests/ext_gstater_demo.rb +171 -0
  96. data/tests/font_demo.rb +67 -0
  97. data/tests/line_demo.rb +301 -0
  98. data/tests/slide_show_demo.rb +139 -0
  99. data/tests/test_all_examples.rb +31 -0
  100. data/tests/text_demo2.rb +189 -0
  101. metadata +147 -0
@@ -0,0 +1,415 @@
1
+ /*
2
+ * << Haru Free PDF Library 2.0.0 >> -- hpdf_annotation.c
3
+ *
4
+ * Copyright (c) 1999-2006 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
+ #include "hpdf_conf.h"
16
+ #include "hpdf_utils.h"
17
+ #include "hpdf_annotation.h"
18
+ #include "hpdf.h"
19
+
20
+ const static char *HPDF_ANNOT_TYPE_NAMES[] = {
21
+ "Text",
22
+ "Link",
23
+ "Sound",
24
+ "FreeText",
25
+ "Stamp",
26
+ "Square",
27
+ "Circle",
28
+ "StrikeOut",
29
+ "Highlight",
30
+ "Underline",
31
+ "Ink",
32
+ "FileAttachment",
33
+ "Popup"
34
+ };
35
+
36
+ const static char *HPDF_ANNOT_ICON_NAMES_NAMES[] = {
37
+ "Comment",
38
+ "Key",
39
+ "Note",
40
+ "Help",
41
+ "NewParagraph",
42
+ "Paragraph",
43
+ "Insert"
44
+ };
45
+
46
+
47
+ static HPDF_BOOL
48
+ CheckSubType (HPDF_Annotation annot,
49
+ HPDF_AnnotType type);
50
+
51
+
52
+ /*----------------------------------------------------------------------------*/
53
+ /*------ HPDF_Annotation -----------------------------------------------------*/
54
+
55
+
56
+ HPDF_Annotation
57
+ HPDF_Annotation_New (HPDF_MMgr mmgr,
58
+ HPDF_Xref xref,
59
+ HPDF_AnnotType type,
60
+ HPDF_Rect rect)
61
+ {
62
+ HPDF_Annotation annot;
63
+ HPDF_Array array;
64
+ HPDF_STATUS ret = HPDF_OK;
65
+ HPDF_REAL tmp;
66
+
67
+ HPDF_PTRACE((" HPDF_Annotation_New\n"));
68
+
69
+ annot = HPDF_Dict_New (mmgr);
70
+ if (!annot)
71
+ return NULL;
72
+
73
+ if (HPDF_Xref_Add (xref, annot) != HPDF_OK)
74
+ return NULL;
75
+
76
+ array = HPDF_Array_New (mmgr);
77
+ if (!array)
78
+ return NULL;
79
+
80
+ if (HPDF_Dict_Add (annot, "Rect", array) != HPDF_OK)
81
+ return NULL;
82
+
83
+ if (rect.top < rect.bottom) {
84
+ tmp = rect.top;
85
+ rect.top = rect.bottom;
86
+ rect.bottom = tmp;
87
+ }
88
+
89
+ ret += HPDF_Array_AddReal (array, rect.left);
90
+ ret += HPDF_Array_AddReal (array, rect.bottom);
91
+ ret += HPDF_Array_AddReal (array, rect.right);
92
+ ret += HPDF_Array_AddReal (array, rect.top);
93
+
94
+ ret += HPDF_Dict_AddName (annot, "Type", "Annot");
95
+ ret += HPDF_Dict_AddName (annot, "Subtype",
96
+ HPDF_ANNOT_TYPE_NAMES[(HPDF_INT)type]);
97
+
98
+ if (ret != HPDF_OK)
99
+ return NULL;
100
+
101
+ annot->header.obj_class |= HPDF_OSUBCLASS_ANNOTATION;
102
+
103
+ return annot;
104
+ }
105
+
106
+
107
+ HPDF_STATUS
108
+ HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot,
109
+ HPDF_BSSubtype subtype,
110
+ HPDF_REAL width,
111
+ HPDF_UINT16 dash_on,
112
+ HPDF_UINT16 dash_off,
113
+ HPDF_UINT16 dash_phase)
114
+ {
115
+ HPDF_Dict bs;
116
+ HPDF_Array dash;
117
+ HPDF_STATUS ret;
118
+
119
+ HPDF_PTRACE((" HPDF_Annotation_SetBoderStyle\n"));
120
+
121
+ bs = HPDF_Dict_New (annot->mmgr);
122
+ if (!bs)
123
+ return HPDF_Error_GetCode (annot->error);
124
+
125
+ if ((ret = HPDF_Dict_Add (annot, "BS", bs)) != HPDF_OK)
126
+ return ret;
127
+
128
+ if (subtype == HPDF_BS_DASHED) {
129
+ dash = HPDF_Array_New (annot->mmgr);
130
+ if (!dash)
131
+ return HPDF_Error_GetCode (annot->error);
132
+
133
+ if ((ret = HPDF_Dict_Add (bs, "D", dash)) != HPDF_OK)
134
+ return ret;
135
+
136
+ ret += HPDF_Dict_AddName (bs, "Type", "Border");
137
+ ret += HPDF_Array_AddReal (dash, dash_on);
138
+ ret += HPDF_Array_AddReal (dash, dash_off);
139
+
140
+ if (dash_phase != 0)
141
+ ret += HPDF_Array_AddReal (dash, dash_off);
142
+ }
143
+
144
+ switch (subtype) {
145
+ case HPDF_BS_SOLID:
146
+ ret += HPDF_Dict_AddName (bs, "S", "S");
147
+ break;
148
+ case HPDF_BS_DASHED:
149
+ ret += HPDF_Dict_AddName (bs, "S", "D");
150
+ break;
151
+ case HPDF_BS_BEVELED:
152
+ ret += HPDF_Dict_AddName (bs, "S", "B");
153
+ break;
154
+ case HPDF_BS_INSET:
155
+ ret += HPDF_Dict_AddName (bs, "S", "I");
156
+ break;
157
+ case HPDF_BS_UNDERLINED:
158
+ ret += HPDF_Dict_AddName (bs, "S", "U");
159
+ break;
160
+ default:
161
+ return HPDF_SetError (annot->error, HPDF_ANNOT_INVALID_BORDER_STYLE, 0);
162
+ }
163
+
164
+ if (width != HPDF_BS_DEF_WIDTH)
165
+ ret += HPDF_Dict_AddReal (bs, "W", width);
166
+
167
+ if (ret != HPDF_OK)
168
+ return HPDF_Error_GetCode (annot->error);
169
+
170
+ return HPDF_OK;
171
+ }
172
+
173
+
174
+ HPDF_Annotation
175
+ HPDF_LinkAnnot_New (HPDF_MMgr mmgr,
176
+ HPDF_Xref xref,
177
+ HPDF_Rect rect,
178
+ HPDF_Destination dst)
179
+ {
180
+ HPDF_Annotation annot;
181
+
182
+ HPDF_PTRACE((" HPDF_LinkAnnot_New\n"));
183
+
184
+ annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_LINK, rect);
185
+ if (!annot)
186
+ return NULL;
187
+
188
+ if (HPDF_Dict_Add (annot, "Dest", dst) != HPDF_OK)
189
+ return NULL;
190
+
191
+ return annot;
192
+ }
193
+
194
+
195
+ HPDF_Annotation
196
+ HPDF_URILinkAnnot_New (HPDF_MMgr mmgr,
197
+ HPDF_Xref xref,
198
+ HPDF_Rect rect,
199
+ const char *uri)
200
+ {
201
+ HPDF_Annotation annot;
202
+ HPDF_Dict action;
203
+ HPDF_STATUS ret;
204
+
205
+ HPDF_PTRACE((" HPDF_URILinkAnnot_New\n"));
206
+
207
+ annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_LINK, rect);
208
+ if (!annot)
209
+ return NULL;
210
+
211
+ /* create action dictionary */
212
+ action = HPDF_Dict_New (mmgr);
213
+ if (!action)
214
+ return NULL;
215
+
216
+ ret = HPDF_Dict_Add (annot, "A", action);
217
+ if (ret != HPDF_OK)
218
+ return NULL;
219
+
220
+ ret += HPDF_Dict_AddName (action, "Type", "Action");
221
+ ret += HPDF_Dict_AddName (action, "S", "URI");
222
+ ret += HPDF_Dict_Add (action, "URI", HPDF_String_New (mmgr, uri, NULL));
223
+
224
+ if (ret != HPDF_OK)
225
+ return NULL;
226
+
227
+ return annot;
228
+ }
229
+
230
+ HPDF_EXPORT(HPDF_STATUS)
231
+ HPDF_LinkAnnot_SetBorderStyle (HPDF_Annotation annot,
232
+ HPDF_REAL width,
233
+ HPDF_UINT16 dash_on,
234
+ HPDF_UINT16 dash_off)
235
+ {
236
+ HPDF_Array array;
237
+ HPDF_STATUS ret;
238
+
239
+ HPDF_PTRACE((" HPDF_LinkAnnot_SetBorderStyle\n"));
240
+
241
+ if (!CheckSubType (annot, HPDF_ANNOT_LINK))
242
+ return HPDF_INVALID_ANNOTATION;
243
+
244
+ if (width < 0)
245
+ return HPDF_RaiseError (annot->error, HPDF_INVALID_PARAMETER, 0);
246
+
247
+ array = HPDF_Array_New (annot->mmgr);
248
+ if (!array)
249
+ return HPDF_CheckError (annot->error);
250
+
251
+ if ((ret = HPDF_Dict_Add (annot, "Border", array)) != HPDF_OK)
252
+ return HPDF_CheckError (annot->error);
253
+
254
+ ret += HPDF_Array_AddNumber (array, 0);
255
+ ret += HPDF_Array_AddNumber (array, 0);
256
+ ret += HPDF_Array_AddReal (array, width);
257
+
258
+ if (ret != HPDF_OK)
259
+ return HPDF_CheckError (annot->error);
260
+
261
+ if (dash_on && dash_off) {
262
+ HPDF_Array dash = HPDF_Array_New (annot->mmgr);
263
+ if (!dash)
264
+ return HPDF_CheckError (annot->error);
265
+
266
+ if ((ret = HPDF_Array_Add (array, dash)) != HPDF_OK)
267
+ return HPDF_CheckError (annot->error);
268
+
269
+ ret += HPDF_Array_AddNumber (dash, dash_on);
270
+ ret += HPDF_Array_AddNumber (dash, dash_off);
271
+ }
272
+
273
+ if (ret != HPDF_OK)
274
+ return HPDF_CheckError (annot->error);
275
+
276
+ return ret;
277
+ }
278
+
279
+ HPDF_EXPORT(HPDF_STATUS)
280
+ HPDF_LinkAnnot_SetHighlightMode (HPDF_Annotation annot,
281
+ HPDF_AnnotHighlightMode mode)
282
+ {
283
+ HPDF_STATUS ret;
284
+
285
+ HPDF_PTRACE((" HPDF_LinkAnnot_SetHighlightMode\n"));
286
+
287
+ if (!CheckSubType (annot, HPDF_ANNOT_LINK))
288
+ return HPDF_INVALID_ANNOTATION;
289
+
290
+ switch (mode) {
291
+ case HPDF_ANNOT_NO_HIGHTLIGHT:
292
+ ret = HPDF_Dict_AddName (annot, "H", "N");
293
+ break;
294
+ case HPDF_ANNOT_INVERT_BORDER:
295
+ ret = HPDF_Dict_AddName (annot, "H", "O");
296
+ break;
297
+ case HPDF_ANNOT_DOWN_APPEARANCE:
298
+ ret = HPDF_Dict_AddName (annot, "H", "P");
299
+ break;
300
+ default: /* HPDF_ANNOT_INVERT_BOX */
301
+ /* default value */
302
+ HPDF_Dict_RemoveElement (annot, "H");
303
+ ret = HPDF_OK;
304
+ }
305
+
306
+ if (ret != HPDF_OK)
307
+ return HPDF_CheckError (annot->error);
308
+
309
+ return ret;
310
+ }
311
+
312
+ HPDF_Annotation
313
+ HPDF_TextAnnot_New (HPDF_MMgr mmgr,
314
+ HPDF_Xref xref,
315
+ HPDF_Rect rect,
316
+ const char *text,
317
+ HPDF_Encoder encoder)
318
+ {
319
+ HPDF_Annotation annot;
320
+ HPDF_String s;
321
+
322
+ HPDF_PTRACE((" HPDF_TextAnnot_New\n"));
323
+
324
+ annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_TEXT_NOTES, rect);
325
+ if (!annot)
326
+ return NULL;
327
+
328
+ s = HPDF_String_New (mmgr, text, encoder);
329
+ if (!s)
330
+ return NULL;
331
+
332
+ if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
333
+ return NULL;
334
+
335
+ return annot;
336
+ }
337
+
338
+
339
+ HPDF_EXPORT(HPDF_STATUS)
340
+ HPDF_TextAnnot_SetIcon (HPDF_Annotation annot,
341
+ HPDF_AnnotIcon icon)
342
+ {
343
+ HPDF_PTRACE((" HPDF_TextAnnot_SetIcon\n"));
344
+
345
+ if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES))
346
+ return HPDF_INVALID_ANNOTATION;
347
+
348
+ if (icon < 0 || icon >= HPDF_ANNOT_ICON_EOF)
349
+ return HPDF_RaiseError (annot->error, HPDF_ANNOT_INVALID_ICON,
350
+ (HPDF_STATUS)icon);
351
+
352
+ if (HPDF_Dict_AddName (annot, "Name",
353
+ HPDF_ANNOT_ICON_NAMES_NAMES[(HPDF_INT)icon]) != HPDF_OK)
354
+ return HPDF_CheckError (annot->error);
355
+
356
+ return HPDF_OK;
357
+ }
358
+
359
+
360
+ HPDF_EXPORT(HPDF_STATUS)
361
+ HPDF_TextAnnot_SetOpened (HPDF_Annotation annot,
362
+ HPDF_BOOL opened)
363
+ {
364
+ HPDF_Boolean b;
365
+
366
+ HPDF_PTRACE((" HPDF_TextAnnot_SetOpend\n"));
367
+
368
+ if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES))
369
+ return HPDF_INVALID_ANNOTATION;
370
+
371
+ b = HPDF_Boolean_New (annot->mmgr, opened);
372
+ if (!b)
373
+ return HPDF_CheckError (annot->error);
374
+
375
+ return HPDF_Dict_Add (annot, "Open", b);
376
+ }
377
+
378
+
379
+ HPDF_BOOL
380
+ HPDF_Annotation_Validate (HPDF_Annotation annot)
381
+ {
382
+ HPDF_PTRACE((" HPDF_Annotation_Validate\n"));
383
+
384
+ if (!annot)
385
+ return HPDF_FALSE;
386
+
387
+ if (annot->header.obj_class !=
388
+ (HPDF_OSUBCLASS_ANNOTATION | HPDF_OCLASS_DICT))
389
+ return HPDF_FALSE;
390
+
391
+ return HPDF_TRUE;
392
+ }
393
+
394
+ static HPDF_BOOL
395
+ CheckSubType (HPDF_Annotation annot,
396
+ HPDF_AnnotType type)
397
+ {
398
+ HPDF_Name subtype;
399
+
400
+ HPDF_PTRACE((" HPDF_Annotation_CheckSubType\n"));
401
+
402
+ if (!HPDF_Annotation_Validate (annot))
403
+ return HPDF_FALSE;
404
+
405
+ subtype = HPDF_Dict_GetItem (annot, "Subtype", HPDF_OCLASS_NAME);
406
+
407
+ if (!subtype || HPDF_StrCmp (subtype->value,
408
+ HPDF_ANNOT_TYPE_NAMES[(HPDF_INT)type]) != 0) {
409
+ HPDF_RaiseError (annot->error, HPDF_INVALID_ANNOTATION, 0);
410
+ return HPDF_FALSE;
411
+ }
412
+
413
+ return HPDF_TRUE;
414
+ }
415
+
@@ -0,0 +1,344 @@
1
+ /*
2
+ * << Haru Free PDF Library 2.0.0 >> -- hpdf_array.c
3
+ *
4
+ * Copyright (c) 1999-2006 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
+ #include "hpdf_conf.h"
16
+ #include "hpdf_utils.h"
17
+ #include "hpdf_objects.h"
18
+
19
+ HPDF_Array
20
+ HPDF_Array_New (HPDF_MMgr mmgr)
21
+ {
22
+ HPDF_Array obj;
23
+
24
+ HPDF_PTRACE((" HPDF_Array_New\n"));
25
+
26
+ obj = HPDF_GetMem (mmgr, sizeof(HPDF_Array_Rec));
27
+ if (obj) {
28
+ HPDF_MemSet (obj, 0, sizeof(HPDF_Array_Rec));
29
+ obj->header.obj_class = HPDF_OCLASS_ARRAY;
30
+ obj->mmgr = mmgr;
31
+ obj->error = mmgr->error;
32
+ obj->list = HPDF_List_New (mmgr, HPDF_DEF_ITEMS_PER_BLOCK);
33
+ if (!obj->list) {
34
+ HPDF_FreeMem (mmgr, obj);
35
+ obj = NULL;
36
+ }
37
+ }
38
+
39
+ return obj;
40
+ }
41
+
42
+
43
+ HPDF_Array
44
+ HPDF_Box_Array_New (HPDF_MMgr mmgr,
45
+ HPDF_Box box)
46
+ {
47
+ HPDF_Array obj;
48
+ HPDF_STATUS ret = HPDF_OK;
49
+
50
+ HPDF_PTRACE((" HPDF_Box_Array_New\n"));
51
+
52
+ obj = HPDF_Array_New (mmgr);
53
+ if (!obj)
54
+ return NULL;
55
+
56
+ ret += HPDF_Array_Add (obj, HPDF_Real_New (mmgr, box.left));
57
+ ret += HPDF_Array_Add (obj, HPDF_Real_New (mmgr, box.bottom));
58
+ ret += HPDF_Array_Add (obj, HPDF_Real_New (mmgr, box.right));
59
+ ret += HPDF_Array_Add (obj, HPDF_Real_New (mmgr, box.top));
60
+
61
+ if (ret != HPDF_OK) {
62
+ HPDF_Array_Free (obj);
63
+ return NULL;
64
+ }
65
+
66
+ return obj;
67
+ }
68
+
69
+
70
+ void
71
+ HPDF_Array_Free (HPDF_Array array)
72
+ {
73
+ if (!array)
74
+ return;
75
+
76
+ HPDF_PTRACE((" HPDF_Array_Free\n"));
77
+
78
+ HPDF_Array_Clear (array);
79
+
80
+ HPDF_List_Free (array->list);
81
+
82
+ array->header.obj_class = 0;
83
+
84
+ HPDF_FreeMem (array->mmgr, array);
85
+ }
86
+
87
+
88
+ HPDF_STATUS
89
+ HPDF_Array_Write (HPDF_Array array,
90
+ HPDF_Stream stream,
91
+ HPDF_Encrypt e)
92
+ {
93
+ HPDF_UINT i;
94
+ HPDF_STATUS ret;
95
+
96
+ HPDF_PTRACE((" HPDF_Array_Write\n"));
97
+
98
+ ret = HPDF_Stream_WriteStr (stream, "[ ");
99
+ if (ret != HPDF_OK)
100
+ return ret;
101
+
102
+ for (i = 0; i < array->list->count; i++) {
103
+ void * element = HPDF_List_ItemAt (array->list, i);
104
+
105
+ ret = HPDF_Obj_Write (element, stream, e);
106
+ if (ret != HPDF_OK)
107
+ return ret;
108
+
109
+ ret = HPDF_Stream_WriteChar (stream, ' ');
110
+ if (ret != HPDF_OK)
111
+ return ret;
112
+ }
113
+
114
+ ret = HPDF_Stream_WriteChar (stream, ']');
115
+
116
+ return ret;
117
+ }
118
+
119
+
120
+ HPDF_STATUS
121
+ HPDF_Array_AddNumber (HPDF_Array array,
122
+ HPDF_INT32 value)
123
+ {
124
+ HPDF_Number n = HPDF_Number_New (array->mmgr, value);
125
+
126
+ HPDF_PTRACE((" HPDF_Array_AddNumber\n"));
127
+
128
+ if (!n)
129
+ return HPDF_Error_GetCode (array->error);
130
+ else
131
+ return HPDF_Array_Add (array, n);
132
+ }
133
+
134
+
135
+ HPDF_STATUS
136
+ HPDF_Array_AddReal (HPDF_Array array,
137
+ HPDF_REAL value)
138
+ {
139
+ HPDF_Real r = HPDF_Real_New (array->mmgr, value);
140
+
141
+ HPDF_PTRACE((" HPDF_Array_AddReal\n"));
142
+
143
+ if (!r)
144
+ return HPDF_Error_GetCode (array->error);
145
+ else
146
+ return HPDF_Array_Add (array, r);
147
+ }
148
+
149
+
150
+ HPDF_STATUS
151
+ HPDF_Array_AddName (HPDF_Array array,
152
+ const char *value)
153
+ {
154
+ HPDF_Name n = HPDF_Name_New (array->mmgr, value);
155
+
156
+ HPDF_PTRACE((" HPDF_Array_AddName\n"));
157
+
158
+ if (!n)
159
+ return HPDF_Error_GetCode (array->error);
160
+ else
161
+ return HPDF_Array_Add (array, n);
162
+ }
163
+
164
+ HPDF_STATUS
165
+ HPDF_Array_Add (HPDF_Array array,
166
+ void *obj)
167
+ {
168
+ HPDF_Obj_Header *header;
169
+ HPDF_STATUS ret;
170
+
171
+ HPDF_PTRACE((" HPDF_Array_Add\n"));
172
+
173
+ if (!obj) {
174
+ if (HPDF_Error_GetCode (array->error) == HPDF_OK)
175
+ return HPDF_SetError (array->error, HPDF_INVALID_OBJECT, 0);
176
+ else
177
+ return HPDF_INVALID_OBJECT;
178
+ }
179
+
180
+ header = (HPDF_Obj_Header *)obj;
181
+
182
+ if (header->obj_id & HPDF_OTYPE_DIRECT)
183
+ return HPDF_SetError (array->error, HPDF_INVALID_OBJECT, 0);
184
+
185
+ if (array->list->count >= HPDF_LIMIT_MAX_ARRAY) {
186
+ HPDF_PTRACE((" HPDF_Array_Add exceed limitatin of array count(%d)\n",
187
+ HPDF_LIMIT_MAX_ARRAY));
188
+
189
+ HPDF_Obj_Free (array->mmgr, obj);
190
+ return HPDF_SetError (array->error, HPDF_ARRAY_COUNT_ERR, 0);
191
+ }
192
+
193
+ if (header->obj_id & HPDF_OTYPE_INDIRECT) {
194
+ HPDF_Proxy proxy = HPDF_Proxy_New (array->mmgr, obj);
195
+
196
+ if (!proxy) {
197
+ HPDF_Obj_Free (array->mmgr, obj);
198
+ return HPDF_Error_GetCode (array->error);
199
+ }
200
+
201
+ proxy->header.obj_id |= HPDF_OTYPE_DIRECT;
202
+ obj = proxy;
203
+ } else
204
+ header->obj_id |= HPDF_OTYPE_DIRECT;
205
+
206
+ ret = HPDF_List_Add (array->list, obj);
207
+ if (ret != HPDF_OK)
208
+ HPDF_Obj_Free (array->mmgr, obj);
209
+
210
+ return ret;
211
+ }
212
+
213
+
214
+ HPDF_STATUS
215
+ HPDF_Array_Insert (HPDF_Array array,
216
+ void *target,
217
+ void *obj)
218
+ {
219
+ HPDF_Obj_Header *header;
220
+ HPDF_STATUS ret;
221
+ HPDF_UINT i;
222
+
223
+ HPDF_PTRACE((" HPDF_Array_Insert\n"));
224
+
225
+ if (!obj) {
226
+ if (HPDF_Error_GetCode (array->error) == HPDF_OK)
227
+ return HPDF_SetError (array->error, HPDF_INVALID_OBJECT, 0);
228
+ else
229
+ return HPDF_INVALID_OBJECT;
230
+ }
231
+
232
+ header = (HPDF_Obj_Header *)obj;
233
+
234
+ if (header->obj_id & HPDF_OTYPE_DIRECT) {
235
+ HPDF_PTRACE((" HPDF_Array_Add this object cannot owned by array "
236
+ "obj=0x%08X\n", (HPDF_UINT)array));
237
+
238
+ return HPDF_SetError (array->error, HPDF_INVALID_OBJECT, 0);
239
+ }
240
+
241
+ if (array->list->count >= HPDF_LIMIT_MAX_ARRAY) {
242
+ HPDF_PTRACE((" HPDF_Array_Add exceed limitatin of array count(%d)\n",
243
+ HPDF_LIMIT_MAX_ARRAY));
244
+
245
+ HPDF_Obj_Free (array->mmgr, obj);
246
+
247
+ return HPDF_SetError (array->error, HPDF_ARRAY_COUNT_ERR, 0);
248
+ }
249
+
250
+ if (header->obj_id & HPDF_OTYPE_INDIRECT) {
251
+ HPDF_Proxy proxy = HPDF_Proxy_New (array->mmgr, obj);
252
+
253
+ if (!proxy) {
254
+ HPDF_Obj_Free (array->mmgr, obj);
255
+ return HPDF_Error_GetCode (array->error);
256
+ }
257
+
258
+ proxy->header.obj_id |= HPDF_OTYPE_DIRECT;
259
+ obj = proxy;
260
+ } else
261
+ header->obj_id |= HPDF_OTYPE_DIRECT;
262
+
263
+ /* get the target-object from object-list
264
+ * consider that the pointer contained in list may be proxy-object.
265
+ */
266
+ for (i = 0; i < array->list->count; i++) {
267
+ void *ptr = HPDF_List_ItemAt (array->list, i);
268
+ void *obj_ptr;
269
+
270
+ header = (HPDF_Obj_Header *)obj;
271
+ if (header->obj_class == HPDF_OCLASS_PROXY)
272
+ obj_ptr = ((HPDF_Proxy)ptr)->obj;
273
+ else
274
+ obj_ptr = ptr;
275
+
276
+ if (obj_ptr == target) {
277
+ ret = HPDF_List_Insert (array->list, ptr, obj);
278
+ if (ret != HPDF_OK)
279
+ HPDF_Obj_Free (array->mmgr, obj);
280
+
281
+ return ret;
282
+ }
283
+ }
284
+
285
+ HPDF_Obj_Free (array->mmgr, obj);
286
+
287
+ return HPDF_ITEM_NOT_FOUND;
288
+ }
289
+
290
+
291
+ void*
292
+ HPDF_Array_GetItem (HPDF_Array array,
293
+ HPDF_UINT index,
294
+ HPDF_UINT16 obj_class)
295
+ {
296
+ void *obj;
297
+ HPDF_Obj_Header *header;
298
+
299
+ HPDF_PTRACE((" HPDF_Array_GetItem\n"));
300
+
301
+ obj = HPDF_List_ItemAt (array->list, index);
302
+
303
+ if (!obj) {
304
+ HPDF_SetError (array->error, HPDF_ARRAY_ITEM_NOT_FOUND, 0);
305
+ return NULL;
306
+ }
307
+
308
+ header = (HPDF_Obj_Header *)obj;
309
+
310
+ if (header->obj_class == HPDF_OCLASS_PROXY) {
311
+ obj = ((HPDF_Proxy)obj)->obj;
312
+ header = (HPDF_Obj_Header *)obj;
313
+ }
314
+
315
+ if ((header->obj_class & HPDF_OCLASS_ANY) != obj_class) {
316
+ HPDF_SetError (array->error, HPDF_ARRAY_ITEM_UNEXPECTED_TYPE, 0);
317
+
318
+ return NULL;
319
+ }
320
+
321
+ return obj;
322
+ }
323
+
324
+ void
325
+ HPDF_Array_Clear (HPDF_Array array)
326
+ {
327
+ HPDF_UINT i;
328
+
329
+ HPDF_PTRACE((" HPDF_Array_Clear\n"));
330
+
331
+ if (!array)
332
+ return;
333
+
334
+ for (i = 0; i < array->list->count; i++) {
335
+ void * obj = HPDF_List_ItemAt (array->list, i);
336
+
337
+ if (obj) {
338
+ HPDF_Obj_Free (array->mmgr, obj);
339
+ }
340
+ }
341
+
342
+ HPDF_List_Clear (array->list);
343
+ }
344
+