From a2663bc3b24925df64dd81d7391928294661b47e Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Sat, 14 Nov 2020 00:41:54 +0200 Subject: Skip glyphs with \fscx0 or \fscy0 after layout These glyphs are effectively invisible. VSFilter draws no border around them, either (because for BorderStyle 1 it finds no pixels to draw a border around, while BorderStyle 3 gets scaled a second time by the same \fscx or \fscy), except current MPC-HC (which doesn't double-scale BorderStyle 3). Since nothing is to be seen on screen, skip the rest of the pipeline altogether. They still affect the layout of other glyphs that may have nonzero scales, so we can only do this after text layout is done. This avoids subsequent divisions by zero when sheared pre-scale coordinates are computed from post-scale coordinates at scale zero. (We eagerly scale all coordinates before shearing because it makes text layout easier.) In apply_baseline_shear itself, the shear displacement for an \fscy0 glyph is always zero, so skipping its calculation is safe. For an \fscx0 glyph, we currently divide 0 by 0, which we want to avoid. Logically, this is supposed to take the cluster's pre-\fscx advance and compute shear from that, but this commit does not do this. When in VSFilter-compatible mode, we're actually supposed to reset the baseline when \fscx becomes nonzero, so this won't matter. Meanwhile, when we're trying to do a "sensible" thing, it's not clear whether shear-before-scale makes sense in the first place. At any rate, this improves upon the current behavior by avoiding the zero division, and at least on x86 this actually happens to match our current layouts in situations where the current code produces visible output at all. Fixes https://github.com/libass/libass/issues/185. Fixes https://github.com/libass/libass/issues/413. Fixes https://github.com/libass/libass/issues/428. Fixes https://github.com/libass/libass/issues/443. --- libass/ass_render.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libass/ass_render.c b/libass/ass_render.c index 058e0ac..7ccd5a8 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -2139,6 +2139,8 @@ static void apply_baseline_shear(ASS_Renderer *render_priv) if (text_info->glyphs[i].linebreak || last_fay != info->fay) shear = 0; last_fay = info->fay; + if (!info->scale_x || !info->scale_y) + info->skip = true; if (info->skip) continue; for (GlyphInfo *cur = info; cur; cur = cur->next) -- cgit v1.2.3