summaryrefslogtreecommitdiffstats
path: root/libass/ass_shaper.c
diff options
context:
space:
mode:
Diffstat (limited to 'libass/ass_shaper.c')
-rw-r--r--libass/ass_shaper.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
index 8cb8654..95222ae 100644
--- a/libass/ass_shaper.c
+++ b/libass/ass_shaper.c
@@ -208,8 +208,12 @@ get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
{
GlyphMetricsHashValue *val;
metrics->hash_key.glyph_index = glyph;
- if (ass_cache_get(metrics->metrics_cache, &metrics->hash_key, &val))
- return val->metrics.width < 0 ? NULL : val;
+ if (ass_cache_get(metrics->metrics_cache, &metrics->hash_key, &val)) {
+ if (val->metrics.width >= 0)
+ return val;
+ ass_cache_dec_ref(val);
+ return NULL;
+ }
if (!val)
return NULL;
@@ -219,6 +223,7 @@ get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
if (FT_Load_Glyph(face, glyph, load_flags)) {
val->metrics.width = -1;
ass_cache_commit(val, 1);
+ ass_cache_dec_ref(val);
return NULL;
}
@@ -244,12 +249,13 @@ get_glyph(hb_font_t *font, void *font_data, hb_codepoint_t unicode,
*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));
+ if (!*glyph)
+ return false;
// 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;
+ GlyphMetricsHashValue *metrics = get_cached_metrics(metrics_priv, face, unicode, *glyph);
+ ass_cache_dec_ref(metrics);
+ return true;
}
static hb_position_t
@@ -259,11 +265,12 @@ 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, 0, glyph);
-
if (!metrics)
return 0;
- return metrics->metrics.horiAdvance;
+ hb_position_t advance = metrics->metrics.horiAdvance;
+ ass_cache_dec_ref(metrics);
+ return advance;
}
static hb_position_t
@@ -273,19 +280,19 @@ 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, 0, glyph);
-
if (!metrics)
return 0;
- return metrics->metrics.vertAdvance;
-
+ hb_position_t advance = metrics->metrics.vertAdvance;
+ ass_cache_dec_ref(metrics);
+ return advance;
}
static hb_bool_t
cached_h_origin(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y, void *user_data)
{
- return 1;
+ return true;
}
static hb_bool_t
@@ -295,14 +302,13 @@ 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, 0, glyph);
-
if (!metrics)
- return 0;
+ return false;
*x = metrics->metrics.horiBearingX - metrics->metrics.vertBearingX;
*y = metrics->metrics.horiBearingY - (-metrics->metrics.vertBearingY);
-
- return 1;
+ ass_cache_dec_ref(metrics);
+ return true;
}
static hb_position_t
@@ -312,7 +318,7 @@ get_h_kerning(hb_font_t *font, void *font_data, hb_codepoint_t first,
FT_Face face = font_data;
FT_Vector kern;
- if (FT_Get_Kerning (face, first, second, FT_KERNING_DEFAULT, &kern))
+ if (FT_Get_Kerning(face, first, second, FT_KERNING_DEFAULT, &kern))
return 0;
return kern.x;
@@ -332,16 +338,15 @@ 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, 0, glyph);
-
if (!metrics)
- return 0;
+ return false;
extents->x_bearing = metrics->metrics.horiBearingX;
extents->y_bearing = metrics->metrics.horiBearingY;
extents->width = metrics->metrics.width;
extents->height = -metrics->metrics.height;
-
- return 1;
+ ass_cache_dec_ref(metrics);
+ return true;
}
static hb_bool_t
@@ -354,15 +359,14 @@ get_contour_point(hb_font_t *font, void *font_data, hb_codepoint_t glyph,
| FT_LOAD_IGNORE_TRANSFORM;
if (FT_Load_Glyph(face, glyph, load_flags))
- return 0;
+ return false;
if (point_index >= (unsigned)face->glyph->outline.n_points)
- return 0;
+ return false;
*x = face->glyph->outline.points[point_index].x;
*y = face->glyph->outline.points[point_index].y;
-
- return 1;
+ return true;
}
/**