diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-09-05 16:01:08 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-09-05 16:05:34 +0300 |
commit | d81aeb60fe7518fcd8d94975a8df4322b501d01a (patch) | |
tree | f52c7427ba4405b5ab402f64999d38876b877380 /source/blender/blenkernel/intern/font.c | |
parent | 66f8a2d67e0ae9b76d87675a88bfc28fa87bef69 (diff) |
Fix for text alignment on multiple text boxes
The original code was already making a distinction between lines in the last
text box and all lines. However I removed that bit since when I tested the
values were the same (I tested with a single text box).
Bringing this distinction back.
Not addressed here: All boxes should respect the alignment. Which at the moment
they don't seem to fully do.
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 31de8d8d51e..1ed386f1447 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -1037,8 +1037,19 @@ makebreak: if (tb_scale.h != 0.0f) { if (i_textbox < slen) { /* All previous textboxes are 'full', only align the last used text-box. */ - struct CharTrans *ct_textbox = chartransdata + i_textbox; + struct CharTrans *ct_last, *ct_textbox; float yoff = 0.0f; + int lines; + + ct_last = chartransdata + slen - 1; + ct_textbox = chartransdata + i_textbox; + + /* Do not use `lnr`. `lnr` correspond to all the text's lines. + * While `lines` is only for the ones from the last text box. */ + lines = ct_last->linenr - ct_textbox->linenr + 1; + if (mem[slen - 1] == '\n') { + lines++; + } /* The initial Y origin of the textbox is harcoded to 1.0f * text scale. */ const float textbox_y_origin = 1.0f; @@ -1050,14 +1061,14 @@ makebreak: yoff = textbox_y_origin - ASCENT(vfd); break; case CU_ALIGN_Y_CENTER: - yoff = ((((vfd->em_height + (lnr - 1) * linedist) * 0.5f) - ASCENT(vfd)) - + yoff = ((((vfd->em_height + (lines - 1) * linedist) * 0.5f) - ASCENT(vfd)) - (tb_scale.h * 0.5f) + textbox_y_origin); break; case CU_ALIGN_Y_BOTTOM_BASELINE: - yoff = textbox_y_origin + ((lnr - 1) * linedist) - tb_scale.h; + yoff = textbox_y_origin + ((lines - 1) * linedist) - tb_scale.h; break; case CU_ALIGN_Y_BOTTOM: - yoff = textbox_y_origin + ((lnr - 1) * linedist) - tb_scale.h + DESCENT(vfd); + yoff = textbox_y_origin + ((lines - 1) * linedist) - tb_scale.h + DESCENT(vfd); break; } |