Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2016-06-21 05:21:24 +0300
committerDalai Felinto <dfelinto@gmail.com>2016-06-21 05:21:24 +0300
commitcb5a77253a719c08986aa69a3d3f7fc8725648c7 (patch)
tree436b7fa179d163801d3f95ea3472a1c1ec0edd78 /source/blender/blenkernel
parent1c199401983bd53577cb180efe83ee5314f04296 (diff)
Text Object: Vertical Alignment
A new option for Font/Text objects vertical alignment: * Top Base-Line (current mode) * Top * Center * Bottom The Top is the equivalent as the Top-Baseline with an empty line at the begin of the text. It's nice to have this option too though, since if we are driving the alignment via Python we don't want to add extra lines to the text only to accomodate to the desired vertical alignment. The Center and Bottom are as intuitive as their name suggest. When working with text boxes, the vertical alignment only work for paragraphs that are not vertically full. Many thanks to Campbell Barton (ideasman42 / @campbellbarton) for the code review, code comments, and overall suggestions and changes :) Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D2061
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/font.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 98757407e89..b4088934ea4 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -628,6 +628,8 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Object *ob, int mode, ListBase *r_nubase
bool use_textbox;
VChar *che;
struct CharTrans *chartransdata = NULL, *ct;
+ /* Text at the beginning of the last used text-box (use for y-axis alignment). */
+ int i_textbox = 0;
struct TempLineInfo *lineinfo;
float *f, xof, yof, xtrax, linedist;
float twidth, maxlen = 0;
@@ -830,6 +832,7 @@ makebreak:
(cu->totbox > (curbox + 1)) &&
((-(yof - tb_scale.y)) > (tb_scale.h - linedist) - yof_scale))
{
+ i_textbox = i + 1;
maxlen = 0;
curbox++;
@@ -983,6 +986,60 @@ makebreak:
}
}
+ /* top-baseline is default, in this case, do nothing */
+ if (cu->align_y != CU_ALIGN_Y_TOP_BASELINE) {
+ if (tb_scale.h != 0.0f) {
+ /* top and top-baseline are the same when text-boxes are used */
+ if (cu->align_y != CU_ALIGN_Y_TOP && i_textbox < slen) {
+ /* all previous textboxes are 'full', only align the last used text-box */
+ float yoff;
+ int lines;
+ struct CharTrans *ct_last, *ct_textbox;
+
+ ct_last = chartransdata + slen - 1;
+ ct_textbox = chartransdata + i_textbox;
+
+ lines = ct_last->linenr - ct_textbox->linenr + 1;
+ if (mem[slen - 1] == '\n') {
+ lines++;
+ }
+
+ if (cu->align_y == CU_ALIGN_Y_BOTTOM) {
+ yoff = (lines * linedist) - tb_scale.h;
+ }
+ else if (cu->align_y == CU_ALIGN_Y_CENTER) {
+ yoff = 0.5f * ((lines * linedist) - tb_scale.h);
+ }
+
+ ct = ct_textbox;
+ for (i = i_textbox - 1; i < slen; i++) {
+ ct->yof += yoff;
+ ct++;
+ }
+ }
+ }
+ else {
+ /* non text-box case handled separately */
+ ct = chartransdata;
+ float yoff;
+
+ if (cu->align_y == CU_ALIGN_Y_TOP) {
+ yoff = -linedist;
+ }
+ else if (cu->align_y == CU_ALIGN_Y_BOTTOM) {
+ yoff = (lnr - 1.0f) * linedist;
+ }
+ else if (cu->align_y == CU_ALIGN_Y_CENTER) {
+ yoff = (lnr - 2.0f) * linedist * 0.5f;
+ }
+
+ for (i = 0; i <= slen; i++) {
+ ct->yof += yoff;
+ ct++;
+ }
+ }
+ }
+
MEM_freeN(lineinfo);
/* TEXT ON CURVE */