If variation selector is not consumed by cmap, pass it on to GSUB
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 13 Jun 2013 23:01:07 +0000 (19:01 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 13 Jun 2013 23:01:07 +0000 (19:01 -0400)
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
src/hb-ot-shape-normalize.cc

index 978230c..d63eba2 100644 (file)
@@ -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
 
index 51ef77b..3fee809 100644 (file)
@@ -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)))
       {