summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
diff options
context:
space:
mode:
authorDr.Smile <vabnick@gmail.com>2019-05-19 20:24:29 +0300
committerDr.Smile <vabnick@gmail.com>2019-05-19 20:24:29 +0300
commite072b72b1a12837b6894d052a08ed3aed57f2f16 (patch)
tree492ddc7dbf70b70f298bcb3298b53ebad03841b6 /libass/ass_font.c
parent5d03af99c6d8f43be973cb6dacb5d6dd0ada33b1 (diff)
downloadlibass-e072b72b1a12837b6894d052a08ed3aed57f2f16.tar.bz2
libass-e072b72b1a12837b6894d052a08ed3aed57f2f16.tar.xz
cache: construct cache values only from corresponding keys
This commit forces construction of cache values using only data available in its companion keys. That ensures logical correctness: keys are guaranteed to have all the necessary data, and prevents accidental collisions. Most fixes of cache logic correspond to minor problem when rendering is done with double parameter but cache key stores its approximate fixed-point representation. The only serious problem is missing scale of clip drawing. Also this commit removes unused scale parameters from glyph metrics cache key. Due to missing scale clip shapes that differed only in scale treated by cache system as identical. That can lead to incorrect reuse of cached bitmap of different scale instead of correct one. The only hack left is in glyph metrics cache with its unicode >= VERTICAL_LOWER_BOUND check.
Diffstat (limited to 'libass/ass_font.c')
-rw-r--r--libass/ass_font.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index 6b369aa..2c488cc 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -224,26 +224,28 @@ static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch)
/**
* \brief Create a new ASS_Font according to "desc" argument
*/
-ASS_Font *ass_font_new(Cache *font_cache, ASS_Library *library,
- FT_Library ftlibrary, ASS_FontSelector *fontsel,
- ASS_FontDesc *desc)
+ASS_Font *ass_font_new(ASS_Renderer *render_priv, ASS_FontDesc *desc)
{
- ASS_Font *font;
- if (ass_cache_get(font_cache, desc, &font)) {
- if (font->desc.family)
- return font;
- ass_cache_dec_ref(font);
- return NULL;
- }
+ ASS_Font *font = ass_cache_get(render_priv->cache.font_cache, desc, render_priv);
if (!font)
return NULL;
+ if (font->desc.family)
+ return font;
+ ass_cache_dec_ref(font);
+ return NULL;
+}
+
+size_t ass_font_construct(void *key, void *value, void *priv)
+{
+ ASS_Renderer *render_priv = priv;
+ ASS_FontDesc *desc = key;
+ ASS_Font *font = value;
- font->library = library;
- font->ftlibrary = ftlibrary;
+ font->library = render_priv->library;
+ font->ftlibrary = render_priv->ftlibrary;
font->shaper_priv = NULL;
font->n_faces = 0;
- ASS_FontDesc *new_desc = ass_cache_key(font);
- font->desc.family = new_desc->family;
+ font->desc.family = desc->family;
font->desc.bold = desc->bold;
font->desc.italic = desc->italic;
font->desc.vertical = desc->vertical;
@@ -251,15 +253,10 @@ ASS_Font *ass_font_new(Cache *font_cache, ASS_Library *library,
font->scale_x = font->scale_y = 1.;
font->size = 0.;
- int error = add_face(fontsel, font, 0);
- if (error == -1) {
+ int error = add_face(render_priv->fontselect, font, 0);
+ if (error == -1)
font->desc.family = NULL;
- ass_cache_commit(font, 1);
- ass_cache_dec_ref(font);
- return NULL;
- }
- ass_cache_commit(font, 1);
- return font;
+ return 1;
}
/**