From 79d1007a501fd63c0ba4d51038c513e6b8b94740 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 13 Jun 2013 19:01:07 -0400 Subject: [PATCH] If variation selector is not consumed by cmap, pass it on to GSUB This changes the semantics of get_glyph() callback and expect that callbacks return false if the requested variant is not available, and then we will call them back with variation_selector=0 and will retain the glyph for the selector in the glyph stream. Apparently most Mongolian fonts implement the Mongolian Variation Selectors using GSUB, not cmap. https://bugs.freedesktop.org/show_bug.cgi?id=65258 Note that this doesn't fix the Mongolian shaping yet, because the way that's implemented is that the, say, 'init' feature ligates the letter and the variation-selector. However, since currently the variation selector doesn't have the 'init' mask on, it will not be matched... --- src/hb-ft.cc | 3 +-- src/hb-ot-shape-normalize.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 978230cd6..d63eba2f0 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -73,8 +73,7 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED, #ifdef HAVE_FT_FACE_GETCHARVARIANTINDEX if (unlikely (variation_selector)) { *glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector); - if (*glyph) - return true; + return *glyph != 0; } #endif diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc index 51ef77b9a..3fee809cf 100644 --- a/src/hb-ot-shape-normalize.cc +++ b/src/hb-ot-shape-normalize.cc @@ -217,8 +217,18 @@ handle_variation_selector_cluster (const hb_ot_shape_normalize_context_t *c, uns for (; buffer->idx < end - 1;) { if (unlikely (buffer->unicode->is_variation_selector (buffer->cur(+1).codepoint))) { /* The next two lines are some ugly lines... But work. */ - c->font->get_glyph (buffer->cur().codepoint, buffer->cur(+1).codepoint, &buffer->cur().glyph_index()); - buffer->replace_glyphs (2, 1, &buffer->cur().codepoint); + if (c->font->get_glyph (buffer->cur().codepoint, buffer->cur(+1).codepoint, &buffer->cur().glyph_index())) + { + buffer->replace_glyphs (2, 1, &buffer->cur().codepoint); + } + else + { + /* Just pass on the two characters separately, let GSUB do its magic. */ + set_glyph (buffer->cur(), c->font); + buffer->next_glyph (); + set_glyph (buffer->cur(), c->font); + buffer->next_glyph (); + } /* Skip any further variation selectors. */ while (buffer->idx < end && unlikely (buffer->unicode->is_variation_selector (buffer->cur().codepoint))) {