From: Grigori Goronzy Date: Mon, 1 Oct 2012 18:39:02 +0000 (+0200) Subject: shaper: improve skipping of zero-width characters X-Git-Tag: 0.10.1~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6c71d8a94172a11a17518387ae5f3db540490c8;p=libass shaper: improve skipping of zero-width characters 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. --- diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c index 16f1c35..a84ae21 100644 --- a/libass/ass_shaper.c +++ b/libass/ass_shaper.c @@ -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++; - } - } } /**