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
@@ -0,0 +1,240 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.5 >> -- hpdf_encryptdict.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
|
+
* 2006.09.04 modified.
|
14
|
+
*---------------------------------------------------------------------------*/
|
15
|
+
|
16
|
+
#include <time.h>
|
17
|
+
#include "hpdf_conf.h"
|
18
|
+
#include "hpdf_utils.h"
|
19
|
+
#include "hpdf_objects.h"
|
20
|
+
#include "hpdf_encryptdict.h"
|
21
|
+
#include "hpdf_info.h"
|
22
|
+
|
23
|
+
/*---------------------------------------------------------------------------*/
|
24
|
+
/*------ HPDF_EncryptDict ---------------------------------------------------*/
|
25
|
+
|
26
|
+
|
27
|
+
HPDF_EncryptDict
|
28
|
+
HPDF_EncryptDict_New (HPDF_MMgr mmgr,
|
29
|
+
HPDF_Xref xref)
|
30
|
+
{
|
31
|
+
HPDF_Encrypt attr;
|
32
|
+
HPDF_EncryptDict dict;
|
33
|
+
|
34
|
+
HPDF_PTRACE((" HPDF_EncryptDict_New\n"));
|
35
|
+
|
36
|
+
dict = HPDF_Dict_New (mmgr);
|
37
|
+
if (!dict)
|
38
|
+
return NULL;
|
39
|
+
|
40
|
+
dict->header.obj_class |= HPDF_OSUBCLASS_ENCRYPT;
|
41
|
+
dict->free_fn = HPDF_EncryptDict_OnFree;
|
42
|
+
|
43
|
+
attr = HPDF_GetMem (dict->mmgr, sizeof(HPDF_Encrypt_Rec));
|
44
|
+
if (!attr) {
|
45
|
+
HPDF_Dict_Free (dict);
|
46
|
+
return NULL;
|
47
|
+
}
|
48
|
+
|
49
|
+
dict->attr = attr;
|
50
|
+
HPDF_Encrypt_Init (attr);
|
51
|
+
|
52
|
+
if (HPDF_Xref_Add (xref, dict) != HPDF_OK)
|
53
|
+
return NULL;
|
54
|
+
|
55
|
+
return dict;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
void
|
60
|
+
HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict,
|
61
|
+
HPDF_Dict info,
|
62
|
+
HPDF_Xref xref)
|
63
|
+
{
|
64
|
+
HPDF_MD5_CTX ctx;
|
65
|
+
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
66
|
+
|
67
|
+
/* use the result of 'time' function to get random value.
|
68
|
+
* when debugging, 'time' value is ignored.
|
69
|
+
*/
|
70
|
+
#ifndef HPDF_DEBUG
|
71
|
+
time_t t = HPDF_TIME (NULL);
|
72
|
+
#endif /* HPDF_DEBUG */
|
73
|
+
|
74
|
+
HPDF_MD5Init (&ctx);
|
75
|
+
|
76
|
+
#ifndef HPDF_DEBUG
|
77
|
+
HPDF_MD5Update(&ctx, (HPDF_BYTE *)&t, sizeof(t));
|
78
|
+
|
79
|
+
/* create File Identifier from elements of Into dictionary. */
|
80
|
+
if (info) {
|
81
|
+
const char *s;
|
82
|
+
HPDF_UINT len;
|
83
|
+
|
84
|
+
/* Author */
|
85
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_AUTHOR);
|
86
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
87
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
88
|
+
|
89
|
+
/* Creator */
|
90
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_CREATOR);
|
91
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
92
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
93
|
+
|
94
|
+
/* Producer */
|
95
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_PRODUCER);
|
96
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
97
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
98
|
+
|
99
|
+
/* Title */
|
100
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_TITLE);
|
101
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
102
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
103
|
+
|
104
|
+
/* Subject */
|
105
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_SUBJECT);
|
106
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
107
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
108
|
+
|
109
|
+
/* Keywords */
|
110
|
+
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_KEYWORDS);
|
111
|
+
if ((len = HPDF_StrLen (s, -1)) > 0)
|
112
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
113
|
+
|
114
|
+
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)&(xref->entries->count),
|
115
|
+
sizeof(HPDF_UINT32));
|
116
|
+
|
117
|
+
}
|
118
|
+
#endif
|
119
|
+
HPDF_MD5Final(attr->encrypt_id, &ctx);
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
HPDF_STATUS
|
124
|
+
HPDF_EncryptDict_Prepare (HPDF_EncryptDict dict,
|
125
|
+
HPDF_Dict info,
|
126
|
+
HPDF_Xref xref)
|
127
|
+
{
|
128
|
+
HPDF_STATUS ret;
|
129
|
+
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
130
|
+
HPDF_Binary user_key;
|
131
|
+
HPDF_Binary owner_key;
|
132
|
+
|
133
|
+
HPDF_PTRACE((" HPDF_EncryptDict_Prepare\n"));
|
134
|
+
|
135
|
+
HPDF_EncryptDict_CreateID (dict, info, xref);
|
136
|
+
HPDF_Encrypt_CreateOwnerKey (attr);
|
137
|
+
HPDF_Encrypt_CreateEncryptionKey (attr);
|
138
|
+
HPDF_Encrypt_CreateUserKey (attr);
|
139
|
+
|
140
|
+
owner_key = HPDF_Binary_New (dict->mmgr, attr->owner_key, HPDF_PASSWD_LEN);
|
141
|
+
if (!owner_key)
|
142
|
+
return HPDF_Error_GetCode (dict->error);
|
143
|
+
|
144
|
+
if ((ret = HPDF_Dict_Add (dict, "O", owner_key)) != HPDF_OK)
|
145
|
+
return ret;
|
146
|
+
|
147
|
+
user_key = HPDF_Binary_New (dict->mmgr, attr->user_key, HPDF_PASSWD_LEN);
|
148
|
+
if (!user_key)
|
149
|
+
return HPDF_Error_GetCode (dict->error);
|
150
|
+
|
151
|
+
if ((ret = HPDF_Dict_Add (dict, "U", user_key)) != HPDF_OK)
|
152
|
+
return ret;
|
153
|
+
|
154
|
+
ret += HPDF_Dict_AddName (dict, "Filter", "Standard");
|
155
|
+
|
156
|
+
if (attr->mode == HPDF_ENCRYPT_R2) {
|
157
|
+
ret += HPDF_Dict_AddNumber (dict, "V", 1);
|
158
|
+
ret += HPDF_Dict_AddNumber (dict, "R", 2);
|
159
|
+
} else if (attr->mode == HPDF_ENCRYPT_R3) {
|
160
|
+
ret += HPDF_Dict_AddNumber (dict, "V", 2);
|
161
|
+
ret += HPDF_Dict_AddNumber (dict, "R", 3);
|
162
|
+
ret += HPDF_Dict_AddNumber (dict, "Length", attr->key_len * 8);
|
163
|
+
}
|
164
|
+
|
165
|
+
ret += HPDF_Dict_AddNumber (dict, "P", attr->permission);
|
166
|
+
|
167
|
+
if (ret != HPDF_OK)
|
168
|
+
return HPDF_Error_GetCode (dict->error);
|
169
|
+
|
170
|
+
return HPDF_OK;
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
void
|
175
|
+
HPDF_EncryptDict_OnFree (HPDF_Dict obj)
|
176
|
+
{
|
177
|
+
HPDF_Encrypt attr = (HPDF_Encrypt)obj->attr;
|
178
|
+
|
179
|
+
HPDF_PTRACE((" HPDF_EncryptDict_OnFree\n"));
|
180
|
+
|
181
|
+
if (attr)
|
182
|
+
HPDF_FreeMem (obj->mmgr, attr);
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
HPDF_STATUS
|
187
|
+
HPDF_EncryptDict_SetPassword (HPDF_EncryptDict dict,
|
188
|
+
const char *owner_passwd,
|
189
|
+
const char *user_passwd)
|
190
|
+
{
|
191
|
+
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
192
|
+
|
193
|
+
HPDF_PTRACE((" HPDF_EncryptDict_SetPassword\n"));
|
194
|
+
|
195
|
+
if (HPDF_StrLen(owner_passwd, 2) == 0)
|
196
|
+
return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0);
|
197
|
+
|
198
|
+
if (owner_passwd && user_passwd &&
|
199
|
+
HPDF_StrCmp (owner_passwd, user_passwd) == 0)
|
200
|
+
return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0);
|
201
|
+
|
202
|
+
HPDF_PadOrTrancatePasswd (owner_passwd, attr->owner_passwd);
|
203
|
+
HPDF_PadOrTrancatePasswd (user_passwd, attr->user_passwd);
|
204
|
+
|
205
|
+
return HPDF_OK;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
HPDF_BOOL
|
210
|
+
HPDF_EncryptDict_Validate (HPDF_EncryptDict dict)
|
211
|
+
{
|
212
|
+
HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict;
|
213
|
+
|
214
|
+
HPDF_PTRACE((" HPDF_EncryptDict_Validate\n"));
|
215
|
+
|
216
|
+
if (!dict || !dict->attr)
|
217
|
+
return HPDF_FALSE;
|
218
|
+
|
219
|
+
if (header->obj_class != (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT))
|
220
|
+
return HPDF_FALSE;
|
221
|
+
|
222
|
+
return HPDF_TRUE;
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
HPDF_Encrypt
|
227
|
+
HPDF_EncryptDict_GetAttr (HPDF_EncryptDict dict)
|
228
|
+
{
|
229
|
+
HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict;
|
230
|
+
|
231
|
+
HPDF_PTRACE((" HPDF_EncryptDict_GetAttr\n"));
|
232
|
+
|
233
|
+
if (dict && dict->attr &&
|
234
|
+
(header->obj_class == (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT)))
|
235
|
+
return (HPDF_Encrypt)dict->attr;
|
236
|
+
|
237
|
+
return NULL;
|
238
|
+
}
|
239
|
+
|
240
|
+
|
data/ext/hpdf_error.c
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.0 >> -- hpdf_error.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_error.h"
|
18
|
+
#include "hpdf_consts.h"
|
19
|
+
|
20
|
+
#ifndef HPDF_STDCALL
|
21
|
+
#ifdef HPDF_DLL_MAKE
|
22
|
+
#define HPDF_STDCALL __stdcall
|
23
|
+
#else
|
24
|
+
#ifdef HPDF_DLL
|
25
|
+
#define HPDF_STDCALL __stdcall
|
26
|
+
#else
|
27
|
+
#define HPDF_STDCALL
|
28
|
+
#endif
|
29
|
+
#endif
|
30
|
+
#endif
|
31
|
+
|
32
|
+
void
|
33
|
+
HPDF_CopyError (HPDF_Error dst,
|
34
|
+
HPDF_Error src);
|
35
|
+
|
36
|
+
|
37
|
+
void
|
38
|
+
HPDF_Error_Init (HPDF_Error error,
|
39
|
+
void *user_data)
|
40
|
+
{
|
41
|
+
HPDF_MemSet(error, 0, sizeof(HPDF_Error_Rec));
|
42
|
+
|
43
|
+
error->user_data = user_data;
|
44
|
+
}
|
45
|
+
|
46
|
+
HPDF_STATUS
|
47
|
+
HPDF_Error_GetCode (HPDF_Error error)
|
48
|
+
{
|
49
|
+
return error->error_no;
|
50
|
+
}
|
51
|
+
|
52
|
+
HPDF_STATUS
|
53
|
+
HPDF_Error_GetDetailCode (HPDF_Error error)
|
54
|
+
{
|
55
|
+
return error->detail_no;
|
56
|
+
}
|
57
|
+
|
58
|
+
void
|
59
|
+
HPDF_CopyError (HPDF_Error dst,
|
60
|
+
HPDF_Error src)
|
61
|
+
{
|
62
|
+
dst->error_no = src->error_no;
|
63
|
+
dst->detail_no = src->detail_no;
|
64
|
+
dst->error_fn = src->error_fn;
|
65
|
+
dst->user_data = src->user_data;
|
66
|
+
}
|
67
|
+
|
68
|
+
HPDF_STATUS
|
69
|
+
HPDF_SetError (HPDF_Error error,
|
70
|
+
HPDF_STATUS error_no,
|
71
|
+
HPDF_STATUS detail_no)
|
72
|
+
{
|
73
|
+
HPDF_PTRACE((" HPDF_SetError: error_no=0x%04X "
|
74
|
+
"detail_no=0x%04X\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no));
|
75
|
+
|
76
|
+
error->error_no = error_no;
|
77
|
+
error->detail_no = detail_no;
|
78
|
+
|
79
|
+
return error_no;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
HPDF_STATUS
|
84
|
+
HPDF_CheckError (HPDF_Error error)
|
85
|
+
{
|
86
|
+
HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n",
|
87
|
+
(HPDF_UINT)error->error_no, (HPDF_UINT)error->detail_no));
|
88
|
+
|
89
|
+
if (error->error_no != HPDF_OK && error->error_fn)
|
90
|
+
error->error_fn (error->error_no, error->detail_no, error->user_data);
|
91
|
+
|
92
|
+
return error->error_no;
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
HPDF_STATUS
|
97
|
+
HPDF_RaiseError (HPDF_Error error,
|
98
|
+
HPDF_STATUS error_no,
|
99
|
+
HPDF_STATUS detail_no)
|
100
|
+
{
|
101
|
+
HPDF_SetError (error, error_no, detail_no);
|
102
|
+
|
103
|
+
return HPDF_CheckError (error);
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
void
|
108
|
+
HPDF_Error_Reset (HPDF_Error error)
|
109
|
+
{
|
110
|
+
error->error_no = HPDF_NOERROR;
|
111
|
+
error->detail_no = HPDF_NOERROR;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
/*
|
2
|
+
* << Haru Free PDF Library 2.0.0 >> -- hpdf_ext_gstate.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_ext_gstate.h"
|
18
|
+
#include "hpdf.h"
|
19
|
+
|
20
|
+
const static char *HPDF_BM_NAMES[] = {
|
21
|
+
"Normal",
|
22
|
+
"Multiply",
|
23
|
+
"Screen",
|
24
|
+
"Overlay",
|
25
|
+
"Darken",
|
26
|
+
"Lighten",
|
27
|
+
"ColorDodge",
|
28
|
+
"ColorBurn",
|
29
|
+
"HardLight",
|
30
|
+
"SoftLight",
|
31
|
+
"Difference",
|
32
|
+
"Exclusion"
|
33
|
+
};
|
34
|
+
|
35
|
+
|
36
|
+
HPDF_BOOL
|
37
|
+
HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate)
|
38
|
+
{
|
39
|
+
if (!ext_gstate || (ext_gstate->header.obj_class !=
|
40
|
+
(HPDF_OSUBCLASS_EXT_GSTATE | HPDF_OCLASS_DICT) &&
|
41
|
+
ext_gstate->header.obj_class !=
|
42
|
+
(HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT)))
|
43
|
+
return HPDF_FALSE;
|
44
|
+
|
45
|
+
return HPDF_TRUE;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
HPDF_STATUS
|
50
|
+
ExtGState_Check (HPDF_ExtGState ext_gstate)
|
51
|
+
{
|
52
|
+
if (!HPDF_ExtGState_Validate (ext_gstate))
|
53
|
+
return HPDF_INVALID_OBJECT;
|
54
|
+
|
55
|
+
if (ext_gstate->header.obj_class ==
|
56
|
+
(HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT))
|
57
|
+
return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_READ_ONLY,
|
58
|
+
0);
|
59
|
+
|
60
|
+
return HPDF_OK;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
HPDF_Dict
|
65
|
+
HPDF_ExtGState_New (HPDF_MMgr mmgr,
|
66
|
+
HPDF_Xref xref)
|
67
|
+
{
|
68
|
+
HPDF_Dict obj = HPDF_Dict_New (mmgr);
|
69
|
+
|
70
|
+
HPDF_PTRACE ((" HPDF_ExtGState_New\n"));
|
71
|
+
|
72
|
+
if (!obj)
|
73
|
+
return NULL;
|
74
|
+
|
75
|
+
if (HPDF_Xref_Add (xref, obj) != HPDF_OK)
|
76
|
+
return NULL;
|
77
|
+
|
78
|
+
if (HPDF_Dict_AddName (obj, "Type", "ExtGState") != HPDF_OK)
|
79
|
+
return NULL;
|
80
|
+
|
81
|
+
obj->header.obj_class |= HPDF_OSUBCLASS_EXT_GSTATE;
|
82
|
+
|
83
|
+
return obj;
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
HPDF_EXPORT(HPDF_STATUS)
|
88
|
+
HPDF_ExtGState_SetAlphaStroke (HPDF_ExtGState ext_gstate,
|
89
|
+
HPDF_REAL value)
|
90
|
+
{
|
91
|
+
HPDF_STATUS ret = ExtGState_Check (ext_gstate);
|
92
|
+
|
93
|
+
if (ret != HPDF_OK)
|
94
|
+
return ret;
|
95
|
+
|
96
|
+
if (value < 0 || value > 1.0f)
|
97
|
+
return HPDF_RaiseError (ext_gstate->error,
|
98
|
+
HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
|
99
|
+
|
100
|
+
return HPDF_Dict_AddReal (ext_gstate, "CA", value);
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
HPDF_EXPORT(HPDF_STATUS)
|
105
|
+
HPDF_ExtGState_SetAlphaFill (HPDF_ExtGState ext_gstate,
|
106
|
+
HPDF_REAL value)
|
107
|
+
{
|
108
|
+
HPDF_STATUS ret = ExtGState_Check (ext_gstate);
|
109
|
+
|
110
|
+
if (ret != HPDF_OK)
|
111
|
+
return ret;
|
112
|
+
|
113
|
+
if (value < 0 || value > 1.0f)
|
114
|
+
return HPDF_RaiseError (ext_gstate->error,
|
115
|
+
HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
|
116
|
+
|
117
|
+
return HPDF_Dict_AddReal (ext_gstate, "ca", value);
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
HPDF_EXPORT(HPDF_STATUS)
|
122
|
+
HPDF_ExtGState_SetBlendMode (HPDF_ExtGState ext_gstate,
|
123
|
+
HPDF_BlendMode bmode)
|
124
|
+
{
|
125
|
+
HPDF_STATUS ret = ExtGState_Check (ext_gstate);
|
126
|
+
|
127
|
+
if (ret != HPDF_OK)
|
128
|
+
return ret;
|
129
|
+
|
130
|
+
if ((int)bmode < 0 || (int)bmode > (int)HPDF_BM_EOF)
|
131
|
+
return HPDF_RaiseError (ext_gstate->error,
|
132
|
+
HPDF_EXT_GSTATE_OUT_OF_RANGE, 0);
|
133
|
+
|
134
|
+
return HPDF_Dict_AddName (ext_gstate, "BM", HPDF_BM_NAMES[(int)bmode]);
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
HPDF_STATUS
|
139
|
+
HPDF_ExtGState_SetStrokeAdjustment (HPDF_ExtGState ext_gstate,
|
140
|
+
HPDF_BOOL value)
|
141
|
+
{
|
142
|
+
HPDF_STATUS ret = ExtGState_Check (ext_gstate);
|
143
|
+
|
144
|
+
if (ret != HPDF_OK)
|
145
|
+
return ret;
|
146
|
+
|
147
|
+
return HPDF_Dict_AddBoolean (ext_gstate, "SA", value);
|
148
|
+
}
|
149
|
+
*/
|
150
|
+
|