Skip to content

Commit

Permalink
shaper: actually correctly handle @font advance
Browse files Browse the repository at this point in the history
The code was confusing glyph index and Unicode codepoint.
256df61 attempted a fix but merely moved the wrong code.

Fixes Google Code issue libass#94.

Vertical ligatures are possibly still broken, but
horizontal ligatures and non-ligatures are correct now.
  • Loading branch information
astiob committed Jan 7, 2014
1 parent 62df9e8 commit 1636a55
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions libass/ass_shaper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1636a55

Please sign in to comment.