]> granicus.if.org Git - libass/commitdiff
shaper: actually correctly handle @font advance
authorOleg Oshmyan <chortos@inbox.lv>
Fri, 3 Jan 2014 17:27:34 +0000 (19:27 +0200)
committerOleg Oshmyan <chortos@inbox.lv>
Tue, 7 Jan 2014 20:23:54 +0000 (22:23 +0200)
The code was confusing glyph index and Unicode codepoint.
256df617 attempted a fix but merely moved the wrong code.

Fixes Google Code issue #94.

Vertical ligatures are possibly still broken, but
horizontal ligatures and non-ligatures are correct now.

libass/ass_shaper.c

index 395f9c56411ac2c15c2be8ced4c3b11436061532..d5a970eefe7326693350335e0b9a2de4b82fda48 100644 (file)
@@ -185,7 +185,7 @@ static void update_hb_size(hb_font_t *hb_font, FT_Face face)
 
 GlyphMetricsHashValue *
 get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
-                   hb_codepoint_t glyph)
+                   hb_codepoint_t unicode, hb_codepoint_t glyph)
 {
     GlyphMetricsHashValue *val;
 
@@ -204,7 +204,7 @@ get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
 
         // if @font rendering is enabled and the glyph should be rotated,
         // make cached_h_advance pick up the right advance later
-        if (metrics->vertical && glyph >= VERTICAL_LOWER_BOUND)
+        if (metrics->vertical && unicode >= VERTICAL_LOWER_BOUND)
             new_val.metrics.horiAdvance = new_val.metrics.vertAdvance;
 
         val = ass_cache_put(metrics->metrics_cache, &metrics->hash_key, &new_val);
@@ -218,12 +218,17 @@ get_glyph(hb_font_t *font, void *font_data, hb_codepoint_t unicode,
           hb_codepoint_t variation, hb_codepoint_t *glyph, void *user_data)
 {
     FT_Face face = font_data;
+    struct ass_shaper_metrics_data *metrics_priv = user_data;
 
     if (variation)
         *glyph = FT_Face_GetCharVariantIndex(face, ass_font_index_magic(face, unicode), variation);
     else
         *glyph = FT_Get_Char_Index(face, ass_font_index_magic(face, unicode));
 
+    // rotate glyph advances for @fonts while we still know the Unicode codepoints
+    if (*glyph != 0)
+        get_cached_metrics(metrics_priv, face, unicode, glyph);
+
     return *glyph != 0;
 }
 
@@ -233,7 +238,7 @@ cached_h_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
 {
     FT_Face face = font_data;
     struct ass_shaper_metrics_data *metrics_priv = user_data;
-    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, glyph);
+    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, 0, glyph);
 
     if (!metrics)
         return 0;
@@ -247,7 +252,7 @@ cached_v_advance(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
 {
     FT_Face face = font_data;
     struct ass_shaper_metrics_data *metrics_priv = user_data;
-    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, glyph);
+    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, 0, glyph);
 
     if (!metrics)
         return 0;
@@ -269,7 +274,7 @@ cached_v_origin(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
 {
     FT_Face face = font_data;
     struct ass_shaper_metrics_data *metrics_priv = user_data;
-    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, glyph);
+    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, 0, glyph);
 
     if (!metrics)
         return 0;
@@ -306,7 +311,7 @@ cached_extents(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
 {
     FT_Face face = font_data;
     struct ass_shaper_metrics_data *metrics_priv = user_data;
-    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, glyph);
+    GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, 0, glyph);
 
     if (!metrics)
         return 0;