diff options
author | Jjgod Jiang <gzjjgod@gmail.com> | 2014-08-09 20:26:41 +0000 |
---|---|---|
committer | Jjgod Jiang <gzjjgod@gmail.com> | 2014-08-09 20:26:41 +0000 |
commit | 0e536590d09e1c58b0521a2a311dcae285f08a59 (patch) | |
tree | fd9662cd5f18003a53dfa03b15f3e577bec5ec80 /Build/source | |
parent | 9462cc23f60af7fbd09a40aa7d70346354343fb0 (diff) |
dvipdfm-x: Simplify ToUnicode handling
Remove used_glyphs and its supporting code for ToUnicode handling,
because for CID fonts, glyph id can be looked up from cid which is
stored in used_chars already, it simplified a lot of code and reduced
memory usage.
Continue dedup create_ToUnicode_cmap{4,12}() with
add_to_cmap_if_used().
git-svn-id: svn://tug.org/texlive/trunk@34885 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfdev.c | 14 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.c | 18 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.h | 1 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/tt_cmap.c | 221 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/tt_cmap.h | 2 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/type0.c | 23 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/type0.h | 2 |
7 files changed, 104 insertions, 177 deletions
diff --git a/Build/source/texk/dvipdfm-x/pdfdev.c b/Build/source/texk/dvipdfm-x/pdfdev.c index 2819a3e79af..ec7605a6ab4 100644 --- a/Build/source/texk/dvipdfm-x/pdfdev.c +++ b/Build/source/texk/dvipdfm-x/pdfdev.c @@ -463,7 +463,6 @@ struct dev_font { pdf_obj *resource; char *used_chars; - char *used_glyphs; /* Font format: * simple, composite or bitmap. @@ -877,8 +876,6 @@ 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); - if (real_font->cff_charsets) - real_font->used_glyphs = pdf_get_font_usedglyphs(real_font->font_id); } if (!real_font->used_on_this_page) { @@ -1158,12 +1155,6 @@ 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 && ctype == -1) { - for (i = 0; i < length; i += 2) { - unsigned short gid = (str_ptr[i] << 8) | str_ptr[i + 1]; - add_to_used_chars2(real_font->used_glyphs, gid); - } - } if (handle_multibyte_string(font, &str_ptr, &length, ctype) < 0) { ERROR("Error in converting input string..."); return; @@ -1171,10 +1162,6 @@ pdf_dev_set_string (spt_t xpos, spt_t ypos, if (real_font->used_chars != NULL) { for (i = 0; i < length; i += 2) { unsigned short cid = (str_ptr[i] << 8) | str_ptr[i + 1]; - if (ctype == 2 && font->cff_charsets) { - unsigned short gid = cff_charsets_lookup_gid(font->cff_charsets, cid); - add_to_used_chars2(real_font->used_glyphs, gid); - } add_to_used_chars2(real_font->used_chars, cid); } } @@ -1549,7 +1536,6 @@ pdf_dev_locate_font (const char *font_name, spt_t ptsize) 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 56a354a15db..9dc400700f3 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.c +++ b/Build/source/texk/dvipdfm-x/pdffont.c @@ -334,24 +334,6 @@ 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) { diff --git a/Build/source/texk/dvipdfm-x/pdffont.h b/Build/source/texk/dvipdfm-x/pdffont.h index 38ca3a590e2..a833fe89dc1 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.h +++ b/Build/source/texk/dvipdfm-x/pdffont.h @@ -63,7 +63,6 @@ extern int pdf_font_findresource (const char *font_name, 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 f288891a195..d0e8af6db68 100644 --- a/Build/source/texk/dvipdfm-x/tt_cmap.c +++ b/Build/source/texk/dvipdfm-x/tt_cmap.c @@ -862,11 +862,13 @@ sfnt_get_glyphname(struct tt_post_table *post, cff_font *cffont, USHORT gid) static USHORT handle_subst_glyphs (CMap *cmap, - CMap *cmap_add, const char *used_glyphs, - sfnt *sfont, cff_font *cffont) + CMap *cmap_add, + const char *used_glyphs, + sfnt *sfont, + cff_font *cffont) { USHORT count; - USHORT i, gid; + USHORT i; struct tt_post_table *post = NULL; if (!cmap_add) @@ -882,10 +884,10 @@ handle_subst_glyphs (CMap *cmap, continue; for (j = 0; j < 8; j++) { - gid = 8 * i + j; + USHORT gid = 8 * i + j; if (!is_used_char2(used_glyphs, gid)) - continue; + continue; if (!cmap_add) { #define MAX_UNICODES 16 @@ -918,35 +920,33 @@ handle_subst_glyphs (CMap *cmap, } RELEASE(name); } else { - wbuf[0] = (gid >> 8) & 0xff; - wbuf[1] = gid & 0xff; - inbuf = wbuf; - inbytesleft = 2; - outbuf = wbuf + 2; - outbytesleft = WBUF_SIZE - 2; - CMap_decode(cmap_add, - &inbuf , &inbytesleft, - &outbuf, &outbytesleft); - if (inbytesleft != 0) { - WARN("CMap conversion failed..."); - } else { - len = WBUF_SIZE - 2 - outbytesleft; - CMap_add_bfchar(cmap, wbuf, 2, wbuf + 2, len); - count++; - - if (verbose > VERBOSE_LEVEL_MIN) { - long _i; - - MESG("otf_cmap>> Additional ToUnicode mapping: <%04X> <", gid); - for (_i = 0; _i < len; _i++) { - MESG("%02X", wbuf[2 + _i]); - } - MESG(">\n"); - } + wbuf[0] = (gid >> 8) & 0xff; + wbuf[1] = gid & 0xff; - } - } + inbuf = wbuf; + inbytesleft = 2; + outbuf = wbuf + 2; + outbytesleft = WBUF_SIZE - 2; + CMap_decode(cmap_add, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + + if (inbytesleft != 0) { + WARN("CMap conversion failed..."); + } else { + len = WBUF_SIZE - 2 - outbytesleft; + CMap_add_bfchar(cmap, wbuf, 2, wbuf + 2, len); + count++; + + if (verbose > VERBOSE_LEVEL_MIN) { + long _i; + MESG("otf_cmap>> Additional ToUnicode mapping: <%04X> <", gid); + for (_i = 0; _i < len; _i++) { + MESG("%02X", wbuf[2 + _i]); + } + MESG(">\n"); + } + } + } } } @@ -977,56 +977,69 @@ prepare_CIDFont_from_sfnt(sfnt* sfont) } static USHORT +add_to_cmap_if_used (CMap *cmap, + cff_font *cffont, + char *used_chars, + USHORT gid, + ULONG ch) +{ + USHORT count = 0; + USHORT cid = cffont ? cff_charsets_lookup_inverse(cffont, gid) : gid; + if (is_used_char2(used_chars, cid)) { + int len; + unsigned char *p = wbuf + 2; + + count++; + + 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); + + /* Skip PUA characters and alphabetic presentation forms, allowing + * handle_subst_glyphs() as it might find better mapping. Fixes the + * mapping of ligatures encoded in PUA in fonts like Linux Libertine + * and old Adobe fonts. + */ + if (!is_PUA_or_presentation(ch)) { + /* Avoid duplicate entry + * There are problem when two Unicode code is mapped to + * single glyph... + */ + used_chars[gid / 8] &= ~(1 << (7 - (gid % 8))); + } + } + + return count; +} + +static USHORT create_ToUnicode_cmap4 (CMap *cmap, struct cmap4 *map, - char *used_glyphs, + char *used_chars, cff_font *cffont) { - USHORT c0, c1, gid, count, ch; - USHORT i, j, d, segCount; + USHORT count = 0, segCount = map->segCountX2 / 2; + USHORT i, j; - segCount = map->segCountX2 / 2; - for (count = 0, i = 0; i < segCount; i++) { - c0 = map->startCount[i]; - c1 = map->endCount[i]; - d = map->idRangeOffset[i] / 2 - (segCount - i); + for (i = 0; i < segCount; i++) { + USHORT c0 = map->startCount[i]; + USHORT c1 = map->endCount[i]; + USHORT d = map->idRangeOffset[i] / 2 - (segCount - i); for (j = 0; j <= c1 - c0; j++) { - ch = c0 + j; + USHORT ch = c0 + j; + USHORT gid; + if (map->idRangeOffset[i] == 0) { - gid = (ch + map->idDelta[i]) & 0xffff; + gid = (ch + map->idDelta[i]) & 0xffff; } else if (c0 == 0xffff && c1 == 0xffff && map->idRangeOffset[i] == 0xffff) { - /* this is for protection against some old broken fonts... */ - gid = 0; + /* this is for protection against some old broken fonts... */ + gid = 0; } else { - gid = (map->glyphIndexArray[j+d] + - map->idDelta[i]) & 0xffff; + gid = (map->glyphIndexArray[j + d] + map->idDelta[i]) & 0xffff; } - if (is_used_char2(used_glyphs, gid)) { - unsigned int cid = cffont ? cff_charsets_lookup_inverse(cffont, gid) : gid; - count++; - - wbuf[0] = (cid >> 8) & 0xff; - wbuf[1] = (cid & 0xff); - - wbuf[2] = (ch >> 8) & 0xff; - wbuf[3] = ch & 0xff; - CMap_add_bfchar(cmap, wbuf, 2, wbuf+2, 2); - - /* Skip PUA characters and alphabetic presentation forms, allowing - * handle_subst_glyphs() as it might find better mapping. Fixes the - * mapping of ligatures encoded in PUA in fonts like Linux Libertine - * and old Adobe fonts. - */ - if (!is_PUA_or_presentation(ch)) { - /* Avoid duplicate entry - * There are problem when two Unicode code is mapped to - * single glyph... - */ - used_glyphs[gid/8] &= ~(1 << (7 - (gid % 8))); - } - count++; - } + count += add_to_cmap_if_used(cmap, cffont, used_chars, gid, ch); } } @@ -1036,45 +1049,17 @@ create_ToUnicode_cmap4 (CMap *cmap, static USHORT create_ToUnicode_cmap12 (CMap *cmap, struct cmap12 *map, - char *used_glyphs, + char *used_chars, cff_font *cffont) { - ULONG i, ch; - USHORT gid, count = 0; + ULONG i, ch, count = 0; for (i = 0; i < map->nGroups; i++) { for (ch = map->groups[i].startCharCode; ch <= map->groups[i].endCharCode; ch++) { - unsigned char *p; - int len; - long d; - - p = wbuf + 2; - d = ch - map->groups[i].startCharCode; - gid = (USHORT) ((map->groups[i].startGlyphID + d) & 0xffff); - if (is_used_char2(used_glyphs, gid)) { - unsigned int cid = cffont ? cff_charsets_lookup_inverse(cffont, gid) : gid; - count++; - 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); - - /* Skip PUA characters and alphabetic presentation forms, allowing - * handle_subst_glyphs() as it might find better mapping. Fixes the - * mapping of ligatures encoded in PUA in fonts like Linux Libertine - * and old Adobe fonts. - */ - if (!is_PUA_or_presentation(ch)) { - /* Avoid duplicate entry - * There are problem when two Unicode code is mapped to - * single glyph... - */ - used_glyphs[gid/8] &= ~(1 << (7 - (gid % 8))); - } - count++; - } + long d = ch - map->groups[i].startCharCode; + USHORT gid = (USHORT) ((map->groups[i].startGlyphID + d) & 0xffff); + count += add_to_cmap_if_used(cmap, cffont, used_chars, gid, ch); } } @@ -1085,14 +1070,13 @@ static pdf_obj * create_ToUnicode_cmap (tt_cmap *ttcmap, const char *cmap_name, CMap *cmap_add, - const char *used_glyphs, + const char *used_chars, sfnt *sfont, CMap *code_to_cid_cmap) { pdf_obj *stream = NULL; CMap *cmap; USHORT i, gid, count = 0; - char used_glyphs_copy[8192]; cff_font *cffont = prepare_CIDFont_from_sfnt(sfont); char is_cidfont = cffont && (cffont->flag & FONTTYPE_CIDFONT); @@ -1105,23 +1089,21 @@ create_ToUnicode_cmap (tt_cmap *ttcmap, if (code_to_cid_cmap && cffont && is_cidfont) { for (i = 0; i < 8192; i++) { - int j; - long len; + int j; - if (used_glyphs[i] == 0) + if (used_chars[i] == 0) continue; for (j = 0; j < 8; j++) { - unsigned int cid; + USHORT cid = 8 * i + j; int ch; - gid = 8 * i + j; - if (!is_used_char2(used_glyphs, gid)) + if (!is_used_char2(used_chars, cid)) continue; - cid = cff_charsets_lookup_inverse(cffont, gid); ch = CMap_reverse_decode(code_to_cid_cmap, cid); if (ch >= 0) { + long len; unsigned char *p = wbuf + 2; wbuf[0] = (cid >> 8) & 0xff; wbuf[1] = cid & 0xff; @@ -1132,24 +1114,25 @@ create_ToUnicode_cmap (tt_cmap *ttcmap, } } } else { - memcpy(used_glyphs_copy, used_glyphs, 8192); + char used_chars_copy[8192]; + memcpy(used_chars_copy, used_chars, 8192); /* For create_ToUnicode_cmap{4,12}(), cffont is for GID -> CID lookup, * so it is only needed for CID fonts. */ switch (ttcmap->format) { case 4: - count = create_ToUnicode_cmap4(cmap, ttcmap->map, used_glyphs_copy, + count = create_ToUnicode_cmap4(cmap, ttcmap->map, used_chars_copy, is_cidfont ? cffont : NULL); break; case 12: - count = create_ToUnicode_cmap12(cmap, ttcmap->map, used_glyphs_copy, + count = create_ToUnicode_cmap12(cmap, ttcmap->map, used_chars_copy, is_cidfont ? cffont : NULL); break; } /* For handle_subst_glyphs(), cffont is for GID -> glyph name lookup, so * it is only needed for non-CID fonts. */ - count += handle_subst_glyphs(cmap, cmap_add, used_glyphs_copy, sfont, + count += handle_subst_glyphs(cmap, cmap_add, used_chars_copy, sfont, is_cidfont ? NULL : cffont); } @@ -1182,7 +1165,7 @@ static cmap_plat_enc_rec cmap_plat_encs[] = { pdf_obj * otf_create_ToUnicode_stream (const char *font_name, int ttc_index, /* 0 for non-TTC */ - const char *used_glyphs, + const char *used_chars, int cmap_id) { pdf_obj *cmap_ref = NULL; @@ -1275,7 +1258,7 @@ otf_create_ToUnicode_stream (const char *font_name, continue; if (ttcmap->format == 4 || ttcmap->format == 12) { - cmap_obj = create_ToUnicode_cmap(ttcmap, cmap_name, cmap_add, used_glyphs, + cmap_obj = create_ToUnicode_cmap(ttcmap, cmap_name, cmap_add, used_chars, sfont, code_to_cid_cmap); break; } diff --git a/Build/source/texk/dvipdfm-x/tt_cmap.h b/Build/source/texk/dvipdfm-x/tt_cmap.h index afc492cb127..2e9bbbbbc17 100644 --- a/Build/source/texk/dvipdfm-x/tt_cmap.h +++ b/Build/source/texk/dvipdfm-x/tt_cmap.h @@ -68,7 +68,7 @@ extern void tt_cmap_release (tt_cmap *cmap); /* Indirect reference */ extern pdf_obj *otf_create_ToUnicode_stream (const char *map_name, int ttc_index, - const char *used_glyphs, + const char *used_chars, int cmap_id); /* CMap ID */ extern int otf_load_Unicode_CMap (const char *map_name, diff --git a/Build/source/texk/dvipdfm-x/type0.c b/Build/source/texk/dvipdfm-x/type0.c index 060c9b9cfe8..5fe77a7f86d 100644 --- a/Build/source/texk/dvipdfm-x/type0.c +++ b/Build/source/texk/dvipdfm-x/type0.c @@ -85,7 +85,6 @@ 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 @@ -114,7 +113,6 @@ 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->cmap_id = -1; @@ -135,8 +133,6 @@ Type0Font_clean (Type0Font *font) ERROR("%s: FontDescriptor unexpected for Type0 font.", TYPE0FONT_DEBUG_STR); if (!(font->flags & FLAG_USED_CHARS_SHARED) && font->used_chars) RELEASE(font->used_chars); - if (!(font->flags & FLAG_USED_CHARS_SHARED) && font->used_glyphs) - RELEASE(font->used_glyphs); if (font->encoding) RELEASE(font->encoding); if (font->fontname) @@ -145,7 +141,6 @@ Type0Font_clean (Type0Font *font) font->indirect = NULL; font->descriptor = NULL; font->used_chars = NULL; - font->used_glyphs = NULL; font->encoding = NULL; font->fontname = NULL; } @@ -157,13 +152,9 @@ Type0Font_clean (Type0Font *font) static 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), - used, + Type0Font_get_usedchars(font), font->cmap_id); } @@ -331,14 +322,6 @@ 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) { @@ -517,7 +500,6 @@ 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)) { @@ -531,12 +513,9 @@ Type0Font_cache_find (const char *map_name, int cmap_id, fontmap_opt *fmap_opt) */ if ((parent_id = CIDFont_get_parent_id(cidfont, wmode ? 0 : 1)) < 0) { font->used_chars = new_used_chars2(); - if (fmap_opt->cff_charsets) - font->used_glyphs = new_used_chars2(); } 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 c22d41e3da0..553de1e760f 100644 --- a/Build/source/texk/dvipdfm-x/type0.h +++ b/Build/source/texk/dvipdfm-x/type0.h @@ -36,8 +36,6 @@ 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); extern void Type0Font_set_ToUnicode (Type0Font *font, pdf_obj *cmap_ref); |