1 | /* |
2 | * << Haru Free PDF Library >> -- hpdf_fontdef_cns.c |
3 | * |
4 | * URL: http://libharu.org |
5 | * |
6 | * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> |
7 | * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org> |
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 | |
18 | #include "hpdf_conf.h" |
19 | #include "hpdf_utils.h" |
20 | #include "hpdf.h" |
21 | |
22 | /*----------------------------------------------------------------------------*/ |
23 | |
24 | static const HPDF_CID_Width SIMSUN_W_ARRAY[] = { |
25 | {668, 500}, |
26 | {669, 500}, |
27 | {670, 500}, |
28 | {671, 500}, |
29 | {672, 500}, |
30 | {673, 500}, |
31 | {674, 500}, |
32 | {675, 500}, |
33 | {676, 500}, |
34 | {677, 500}, |
35 | {678, 500}, |
36 | {679, 500}, |
37 | {680, 500}, |
38 | {681, 500}, |
39 | {682, 500}, |
40 | {683, 500}, |
41 | {684, 500}, |
42 | {685, 500}, |
43 | {686, 500}, |
44 | {687, 500}, |
45 | {688, 500}, |
46 | {689, 500}, |
47 | {690, 500}, |
48 | {691, 500}, |
49 | {692, 500}, |
50 | {693, 500}, |
51 | {694, 500}, |
52 | {696, 500}, |
53 | {697, 500}, |
54 | {698, 500}, |
55 | {699, 500}, |
56 | {814, 500}, |
57 | {815, 500}, |
58 | {816, 500}, |
59 | {817, 500}, |
60 | {818, 500}, |
61 | {819, 500}, |
62 | {820, 500}, |
63 | {821, 500}, |
64 | {822, 500}, |
65 | {823, 500}, |
66 | {824, 500}, |
67 | {825, 500}, |
68 | {826, 500}, |
69 | {827, 500}, |
70 | {828, 500}, |
71 | {829, 500}, |
72 | {830, 500}, |
73 | {831, 500}, |
74 | {832, 500}, |
75 | {833, 500}, |
76 | {834, 500}, |
77 | {835, 500}, |
78 | {836, 500}, |
79 | {837, 500}, |
80 | {838, 500}, |
81 | {839, 500}, |
82 | {840, 500}, |
83 | {841, 500}, |
84 | {842, 500}, |
85 | {843, 500}, |
86 | {844, 500}, |
87 | {845, 500}, |
88 | {846, 500}, |
89 | {847, 500}, |
90 | {848, 500}, |
91 | {849, 500}, |
92 | {850, 500}, |
93 | {851, 500}, |
94 | {852, 500}, |
95 | {853, 500}, |
96 | {854, 500}, |
97 | {855, 500}, |
98 | {856, 500}, |
99 | {857, 500}, |
100 | {858, 500}, |
101 | {859, 500}, |
102 | {860, 500}, |
103 | {861, 500}, |
104 | {862, 500}, |
105 | {863, 500}, |
106 | {864, 500}, |
107 | {865, 500}, |
108 | {866, 500}, |
109 | {867, 500}, |
110 | {868, 500}, |
111 | {869, 500}, |
112 | {870, 500}, |
113 | {871, 500}, |
114 | {872, 500}, |
115 | {873, 500}, |
116 | {874, 500}, |
117 | {875, 500}, |
118 | {876, 500}, |
119 | {877, 500}, |
120 | {878, 500}, |
121 | {879, 500}, |
122 | {880, 500}, |
123 | {881, 500}, |
124 | {882, 500}, |
125 | {883, 500}, |
126 | {884, 500}, |
127 | {885, 500}, |
128 | {886, 500}, |
129 | {887, 500}, |
130 | {888, 500}, |
131 | {889, 500}, |
132 | {890, 500}, |
133 | {891, 500}, |
134 | {892, 500}, |
135 | {893, 500}, |
136 | {894, 500}, |
137 | {895, 500}, |
138 | {896, 500}, |
139 | {897, 500}, |
140 | {898, 500}, |
141 | {899, 500}, |
142 | {900, 500}, |
143 | {901, 500}, |
144 | {902, 500}, |
145 | {903, 500}, |
146 | {904, 500}, |
147 | {905, 500}, |
148 | {906, 500}, |
149 | {907, 500}, |
150 | {7716, 500}, |
151 | {0xFFFF, 0} |
152 | }; |
153 | |
154 | |
155 | static const HPDF_CID_Width SIMHEI_W_ARRAY[] = { |
156 | {668, 500}, |
157 | {669, 500}, |
158 | {670, 500}, |
159 | {671, 500}, |
160 | {672, 500}, |
161 | {673, 500}, |
162 | {674, 500}, |
163 | {675, 500}, |
164 | {676, 500}, |
165 | {677, 500}, |
166 | {678, 500}, |
167 | {679, 500}, |
168 | {680, 500}, |
169 | {681, 500}, |
170 | {682, 500}, |
171 | {683, 500}, |
172 | {684, 500}, |
173 | {685, 500}, |
174 | {686, 500}, |
175 | {687, 500}, |
176 | {688, 500}, |
177 | {689, 500}, |
178 | {690, 500}, |
179 | {691, 500}, |
180 | {692, 500}, |
181 | {693, 500}, |
182 | {694, 500}, |
183 | {696, 500}, |
184 | {697, 500}, |
185 | {698, 500}, |
186 | {699, 500}, |
187 | {814, 500}, |
188 | {815, 500}, |
189 | {816, 500}, |
190 | {817, 500}, |
191 | {818, 500}, |
192 | {819, 500}, |
193 | {820, 500}, |
194 | {821, 500}, |
195 | {822, 500}, |
196 | {823, 500}, |
197 | {824, 500}, |
198 | {825, 500}, |
199 | {826, 500}, |
200 | {827, 500}, |
201 | {828, 500}, |
202 | {829, 500}, |
203 | {830, 500}, |
204 | {831, 500}, |
205 | {832, 500}, |
206 | {833, 500}, |
207 | {834, 500}, |
208 | {835, 500}, |
209 | {836, 500}, |
210 | {837, 500}, |
211 | {838, 500}, |
212 | {839, 500}, |
213 | {840, 500}, |
214 | {841, 500}, |
215 | {842, 500}, |
216 | {843, 500}, |
217 | {844, 500}, |
218 | {845, 500}, |
219 | {846, 500}, |
220 | {847, 500}, |
221 | {848, 500}, |
222 | {849, 500}, |
223 | {850, 500}, |
224 | {851, 500}, |
225 | {852, 500}, |
226 | {853, 500}, |
227 | {854, 500}, |
228 | {855, 500}, |
229 | {856, 500}, |
230 | {857, 500}, |
231 | {858, 500}, |
232 | {859, 500}, |
233 | {860, 500}, |
234 | {861, 500}, |
235 | {862, 500}, |
236 | {863, 500}, |
237 | {864, 500}, |
238 | {865, 500}, |
239 | {866, 500}, |
240 | {867, 500}, |
241 | {868, 500}, |
242 | {869, 500}, |
243 | {870, 500}, |
244 | {871, 500}, |
245 | {872, 500}, |
246 | {873, 500}, |
247 | {874, 500}, |
248 | {875, 500}, |
249 | {876, 500}, |
250 | {877, 500}, |
251 | {878, 500}, |
252 | {879, 500}, |
253 | {880, 500}, |
254 | {881, 500}, |
255 | {882, 500}, |
256 | {883, 500}, |
257 | {884, 500}, |
258 | {885, 500}, |
259 | {886, 500}, |
260 | {887, 500}, |
261 | {888, 500}, |
262 | {889, 500}, |
263 | {890, 500}, |
264 | {891, 500}, |
265 | {892, 500}, |
266 | {893, 500}, |
267 | {894, 500}, |
268 | {895, 500}, |
269 | {896, 500}, |
270 | {897, 500}, |
271 | {898, 500}, |
272 | {899, 500}, |
273 | {900, 500}, |
274 | {901, 500}, |
275 | {902, 500}, |
276 | {903, 500}, |
277 | {904, 500}, |
278 | {905, 500}, |
279 | {906, 500}, |
280 | {907, 500}, |
281 | {7716, 500}, |
282 | {0xFFFF, 0} |
283 | }; |
284 | |
285 | |
286 | /*---------------------------------------------------------------------------*/ |
287 | /*----- SimHei Font ---------------------------------------------------------*/ |
288 | |
289 | |
290 | static HPDF_STATUS |
291 | SimSun_Init (HPDF_FontDef fontdef) |
292 | { |
293 | HPDF_STATUS ret; |
294 | |
295 | HPDF_PTRACE ((" HPDF_FontDef_SimSun_Init\n" )); |
296 | |
297 | fontdef->ascent = 859; |
298 | fontdef->descent = -140; |
299 | fontdef->cap_height = 683; |
300 | fontdef->font_bbox = HPDF_ToBox(0, -140, 996, 855); |
301 | fontdef->flags = HPDF_FONT_SYMBOLIC + HPDF_FONT_FIXED_WIDTH + |
302 | HPDF_FONT_SERIF; |
303 | fontdef->italic_angle = 0; |
304 | fontdef->stemv = 78; |
305 | if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, SIMSUN_W_ARRAY)) != |
306 | HPDF_OK) { |
307 | return ret; |
308 | } |
309 | |
310 | fontdef->type = HPDF_FONTDEF_TYPE_CID; |
311 | fontdef->valid = HPDF_TRUE; |
312 | |
313 | return HPDF_OK; |
314 | } |
315 | |
316 | |
317 | static HPDF_STATUS |
318 | SimSun_Bold_Init (HPDF_FontDef fontdef) |
319 | { |
320 | HPDF_STATUS ret = SimSun_Init (fontdef); |
321 | |
322 | if (ret != HPDF_OK) |
323 | return ret; |
324 | |
325 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_FALSE); |
326 | } |
327 | |
328 | |
329 | static HPDF_STATUS |
330 | SimSun_Italic_Init (HPDF_FontDef fontdef) |
331 | { |
332 | HPDF_STATUS ret = SimSun_Init (fontdef); |
333 | |
334 | if (ret != HPDF_OK) |
335 | return ret; |
336 | |
337 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_FALSE, HPDF_TRUE); |
338 | } |
339 | |
340 | static HPDF_STATUS |
341 | SimSun_BoldItalic_Init (HPDF_FontDef fontdef) |
342 | { |
343 | HPDF_STATUS ret = SimSun_Init (fontdef); |
344 | |
345 | if (ret != HPDF_OK) |
346 | return ret; |
347 | |
348 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_TRUE); |
349 | } |
350 | |
351 | |
352 | static HPDF_STATUS |
353 | SimHei_Init (HPDF_FontDef fontdef) |
354 | { |
355 | HPDF_STATUS ret; |
356 | |
357 | HPDF_PTRACE ((" HPDF_FontDef_SimHei_Init\n" )); |
358 | |
359 | fontdef->ascent = 859; |
360 | fontdef->descent = -140; |
361 | fontdef->cap_height = 769; |
362 | fontdef->font_bbox = HPDF_ToBox(-0, -140, 996, 855); |
363 | fontdef->flags = HPDF_FONT_SYMBOLIC + HPDF_FONT_FIXED_WIDTH; |
364 | fontdef->italic_angle = 0; |
365 | fontdef->stemv = 78; |
366 | if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, SIMHEI_W_ARRAY)) != |
367 | HPDF_OK) { |
368 | return ret; |
369 | } |
370 | |
371 | fontdef->type = HPDF_FONTDEF_TYPE_CID; |
372 | fontdef->valid = HPDF_TRUE; |
373 | |
374 | return HPDF_OK; |
375 | } |
376 | |
377 | |
378 | static HPDF_STATUS |
379 | SimHei_Bold_Init (HPDF_FontDef fontdef) |
380 | { |
381 | HPDF_STATUS ret = SimHei_Init (fontdef); |
382 | |
383 | if (ret != HPDF_OK) |
384 | return ret; |
385 | |
386 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_FALSE); |
387 | } |
388 | |
389 | |
390 | static HPDF_STATUS |
391 | SimHei_Italic_Init (HPDF_FontDef fontdef) |
392 | { |
393 | HPDF_STATUS ret = SimHei_Init (fontdef); |
394 | |
395 | if (ret != HPDF_OK) |
396 | return ret; |
397 | |
398 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_FALSE, HPDF_TRUE); |
399 | } |
400 | |
401 | static HPDF_STATUS |
402 | SimHei_BoldItalic_Init (HPDF_FontDef fontdef) |
403 | { |
404 | HPDF_STATUS ret = SimHei_Init (fontdef); |
405 | |
406 | if (ret != HPDF_OK) |
407 | return ret; |
408 | |
409 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_TRUE); |
410 | } |
411 | |
412 | |
413 | HPDF_EXPORT(HPDF_STATUS) |
414 | HPDF_UseCNSFonts (HPDF_Doc pdf) |
415 | { |
416 | HPDF_FontDef fontdef; |
417 | HPDF_STATUS ret; |
418 | |
419 | if (!HPDF_HasDoc (pdf)) |
420 | return HPDF_INVALID_DOCUMENT; |
421 | |
422 | /* SimSun */ |
423 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimSun" , |
424 | SimSun_Init); |
425 | |
426 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
427 | return ret; |
428 | |
429 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimSun,Bold" , |
430 | SimSun_Bold_Init); |
431 | |
432 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
433 | return ret; |
434 | |
435 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimSun,Italic" , |
436 | SimSun_Italic_Init); |
437 | |
438 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
439 | return ret; |
440 | |
441 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimSun,BoldItalic" , |
442 | SimSun_BoldItalic_Init); |
443 | |
444 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
445 | return ret; |
446 | |
447 | /* SimHei */ |
448 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimHei" , |
449 | SimHei_Init); |
450 | |
451 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
452 | return ret; |
453 | |
454 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimHei,Bold" , |
455 | SimHei_Bold_Init); |
456 | |
457 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
458 | return ret; |
459 | |
460 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimHei,Italic" , |
461 | SimHei_Italic_Init); |
462 | |
463 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
464 | return ret; |
465 | |
466 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "SimHei,BoldItalic" , |
467 | SimHei_BoldItalic_Init); |
468 | |
469 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) |
470 | return ret; |
471 | |
472 | return HPDF_OK; |
473 | } |
474 | |
475 | |