diff options
author | Grigori Goronzy <greg@blackbox> | 2012-10-01 20:39:02 +0200 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2012-10-01 20:52:04 +0200 |
commit | e6c71d8a94172a11a17518387ae5f3db540490c8 (patch) | |
tree | 353737f9a32d2914b531d9c7d23ba8c0aad9a48d | |
parent | b61d260b3e92a3fc4c0e054ad5b030182030f996 (diff) | |
download | libass-e6c71d8a94172a11a17518387ae5f3db540490c8.tar.bz2 libass-e6c71d8a94172a11a17518387ae5f3db540490c8.tar.xz |
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.
-rw-r--r-- | libass/ass_shaper.c | 38 |
1 files changed, 25 insertions, 13 deletions
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 @@ -600,6 +600,29 @@ void ass_shaper_set_level(ASS_Shaper *shaper, ASS_ShapingLevel 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++; - } - } } /** |