summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2020-11-14 00:30:58 +0200
committerOleg Oshmyan <chortos@inbox.lv>2021-04-29 03:15:40 +0300
commitd9b74844da420730d90de28e881ec3e9d396682f (patch)
treecf604c099ffa5d93e6fb496ab4238ba078f760cc
parent1140b6b885c89d37eef13dc1f31f144e9a76a4d7 (diff)
downloadlibass-d9b74844da420730d90de28e881ec3e9d396682f.tar.bz2
libass-d9b74844da420730d90de28e881ec3e9d396682f.tar.xz
Ignore glyphs[0].pos.y in compute_string_bbox
In most cases, text_info->glyphs[0].pos.y is 0. This makes the bbox in compute_string_bbox have bbox.y_min = -text_info->lines[0].asc. Thus, during event positioning, we refer to the text's top and bottom edge coordinates in two equivalent ways: \an4-6, \pos, \move and Scroll effects use bbox.y_min and bbox.y_max, while \an1-3 and \an7-9 use -text_info->lines[0].asc and text_info->height - text_info->lines[0].asc. However, text->glyphs[0].pos.y is not *actually always* 0. Specifically, it is nonzero for events that begin with right-to-left text with nonzero \fay (at least two visible glyphs with the same \fay). In this case, the anchoring point we use for vertical positioning is different between \an1-3,7-9 and the other cases. For \an1-3,7-9, it is the middle point of the text's left edge, which makes sense. But for \an4-6, \pos, \move and Scroll effects, it is shifted up. It is easiest to describe for a single-line event: the anchor is the middle point of the *left edge of the rightmost glyph*. That is, the anchor point is not the middle of *either* edge of the full text, and it is hard to understand intuitively, more so in a multiline event. VSFilter in the same situation places the anchor in the middle of the whole event's left edge, just as we do for \an1-3 and \an7-9. This also affects the position of rotation origin, which is likewise unintuitive and VSFilter-incompatible. Fix this by making compute_string_bbox ignore text->glyphs[0].pos.y even in the rare case that it is nonzero. This makes our behavior obvious and VSFilter-compatible, and our code easier to understand (as the reader no longer has to wonder whether there is a difference between the various alignments, wonder *why* there seems to be no difference after testing common cases, and make the wrong conclusion that glyphs[0].pos.y is always 0).
-rw-r--r--libass/ass_render.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libass/ass_render.c b/libass/ass_render.c
index 1ed0a14..5cecbb7 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -845,7 +845,7 @@ static void compute_string_bbox(TextInfo *text, ASS_DRect *bbox)
if (text->length > 0) {
bbox->x_min = +32000;
bbox->x_max = -32000;
- bbox->y_min = d6_to_double(text->glyphs[0].pos.y) - text->lines[0].asc;
+ bbox->y_min = -text->lines[0].asc;
bbox->y_max = bbox->y_min + text->height;
for (int i = 0; i < text->length; i++) {