forked from bartvdbraak/blender
Text3d: avoid converting utf8 to wchar_t in editmode
This commit is contained in:
parent
f345414b89
commit
a5cb2229ab
@ -77,7 +77,8 @@ void BKE_vfont_free(struct VFont *sc);
|
||||
struct VFont *BKE_vfont_builtin_get(void);
|
||||
struct VFont *BKE_vfont_load(struct Main *bmain, const char *name);
|
||||
|
||||
struct CharTrans *BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode);
|
||||
bool BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode,
|
||||
struct CharTrans **r_chartransdata);
|
||||
|
||||
int BKE_vfont_select_get(struct Object *ob, int *start, int *end);
|
||||
|
||||
|
@ -1613,7 +1613,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int persiste
|
||||
{
|
||||
Object *ob, *obar[256] = {NULL};
|
||||
Curve *cu;
|
||||
struct CharTrans *ct, *chartransdata;
|
||||
struct CharTrans *ct, *chartransdata = NULL;
|
||||
float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof;
|
||||
int slen, a;
|
||||
|
||||
@ -1624,7 +1624,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int persiste
|
||||
|
||||
/* in par the family name is stored, use this to find the other objects */
|
||||
|
||||
chartransdata = BKE_vfont_to_curve(G.main, scene, par, FO_DUPLI);
|
||||
BKE_vfont_to_curve(G.main, scene, par, FO_DUPLI, &chartransdata);
|
||||
if (chartransdata == NULL) return;
|
||||
|
||||
cu = par->data;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_vfont_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_memarena.h"
|
||||
@ -1374,7 +1375,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
|
||||
ob->curve_cache->path = NULL;
|
||||
|
||||
if (ob->type == OB_FONT)
|
||||
BKE_vfont_to_curve(G.main, scene, ob, 0);
|
||||
BKE_vfont_to_curve(G.main, scene, ob, FO_EDIT, NULL);
|
||||
|
||||
BKE_nurbList_duplicate(&nubase, BKE_curve_nurbs_get(cu));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
/* Create unicode string */
|
||||
utf8len = BLI_strlen_utf8(cu->str);
|
||||
mem = MEM_mallocN(((utf8len + 1) * sizeof(wchar_t)), "convertedmem");
|
||||
|
||||
slen = BLI_strncpy_wchar_from_utf8(mem, cu->str, utf8len + 1);
|
||||
|
||||
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)
|
||||
custrinfo = cu->editfont->textbufinfo;
|
||||
|
||||
if (cu->tb == NULL)
|
||||
cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat");
|
||||
if (cu->str == NULL) return ok;
|
||||
if (vfont == NULL) return ok;
|
||||
|
||||
vfd = vfont_get_data(bmain, vfont);
|
||||
|
||||
/* The VFont Data can not be found */
|
||||
if (!vfd) {
|
||||
if (mem)
|
||||
MEM_freeN(mem);
|
||||
return NULL;
|
||||
if (!vfd) return ok;
|
||||
|
||||
if (cu->ulheight == 0.0f)
|
||||
cu->ulheight = 0.05f;
|
||||
|
||||
if (cu->editfont) {
|
||||
slen = cu->len;
|
||||
mem = cu->editfont->textbuf;
|
||||
custrinfo = cu->editfont->textbufinfo;
|
||||
}
|
||||
else {
|
||||
size_t utf8len;
|
||||
|
||||
utf8len = BLI_strlen_utf8(cu->str);
|
||||
|
||||
/* 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) {
|
||||
ok = true;
|
||||
|
||||
finally:
|
||||
|
||||
if (cu->editfont == NULL)
|
||||
MEM_freeN(mem);
|
||||
return chartransdata;
|
||||
|
||||
if (r_chartransdata) {
|
||||
*r_chartransdata = chartransdata;
|
||||
}
|
||||
|
||||
if (mem)
|
||||
MEM_freeN(mem);
|
||||
|
||||
else {
|
||||
MEM_freeN(chartransdata);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ static void text_update_edited(bContext *C, Scene *scene, Object *obedit, int re
|
||||
if (mode == FO_EDIT)
|
||||
update_string(cu);
|
||||
|
||||
BKE_vfont_to_curve(bmain, scene, obedit, mode);
|
||||
BKE_vfont_to_curve(bmain, scene, obedit, mode, NULL);
|
||||
|
||||
if (recalc)
|
||||
DAG_id_tag_update(obedit->data, 0);
|
||||
@ -955,7 +955,7 @@ static int move_cursor(bContext *C, int type, int select)
|
||||
struct Main *bmain = CTX_data_main(C);
|
||||
cu->selstart = cu->selend = 0;
|
||||
update_string(cu);
|
||||
BKE_vfont_to_curve(bmain, scene, obedit, FO_SELCHANGE);
|
||||
BKE_vfont_to_curve(bmain, scene, obedit, FO_SELCHANGE, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -931,7 +931,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
|
||||
cu1->vfontbi = cu->vfontbi;
|
||||
id_us_plus((ID *)cu1->vfontbi);
|
||||
|
||||
BKE_vfont_to_curve(bmain, scene, base->object, 0); /* needed? */
|
||||
BKE_vfont_to_curve(bmain, scene, base->object, FO_EDIT, NULL); /* needed? */
|
||||
|
||||
|
||||
BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
|
||||
|
@ -280,7 +280,7 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
|
||||
if (ob->type == OB_FONT) {
|
||||
Curve *cu = ob->data;
|
||||
freedisplist(&cu->disp);
|
||||
BKE_vfont_to_curve(sce, ob, CU_LEFT);
|
||||
BKE_vfont_to_curve(bmain, sce, ob, FO_EDIT, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user