From 858d2c9bc2f38514b4e7e4ab15d64291bd4e2e85 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Wed, 23 Jul 2014 14:48:04 +0000 Subject: Support CID-keyed OpenType fonts in xdvipdfmx (from Jiang Jiang) git-svn-id: svn://tug.org/texlive/trunk@34700 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/type0.c | 98 +++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 31 deletions(-) (limited to 'Build/source/texk/dvipdfm-x/type0.c') 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; -- cgit v1.2.3