]> granicus.if.org Git - libass/blobdiff - libass/ass_shaper.c
cache: switch to gradual cache clearing
[libass] / libass / ass_shaper.c
index 01642d1bfeb20041a547e3af5117a48338fb9bda..95ffda3c356ce48b0e79288366980bb7d969fc89 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "config.h"
+#include "ass_compat.h"
 
 #include "ass_shaper.h"
 #include "ass_render.h"
@@ -79,7 +80,7 @@ struct ass_shaper_font_data {
  */
 void ass_shaper_info(ASS_Library *lib)
 {
-    ass_msg(lib, MSGL_V, "Shaper: FriBidi "
+    ass_msg(lib, MSGL_INFO, "Shaper: FriBidi "
             FRIBIDI_VERSION " (SIMPLE)"
 #ifdef CONFIG_HARFBUZZ
             " HarfBuzz-ng %s (COMPLEX)", hb_version_string()
@@ -206,26 +207,25 @@ get_cached_metrics(struct ass_shaper_metrics_data *metrics, FT_Face face,
                    hb_codepoint_t unicode, hb_codepoint_t glyph)
 {
     GlyphMetricsHashValue *val;
-
     metrics->hash_key.glyph_index = glyph;
-    val = ass_cache_get(metrics->metrics_cache, &metrics->hash_key);
-
-    if (!val) {
+    if (!ass_cache_get(metrics->metrics_cache, &metrics->hash_key, &val)) {
         int load_flags = FT_LOAD_DEFAULT | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
             | FT_LOAD_IGNORE_TRANSFORM;
-        GlyphMetricsHashValue new_val;
 
-        if (FT_Load_Glyph(face, glyph, load_flags))
+        if (FT_Load_Glyph(face, glyph, load_flags)) {
+            ass_cache_cancel(val);
             return NULL;
+        }
 
-        memcpy(&new_val.metrics, &face->glyph->metrics, sizeof(FT_Glyph_Metrics));
+        memcpy(&val->metrics, &face->glyph->metrics, sizeof(FT_Glyph_Metrics));
 
         // if @font rendering is enabled and the glyph should be rotated,
         // make cached_h_advance pick up the right advance later
         if (metrics->vertical && unicode >= VERTICAL_LOWER_BOUND)
-            new_val.metrics.horiAdvance = new_val.metrics.vertAdvance;
+            val->metrics.horiAdvance = val->metrics.vertAdvance;
 
-        val = ass_cache_put(metrics->metrics_cache, &metrics->hash_key, &new_val);
+        ass_cache_inc_ref(metrics->hash_key.font);
+        ass_cache_commit(val);
     }
 
     return val;
@@ -964,11 +964,10 @@ FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
 }
 
 /**
- * \brief Resolve a Windows font charset number to a suitable
- * base direction. 177 and 178 are Hebrew and Arabic respectively, and
- * they map to RTL. Everything else maps to LTR for compatibility
- * reasons. The special value -1, which is not a legal Windows font charset
- * number, can be used for autodetection.
+ * \brief Resolve a Windows font charset number to a suitable base
+ * direction. Generally, use LTR for compatibility with VSFilter. The
+ * special value -1, which is not a legal Windows font charset number,
+ * can be used for autodetection.
  * \param enc Windows font encoding
  */
 FriBidiParType resolve_base_direction(int enc)
@@ -976,9 +975,6 @@ FriBidiParType resolve_base_direction(int enc)
     switch (enc) {
         case -1:
             return FRIBIDI_PAR_ON;
-        case 177:
-        case 178:
-            return FRIBIDI_PAR_RTL;
         default:
             return FRIBIDI_PAR_LTR;
     }