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:
authorCampbell Barton <ideasman42@gmail.com>2020-09-03 14:20:56 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-09-03 14:20:56 +0300
commita505a85873602a9e265bafb107d2ea356fc23a17 (patch)
tree1fa31df1cec7e87576c9a47e84337c325a45e814
parent930021129a1ed4c908ddafad62e31070b93dbb58 (diff)
Fix 3D text cursor alignment without any text
Part of fix for T80340.
-rw-r--r--source/blender/blenkernel/intern/font.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index fb7c7c54aa2..890cfd91710 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -1274,18 +1274,21 @@ static bool vfont_to_curve(Object *ob,
/* We put the x-coordinate exact at the curve, the y is rotated. */
/* length correction */
- float chartrans_size_x = maxx - minx;
- if (UNLIKELY(chartrans_size_x == 0.0f)) {
- /* Happens when there are no characters,
- * the result isn't useful in this case, just avoid divide by zero. */
- chartrans_size_x = 1.0f;
+ const float chartrans_size_x = maxx - minx;
+ if (chartrans_size_x != 0.0f) {
+ const float totdist = cu->textoncurve->runtime.curve_cache->path->totdist;
+ distfac = (sizefac * totdist) / chartrans_size_x;
+ distfac = (distfac > 1.0f) ? (1.0f / distfac) : 1.0f;
}
- distfac = sizefac * cu->textoncurve->runtime.curve_cache->path->totdist / chartrans_size_x;
+ else {
+ /* Happens when there are no characters, set this value to place the text cursor. */
+ distfac = 0.0f;
+ }
+
timeofs = 0.0f;
- if (distfac > 1.0f) {
+ if (distfac < 1.0f) {
/* Path longer than text: space-mode is involved. */
- distfac = 1.0f / distfac;
if (cu->spacemode == CU_ALIGN_X_RIGHT) {
timeofs = 1.0f - distfac;
@@ -1297,11 +1300,10 @@ static bool vfont_to_curve(Object *ob,
distfac = 1.0f;
}
}
- else {
- distfac = 1.0;
- }
- distfac /= chartrans_size_x;
+ if (chartrans_size_x != 0.0f) {
+ distfac /= chartrans_size_x;
+ }
timeofs += distfac * cu->xof; /* not cyclic */