]> granicus.if.org Git - libass/commitdiff
shaper: improve skipping of zero-width characters
authorGrigori Goronzy <greg@blackbox>
Mon, 1 Oct 2012 18:39:02 +0000 (20:39 +0200)
committerGrigori Goronzy <greg@blackbox>
Mon, 1 Oct 2012 18:52:04 +0000 (20:52 +0200)
The list was somewhat incomplete. Add what's important and left, and
disable removal if HarfBuzz is used. HarfBuzz removes these characters
now by itself. Refactor a little into a separate function.

libass/ass_shaper.c

index 16f1c352f0f0f1d45d3f06881a601abdc1570d34..a84ae21143534b53e1ec8cd40c383b80faed3f0b 100644 (file)
@@ -599,6 +599,29 @@ void ass_shaper_set_level(ASS_Shaper *shaper, ASS_ShapingLevel level)
     shaper->shaping_level = level;
 }
 
+/**
+  * \brief Remove all zero-width invisible characters from the text.
+  * \param text_info text
+  */
+static void ass_shaper_skip_characters(TextInfo *text_info)
+{
+    int i;
+    GlyphInfo *glyphs = text_info->glyphs;
+
+    for (i = 0; i < text_info->length; i++) {
+        // Skip direction override control characters
+        if ((glyphs[i].symbol <= 0x202e && glyphs[i].symbol >= 0x202a)
+                || (glyphs[i].symbol <= 0x200f && glyphs[i].symbol >= 0x200b)
+                || (glyphs[i].symbol <= 0x2063 && glyphs[i].symbol >= 0x2060)
+                || glyphs[i].symbol == 0xfeff
+                || glyphs[i].symbol == 0x00ad
+                || glyphs[i].symbol == 0x034f) {
+            glyphs[i].symbol = 0;
+            glyphs[i].skip++;
+        }
+    }
+}
+
 /**
  * \brief Shape an event's text. Calculates directional runs and shapes them.
  * \param text_info event's text
@@ -635,6 +658,7 @@ void ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
     switch (shaper->shaping_level) {
     case ASS_SHAPING_SIMPLE:
         shape_fribidi(shaper, glyphs, text_info->length);
+        ass_shaper_skip_characters(text_info);
         break;
     case ASS_SHAPING_COMPLEX:
         shape_harfbuzz(shaper, glyphs, text_info->length);
@@ -642,20 +666,8 @@ void ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
     }
 #else
         shape_fribidi(shaper, glyphs, text_info->length);
+        ass_shaper_skip_characters(text_info);
 #endif
-
-
-    // clean up
-    for (i = 0; i < text_info->length; i++) {
-        // Skip direction override control characters
-        // NOTE: Behdad said HarfBuzz is supposed to remove these, but this hasn't
-        // been implemented yet
-        if ((glyphs[i].symbol <= 0x202e && glyphs[i].symbol >= 0x202a)
-                || (glyphs[i].symbol <= 0x200f && glyphs[i].symbol >= 0x200c)) {
-            glyphs[i].symbol = 0;
-            glyphs[i].skip++;
-        }
-    }
 }
 
 /**