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>2014-01-03 07:18:06 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-03 07:20:35 +0400
commita5cb2229abbc7d43f34dabea332afd33614fc0db (patch)
tree3b039eeccbcc69589b0c9ac98245f941435b9fcd /source/blender/blenkernel/intern/font.c
parentf345414b89a9d94cca668c10ce8f0464d06dea4f (diff)
Text3d: avoid converting utf8 to wchar_t in editmode
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r--source/blender/blenkernel/intern/font.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 63095091fa6..90362c7a3ad 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -494,7 +494,8 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info)
}
}
-struct CharTrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode)
+bool BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode,
+ struct CharTrans **r_chartransdata)
{
VFont *vfont, *oldvfont;
VFontData *vfd = NULL;
@@ -508,53 +509,56 @@ struct CharTrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int
int i, slen, j;
int curbox;
int selstart, selend;
- int utf8len;
short cnr = 0, lnr = 0, wsnr = 0;
wchar_t *mem, *tmp, ascii;
+ bool ok = false;
/* remark: do calculations including the trailing '\0' of a string
* because the cursor can be at that location */
- if (ob->type != OB_FONT) return NULL;
+ BLI_assert(ob->type == OB_FONT);
/* Set font data */
cu = (Curve *) ob->data;
vfont = cu->vfont;
- if (cu->str == NULL) return NULL;
- if (vfont == NULL) return NULL;
+ if (cu->str == NULL) return ok;
+ if (vfont == NULL) return ok;
- /* Create unicode string */
- utf8len = BLI_strlen_utf8(cu->str);
- mem = MEM_mallocN(((utf8len + 1) * sizeof(wchar_t)), "convertedmem");
+ vfd = vfont_get_data(bmain, vfont);
- slen = BLI_strncpy_wchar_from_utf8(mem, cu->str, utf8len + 1);
+ /* The VFont Data can not be found */
+ if (!vfd) return ok;
if (cu->ulheight == 0.0f)
cu->ulheight = 0.05f;
- if (cu->strinfo == NULL) /* old file */
- cu->strinfo = MEM_callocN((slen + 4) * sizeof(CharInfo), "strinfo compat");
-
- custrinfo = cu->strinfo;
- if (cu->editfont)
+ if (cu->editfont) {
+ slen = cu->len;
+ mem = cu->editfont->textbuf;
custrinfo = cu->editfont->textbufinfo;
-
- if (cu->tb == NULL)
- cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat");
+ }
+ else {
+ size_t utf8len;
- vfd = vfont_get_data(bmain, vfont);
+ utf8len = BLI_strlen_utf8(cu->str);
- /* The VFont Data can not be found */
- if (!vfd) {
- if (mem)
- MEM_freeN(mem);
- return NULL;
+ /* Create unicode string */
+ mem = MEM_mallocN(((utf8len + 1) * sizeof(wchar_t)), "convertedmem");
+
+ slen = BLI_strncpy_wchar_from_utf8(mem, cu->str, utf8len + 1);
+
+ if (cu->strinfo == NULL) { /* old file */
+ cu->strinfo = MEM_callocN((slen + 4) * sizeof(CharInfo), "strinfo compat");
+ }
+ custrinfo = cu->strinfo;
}
+ if (cu->tb == NULL)
+ cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat");
+
/* calc offset and rotation of each char */
- ct = chartransdata =
- (struct CharTrans *)MEM_callocN((slen + 1) * sizeof(struct CharTrans), "buildtext");
+ ct = chartransdata = MEM_callocN((slen + 1) * sizeof(struct CharTrans), "buildtext");
/* We assume the worst case: 1 character per line (is freed at end anyway) */
@@ -628,10 +632,9 @@ makebreak:
/* No VFont found */
if (vfont == NULL) {
- if (mem)
- MEM_freeN(mem);
MEM_freeN(chartransdata);
- return NULL;
+ chartransdata = NULL;
+ goto finally;
}
if (vfont != oldvfont) {
@@ -641,10 +644,9 @@ makebreak:
/* VFont Data for VFont couldn't be found */
if (!vfd) {
- if (mem)
- MEM_freeN(mem);
MEM_freeN(chartransdata);
- return NULL;
+ chartransdata = NULL;
+ goto finally;
}
twidth = char_width(cu, che, info);
@@ -1010,8 +1012,8 @@ makebreak:
if (mode == FO_SELCHANGE) {
MEM_freeN(chartransdata);
- MEM_freeN(mem);
- return NULL;
+ chartransdata = NULL;
+ goto finally;
}
if (mode == FO_EDIT) {
@@ -1080,14 +1082,19 @@ makebreak:
}
}
- if (mode == FO_DUPLI) {
- MEM_freeN(mem);
- return chartransdata;
- }
+ ok = true;
+
+finally:
- if (mem)
+ if (cu->editfont == NULL)
MEM_freeN(mem);
- MEM_freeN(chartransdata);
- return NULL;
+ if (r_chartransdata) {
+ *r_chartransdata = chartransdata;
+ }
+ else {
+ MEM_freeN(chartransdata);
+ }
+
+ return ok;
}