hpdf 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History +57 -0
- data/License +25 -0
- data/README +165 -0
- data/examples/arc_demo.rb +82 -0
- data/examples/demo.rb +92 -0
- data/examples/encryption.rb +41 -0
- data/examples/ext_gstater_demo.rb +171 -0
- data/examples/font_demo.rb +67 -0
- data/examples/jpfont_demo.rb +122 -0
- data/examples/line_demo.rb +301 -0
- data/examples/slide_show_demo.rb +139 -0
- data/examples/text_demo2.rb +189 -0
- data/examples/ttfont_demo.rb +106 -0
- data/ext/extconf.rb +6 -0
- data/ext/hpdf.c +3779 -0
- data/ext/hpdf_annotation.c +415 -0
- data/ext/hpdf_array.c +344 -0
- data/ext/hpdf_binary.c +117 -0
- data/ext/hpdf_boolean.c +47 -0
- data/ext/hpdf_catalog.c +354 -0
- data/ext/hpdf_destination.c +339 -0
- data/ext/hpdf_dict.c +488 -0
- data/ext/hpdf_doc.c +2020 -0
- data/ext/hpdf_doc_png.c +137 -0
- data/ext/hpdf_encoder.c +2991 -0
- data/ext/hpdf_encoder_cns.c +36359 -0
- data/ext/hpdf_encoder_cnt.c +15307 -0
- data/ext/hpdf_encoder_jp.c +16125 -0
- data/ext/hpdf_encoder_kr.c +27978 -0
- data/ext/hpdf_encrypt.c +632 -0
- data/ext/hpdf_encryptdict.c +240 -0
- data/ext/hpdf_error.c +114 -0
- data/ext/hpdf_ext_gstate.c +150 -0
- data/ext/hpdf_font.c +229 -0
- data/ext/hpdf_font_cid.c +1030 -0
- data/ext/hpdf_font_tt.c +406 -0
- data/ext/hpdf_font_type1.c +391 -0
- data/ext/hpdf_fontdef.c +56 -0
- data/ext/hpdf_fontdef_base14.c +4506 -0
- data/ext/hpdf_fontdef_cid.c +194 -0
- data/ext/hpdf_fontdef_cns.c +471 -0
- data/ext/hpdf_fontdef_cnt.c +250 -0
- data/ext/hpdf_fontdef_jp.c +1904 -0
- data/ext/hpdf_fontdef_kr.c +1572 -0
- data/ext/hpdf_fontdef_tt.c +2230 -0
- data/ext/hpdf_fontdef_type1.c +524 -0
- data/ext/hpdf_gstate.c +119 -0
- data/ext/hpdf_image.c +568 -0
- data/ext/hpdf_image_png.c +424 -0
- data/ext/hpdf_info.c +164 -0
- data/ext/hpdf_list.c +333 -0
- data/ext/hpdf_mmgr.c +243 -0
- data/ext/hpdf_name.c +71 -0
- data/ext/hpdf_null.c +31 -0
- data/ext/hpdf_number.c +49 -0
- data/ext/hpdf_objects.c +172 -0
- data/ext/hpdf_outline.c +329 -0
- data/ext/hpdf_page_label.c +74 -0
- data/ext/hpdf_page_operator.c +2764 -0
- data/ext/hpdf_pages.c +1508 -0
- data/ext/hpdf_real.c +61 -0
- data/ext/hpdf_streams.c +1435 -0
- data/ext/hpdf_string.c +189 -0
- data/ext/hpdf_utils.c +438 -0
- data/ext/hpdf_xref.c +348 -0
- data/ext/include/hpdf.h +1227 -0
- data/ext/include/hpdf_annotation.h +74 -0
- data/ext/include/hpdf_catalog.h +81 -0
- data/ext/include/hpdf_conf.h +76 -0
- data/ext/include/hpdf_consts.h +549 -0
- data/ext/include/hpdf_destination.h +41 -0
- data/ext/include/hpdf_doc.h +159 -0
- data/ext/include/hpdf_encoder.h +311 -0
- data/ext/include/hpdf_encrypt.h +156 -0
- data/ext/include/hpdf_encryptdict.h +66 -0
- data/ext/include/hpdf_error.h +201 -0
- data/ext/include/hpdf_ext_gstate.h +38 -0
- data/ext/include/hpdf_font.h +112 -0
- data/ext/include/hpdf_fontdef.h +403 -0
- data/ext/include/hpdf_gstate.h +80 -0
- data/ext/include/hpdf_image.h +72 -0
- data/ext/include/hpdf_info.h +48 -0
- data/ext/include/hpdf_list.h +85 -0
- data/ext/include/hpdf_mmgr.h +82 -0
- data/ext/include/hpdf_objects.h +587 -0
- data/ext/include/hpdf_outline.h +74 -0
- data/ext/include/hpdf_page_label.h +35 -0
- data/ext/include/hpdf_pages.h +128 -0
- data/ext/include/hpdf_streams.h +276 -0
- data/ext/include/hpdf_types.h +488 -0
- data/ext/include/hpdf_utils.h +161 -0
- data/tests/arc_demo.rb +82 -0
- data/tests/demo.rb +91 -0
- data/tests/encryption.rb +41 -0
- data/tests/ext_gstater_demo.rb +171 -0
- data/tests/font_demo.rb +67 -0
- data/tests/line_demo.rb +301 -0
- data/tests/slide_show_demo.rb +139 -0
- data/tests/test_all_examples.rb +31 -0
- data/tests/text_demo2.rb +189 -0
- metadata +147 -0
data/ext/hpdf_name.c
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.0 >> -- hpdf_name.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
|
+
|
20
|
+
HPDF_Name
|
21
|
+
HPDF_Name_New (HPDF_MMgr mmgr,
|
22
|
+
const char *value)
|
23
|
+
{
|
24
|
+
HPDF_Name obj;
|
25
|
+
|
26
|
+
obj = HPDF_GetMem (mmgr, sizeof(HPDF_Name_Rec));
|
27
|
+
|
28
|
+
if (obj) {
|
29
|
+
HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header));
|
30
|
+
obj->header.obj_class = HPDF_OCLASS_NAME;
|
31
|
+
obj->error = mmgr->error;
|
32
|
+
if (HPDF_Name_SetValue (obj, value) == HPDF_NAME_INVALID_VALUE) {
|
33
|
+
HPDF_FreeMem (mmgr, obj);
|
34
|
+
return NULL;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
return obj;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
HPDF_STATUS
|
43
|
+
HPDF_Name_Write (HPDF_Name obj,
|
44
|
+
HPDF_Stream stream)
|
45
|
+
{
|
46
|
+
return HPDF_Stream_WriteEscapeName (stream, obj->value);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
HPDF_STATUS
|
51
|
+
HPDF_Name_SetValue (HPDF_Name obj,
|
52
|
+
const char *value)
|
53
|
+
{
|
54
|
+
if (!value || value[0] == 0)
|
55
|
+
return HPDF_SetError (obj->error, HPDF_NAME_INVALID_VALUE, 0);
|
56
|
+
|
57
|
+
if (HPDF_StrLen (value, HPDF_LIMIT_MAX_NAME_LEN + 1) >
|
58
|
+
HPDF_LIMIT_MAX_NAME_LEN)
|
59
|
+
return HPDF_SetError (obj->error, HPDF_NAME_OUT_OF_RANGE, 0);
|
60
|
+
|
61
|
+
HPDF_StrCpy (obj->value, value, obj->value + HPDF_LIMIT_MAX_NAME_LEN);
|
62
|
+
|
63
|
+
return HPDF_OK;
|
64
|
+
}
|
65
|
+
|
66
|
+
const char*
|
67
|
+
HPDF_Name_GetValue (HPDF_Name obj)
|
68
|
+
{
|
69
|
+
return (const char *)obj->value;
|
70
|
+
}
|
71
|
+
|
data/ext/hpdf_null.c
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.0 >> -- hpdf_null.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_utils.h"
|
16
|
+
#include "hpdf_objects.h"
|
17
|
+
|
18
|
+
|
19
|
+
HPDF_Null
|
20
|
+
HPDF_Null_New (HPDF_MMgr mmgr)
|
21
|
+
{
|
22
|
+
HPDF_Null obj = HPDF_GetMem (mmgr, sizeof(HPDF_Null_Rec));
|
23
|
+
|
24
|
+
if (obj) {
|
25
|
+
HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header));
|
26
|
+
obj->header.obj_class = HPDF_OCLASS_NULL;
|
27
|
+
}
|
28
|
+
|
29
|
+
return obj;
|
30
|
+
}
|
31
|
+
|
data/ext/hpdf_number.c
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.0 >> -- hpdf_number.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_utils.h"
|
16
|
+
#include "hpdf_objects.h"
|
17
|
+
|
18
|
+
|
19
|
+
HPDF_Number
|
20
|
+
HPDF_Number_New (HPDF_MMgr mmgr,
|
21
|
+
HPDF_INT32 value)
|
22
|
+
{
|
23
|
+
HPDF_Number obj = HPDF_GetMem (mmgr, sizeof(HPDF_Number_Rec));
|
24
|
+
|
25
|
+
if (obj) {
|
26
|
+
HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header));
|
27
|
+
obj->header.obj_class = HPDF_OCLASS_NUMBER;
|
28
|
+
obj->value = value;
|
29
|
+
}
|
30
|
+
|
31
|
+
return obj;
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
HPDF_STATUS
|
36
|
+
HPDF_Number_Write (HPDF_Number obj,
|
37
|
+
HPDF_Stream stream)
|
38
|
+
{
|
39
|
+
return HPDF_Stream_WriteInt (stream, obj->value);
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
void
|
44
|
+
HPDF_Number_SetValue (HPDF_Number obj,
|
45
|
+
HPDF_INT32 value)
|
46
|
+
{
|
47
|
+
obj->value =value;
|
48
|
+
}
|
49
|
+
|
data/ext/hpdf_objects.c
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.3 >> -- HPDF_objects.c
|
3
|
+
*
|
4
|
+
* Copyright (c) 1999-2004 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
|
+
void
|
20
|
+
HPDF_Obj_Free (HPDF_MMgr mmgr,
|
21
|
+
void *obj)
|
22
|
+
{
|
23
|
+
HPDF_Obj_Header *header;
|
24
|
+
|
25
|
+
HPDF_PTRACE((" HPDF_Obj_Free\n"));
|
26
|
+
|
27
|
+
if (!obj)
|
28
|
+
return;
|
29
|
+
|
30
|
+
header = (HPDF_Obj_Header *)obj;
|
31
|
+
|
32
|
+
if (!(header->obj_id & HPDF_OTYPE_INDIRECT))
|
33
|
+
HPDF_Obj_ForceFree (mmgr, obj);
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
void
|
38
|
+
HPDF_Obj_ForceFree (HPDF_MMgr mmgr,
|
39
|
+
void *obj)
|
40
|
+
{
|
41
|
+
HPDF_Obj_Header *header;
|
42
|
+
|
43
|
+
HPDF_PTRACE((" HPDF_Obj_ForceFree\n"));
|
44
|
+
|
45
|
+
if (!obj)
|
46
|
+
return;
|
47
|
+
|
48
|
+
header = (HPDF_Obj_Header *)obj;
|
49
|
+
|
50
|
+
HPDF_PTRACE((" HPDF_Obj_ForceFree obj=0x%08X obj_id=0x%08X "
|
51
|
+
"obj_class=0x%08X\n",
|
52
|
+
(HPDF_UINT)obj, (HPDF_UINT)(header->obj_id),
|
53
|
+
(HPDF_UINT)(header->obj_class)));
|
54
|
+
|
55
|
+
switch (header->obj_class & HPDF_OCLASS_ANY) {
|
56
|
+
case HPDF_OCLASS_STRING:
|
57
|
+
HPDF_String_Free (obj);
|
58
|
+
break;
|
59
|
+
case HPDF_OCLASS_BINARY:
|
60
|
+
HPDF_Binary_Free (obj);
|
61
|
+
break;
|
62
|
+
case HPDF_OCLASS_ARRAY:
|
63
|
+
HPDF_Array_Free (obj);
|
64
|
+
break;
|
65
|
+
case HPDF_OCLASS_DICT:
|
66
|
+
HPDF_Dict_Free (obj);
|
67
|
+
break;
|
68
|
+
default:
|
69
|
+
HPDF_FreeMem (mmgr, obj);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
HPDF_STATUS
|
74
|
+
HPDF_Obj_Write (void *obj,
|
75
|
+
HPDF_Stream stream,
|
76
|
+
HPDF_Encrypt e)
|
77
|
+
{
|
78
|
+
HPDF_Obj_Header *header = (HPDF_Obj_Header *)obj;
|
79
|
+
|
80
|
+
HPDF_PTRACE((" HPDF_Obj_Write\n"));
|
81
|
+
|
82
|
+
if (header->obj_id & HPDF_OTYPE_HIDDEN) {
|
83
|
+
HPDF_PTRACE(("#HPDF_Obj_Write obj=0x%08X skipped\n", (HPDF_UINT)obj));
|
84
|
+
return HPDF_OK;
|
85
|
+
}
|
86
|
+
|
87
|
+
if (header->obj_class == HPDF_OCLASS_PROXY) {
|
88
|
+
char buf[HPDF_SHORT_BUF_SIZ];
|
89
|
+
char *pbuf = buf;
|
90
|
+
char *eptr = buf + HPDF_SHORT_BUF_SIZ - 1;
|
91
|
+
HPDF_Proxy p = obj;
|
92
|
+
|
93
|
+
header = (HPDF_Obj_Header*)p->obj;
|
94
|
+
|
95
|
+
pbuf = HPDF_IToA (pbuf, header->obj_id & 0x00FFFFFF, eptr);
|
96
|
+
*pbuf++ = ' ';
|
97
|
+
pbuf = HPDF_IToA (pbuf, header->gen_no, eptr);
|
98
|
+
HPDF_StrCpy(pbuf, " R", eptr);
|
99
|
+
|
100
|
+
return HPDF_Stream_WriteStr(stream, buf);
|
101
|
+
}
|
102
|
+
|
103
|
+
return HPDF_Obj_WriteValue(obj, stream, e);
|
104
|
+
}
|
105
|
+
|
106
|
+
HPDF_STATUS
|
107
|
+
HPDF_Obj_WriteValue (void *obj,
|
108
|
+
HPDF_Stream stream,
|
109
|
+
HPDF_Encrypt e)
|
110
|
+
{
|
111
|
+
HPDF_Obj_Header *header;
|
112
|
+
HPDF_STATUS ret;
|
113
|
+
|
114
|
+
HPDF_PTRACE((" HPDF_Obj_WriteValue\n"));
|
115
|
+
|
116
|
+
header = (HPDF_Obj_Header *)obj;
|
117
|
+
|
118
|
+
HPDF_PTRACE((" HPDF_Obj_WriteValue obj=0x%08X obj_class=0x%04X\n",
|
119
|
+
(HPDF_UINT)obj, (HPDF_UINT)header->obj_class));
|
120
|
+
|
121
|
+
switch (header->obj_class & HPDF_OCLASS_ANY) {
|
122
|
+
case HPDF_OCLASS_NAME:
|
123
|
+
ret = HPDF_Name_Write (obj, stream);
|
124
|
+
break;
|
125
|
+
case HPDF_OCLASS_NUMBER:
|
126
|
+
ret = HPDF_Number_Write (obj, stream);
|
127
|
+
break;
|
128
|
+
case HPDF_OCLASS_REAL:
|
129
|
+
ret = HPDF_Real_Write (obj, stream);
|
130
|
+
break;
|
131
|
+
case HPDF_OCLASS_STRING:
|
132
|
+
ret = HPDF_String_Write (obj, stream, e);
|
133
|
+
break;
|
134
|
+
case HPDF_OCLASS_BINARY:
|
135
|
+
ret = HPDF_Binary_Write (obj, stream, e);
|
136
|
+
break;
|
137
|
+
case HPDF_OCLASS_ARRAY:
|
138
|
+
ret = HPDF_Array_Write (obj, stream, e);
|
139
|
+
break;
|
140
|
+
case HPDF_OCLASS_DICT:
|
141
|
+
ret = HPDF_Dict_Write (obj, stream, e);
|
142
|
+
break;
|
143
|
+
case HPDF_OCLASS_BOOLEAN:
|
144
|
+
ret = HPDF_Boolean_Write (obj, stream);
|
145
|
+
break;
|
146
|
+
case HPDF_OCLASS_NULL:
|
147
|
+
ret = HPDF_Stream_WriteStr (stream, "null");
|
148
|
+
break;
|
149
|
+
default:
|
150
|
+
ret = HPDF_ERR_UNKNOWN_CLASS;
|
151
|
+
}
|
152
|
+
|
153
|
+
return ret;
|
154
|
+
}
|
155
|
+
|
156
|
+
HPDF_Proxy
|
157
|
+
HPDF_Proxy_New (HPDF_MMgr mmgr,
|
158
|
+
void *obj)
|
159
|
+
{
|
160
|
+
HPDF_Proxy p = HPDF_GetMem (mmgr, sizeof(HPDF_Proxy_Rec));
|
161
|
+
|
162
|
+
HPDF_PTRACE((" HPDF_Proxy_New\n"));
|
163
|
+
|
164
|
+
if (p) {
|
165
|
+
HPDF_MemSet (&p->header, 0, sizeof(HPDF_Obj_Header));
|
166
|
+
p->header.obj_class = HPDF_OCLASS_PROXY;
|
167
|
+
p->obj = obj;
|
168
|
+
}
|
169
|
+
|
170
|
+
return p;
|
171
|
+
}
|
172
|
+
|
data/ext/hpdf_outline.c
ADDED
@@ -0,0 +1,329 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.3 >> -- hpdf_outline.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_destination.h"
|
18
|
+
#include "hpdf.h"
|
19
|
+
|
20
|
+
#define HPDF_OUTLINE_CLOSED 0
|
21
|
+
#define HPDF_OUTLINE_OPENED 1
|
22
|
+
|
23
|
+
|
24
|
+
static HPDF_STATUS
|
25
|
+
AddChild (HPDF_Outline parent,
|
26
|
+
HPDF_Outline item);
|
27
|
+
|
28
|
+
|
29
|
+
static HPDF_STATUS
|
30
|
+
BeforeWrite (HPDF_Dict obj);
|
31
|
+
|
32
|
+
|
33
|
+
static HPDF_UINT
|
34
|
+
CountChild (HPDF_Outline outline);
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
/*----------------------------------------------------------------------------*/
|
39
|
+
/*----- HPDF_Outline ---------------------------------------------------------*/
|
40
|
+
|
41
|
+
HPDF_Outline
|
42
|
+
HPDF_OutlineRoot_New (HPDF_MMgr mmgr,
|
43
|
+
HPDF_Xref xref)
|
44
|
+
{
|
45
|
+
HPDF_Outline outline;
|
46
|
+
HPDF_STATUS ret = HPDF_OK;
|
47
|
+
HPDF_Number open_flg;
|
48
|
+
|
49
|
+
HPDF_PTRACE((" HPDF_OutlineRoot_New\n"));
|
50
|
+
|
51
|
+
outline = HPDF_Dict_New (mmgr);
|
52
|
+
if (!outline)
|
53
|
+
return NULL;
|
54
|
+
|
55
|
+
outline->before_write_fn = BeforeWrite;
|
56
|
+
|
57
|
+
if (HPDF_Xref_Add (xref, outline) != HPDF_OK)
|
58
|
+
return NULL;
|
59
|
+
|
60
|
+
open_flg = HPDF_Number_New (mmgr, HPDF_OUTLINE_OPENED);
|
61
|
+
if (!open_flg)
|
62
|
+
return NULL;
|
63
|
+
|
64
|
+
open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN;
|
65
|
+
|
66
|
+
ret += HPDF_Dict_Add (outline, "_OPENED", open_flg);
|
67
|
+
ret += HPDF_Dict_AddName (outline, "Type", "Outline");
|
68
|
+
|
69
|
+
if (ret != HPDF_OK)
|
70
|
+
return NULL;
|
71
|
+
|
72
|
+
outline->header.obj_class |= HPDF_OSUBCLASS_OUTLINE;
|
73
|
+
|
74
|
+
return outline;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
HPDF_Outline
|
79
|
+
HPDF_Outline_New (HPDF_MMgr mmgr,
|
80
|
+
HPDF_Outline parent,
|
81
|
+
const char *title,
|
82
|
+
HPDF_Encoder encoder,
|
83
|
+
HPDF_Xref xref)
|
84
|
+
{
|
85
|
+
HPDF_Outline outline;
|
86
|
+
HPDF_String s;
|
87
|
+
HPDF_STATUS ret = HPDF_OK;
|
88
|
+
HPDF_Number open_flg;
|
89
|
+
|
90
|
+
HPDF_PTRACE((" HPDF_Outline_New\n"));
|
91
|
+
|
92
|
+
if (!mmgr || !parent || !xref)
|
93
|
+
return NULL;
|
94
|
+
|
95
|
+
outline = HPDF_Dict_New (mmgr);
|
96
|
+
if (!outline)
|
97
|
+
return NULL;
|
98
|
+
|
99
|
+
outline->before_write_fn = BeforeWrite;
|
100
|
+
|
101
|
+
if (HPDF_Xref_Add (xref, outline) != HPDF_OK)
|
102
|
+
return NULL;
|
103
|
+
|
104
|
+
s = HPDF_String_New (mmgr, title, encoder);
|
105
|
+
if (!s)
|
106
|
+
return NULL;
|
107
|
+
else
|
108
|
+
ret += HPDF_Dict_Add (outline, "Title", s);
|
109
|
+
|
110
|
+
open_flg = HPDF_Number_New (mmgr, HPDF_OUTLINE_OPENED);
|
111
|
+
if (!open_flg)
|
112
|
+
return NULL;
|
113
|
+
|
114
|
+
open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN;
|
115
|
+
ret += HPDF_Dict_Add (outline, "_OPENED", open_flg);
|
116
|
+
|
117
|
+
ret += HPDF_Dict_AddName (outline, "Type", "Outline");
|
118
|
+
ret += AddChild (parent, outline);
|
119
|
+
|
120
|
+
if (ret != HPDF_OK)
|
121
|
+
return NULL;
|
122
|
+
|
123
|
+
outline->header.obj_class |= HPDF_OSUBCLASS_OUTLINE;
|
124
|
+
|
125
|
+
return outline;
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
static HPDF_STATUS
|
131
|
+
AddChild (HPDF_Outline parent,
|
132
|
+
HPDF_Outline item)
|
133
|
+
{
|
134
|
+
HPDF_Outline first = (HPDF_Outline)HPDF_Dict_GetItem (parent, "First",
|
135
|
+
HPDF_OCLASS_DICT);
|
136
|
+
HPDF_Outline last = (HPDF_Outline)HPDF_Dict_GetItem (parent, "Last",
|
137
|
+
HPDF_OCLASS_DICT);
|
138
|
+
HPDF_STATUS ret = 0;
|
139
|
+
|
140
|
+
HPDF_PTRACE((" AddChild\n"));
|
141
|
+
|
142
|
+
if (!first)
|
143
|
+
ret += HPDF_Dict_Add (parent, "First", item);
|
144
|
+
|
145
|
+
if (last) {
|
146
|
+
ret += HPDF_Dict_Add (last, "Next", item);
|
147
|
+
ret += HPDF_Dict_Add (item, "Prev", last);
|
148
|
+
}
|
149
|
+
|
150
|
+
ret += HPDF_Dict_Add (parent, "Last", item);
|
151
|
+
ret += HPDF_Dict_Add (item, "Parent", parent);
|
152
|
+
|
153
|
+
if (ret != HPDF_OK)
|
154
|
+
return HPDF_Error_GetCode (item->error);
|
155
|
+
|
156
|
+
return HPDF_OK;
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
HPDF_BOOL
|
161
|
+
HPDF_Outline_GetOpened (HPDF_Outline outline)
|
162
|
+
{
|
163
|
+
HPDF_Number n = (HPDF_Number)HPDF_Dict_GetItem (outline, "_OPENED",
|
164
|
+
HPDF_OCLASS_NUMBER);
|
165
|
+
|
166
|
+
HPDF_PTRACE((" HPDF_Outline_GetOpened\n"));
|
167
|
+
|
168
|
+
if (!n)
|
169
|
+
return HPDF_FALSE;
|
170
|
+
|
171
|
+
return (HPDF_BOOL)n->value;
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
HPDF_Outline
|
176
|
+
HPDF_Outline_GetFirst (HPDF_Outline outline)
|
177
|
+
{
|
178
|
+
HPDF_PTRACE((" HPDF_Outline_GetFirst\n"));
|
179
|
+
|
180
|
+
return (HPDF_Outline)HPDF_Dict_GetItem (outline, "First",
|
181
|
+
HPDF_OCLASS_DICT);
|
182
|
+
}
|
183
|
+
|
184
|
+
|
185
|
+
HPDF_Outline
|
186
|
+
HPDF_Outline_GetLast (HPDF_Outline outline)
|
187
|
+
{
|
188
|
+
HPDF_PTRACE((" HPDF_Outline_GetLast\n"));
|
189
|
+
|
190
|
+
return (HPDF_Outline)HPDF_Dict_GetItem (outline, "Last", HPDF_OCLASS_DICT);
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
HPDF_Outline
|
195
|
+
HPDF_Outline_GetPrev (HPDF_Outline outline)
|
196
|
+
{
|
197
|
+
HPDF_PTRACE((" HPDF_Outline_GetPrev\n"));
|
198
|
+
|
199
|
+
return (HPDF_Outline)HPDF_Dict_GetItem (outline, "Prev", HPDF_OCLASS_DICT);
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
HPDF_Outline
|
204
|
+
HPDF_Outline_GetNext (HPDF_Outline outline)
|
205
|
+
{
|
206
|
+
HPDF_PTRACE((" HPDF_Outline_GetNext\n"));
|
207
|
+
|
208
|
+
return (HPDF_Outline)HPDF_Dict_GetItem (outline, "Next", HPDF_OCLASS_DICT);
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
HPDF_Outline
|
213
|
+
HPDF_Outline_GetParent (HPDF_Outline outline)
|
214
|
+
{
|
215
|
+
HPDF_PTRACE((" HPDF_Outline_GetParent\n"));
|
216
|
+
|
217
|
+
return (HPDF_Outline)HPDF_Dict_GetItem (outline, "Parent",
|
218
|
+
HPDF_OCLASS_DICT);
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
static HPDF_STATUS
|
223
|
+
BeforeWrite (HPDF_Dict obj)
|
224
|
+
{
|
225
|
+
HPDF_Number n = (HPDF_Number)HPDF_Dict_GetItem (obj, "Count",
|
226
|
+
HPDF_OCLASS_NUMBER);
|
227
|
+
HPDF_UINT count = CountChild ((HPDF_Outline)obj);
|
228
|
+
|
229
|
+
HPDF_PTRACE((" BeforeWrite\n"));
|
230
|
+
|
231
|
+
if (count == 0 && n)
|
232
|
+
return HPDF_Dict_RemoveElement (obj, "Count");
|
233
|
+
|
234
|
+
if (!HPDF_Outline_GetOpened ((HPDF_Outline)obj))
|
235
|
+
count *= -1;
|
236
|
+
|
237
|
+
if (n)
|
238
|
+
n->value = count;
|
239
|
+
else
|
240
|
+
if (count)
|
241
|
+
return HPDF_Dict_AddNumber (obj, "Count", count);
|
242
|
+
|
243
|
+
return HPDF_OK;
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
static HPDF_UINT
|
248
|
+
CountChild (HPDF_Outline outline)
|
249
|
+
{
|
250
|
+
HPDF_Outline child = HPDF_Outline_GetFirst (outline);
|
251
|
+
HPDF_UINT count = 0;
|
252
|
+
|
253
|
+
HPDF_PTRACE((" CountChild\n"));
|
254
|
+
|
255
|
+
while (child) {
|
256
|
+
count++;
|
257
|
+
|
258
|
+
if (HPDF_Outline_GetOpened (child))
|
259
|
+
count += CountChild (child);
|
260
|
+
|
261
|
+
child = HPDF_Outline_GetNext (child);
|
262
|
+
}
|
263
|
+
|
264
|
+
return count;
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
HPDF_BOOL
|
269
|
+
HPDF_Outline_Validate (HPDF_Outline outline)
|
270
|
+
{
|
271
|
+
if (!outline)
|
272
|
+
return HPDF_FALSE;
|
273
|
+
|
274
|
+
HPDF_PTRACE((" HPDF_Outline_Validate\n"));
|
275
|
+
|
276
|
+
if (outline->header.obj_class !=
|
277
|
+
(HPDF_OSUBCLASS_OUTLINE | HPDF_OCLASS_DICT))
|
278
|
+
return HPDF_FALSE;
|
279
|
+
|
280
|
+
return HPDF_TRUE;
|
281
|
+
}
|
282
|
+
|
283
|
+
HPDF_EXPORT(HPDF_STATUS)
|
284
|
+
HPDF_Outline_SetDestination (HPDF_Outline outline,
|
285
|
+
HPDF_Destination dst)
|
286
|
+
{
|
287
|
+
HPDF_PTRACE((" HPDF_Outline_SetDestination\n"));
|
288
|
+
|
289
|
+
if (!HPDF_Outline_Validate (outline))
|
290
|
+
return HPDF_INVALID_OUTLINE;
|
291
|
+
|
292
|
+
if (!HPDF_Destination_Validate (dst))
|
293
|
+
return HPDF_RaiseError (outline->error, HPDF_INVALID_DESTINATION, 0);
|
294
|
+
|
295
|
+
if (dst == NULL)
|
296
|
+
return HPDF_Dict_RemoveElement (outline, "Dest");
|
297
|
+
|
298
|
+
if (HPDF_Dict_Add (outline, "Dest", dst) != HPDF_OK)
|
299
|
+
return HPDF_CheckError (outline->error);
|
300
|
+
|
301
|
+
return HPDF_OK;
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
HPDF_EXPORT(HPDF_STATUS)
|
306
|
+
HPDF_Outline_SetOpened (HPDF_Outline outline,
|
307
|
+
HPDF_BOOL opened)
|
308
|
+
{
|
309
|
+
HPDF_Number n;
|
310
|
+
|
311
|
+
if (!HPDF_Outline_Validate (outline))
|
312
|
+
return HPDF_INVALID_OUTLINE;
|
313
|
+
|
314
|
+
n = (HPDF_Number)HPDF_Dict_GetItem (outline, "_OPENED",
|
315
|
+
HPDF_OCLASS_NUMBER);
|
316
|
+
|
317
|
+
HPDF_PTRACE((" HPDF_Outline_SetOpened\n"));
|
318
|
+
|
319
|
+
if (!n) {
|
320
|
+
n = HPDF_Number_New (outline->mmgr, (HPDF_INT)opened);
|
321
|
+
if (!n || HPDF_Dict_Add (outline, "_OPENED", n) != HPDF_OK)
|
322
|
+
return HPDF_CheckError (outline->error);
|
323
|
+
} else
|
324
|
+
n->value = (HPDF_INT)opened;
|
325
|
+
|
326
|
+
return HPDF_OK;
|
327
|
+
}
|
328
|
+
|
329
|
+
|