1
/* $Header: /home/cvsroot/dvipdfmx/src/cidtype2.c,v 1.33 2005/07/17 09:53:38 hirata Exp $
3
This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
5
Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata,
6
the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
* TrueType glyf table is sorted by CID and no CIDToGIDMap is used here.
25
* GhostScript can't handle CIDToGIDMap correctly.
39
/* pseudo unique tag */
42
#ifndef PDF_NAME_LEN_MAX
43
# define PDF_NAME_LEN_MAX 255
62
static int verbose = 0;
63
static int opt_flags = 0;
66
CIDFont_type2_set_verbose (void)
72
CIDFont_type2_set_flags (long flags)
78
* PDF viewer applications use following tables (CIDFontType 2)
80
* head, hhea, loca, maxp, glyf, hmtx, fpgm, cvt_, prep
82
* - from PDF Ref. v.1.3, 2nd ed.
84
* The fpgm, cvt_, and prep tables appears only when TrueType instructions
85
* requires them. Those tables must be preserved if they exist.
86
* We use must_exist flag to indicate `preserve it if present'
87
* and to make sure not to cause an error when it does not exist.
89
* post and name table must exist in ordinary TrueType font file,
90
* but when a TrueType font is converted to CIDFontType 2 font, those tables
91
* are no longer required.
93
* The OS/2 table (required for TrueType font for Windows and OS/2) contains
94
* liscencing information, but PDF viewers seems not using them.
96
* The 'name' table added. See comments in ttf.c.
103
} required_table[] = {
104
{"OS/2", 1}, {"head", 1}, {"hhea", 1}, {"loca", 1}, {"maxp", 1},
105
{"name", 1}, {"glyf", 1}, {"hmtx", 1}, {"fpgm", 0}, {"cvt ", 0},
106
{"prep", 0}, {NULL, 0}
110
validate_name (char *fontname, int len)
114
static const char *badstrlist[] = {
122
for (count = 0, i = 0; i < len; i++) {
123
if (fontname[i] == 0) {
124
memmove(fontname + i, fontname + i + 1, len - i);
130
WARN("Removed %d null character(s) from fontname --> %s",
133
fontname[len] = '\0';
135
/* For some fonts that have bad PS name. ad hoc. remove me. */
136
for (i = 0; badstrlist[i] != NULL; i++) {
137
p = strstr(fontname, badstrlist[i]);
138
if (p && p > fontname) {
139
WARN("Removed string \"%s\" from fontname \"%s\".",
140
badstrlist[i], fontname);
142
len = (int) (p - fontname);
148
ERROR("No valid character found in fontname string.");
153
* We will follow the convension for finding ToUnicode CMap described in PDF
154
* Reference 4th ed., page 432. The name of "ToCode" (not limited to Unicode
155
* here) CMap is obtained by concatenating the registry, ordering, and the
158
* UCSms-UCS4, UCSms-UCS2, UCS4 added...
161
#define WIN_UCS_INDEX_MAX 1
162
#define KNOWN_ENCODINGS_MAX 8
165
unsigned short platform;
166
unsigned short encoding;
167
const char *pdfnames[5];
168
} known_encodings[] = {
169
{TT_WIN, TT_WIN_UCS4, {"UCSms-UCS4", "UCSms-UCS2", "UCS4", "UCS2", NULL}},
170
{TT_WIN, TT_WIN_UNICODE, {"UCSms-UCS4", "UCSms-UCS2", "UCS4", "UCS2", NULL}},
171
{TT_WIN, TT_WIN_SJIS, {"90ms-RKSJ", NULL}},
172
{TT_WIN, TT_WIN_RPC, {"GBK-EUC", NULL}},
173
{TT_WIN, TT_WIN_BIG5, {"ETen-B5", NULL}},
174
{TT_WIN, TT_WIN_WANSUNG, {"KSCms-UHC", NULL}},
175
{TT_MAC, TT_MAC_JAPANESE, {"90pv-RKSJ", NULL}},
176
{TT_MAC, TT_MAC_TRADITIONAL_CHINESE, {"B5pc", NULL}},
177
{TT_MAC, TT_MAC_SIMPLIFIED_CHINESE, {"GBpc-EUC", NULL}},
178
{TT_MAC, TT_MAC_KOREAN, {"KSCpc-EUC", NULL}},
183
find_tocode_cmap (const char *reg, const char *ord, int select)
190
select < 0 || select > KNOWN_ENCODINGS_MAX)
191
ERROR("Character set unknown.");
193
if (!strcmp(ord, "UCS") &&
194
select <= WIN_UCS_INDEX_MAX)
197
for (i = 0; cmap_id < 0 && i < 5; i++) {
198
append = (char *) known_encodings[select].pdfnames[i];
201
cmap_name = NEW(strlen(reg) + strlen(ord) + strlen(append) + 3, char);
202
sprintf(cmap_name, "%s-%s-%s", reg, ord, append);
203
cmap_id = CMap_cache_find(cmap_name);
207
WARN("Could not find CID-to-Code mapping for \"%s-%s\".", reg, ord);
208
WARN("I tried to load (one of) the following file(s):");
209
for (i = 0; i < 5; i++) {
210
append = (char *) known_encodings[select].pdfnames[i];
213
MESG(" %s-%s-%s", reg, ord, append);
215
WARN("Please check if this file exists.");
216
ERROR("Cannot continue...");
219
return CMap_cache_get(cmap_id);
224
* CIDFont glyph metrics:
225
* Mostly same as add_CID[HV]Metrics in cidtype0.c.
227
#define PDFUNIT(v) ((double) (ROUND(1000.0*(v)/(g->emsize), 1)))
230
add_TTCIDHMetrics (pdf_obj *fontdict, struct tt_glyphs *g,
231
char *used_chars, unsigned char *cidtogidmap, unsigned short last_cid)
233
long cid, start = 0, prev = 0;
234
pdf_obj *w_array, *an_array = NULL;
238
w_array = pdf_new_array();
239
if (g->dw != 0 && g->dw <= g->emsize) {
242
dw = PDFUNIT(g->gd[0].advw);
244
for (cid = 0; cid <= last_cid; cid++) {
248
if (!is_used_char2(used_chars, cid))
250
gid = (cidtogidmap) ? ((cidtogidmap[2*cid] << 8)|cidtogidmap[2*cid+1]) : cid;
251
idx = tt_get_index(g, gid);
252
if (cid != 0 && idx == 0)
254
width = PDFUNIT((g->gd)[idx].advw);
257
pdf_add_array(w_array, pdf_new_number(start));
258
pdf_add_array(w_array, an_array);
263
if (cid != prev + 1) {
265
pdf_add_array(w_array, pdf_new_number(start));
266
pdf_add_array(w_array, an_array);
271
if (an_array == NULL) {
272
an_array = pdf_new_array();
275
pdf_add_array(an_array, pdf_new_number(width));
281
pdf_add_array(w_array, pdf_new_number(start));
282
pdf_add_array(w_array, an_array);
286
pdf_add_dict(fontdict,
290
pdf_add_dict(fontdict,
292
pdf_ref_obj(w_array));
294
pdf_release_obj(w_array);
300
add_TTCIDVMetrics (pdf_obj *fontdict, struct tt_glyphs *g,
301
char *used_chars, unsigned char *cidtogidmap, unsigned short last_cid)
303
pdf_obj *w2_array, *an_array = NULL;
304
long cid, prev, start;
305
double defaultVertOriginY, defaultAdvanceHeight;
308
defaultVertOriginY = PDFUNIT(g->default_advh - g->default_tsb);
309
defaultAdvanceHeight = PDFUNIT(g->default_advh);
311
w2_array = pdf_new_array();
313
for (cid = 0; cid <= last_cid; cid++) {
315
double vertOriginX, vertOriginY, advanceHeight;
317
if (!is_used_char2(used_chars, cid))
319
gid = (cidtogidmap) ? ((cidtogidmap[2*cid] << 8)|cidtogidmap[2*cid+1]) : cid;
320
idx = tt_get_index(g, cid);
321
if (cid != 0 && idx == 0)
323
advanceHeight = PDFUNIT(g->gd[idx].advh);
324
vertOriginX = PDFUNIT(0.5*(g->gd[idx].advw));
325
vertOriginY = PDFUNIT(g->gd[idx].tsb + g->gd[idx].ury);
328
* c [w1_1y v_1x v_1y w1_2y v_2x v_2y ...]
329
* Not working... Why?
331
* Wrong rendering, interpretation of position vector is wrong.
332
* Xpdf and gs: ignores W2?
334
if (vertOriginY == defaultVertOriginY &&
335
advanceHeight == defaultAdvanceHeight) {
337
pdf_add_array(w2_array, pdf_new_number(start));
338
pdf_add_array(w2_array, an_array);
343
if (cid != prev + 1 && an_array) {
344
pdf_add_array(w2_array, pdf_new_number(start));
345
pdf_add_array(w2_array, an_array);
349
if (an_array == NULL) {
350
an_array = pdf_new_array();
353
pdf_add_array(an_array, pdf_new_number(-advanceHeight));
354
pdf_add_array(an_array, pdf_new_number(vertOriginX));
355
pdf_add_array(an_array, pdf_new_number(vertOriginY));
360
* c_first c_last w1_y v_x v_y
361
* This form may hit Acrobat's implementation limit of array element size,
362
* 8192. AFPL GhostScript 8.11 stops with rangecheck error with this.
365
if (vertOriginY != defaultVertOriginY ||
366
advanceHeight != defaultAdvanceHeight) {
367
pdf_add_array(w2_array, pdf_new_number(cid));
368
pdf_add_array(w2_array, pdf_new_number(cid));
369
pdf_add_array(w2_array, pdf_new_number(-advanceHeight));
370
pdf_add_array(w2_array, pdf_new_number(vertOriginX));
371
pdf_add_array(w2_array, pdf_new_number(vertOriginY));
379
pdf_add_array(w2_array, pdf_new_number(start));
380
pdf_add_array(w2_array, an_array);
385
if (defaultVertOriginY != 880 || defaultAdvanceHeight != 1000) {
386
an_array = pdf_new_array();
387
pdf_add_array(an_array, pdf_new_number(defaultVertOriginY));
388
pdf_add_array(an_array, pdf_new_number(-defaultAdvanceHeight));
389
pdf_add_dict(fontdict, pdf_new_name ("DW2"), an_array);
392
pdf_add_dict(fontdict,
394
pdf_ref_obj(w2_array));
396
pdf_release_obj(w2_array);
402
* The following routine fixes few problems caused by vendor specific
406
#define FIX_CJK_UNIOCDE_SYMBOLS 1
408
static unsigned short
409
fix_CJK_symbols (unsigned short code)
411
unsigned short alt_code;
416
} CJK_Uni_symbols[] = {
418
* Microsoft/Apple Unicode mapping difference:
419
* They are taken from SJIS-Unicode mapping difference but nearly
420
* same thing might be applied to Chinese (e.g., Big5) too.
422
{0x2014, 0x2015}, /* EM DASH <-> HORIZONTAL BAR */
423
{0x2016, 0x2225}, /* DOUBLE VERTICAL LINE <-> PARALLEL TO */
424
{0x203E, 0xFFE3}, /* OVERLINE <-> FULLWIDTH MACRON */
425
{0x2026, 0x22EF}, /* HORIZONTAL ELLIPSIS <-> MIDLINE HORIZONTAL ELLIPSIS */
426
{0x2212, 0xFF0D}, /* MINUS SIGN <-> FULLWIDTH HYPHEN-MINUS */
427
{0x301C, 0xFF5E}, /* WAVE DASH <-> FULLWIDTH TILDE */
428
{0xFFE0, 0x00A2}, /* FULLWIDTH CENT SIGN <-> CENT SIGN */
429
{0xFFE1, 0x00A3}, /* FULLWIDTH POUND SIGN <-> POUND SIGN */
430
{0xFFE2, 0x00AC}, /* FULLWIDTH NOT SIGN <-> NOT SIGN */
431
{0xFFFF, 0xFFFF}, /* EOD */
433
#define NUM_CJK_SYMBOLS (sizeof(CJK_Uni_symbols)/sizeof(CJK_Uni_symbols[0]))
437
for (i = 0; i < NUM_CJK_SYMBOLS; i++) {
438
if (CJK_Uni_symbols[i].alt1 == code) {
439
alt_code = CJK_Uni_symbols[i].alt2;
441
} else if (CJK_Uni_symbols[i].alt2 == code) {
442
alt_code = CJK_Uni_symbols[i].alt1;
451
cid_to_code (CMap *cmap, CID cid)
453
unsigned char inbuf[2], outbuf[32];
454
long inbytesleft = 2, outbytesleft = 32;
455
unsigned char *p, *q;
460
inbuf[0] = (cid >> 8) & 0xff;
461
inbuf[1] = cid & 0xff;
462
p = inbuf; q = outbuf;
464
CMap_decode_char(cmap, (const unsigned char **) &p, &inbytesleft, &q, &outbytesleft);
466
if (inbytesleft != 0)
468
else if (outbytesleft == 31)
469
return (long) outbuf[0];
470
else if (outbytesleft == 30)
471
return (long) (outbuf[0] << 8|outbuf[1]);
472
else if (outbytesleft == 28)
473
return (long) (outbuf[0] << 24|outbuf[1] << 16|outbuf[2] << 8|outbuf[3]);
478
/* #define NO_GHOSTSCRIPT_BUG 1 */
481
CIDFont_type2_dofont (CIDFont *font)
485
char *h_used_chars, *v_used_chars, *used_chars;
486
struct tt_glyphs *glyphs;
488
tt_cmap *ttcmap = NULL;
489
unsigned long offset = 0;
491
unsigned char *cidtogidmap;
493
int i, glyph_ordering = 0, unicode_cmap = 0;
499
pdf_add_dict(font->fontdict,
500
pdf_new_name("FontDescriptor"), pdf_ref_obj(font->descriptor));
502
if (CIDFont_is_BaseFont(font))
506
* CIDSystemInfo comes here since Supplement can be increased.
511
tmp = pdf_new_dict ();
513
pdf_new_name("Registry"),
514
pdf_new_string(font->csi->registry, strlen(font->csi->registry)));
516
pdf_new_name("Ordering"),
517
pdf_new_string(font->csi->ordering, strlen(font->csi->ordering)));
519
pdf_new_name("Supplement"),
520
pdf_new_number(font->csi->supplement));
521
pdf_add_dict(font->fontdict, pdf_new_name("CIDSystemInfo"), tmp);
524
/* Quick exit for non-embedded & fixed-pitch font. */
525
if (!CIDFont_get_embedding(font) &&
526
(opt_flags & CIDFONT_FORCE_FIXEDPITCH)) {
527
pdf_add_dict(font->fontdict,
528
pdf_new_name("DW"), pdf_new_number(1000.0));
532
fp = DPXFOPEN(font->ident, DPX_RES_TYPE_TTFONT);
534
ERROR("Could not open TTF file: %s", font->ident);
536
sfont = sfnt_open(fp);
538
ERROR("Could not open TTF file: %s", font->ident);
541
switch (sfont->type) {
543
offset = ttc_read_offset(sfont, font->options->index);
545
ERROR("Invalid TTC index in %s.", font->ident);
547
case SFNT_TYPE_TRUETYPE:
548
if (font->options->index > 0)
549
ERROR("Found TrueType font file while expecting TTC file (%s).", font->ident);
553
ERROR("Not a TrueType/TTC font (%s)?", font->ident);
557
if (sfnt_read_table_directory(sfont, offset) < 0)
558
ERROR("Could not read TrueType table directory (%s).", font->ident);
561
* Adobe-Identity means font's internal glyph ordering here.
563
if (!strcmp(font->csi->registry, "Adobe") &&
564
!strcmp(font->csi->ordering, "Identity")) {
571
* Select TrueType cmap table, find ToCode CMap for each TrueType encodings.
573
if (glyph_ordering) {
578
* This part contains a bug. It may choose SJIS encoding TrueType cmap
579
* table for Adobe-GB1.
581
for (i = 0; i <= KNOWN_ENCODINGS_MAX; i++) {
582
ttcmap = tt_cmap_read(sfont,
583
known_encodings[i].platform,
584
known_encodings[i].encoding);
589
WARN("No usable TrueType cmap table found for font \"%s\".", font->ident);
590
WARN("CID character collection for this font is set to \"%s-%s\"",
591
font->csi->registry, font->csi->ordering);
592
ERROR("Cannot continue without this...");
593
} else if (i <= WIN_UCS_INDEX_MAX) {
600
* NULL is returned if CMap is Identity CMap.
602
cmap = find_tocode_cmap(font->csi->registry,
603
font->csi->ordering, i);
606
glyphs = tt_build_init();
609
num_glyphs = 1; /* .notdef */
610
used_chars = h_used_chars = v_used_chars = NULL;
615
if ((parent_id = CIDFont_get_parent_id(font, 0)) >= 0) {
616
parent = Type0Font_cache_get(parent_id);
617
h_used_chars = Type0Font_get_usedchars(parent);
619
if ((parent_id = CIDFont_get_parent_id(font, 1)) >= 0) {
620
parent = Type0Font_cache_get(parent_id);
621
v_used_chars = Type0Font_get_usedchars(parent);
623
if (!h_used_chars && !v_used_chars)
624
ERROR("Unexpected error.");
627
* Quick check of max CID.
630
for (i = 8191; i >= 0; i--) {
631
if (h_used_chars && h_used_chars[i] != 0) {
632
last_cid = i * 8 + 7;
636
if (v_used_chars && v_used_chars[i] != 0) {
637
last_cid = i * 8 + 7;
643
for (i = 0; i < 8; i++) {
649
if (last_cid >= 0xFFFFu) {
650
ERROR("CID count > 65535");
654
#ifndef NO_GHOSTSCRIPT_BUG
657
cidtogidmap = NEW((last_cid + 1) * 2, unsigned char);
658
memset(cidtogidmap, 0, (last_cid + 1) * 2);
659
#endif /* !NO_GHOSTSCRIPT_BUG */
663
* Horizontal and vertical used_chars are merged.
670
used_chars = h_used_chars;
671
for (cid = 1; cid <= last_cid; cid++) {
675
if (!is_used_char2(h_used_chars, cid))
678
if (glyph_ordering) {
682
code = cid_to_code(cmap, cid);
683
gid = tt_cmap_lookup(ttcmap, code);
684
#ifdef FIX_CJK_UNIOCDE_SYMBOLS
685
if (gid == 0 && unicode_cmap) {
688
alt_code = fix_CJK_symbols(code);
689
if (alt_code != code) {
690
gid = tt_cmap_lookup(ttcmap, alt_code);
692
WARN("Unicode char U+%04x replaced with U+%04x.",
697
#endif /* FIX_CJK_UNIOCDE_SYMBOLS */
701
WARN("Glyph missing in font. (CID=%u, code=0x%04x)", cid, code);
704
/* TODO: duplicated glyph */
705
#ifndef NO_GHOSTSCRIPT_BUG
706
gid = tt_add_glyph(glyphs, gid, cid);
708
gid = tt_add_glyph(glyphs, gid, num_glyphs);
709
cidtogidmap[2*cid ] = gid >> 8;
710
cidtogidmap[2*cid+1] = gid & 0xff;
711
#endif /* !NO_GHOSTSCRIPT_BUG */
721
otl_gsub *gsub_list = NULL;
724
* Require `vrt2' or `vert'.
726
if (glyph_ordering) {
729
gsub_list = otl_gsub_new();
730
if (otl_gsub_add_feat(gsub_list,
731
"*", "*", "vrt2", sfont) < 0) {
732
if (otl_gsub_add_feat(gsub_list,
733
"*", "*", "vert", sfont) < 0) {
734
WARN("GSUB feature vrt2/vert not found.");
735
otl_gsub_release(gsub_list);
738
otl_gsub_select(gsub_list, "*", "*", "vert");
741
otl_gsub_select(gsub_list, "*", "*", "vrt2");
745
for (cid = 1; cid <= last_cid; cid++) {
749
if (!is_used_char2(v_used_chars, cid))
752
/* There may be conflict of horizontal and vertical glyphs
753
* when font is used with /UCS. However, we simply ignore
756
if (h_used_chars && is_used_char2(h_used_chars, cid)) {
760
if (glyph_ordering) {
764
code = cid_to_code(cmap, cid);
765
gid = tt_cmap_lookup(ttcmap, code);
766
#ifdef FIX_CJK_UNIOCDE_SYMBOLS
767
if (gid == 0 && unicode_cmap) {
770
alt_code = fix_CJK_symbols(code);
771
if (alt_code != code) {
772
gid = tt_cmap_lookup(ttcmap, alt_code);
774
WARN("Unicode char U+%04x replaced with U+%04x.",
779
#endif /* FIX_CJK_UNIOCDE_SYMBOLS */
782
WARN("Glyph missing in font. (CID=%u, code=0x%04x)", cid, code);
783
} else if (gsub_list) {
784
otl_gsub_apply(gsub_list, &gid);
787
#ifndef NO_GHOSTSCRIPT_BUG
788
gid = tt_add_glyph(glyphs, gid, cid);
790
gid = tt_add_glyph(glyphs, gid, num_glyphs);
791
cidtogidmap[2*cid ] = gid >> 8;
792
cidtogidmap[2*cid+1] = gid & 0xff;
793
#endif /* !NO_GHOSTSCRIPT_BUG */
795
if (used_chars) /* merge vertical used_chars to horizontal */
796
add_to_used_chars2(used_chars, cid);
802
otl_gsub_release(gsub_list);
804
if (!used_chars) /* We have no horizontal. */
805
used_chars = v_used_chars;
809
ERROR("Unexpected error.");
811
tt_cmap_release(ttcmap);
813
if (CIDFont_get_embedding(font)) {
814
if (tt_build_tables(sfont, glyphs) < 0)
815
ERROR("Could not created FontFile stream.");
817
MESG("[%u glyphs (Max CID: %u)]", glyphs->num_glyphs, last_cid);
819
if (tt_get_metrics(sfont, glyphs) < 0)
820
ERROR("Reading glyph metrics failed...");
826
if (opt_flags & CIDFONT_FORCE_FIXEDPITCH) {
827
pdf_add_dict(font->fontdict,
828
pdf_new_name("DW"), pdf_new_number(1000.0));
830
add_TTCIDHMetrics(font->fontdict, glyphs, used_chars, cidtogidmap, last_cid);
832
add_TTCIDVMetrics(font->fontdict, glyphs, used_chars, cidtogidmap, last_cid);
835
tt_build_finish(glyphs);
837
/* Finish here if not embedded. */
838
if (!CIDFont_get_embedding(font)) {
840
RELEASE(cidtogidmap);
847
/* Create font file */
848
for (i = 0; required_table[i].name; i++) {
849
if (sfnt_require_table(sfont,
850
required_table[i].name,
851
required_table[i].must_exist) < 0) {
852
ERROR("Some required TrueType table does not exist.");
859
fontfile = sfnt_create_FontFile_stream(sfont);
865
ERROR("Could not created FontFile stream for \"%s\".", font->ident);
868
MESG("[%ld bytes]", pdf_stream_length(fontfile));
871
pdf_add_dict(font->descriptor,
872
pdf_new_name("FontFile2"),
873
pdf_ref_obj (fontfile));
874
pdf_release_obj(fontfile);
882
cidset = pdf_new_stream(STREAM_COMPRESS);
883
pdf_add_stream(cidset, used_chars, last_cid/8 + 1);
884
pdf_add_dict(font->descriptor,
885
pdf_new_name("CIDSet"),
886
pdf_ref_obj(cidset));
887
pdf_release_obj(cidset);
896
c2gmstream = pdf_new_stream(STREAM_COMPRESS);
897
pdf_add_stream(c2gmstream, cidtogidmap, (last_cid + 1) * 2);
898
pdf_add_dict(font->fontdict,
899
pdf_new_name("CIDToGIDMap"),
900
pdf_ref_obj (c2gmstream));
901
pdf_release_obj(c2gmstream);
902
RELEASE(cidtogidmap);
909
CIDFont_type2_open (CIDFont *font, const char *name,
910
CIDSysInfo *cmap_csi, cid_opt *opt)
914
unsigned long offset = 0;
919
fp = DPXFOPEN(name, DPX_RES_TYPE_TTFONT);
923
sfont = sfnt_open(fp);
929
switch (sfont->type) {
931
offset = ttc_read_offset(sfont, opt->index);
933
case SFNT_TYPE_TRUETYPE:
934
if (opt->index > 0) {
935
ERROR("Invalid TTC index (not TTC font): %s", name);
947
if (sfnt_read_table_directory(sfont, offset) < 0) {
948
ERROR("Reading TrueType table directory failed.");
955
/* MAC-ROMAN-EN-POSTSCRIPT or WIN-UNICODE-EN(US)-POSTSCRIPT */
956
shortname = NEW(PDF_NAME_LEN_MAX, char);
957
namelen = tt_get_ps_fontname(sfont, shortname, PDF_NAME_LEN_MAX);
959
memset(shortname, 0, PDF_NAME_LEN_MAX);
960
strncpy(shortname, name, PDF_NAME_LEN_MAX);
961
namelen = strlen(shortname);
963
validate_name(shortname, namelen); /* for SJIS, UTF-16, ... string */
965
* Strlen works, after validate_named string.
966
* Mangled name requires more 7 bytes.
967
* Style requires more 11 bytes.
969
fontname = NEW(strlen(shortname)+19, char);
970
strcpy(fontname, shortname);
974
if (opt->embed && opt->style != FONT_STYLE_NONE) {
975
WARN("Embedding disabled due to style option for %s.", name);
978
switch (opt->style) {
979
case FONT_STYLE_BOLD:
980
strcat(fontname, ",Bold");
982
case FONT_STYLE_ITALIC:
983
strcat(fontname, ",Italic");
985
case FONT_STYLE_BOLDITALIC:
986
strcat(fontname, ",BoldItalic");
990
* CIDSystemInfo is determined from CMap or from map record option.
992
font->fontname = fontname;
993
font->subtype = CIDFONT_TYPE2;
994
font->csi = NEW(1, CIDSysInfo);
997
if (strcmp(opt->csi->registry, cmap_csi->registry) ||
998
strcmp(opt->csi->ordering, cmap_csi->ordering)) {
999
WARN("CID character collection mismatched:\n");
1000
MESG("\tFont: %s-%s-%d\n",
1001
opt->csi->registry, opt->csi->ordering, opt->csi->supplement);
1002
MESG("\tCMap: %s-%s-%d\n",
1003
cmap_csi->registry, cmap_csi->ordering, cmap_csi->supplement);
1004
ERROR("Incompatible CMap specified for this font.");
1006
if (opt->csi->supplement < cmap_csi->supplement) {
1007
WARN("Supplmement value in CIDSystemInfo increased.");
1008
WARN("Some characters may not shown.");
1009
opt->csi->supplement = cmap_csi->supplement;
1012
font->csi->registry = NEW(strlen(opt->csi->registry)+1, char);
1013
strcpy(font->csi->registry, opt->csi->registry);
1014
font->csi->ordering = NEW(strlen(opt->csi->ordering)+1, char);
1015
strcpy(font->csi->ordering, opt->csi->ordering);
1016
font->csi->supplement = opt->csi->supplement;
1017
} else if (cmap_csi) {
1018
font->csi->registry = NEW(strlen(cmap_csi->registry)+1, char);
1019
strcpy(font->csi->registry, cmap_csi->registry);
1020
font->csi->ordering = NEW(strlen(cmap_csi->ordering)+1, char);
1021
strcpy(font->csi->ordering, cmap_csi->ordering);
1022
font->csi->supplement = cmap_csi->supplement;
1023
} else { /* This means font's internal glyph ordering. */
1024
font->csi->registry = NEW(strlen("Adobe")+1, char);
1025
strcpy(font->csi->registry, "Adobe");
1026
font->csi->ordering = NEW(strlen("Identity")+1, char);
1027
strcpy(font->csi->ordering, "Identity");
1028
font->csi->supplement = 0;
1031
font->fontdict = pdf_new_dict();
1032
pdf_add_dict(font->fontdict,
1033
pdf_new_name("Type"),
1034
pdf_new_name("Font"));
1035
pdf_add_dict(font->fontdict,
1036
pdf_new_name("Subtype"),
1037
pdf_new_name("CIDFontType2"));
1039
font->descriptor = tt_get_fontdesc(sfont, &(opt->embed), 0);
1040
if (!font->descriptor) {
1041
ERROR("Could not obtain neccesary font info.");
1045
memmove(fontname + 7, fontname, strlen(fontname) + 1);
1046
pdf_font_make_uniqueTag(fontname);
1050
pdf_add_dict(font->descriptor,
1051
pdf_new_name("FontName"),
1052
pdf_new_name(fontname));
1053
pdf_add_dict(font->fontdict,
1054
pdf_new_name("BaseFont"),
1055
pdf_new_name(fontname));
1061
* Don't write fontdict here.
1062
* /Supplement in /CIDSystemInfo may change.
1069
CIDFont_type2_release (CIDFont *font)