diff options
-rw-r--r-- | Build/source/texk/dvipdfm-x/ChangeLog | 5 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/cff.c | 6 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfdev.c | 33 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.c | 28 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.h | 2 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/tt_cmap.c | 24 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/type0.c | 98 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/type0.h | 1 |
8 files changed, 159 insertions, 38 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index cca422e00d7..b4fec2eb3e1 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,8 @@ +2014-07-23 Jiang Jiang <gzjjgod@gmail.com> + + * cff.c, pdfdev.c, pdffont.c, pdffont.h, tt_cmap.c, type0.c, type0.h: + Support CID-keyed OpenType fonts. + 2014-07-22 Khaled Hosny <khaledhosny@eglug.org> * src/dvi.c, src/dvicodes.h: Support DVI-IVD inspired text reflection diff --git a/Build/source/texk/dvipdfm-x/cff.c b/Build/source/texk/dvipdfm-x/cff.c index 7a54e3fecfd..40ff4648ce7 100644 --- a/Build/source/texk/dvipdfm-x/cff.c +++ b/Build/source/texk/dvipdfm-x/cff.c @@ -326,9 +326,13 @@ cff_get_index_header (cff_font *cff) ERROR("invalid offsize data"); idx->offset = NEW(count+1, l_offset); - for (i=0;i<count+1;i++) { + for (i=0;i<count;i++) { (idx->offset)[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); } + if (count == 0xFFFF) + cff_seek(cff, cff_tell(cff) + idx->offsize); + else + (idx->offset)[i] = get_offset(cff->SFONT_OR_STREAM, idx->offsize); if (idx->offset[0] != 1) ERROR("cff_get_index(): invalid index data"); diff --git a/Build/source/texk/dvipdfm-x/pdfdev.c b/Build/source/texk/dvipdfm-x/pdfdev.c index 54f1a9aa457..593a9890cf5 100644 --- a/Build/source/texk/dvipdfm-x/pdfdev.c +++ b/Build/source/texk/dvipdfm-x/pdfdev.c @@ -52,6 +52,10 @@ #include "pdfdev.h" +#ifdef XETEX +#include FT_CID_H +#endif + static int verbose = 0; void @@ -457,6 +461,7 @@ struct dev_font { int enc_id; #ifdef XETEX unsigned short *ft_to_gid; + FT_Bool is_cid_keyed; #endif /* if >= 0, index of a dev_font that really has the resource and used_chars */ @@ -464,6 +469,7 @@ struct dev_font { pdf_obj *resource; char *used_chars; + char *used_glyphs; /* Font format: * simple, composite or bitmap. @@ -875,6 +881,10 @@ dev_set_font (int font_id) if (!real_font->resource) { real_font->resource = pdf_get_font_reference(real_font->font_id); real_font->used_chars = pdf_get_font_usedchars(real_font->font_id); +#ifdef XETEX + if (real_font->is_cid_keyed) + real_font->used_glyphs = pdf_get_font_usedglyphs(real_font->font_id); +#endif } if (!real_font->used_on_this_page) { @@ -959,15 +969,22 @@ handle_multibyte_string (struct dev_font *font, #ifdef XETEX if (ctype == -1) { /* freetype glyph indexes */ - if (font->ft_to_gid) { + if (font->ft_to_gid || font->is_cid_keyed) { /* convert freetype glyph indexes to physical GID */ const unsigned char *inbuf = p; unsigned char *outbuf = sbuf0; + FT_Face face = pdf_font_get_ft_face(pdf_get_font(font->font_id)); for (i = 0; i < length; i += 2) { unsigned int gid; gid = *inbuf++ << 8; gid += *inbuf++; - gid = font->ft_to_gid[gid]; + if (font->is_cid_keyed) { + FT_UInt cid = 0; + FT_Get_CID_From_Glyph_Index(face, gid, &cid); + gid = cid; + } else { + gid = font->ft_to_gid[gid]; + } *outbuf++ = gid >> 8; *outbuf++ = gid & 0xff; } @@ -1156,6 +1173,11 @@ pdf_dev_set_string (spt_t xpos, spt_t ypos, length = instr_len; if (font->format == PDF_FONTTYPE_COMPOSITE) { + if (real_font->used_glyphs != NULL) { + for (i = 0; i < length; i += 2) + add_to_used_chars2(real_font->used_glyphs, + (unsigned short) (str_ptr[i] << 8)|str_ptr[i+1]); + } if (handle_multibyte_string(font, &str_ptr, &length, ctype) < 0) { ERROR("Error in converting input string..."); return; @@ -1531,10 +1553,17 @@ pdf_dev_locate_font (const char *font_name, spt_t ptsize) font->enc_id = pdf_get_font_encoding(font->font_id); #ifdef XETEX font->ft_to_gid = pdf_get_font_ft_to_gid(font->font_id); + + font->is_cid_keyed = 0; + { + FT_Face face = pdf_font_get_ft_face(pdf_get_font(font->font_id)); + FT_Get_CID_Is_Internally_CID_Keyed(face, &font->is_cid_keyed); + } #endif font->resource = NULL; /* Don't ref obj until font is actually used. */ font->used_chars = NULL; + font->used_glyphs = NULL; font->extend = 1.0; font->slant = 0.0; diff --git a/Build/source/texk/dvipdfm-x/pdffont.c b/Build/source/texk/dvipdfm-x/pdffont.c index 570e0663301..2bea295e7d8 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.c +++ b/Build/source/texk/dvipdfm-x/pdffont.c @@ -343,6 +343,24 @@ pdf_get_font_usedchars (int font_id) } } +char * +pdf_get_font_usedglyphs (int font_id) +{ + pdf_font *font; + + CHECK_ID(font_id); + + font = GET_FONT(font_id); + if (font->subtype == PDF_FONT_FONTTYPE_TYPE0) { + Type0Font *t0font; + + t0font = Type0Font_cache_get(font->font_id); + return Type0Font_get_usedglyphs(t0font); + } + + return NULL; +} + int pdf_get_font_wmode (int font_id) { @@ -361,6 +379,16 @@ pdf_get_font_wmode (int font_id) } } +pdf_font * +pdf_get_font (int font_id) +{ + pdf_font *font; + + CHECK_ID(font_id); + + return GET_FONT(font_id); +} + int pdf_get_font_subtype (int font_id) { diff --git a/Build/source/texk/dvipdfm-x/pdffont.h b/Build/source/texk/dvipdfm-x/pdffont.h index 6d3ea72b56f..d2afc7a7a3f 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.h +++ b/Build/source/texk/dvipdfm-x/pdffont.h @@ -60,9 +60,11 @@ extern void pdf_close_fonts (void); extern int pdf_font_findresource (const char *font_name, double font_scale, fontmap_rec *mrec); +extern pdf_font* pdf_get_font (int font_id); extern int pdf_get_font_subtype (int font_id); extern pdf_obj *pdf_get_font_reference (int font_id); extern char *pdf_get_font_usedchars (int font_id); +extern char *pdf_get_font_usedglyphs (int font_id); #if 0 extern char *pdf_get_font_fontname (int font_id); /* without unique tag */ diff --git a/Build/source/texk/dvipdfm-x/tt_cmap.c b/Build/source/texk/dvipdfm-x/tt_cmap.c index aa49979be6c..a2e8e21f679 100644 --- a/Build/source/texk/dvipdfm-x/tt_cmap.c +++ b/Build/source/texk/dvipdfm-x/tt_cmap.c @@ -55,6 +55,10 @@ #include "tt_cmap.h" +#ifdef XETEX +#include FT_CID_H +#endif + #define VERBOSE_LEVEL_MIN 0 static int verbose = 0; void @@ -947,6 +951,16 @@ handle_subst_glyphs (CMap *cmap, return count; } +unsigned int +gid_to_cid(sfnt *sfont, USHORT gid) +{ + unsigned int cid = 0; +#ifdef XETEX + FT_Get_CID_From_Glyph_Index(sfont->ft_face, gid, &cid); +#endif + return cid ? cid : gid; +} + static pdf_obj * create_ToUnicode_cmap4 (struct cmap4 *map, const char *cmap_name, CMap *cmap_add, @@ -985,10 +999,11 @@ create_ToUnicode_cmap4 (struct cmap4 *map, map->idDelta[i]) & 0xffff; } if (is_used_char2(used_glyphs_copy, gid)) { + unsigned int cid = gid_to_cid(sfont, gid); count++; - wbuf[0] = (gid >> 8) & 0xff; - wbuf[1] = (gid & 0xff); + wbuf[0] = (cid >> 8) & 0xff; + wbuf[1] = (cid & 0xff); wbuf[2] = (ch >> 8) & 0xff; wbuf[3] = ch & 0xff; @@ -1057,9 +1072,10 @@ create_ToUnicode_cmap12 (struct cmap12 *map, d = ch - map->groups[i].startCharCode; gid = (USHORT) ((map->groups[i].startGlyphID + d) & 0xffff); if (is_used_char2(used_glyphs_copy, gid)) { + unsigned int cid = gid_to_cid(sfont, gid); count++; - wbuf[0] = (gid >> 8) & 0xff; - wbuf[1] = (gid & 0xff); + wbuf[0] = (cid >> 8) & 0xff; + wbuf[1] = (cid & 0xff); len = UC_sput_UTF16BE((long)ch, &p, wbuf+WBUF_SIZE); CMap_add_bfchar(cmap, wbuf, 2, wbuf+2, len); diff --git a/Build/source/texk/dvipdfm-x/type0.c b/Build/source/texk/dvipdfm-x/type0.c index 3238b0949d7..b74b3f27e02 100644 --- a/Build/source/texk/dvipdfm-x/type0.c +++ b/Build/source/texk/dvipdfm-x/type0.c @@ -45,6 +45,9 @@ #include "type0.h" +#ifdef XETEX +#include FT_CID_H +#endif #define TYPE0FONT_DEBUG_STR "Type0" #define TYPE0FONT_DEBUG 3 @@ -85,6 +88,7 @@ struct Type0Font { char *fontname; /* BaseFont */ char *encoding; /* "Identity-H" or "Identity-V" (not ID) */ char *used_chars; /* Used chars (CIDs) */ + char *used_glyphs; /* Used glyphs (GIDs) */ /* * Type0 only @@ -112,6 +116,7 @@ Type0Font_init_font_struct (Type0Font *font) font->descriptor = NULL; font->encoding = NULL; font->used_chars = NULL; + font->used_glyphs = NULL; font->descendant = NULL; font->wmode = -1; font->flags = FLAG_NONE; @@ -139,6 +144,7 @@ Type0Font_clean (Type0Font *font) font->indirect = NULL; font->descriptor = NULL; font->used_chars = NULL; + font->used_glyphs = NULL; font->encoding = NULL; font->fontname = NULL; } @@ -147,13 +153,47 @@ Type0Font_clean (Type0Font *font) /* PLEASE FIX THIS */ #include "tt_cmap.h" +pdf_obj *Type0Font_create_ToUnicode_stream(Type0Font *font) { + CIDFont *cidfont = font->descendant; + char *used = Type0Font_get_usedglyphs(font); + if (!used) + used = Type0Font_get_usedchars(font); + return otf_create_ToUnicode_stream(CIDFont_get_ident(cidfont), + CIDFont_get_opt_index(cidfont), +#ifdef XETEX + CIDFont_get_ft_face(cidfont), +#endif + used); +} + +/* Try to load ToUnicode CMap from file system first, if not found fallback to + * font CMap reverse lookup. */ +pdf_obj *Type0Font_try_load_ToUnicode_stream(Type0Font *font, char *cmap_base) { + char *cmap_name = NEW(strlen(cmap_base) + strlen("-UTF-16"), char); + pdf_obj *tounicode; + + sprintf(cmap_name, "%s-UTF16", cmap_base); + tounicode = pdf_read_ToUnicode_file(cmap_name); + if (!tounicode) { + sprintf(cmap_name, "%s-UCS2", cmap_base); + tounicode = pdf_read_ToUnicode_file(cmap_name); + } + + RELEASE(cmap_name); + + if (!tounicode) + tounicode = Type0Font_create_ToUnicode_stream(font); + + return tounicode; +} + static void add_ToUnicode (Type0Font *font) { pdf_obj *tounicode; CIDFont *cidfont; CIDSysInfo *csi; - char *cmap_name, *fontname; + char *fontname; /* * ToUnicode CMap: @@ -197,45 +237,24 @@ add_ToUnicode (Type0Font *font) switch (CIDFont_get_subtype(cidfont)) { case CIDFONT_TYPE2: /* PLEASE FIX THIS */ - tounicode = otf_create_ToUnicode_stream(CIDFont_get_ident(cidfont), - CIDFont_get_opt_index(cidfont), -#ifdef XETEX - CIDFont_get_ft_face(cidfont), -#endif - Type0Font_get_usedchars(font)); + tounicode = Type0Font_create_ToUnicode_stream(font); break; default: if (CIDFont_get_flag(cidfont, CIDFONT_FLAG_TYPE1C)) { /* FIXME */ - tounicode = otf_create_ToUnicode_stream(CIDFont_get_ident(cidfont), - CIDFont_get_opt_index(cidfont), -#ifdef XETEX - CIDFont_get_ft_face(cidfont), -#endif - Type0Font_get_usedchars(font)); + tounicode = Type0Font_create_ToUnicode_stream(font); } else if (CIDFont_get_flag(cidfont, CIDFONT_FLAG_TYPE1)) { /* FIXME */ /* Font loader will create ToUnicode and set. */ return; } else { - cmap_name = NEW(strlen(fontname) + 7, char); - sprintf(cmap_name, "%s-UTF16", fontname); - tounicode = pdf_read_ToUnicode_file(cmap_name); - if (!tounicode) { - sprintf(cmap_name, "%s-UCS2", fontname); - tounicode = pdf_read_ToUnicode_file(cmap_name); - } - RELEASE(cmap_name); + tounicode = Type0Font_try_load_ToUnicode_stream(font, fontname); } break; } } else { - cmap_name = NEW(strlen(csi->registry)+strlen(csi->ordering)+8, char); - sprintf(cmap_name, "%s-%s-UTF16", csi->registry, csi->ordering); - tounicode = pdf_read_ToUnicode_file(cmap_name); - if (!tounicode) { - sprintf(cmap_name, "%s-%s-UCS2", csi->registry, csi->ordering); - tounicode = pdf_read_ToUnicode_file(cmap_name); - } - RELEASE(cmap_name); + char *cmap_base = NEW(strlen(csi->registry) + strlen(csi->ordering) + 2, char); + sprintf(cmap_base, "%s-%s", csi->registry, csi->ordering); + tounicode = Type0Font_try_load_ToUnicode_stream(font, cmap_base); + RELEASE(cmap_base); } if (tounicode) { @@ -310,6 +329,14 @@ Type0Font_get_usedchars (Type0Font *font) return font->used_chars; } +char * +Type0Font_get_usedglyphs (Type0Font *font) +{ + ASSERT(font); + + return font->used_glyphs; +} + pdf_obj * Type0Font_get_resource (Type0Font *font) { @@ -495,6 +522,7 @@ Type0Font_cache_find (const char *map_name, int cmap_id, fontmap_opt *fmap_opt) */ font->used_chars = NULL; + font->used_glyphs = NULL; font->flags = FLAG_NONE; switch (CIDFont_get_subtype(cidfont)) { @@ -506,11 +534,19 @@ Type0Font_cache_find (const char *map_name, int cmap_id, fontmap_opt *fmap_opt) /* * Need used_chars to write W, W2. */ - if ((parent_id = CIDFont_get_parent_id(cidfont, wmode ? 0 : 1)) < 0) + if ((parent_id = CIDFont_get_parent_id(cidfont, wmode ? 0 : 1)) < 0) { +#ifdef XETEX + FT_Face face = CIDFont_get_ft_face(cidfont); + FT_Bool is_cid_keyed = 0; + FT_Get_CID_Is_Internally_CID_Keyed(face, &is_cid_keyed); + if (is_cid_keyed) + font->used_glyphs = new_used_chars2(); +#endif font->used_chars = new_used_chars2(); - else { + } else { /* Don't allocate new one. */ font->used_chars = Type0Font_get_usedchars(Type0Font_cache_get(parent_id)); + font->used_glyphs = Type0Font_get_usedglyphs(Type0Font_cache_get(parent_id)); font->flags |= FLAG_USED_CHARS_SHARED; } break; diff --git a/Build/source/texk/dvipdfm-x/type0.h b/Build/source/texk/dvipdfm-x/type0.h index 6b8fa1d1c39..7e140bc8719 100644 --- a/Build/source/texk/dvipdfm-x/type0.h +++ b/Build/source/texk/dvipdfm-x/type0.h @@ -35,6 +35,7 @@ extern int Type0Font_get_wmode (Type0Font *font); extern char *Type0Font_get_encoding (Type0Font *font); #endif extern char *Type0Font_get_usedchars (Type0Font *font); +extern char *Type0Font_get_usedglyphs (Type0Font *font); extern pdf_obj *Type0Font_get_resource (Type0Font *font); |