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,424 @@
1
+ /*
2
+ * << Haru Free PDF Library 2.0.3 >> -- hpdf_image.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_image.h"
18
+
19
+ #ifndef HPDF_NOPNGLIB
20
+ #include <png.h>
21
+
22
+ static void
23
+ PngErrorFunc (png_structp png_ptr,
24
+ const char *msg);
25
+
26
+
27
+ static void
28
+ PngReadFunc (png_structp png_ptr,
29
+ png_bytep data,
30
+ png_uint_32 length)
31
+ {
32
+ HPDF_UINT len = length;
33
+ HPDF_Stream stream = (HPDF_Stream)png_get_io_ptr (png_ptr);
34
+
35
+ HPDF_Stream_Read (stream, data, &len);
36
+ }
37
+
38
+
39
+ static HPDF_STATUS
40
+ LoadPngData (HPDF_Dict image,
41
+ HPDF_Stream png_data,
42
+ HPDF_BOOL delayed_loading);
43
+
44
+
45
+ static void
46
+ PngErrorFunc (png_structp png_ptr,
47
+ const char *msg);
48
+
49
+
50
+ static HPDF_STATUS
51
+ ReadPngData_Interlaced (HPDF_Dict image,
52
+ png_structp png_ptr,
53
+ png_infop info_ptr);
54
+
55
+
56
+ static HPDF_STATUS
57
+ ReadPngData (HPDF_Dict image,
58
+ png_structp png_ptr,
59
+ png_infop info_ptr);
60
+
61
+
62
+ static HPDF_STATUS
63
+ CreatePallet (HPDF_Dict image,
64
+ png_structp png_ptr,
65
+ png_infop info_ptr);
66
+
67
+
68
+ static HPDF_STATUS
69
+ PngBeforeWrite (HPDF_Dict obj);
70
+
71
+
72
+ static HPDF_STATUS
73
+ PngAfterWrite (HPDF_Dict obj);
74
+
75
+
76
+ /*---------------------------------------------------------------------------*/
77
+
78
+ static void
79
+ PngErrorFunc (png_structp png_ptr,
80
+ const char *msg)
81
+ {
82
+ char error_number[16];
83
+ HPDF_UINT i;
84
+ HPDF_STATUS detail_no;
85
+ HPDF_Error error;
86
+
87
+ /* pick out error-number from error message */
88
+ HPDF_MemSet (error_number, 0, 16);
89
+
90
+ for (i = 0; i < 15; i++) {
91
+ error_number[i] = *(msg + i);
92
+ if (*(msg + i + 1) == ' ')
93
+ break;
94
+ }
95
+
96
+ error = (HPDF_Error)png_get_error_ptr (png_ptr);
97
+ detail_no = (HPDF_STATUS)HPDF_AToI (error_number);
98
+ HPDF_SetError (error, HPDF_LIBPNG_ERROR, detail_no);
99
+ }
100
+
101
+
102
+ static HPDF_STATUS
103
+ ReadPngData_Interlaced (HPDF_Dict image,
104
+ png_structp png_ptr,
105
+ png_infop info_ptr)
106
+ {
107
+ png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
108
+ png_bytep* row_pointers = HPDF_GetMem (image->mmgr,
109
+ info_ptr->height * sizeof (png_bytep));
110
+
111
+ if (row_pointers) {
112
+ HPDF_UINT i;
113
+
114
+ HPDF_MemSet (row_pointers, 0, info_ptr->height * sizeof (png_bytep));
115
+ for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
116
+ row_pointers[i] = HPDF_GetMem (image->mmgr, len);
117
+
118
+ if (image->error->error_no != HPDF_OK)
119
+ break;
120
+ }
121
+
122
+ if (image->error->error_no == HPDF_OK) {
123
+ /* } else { remove this line */
124
+ png_read_image(png_ptr, row_pointers);
125
+ /* if (image->error->error_no != HPDF_OK) { remove this line */
126
+ if (image->error->error_no == HPDF_OK) { /* add this line */
127
+ for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
128
+ if (HPDF_Stream_Write (image->stream, row_pointers[i], len) !=
129
+ HPDF_OK)
130
+ break;
131
+ }
132
+ }
133
+ }
134
+
135
+ /* clean up */
136
+ for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
137
+ HPDF_FreeMem (image->mmgr, row_pointers[i]);
138
+ /* i-- remove this line */
139
+ }
140
+
141
+ HPDF_FreeMem (image->mmgr, row_pointers);
142
+ }
143
+
144
+ return image->error->error_no;
145
+ }
146
+
147
+ static HPDF_STATUS
148
+ ReadPngData (HPDF_Dict image,
149
+ png_structp png_ptr,
150
+ png_infop info_ptr)
151
+ {
152
+ png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
153
+ png_bytep buf_ptr = HPDF_GetMem (image->mmgr, len);
154
+
155
+ if (buf_ptr) {
156
+ HPDF_UINT i;
157
+
158
+ for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
159
+ png_read_rows(png_ptr, (png_byte**)&buf_ptr, NULL, 1);
160
+ if (image->error->error_no != HPDF_OK)
161
+ break;
162
+
163
+ if (HPDF_Stream_Write (image->stream, buf_ptr, len) != HPDF_OK)
164
+ break;
165
+ }
166
+
167
+ HPDF_FreeMem (image->mmgr, buf_ptr);
168
+ }
169
+
170
+ return image->error->error_no;
171
+ }
172
+
173
+
174
+ static HPDF_STATUS
175
+ CreatePallet (HPDF_Dict image,
176
+ png_structp png_ptr,
177
+ png_infop info_ptr)
178
+ {
179
+ HPDF_INT num_pl = 0;
180
+ png_color *src_pl = NULL;
181
+ HPDF_BYTE *ppallet;
182
+ HPDF_BYTE *p;
183
+ HPDF_UINT i;
184
+ HPDF_Array array;
185
+
186
+ /* png_get_PLTE does not call PngErrorFunc even if it failed.
187
+ * so we call HPDF_Set_Error to set error-code.
188
+ */
189
+ if (png_get_PLTE(png_ptr, info_ptr, (png_color**)&src_pl, &num_pl) !=
190
+ PNG_INFO_PLTE)
191
+ return HPDF_SetError (image->error, HPDF_LIBPNG_ERROR,
192
+ HPDF_CANNOT_GET_PALLET);
193
+
194
+
195
+ /* make a pallet array for indexed image. */
196
+ ppallet = HPDF_GetMem (image->mmgr, num_pl * 3);
197
+ if (!ppallet)
198
+ return image->error->error_no;
199
+
200
+ p = ppallet;
201
+ for (i = 0; i < num_pl; i++, src_pl++) {
202
+ *p++ = src_pl->red;
203
+ *p++ = src_pl->green;
204
+ *p++ = src_pl->blue;
205
+ }
206
+
207
+ array = HPDF_Array_New (image->mmgr);
208
+ if (array) {
209
+ HPDF_Binary b;
210
+
211
+ HPDF_Dict_Add (image, "ColorSpace", array);
212
+
213
+ HPDF_Array_AddName (array, "Indexed");
214
+ HPDF_Array_AddName (array, "DeviceRGB");
215
+ HPDF_Array_AddNumber (array, num_pl - 1);
216
+
217
+ b = HPDF_Binary_New (image->mmgr, ppallet, num_pl * 3);
218
+ if (b)
219
+ HPDF_Array_Add (array, b);
220
+ }
221
+
222
+ HPDF_FreeMem (image->mmgr, ppallet);
223
+
224
+ return image->error->error_no;
225
+ }
226
+
227
+ #define HPDF_PNG_BYTES_TO_CHECK 8
228
+
229
+ HPDF_Image
230
+ HPDF_Image_LoadPngImage (HPDF_MMgr mmgr,
231
+ HPDF_Stream png_data,
232
+ HPDF_Xref xref,
233
+ HPDF_BOOL delayed_loading)
234
+ {
235
+ HPDF_STATUS ret;
236
+ HPDF_Dict image;
237
+ png_byte header[HPDF_PNG_BYTES_TO_CHECK];
238
+ HPDF_UINT len = HPDF_PNG_BYTES_TO_CHECK;
239
+
240
+ HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n"));
241
+
242
+ HPDF_MemSet (header, 0x00, HPDF_PNG_BYTES_TO_CHECK);
243
+ ret = HPDF_Stream_Read (png_data, header, &len);
244
+ if (ret != HPDF_OK ||
245
+ png_sig_cmp (header, (png_size_t)0, HPDF_PNG_BYTES_TO_CHECK)) {
246
+ HPDF_SetError (mmgr->error, HPDF_INVALID_PNG_IMAGE, 0);
247
+ return NULL;
248
+ }
249
+
250
+ image = HPDF_DictStream_New (mmgr, xref);
251
+ if (!image)
252
+ return NULL;
253
+
254
+ image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
255
+ ret += HPDF_Dict_AddName (image, "Type", "XObject");
256
+ ret += HPDF_Dict_AddName (image, "Subtype", "Image");
257
+ if (ret != HPDF_OK)
258
+ return NULL;
259
+
260
+ if (LoadPngData (image, png_data, delayed_loading) != HPDF_OK)
261
+ return NULL;
262
+
263
+ return image;
264
+ }
265
+
266
+
267
+ static HPDF_STATUS
268
+ LoadPngData (HPDF_Dict image,
269
+ HPDF_Stream png_data,
270
+ HPDF_BOOL delayed_loading)
271
+
272
+ {
273
+ HPDF_STATUS ret;
274
+ png_structp png_ptr = NULL;
275
+ png_infop info_ptr = NULL;
276
+
277
+ HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n"));
278
+
279
+ /* create read_struct. */
280
+ png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
281
+ image->error, PngErrorFunc, PngErrorFunc);
282
+
283
+ if (png_ptr == NULL) {
284
+ HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
285
+ return HPDF_FAILD_TO_ALLOC_MEM;
286
+ }
287
+
288
+ /* create info-struct */
289
+ info_ptr = png_create_info_struct (png_ptr);
290
+
291
+ if (info_ptr == NULL) {
292
+ HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
293
+ goto Exit;
294
+ }
295
+
296
+ png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK);
297
+ png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc);
298
+
299
+ /* reading info structure. */
300
+ png_read_info(png_ptr, info_ptr);
301
+ if (image->error->error_no != HPDF_OK)
302
+ goto Exit;
303
+
304
+ /* 16bit image and alpha color type are not supported. */
305
+ if (info_ptr->bit_depth == 16)
306
+ png_set_strip_16(png_ptr);
307
+
308
+ if (PNG_COLOR_MASK_ALPHA & info_ptr->color_type) {
309
+ /* png image with alpha chanel is not supported. */
310
+ png_set_strip_alpha(png_ptr);
311
+ }
312
+
313
+ png_read_update_info(png_ptr, info_ptr);
314
+ if (image->error->error_no != HPDF_OK)
315
+ goto Exit;
316
+
317
+ /* if the image has color palette, copy the pallet of the image to
318
+ * create color map.
319
+ */
320
+ if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
321
+ ret = CreatePallet(image, png_ptr, info_ptr);
322
+ else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
323
+ ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
324
+ else
325
+ ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
326
+
327
+ if (ret != HPDF_OK)
328
+ goto Exit;
329
+
330
+ /* read image-data
331
+ * if the image is interlaced, read whole image at once.
332
+ * if delayed_loading is HPDF_TRUE, the data does not load this phase.
333
+ */
334
+ if (delayed_loading) {
335
+ image->before_write_fn = PngBeforeWrite;
336
+ image->after_write_fn = PngAfterWrite;
337
+ } else {
338
+ if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE)
339
+ ret = ReadPngData_Interlaced(image, png_ptr, info_ptr);
340
+ else
341
+ ret = ReadPngData(image, png_ptr, info_ptr);
342
+
343
+ if (ret != HPDF_OK)
344
+ goto Exit;
345
+ }
346
+
347
+ /* setting the info of the image. */
348
+ if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width)
349
+ != HPDF_OK)
350
+ goto Exit;
351
+
352
+ if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height)
353
+ != HPDF_OK)
354
+ goto Exit;
355
+
356
+ if (HPDF_Dict_AddNumber (image, "BitsPerComponent",
357
+ (HPDF_UINT)info_ptr->bit_depth) != HPDF_OK)
358
+ goto Exit;
359
+
360
+ /* clean up */
361
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
362
+
363
+ return HPDF_OK;
364
+
365
+ Exit:
366
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
367
+
368
+ return image->error->error_no;
369
+ }
370
+
371
+
372
+ static HPDF_STATUS
373
+ PngBeforeWrite (HPDF_Dict obj)
374
+ {
375
+ HPDF_STATUS ret;
376
+ png_byte header[HPDF_PNG_BYTES_TO_CHECK];
377
+ HPDF_UINT len = HPDF_PNG_BYTES_TO_CHECK;
378
+ HPDF_Stream png_data;
379
+ HPDF_String s;
380
+
381
+ HPDF_PTRACE ((" PngBeforeWrite\n"));
382
+
383
+ HPDF_MemStream_FreeData(obj->stream);
384
+
385
+ s = HPDF_Dict_GetItem (obj, "_FILE_NAME", HPDF_OCLASS_STRING);
386
+ if (!s)
387
+ return HPDF_SetError (obj->error, HPDF_MISSING_FILE_NAME_ENTRY, 0);
388
+
389
+ png_data = HPDF_FileReader_New (obj->mmgr, s->value);
390
+ if (!HPDF_Stream_Validate (png_data))
391
+ return obj->error->error_no;
392
+
393
+ HPDF_MemSet (header, 0x00, HPDF_PNG_BYTES_TO_CHECK);
394
+ ret = HPDF_Stream_Read (png_data, header, &len);
395
+ if (ret != HPDF_OK ||
396
+ png_sig_cmp (header, (png_size_t)0, HPDF_PNG_BYTES_TO_CHECK)) {
397
+ HPDF_Stream_Free(png_data);
398
+ return HPDF_SetError (obj->error, HPDF_INVALID_PNG_IMAGE, 0);
399
+ }
400
+
401
+ if ((ret = LoadPngData (obj, png_data, HPDF_FALSE)) != HPDF_OK) {
402
+ HPDF_Stream_Free(png_data);
403
+ return ret;
404
+ }
405
+
406
+ HPDF_Stream_Free(png_data);
407
+
408
+ return HPDF_OK;
409
+ }
410
+
411
+
412
+ static HPDF_STATUS
413
+ PngAfterWrite (HPDF_Dict obj)
414
+ {
415
+ HPDF_PTRACE ((" PngAfterWrite\n"));
416
+
417
+ HPDF_MemStream_FreeData(obj->stream);
418
+
419
+ return HPDF_OK;
420
+ }
421
+
422
+
423
+ #endif /* HPDF_NOPNGLIB */
424
+
@@ -0,0 +1,164 @@
1
+ /*
2
+ * << Haru Free PDF Library 2.0.0 >> -- hpdf_info.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_info.h"
18
+
19
+ static const char *HPDF_INFO_ATTR_NAMES[] = {
20
+ "CreationDate",
21
+ "ModDate",
22
+ "Author",
23
+ "Creator",
24
+ "Producer",
25
+ "Title",
26
+ "Subject",
27
+ "Keywords",
28
+ NULL
29
+ };
30
+
31
+
32
+ static const char*
33
+ InfoTypeToName (HPDF_InfoType type);
34
+
35
+
36
+ /*---------------------------------------------------------------------------*/
37
+
38
+ static const char*
39
+ InfoTypeToName (HPDF_InfoType type)
40
+ {
41
+ HPDF_UINT idx = (HPDF_UINT)type;
42
+
43
+ return HPDF_INFO_ATTR_NAMES[idx];
44
+ }
45
+
46
+
47
+ HPDF_STATUS
48
+ HPDF_Info_SetInfoAttr (HPDF_Dict info,
49
+ HPDF_InfoType type,
50
+ const char *value,
51
+ HPDF_Encoder encoder)
52
+ {
53
+ const char* name = InfoTypeToName (type);
54
+
55
+ HPDF_PTRACE((" HPDF_Info_SetInfoAttr\n"));
56
+
57
+ if (type <= HPDF_INFO_MOD_DATE)
58
+ return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0);
59
+
60
+ return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, value,
61
+ encoder));
62
+ }
63
+
64
+
65
+ const char*
66
+ HPDF_Info_GetInfoAttr (HPDF_Dict info,
67
+ HPDF_InfoType type)
68
+ {
69
+ const char* name = InfoTypeToName (type);
70
+ HPDF_String s;
71
+
72
+ HPDF_PTRACE((" HPDF_Info_GetInfoAttr\n"));
73
+
74
+ if (!info)
75
+ return NULL;
76
+
77
+ s = HPDF_Dict_GetItem (info, name, HPDF_OCLASS_STRING);
78
+
79
+ if (!s)
80
+ return NULL;
81
+ else
82
+ return s->value;
83
+ }
84
+
85
+
86
+ HPDF_STATUS
87
+ HPDF_Info_SetInfoDateAttr (HPDF_Dict info,
88
+ HPDF_InfoType type,
89
+ HPDF_Date value)
90
+ {
91
+ char tmp[HPDF_DATE_TIME_STR_LEN + 1];
92
+ char* ptmp;
93
+ const char* name = InfoTypeToName (type);
94
+
95
+ HPDF_PTRACE((" HPDF_Info_SetInfoDateAttr\n"));
96
+
97
+ if (type > HPDF_INFO_MOD_DATE)
98
+ return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0);
99
+
100
+ HPDF_MemSet (tmp, 0, HPDF_DATE_TIME_STR_LEN + 1);
101
+ if (value.month < 1 || 12 < value.month ||
102
+ value.day < 1 ||
103
+ 23 < value.hour ||
104
+ 59 < value.minutes ||
105
+ 59 < value.seconds ||
106
+ (value.ind != '+' && value.ind != '-' && value.ind != 'Z' &&
107
+ value.ind != ' ') ||
108
+ 23 < value.off_hour ||
109
+ 59 < value.off_minutes) {
110
+ return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
111
+ }
112
+
113
+ switch (value.month) {
114
+ case 1:
115
+ case 3:
116
+ case 5:
117
+ case 7:
118
+ case 8:
119
+ case 10:
120
+ case 12:
121
+ if (value.day > 31)
122
+ return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
123
+
124
+ break;
125
+ case 4:
126
+ case 6:
127
+ case 9:
128
+ case 11:
129
+ if (value.day > 30)
130
+ return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
131
+
132
+ break;
133
+ case 2:
134
+ if (value.day > 29 || (value.day == 29 &&
135
+ (value.year % 4 != 0 ||
136
+ (value.year % 100 == 0 && value.year % 400 != 0))))
137
+ return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
138
+
139
+ break;
140
+ default:
141
+ return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
142
+ }
143
+
144
+ ptmp = HPDF_MemCpy (tmp, "D:", 2);
145
+ ptmp = HPDF_IToA2 (ptmp, value.year, 5);
146
+ ptmp = HPDF_IToA2 (ptmp, value.month, 3);
147
+ ptmp = HPDF_IToA2 (ptmp, value.day, 3);
148
+ ptmp = HPDF_IToA2 (ptmp, value.hour, 3);
149
+ ptmp = HPDF_IToA2 (ptmp, value.minutes, 3);
150
+ ptmp = HPDF_IToA2 (ptmp, value.seconds, 3);
151
+ if (value.ind != ' ') {
152
+ *ptmp++ = value.ind;
153
+ ptmp = HPDF_IToA2 (ptmp, value.off_hour, 3);
154
+ *ptmp++ = '\'';
155
+ ptmp = HPDF_IToA2 (ptmp, value.off_minutes, 3);
156
+ *ptmp++ = '\'';
157
+ }
158
+ *ptmp = 0;
159
+
160
+ return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, tmp,
161
+ NULL));
162
+ }
163
+
164
+