diff options
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 78 |
1 files changed, 67 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index aed33d2c64d..5e1f8814ed6 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -95,10 +95,9 @@ void BKE_vfont_free_data(struct VFont *vfont) } } +/** Free (or release) any data used by this font (does not free the font itself). */ void BKE_vfont_free(struct VFont *vf) { - if (vf == NULL) return; - BKE_vfont_free_data(vf); if (vf->packedfile) { @@ -541,7 +540,7 @@ int BKE_vfont_select_get(Object *ob, int *r_start, int *r_end) BLI_assert(ef->len >= 0); BLI_assert(ef->selstart >= 0 && ef->selstart <= ef->len + 1); - BLI_assert(ef->selend >= 0 && ef->selend <= ef->len); + BLI_assert(ef->selend >= 0 && ef->selend <= ef->len + 1); BLI_assert(ef->pos >= 0 && ef->pos <= ef->len); if (ef->selstart == 0) { @@ -628,6 +627,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 +831,7 @@ makebreak: (cu->totbox > (curbox + 1)) && ((-(yof - tb_scale.y)) > (tb_scale.h - linedist) - yof_scale)) { + i_textbox = i + 1; maxlen = 0; curbox++; @@ -908,10 +910,10 @@ makebreak: /* linedata is now: width of line */ - if (cu->spacemode != CU_LEFT) { + if (cu->spacemode != CU_ALIGN_X_LEFT) { ct = chartransdata; - if (cu->spacemode == CU_RIGHT) { + if (cu->spacemode == CU_ALIGN_X_RIGHT) { struct TempLineInfo *li; for (i = 0, li = lineinfo; i < lnr; i++, li++) { @@ -923,7 +925,7 @@ makebreak: ct++; } } - else if (cu->spacemode == CU_MIDDLE) { + else if (cu->spacemode == CU_ALIGN_X_MIDDLE) { struct TempLineInfo *li; for (i = 0, li = lineinfo; i < lnr; i++, li++) { @@ -935,7 +937,7 @@ makebreak: ct++; } } - else if ((cu->spacemode == CU_FLUSH) && use_textbox) { + else if ((cu->spacemode == CU_ALIGN_X_FLUSH) && use_textbox) { struct TempLineInfo *li; for (i = 0, li = lineinfo; i < lnr; i++, li++) { @@ -956,7 +958,7 @@ makebreak: ct++; } } - else if ((cu->spacemode == CU_JUSTIFY) && use_textbox) { + else if ((cu->spacemode == CU_ALIGN_X_JUSTIFY) && use_textbox) { float curofs = 0.0f; for (i = 0; i <= slen; i++) { for (j = i; @@ -983,6 +985,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 */ @@ -1021,13 +1077,13 @@ makebreak: /* path longer than text: spacemode involves */ distfac = 1.0f / distfac; - if (cu->spacemode == CU_RIGHT) { + if (cu->spacemode == CU_ALIGN_X_RIGHT) { timeofs = 1.0f - distfac; } - else if (cu->spacemode == CU_MIDDLE) { + else if (cu->spacemode == CU_ALIGN_X_MIDDLE) { timeofs = (1.0f - distfac) / 2.0f; } - else if (cu->spacemode == CU_FLUSH) { + else if (cu->spacemode == CU_ALIGN_X_FLUSH) { distfac = 1.0f; } } |