From b38f3bfebd138062c55a521161ad20e5795f41a2 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 20 Oct 2006 16:43:47 +0000 Subject: [PATCH] * lily/ttf.cc (print_trailer): if all else fails: use glyphIndexXXXX as glyph name. * lily/pango-font.cc (pango_item_string_stencil): only use cmap entry if cmap contains glyph. (get_index_to_charcode_map): remove from Pango_font class, use global filename -> font mapping. (get_glyph_index_name): new function. (pango_item_string_stencil): use glyphIndexXXXX as glyph name, only for TTF. --- ChangeLog | 8 ++++++++ lily/include/open-type-font.hh | 1 + lily/include/pango-font.hh | 3 --- lily/pango-font.cc | 36 ++++++++++++++++++++++++---------- lily/ttf.cc | 22 ++++++++++++++++++--- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5495d56b80..62c4b1ae93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,15 @@ 2006-10-20 Han-Wen Nienhuys + * lily/ttf.cc (print_trailer): if all else fails: use + glyphIndexXXXX as glyph name. + * lily/pango-font.cc (pango_item_string_stencil): only use cmap entry if cmap contains glyph. + (get_index_to_charcode_map): remove from Pango_font class, use + global filename -> font mapping. + (get_glyph_index_name): new function. + (pango_item_string_stencil): use glyphIndexXXXX as glyph name, + only for TTF. * scripts/lilypond-book.py (main): use -deps-box-padding=-3 diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index be1f85bf7a..c0490be6e5 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -18,6 +18,7 @@ using namespace std; typedef map Index_to_charcode_map; Index_to_charcode_map make_index_to_charcode_map (FT_Face face); void get_unicode_name (char*s, FT_ULong code); +void get_glyph_index_name (char*s, FT_ULong code); class Open_type_font : public Font_metric { diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index 9e330faeab..5449ec0a42 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -29,9 +29,6 @@ class Pango_font : public Font_metric SCM physical_font_tab_; Direction text_direction_; - map charcode_maps_; - - Index_to_charcode_map const *get_index_to_charcode_map (string postscript_name, FT_Face face); public: SCM physical_font_tab () const; Pango_font (PangoFT2FontMap *, diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 63029b3bbc..7da47e6672 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -76,16 +76,26 @@ Pango_font::derived_mark () const } +map filename_charcode_maps_map; +Index_to_charcode_map const *get_index_to_charcode_map (string postscript_name, FT_Face face); + + Index_to_charcode_map const * -Pango_font::get_index_to_charcode_map (string key, FT_Face face) +get_index_to_charcode_map (string filename, FT_Face face) { - if (charcode_maps_.find (key) == charcode_maps_.end ()) - charcode_maps_[key] = make_index_to_charcode_map (face); + if (filename_charcode_maps_map.find (filename) == filename_charcode_maps_map.end ()) + filename_charcode_maps_map[filename] = make_index_to_charcode_map (face); - if (charcode_maps_.find (key) == charcode_maps_.end ()) + if (filename_charcode_maps_map.find (filename) == filename_charcode_maps_map.end ()) return 0; - return &charcode_maps_[key]; + return &filename_charcode_maps_map[filename]; +} + +void +get_glyph_index_name (char *s, FT_ULong code) +{ + sprintf (s, "glyphIndex%lX", code); } void @@ -149,8 +159,9 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str, Index_to_charcode_map const *cmap = 0; bool has_glyph_names = ftface->face_flags & FT_FACE_FLAG_GLYPH_NAMES; if (! has_glyph_names) - cmap = ((Pango_font*)this)->get_index_to_charcode_map (file_name, ftface); - + cmap = get_index_to_charcode_map (file_name, ftface); + bool is_ttf = (file_name.find (".ttf") != NPOS + || file_name.find (".TTF") != NPOS); bool cid_keyed = false; for (int i = 0; i < pgs->num_glyphs; i++) { @@ -172,8 +183,7 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str, && cmap /* Ugh should ask FreeType about font type. */ - && (file_name.find (".ttf") != NPOS - || file_name.find (".TTF") != NPOS) + && is_ttf && cmap->find (pg) != cmap->end ()) { FT_ULong char_code = cmap->find (pg)->second; @@ -188,7 +198,13 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str, file_name.c_str ())); continue; } - + + if (glyph_name[0] == '\0' && is_ttf) + { + // access by glyph index directly. + get_glyph_index_name (glyph_name, pg); + } + if (glyph_name[0] == '\0') { /* diff --git a/lily/ttf.cc b/lily/ttf.cc index 9f5fbfb8a2..4f2d6c8748 100644 --- a/lily/ttf.cc +++ b/lily/ttf.cc @@ -26,11 +26,18 @@ make_index_to_charcode_map (FT_Face face) FT_UInt gindex; FT_CharMap current_cmap = face->charmap; - FT_Select_Charmap(face, FT_ENCODING_UNICODE); + // FT_Select_Charmap(face, FT_ENCODING_UNICODE); + FT_Select_Charmap(face, FT_ENCODING_NONE); + + int j = 0; for (charcode = FT_Get_First_Char (face, &gindex); gindex != 0; charcode = FT_Get_Next_Char (face, charcode, &gindex)) - m[gindex] = charcode; + { + m[gindex] = charcode; + j++; + } FT_Set_Charmap (face, current_cmap); + return m; } @@ -174,12 +181,21 @@ print_trailer (void *out, get_unicode_name (glyph_name, ucode); } + if (!glyph_name[0]) + { + get_glyph_index_name (glyph_name, i); + } + if (glyph_name[0]) { lily_cookie_fprintf (out, "/%s %d def ", glyph_name, i); output_count ++; } - + else + { + programming_error (to_string ("no name for glyph %d", i)); + } + if (! (output_count % 5)) lily_cookie_fprintf (out, "\n"); } -- 2.39.2