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 10:04:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-03 10:08:23 +0400
commit15bc30f4ee49c69f3ed6f92701a0f5cd52d306c5 (patch)
treefc77fe7096673256d90c512267adb58eb53c23de /source/blender/makesrna/intern/rna_curve.c
parenta5cb2229abbc7d43f34dabea332afd33614fc0db (diff)
Text3d: store number of characters and utf8 length separately
EditFont's use of Curve.len was very confusing, in editmode it represented the number of characters, in object mode the number of bytes. add Curve.len_wchar and keep track of both. Also don't convert the editmode text into utf8 on every keystroke. Now this is done on exiting editmode or save - to match most other object types. This also fixes curves 'body_format' being reported with an invalid size.
Diffstat (limited to 'source/blender/makesrna/intern/rna_curve.c')
-rw-r--r--source/blender/makesrna/intern/rna_curve.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c
index da5b6676cb9..97c1725ff01 100644
--- a/source/blender/makesrna/intern/rna_curve.c
+++ b/source/blender/makesrna/intern/rna_curve.c
@@ -448,28 +448,29 @@ static void rna_Curve_body_get(PointerRNA *ptr, char *value)
static int rna_Curve_body_length(PointerRNA *ptr)
{
Curve *cu = (Curve *)ptr->id.data;
- return cu->editfont ? strlen(cu->str) : cu->len;
+ return cu->len;
}
-/* TODO - check UTF & python play nice */
+/* TODO, how to handle editmode? */
static void rna_Curve_body_set(PointerRNA *ptr, const char *value)
{
- int len = strlen(value);
+ size_t len_bytes;
+ size_t len_chars = BLI_strlen_utf8_ex(value, &len_bytes);
+
Curve *cu = (Curve *)ptr->id.data;
- cu->len = cu->pos = len;
+ cu->len = len_bytes;
+ cu->pos = len_chars;
if (cu->str)
MEM_freeN(cu->str);
if (cu->strinfo)
MEM_freeN(cu->strinfo);
- cu->str = MEM_callocN(len + sizeof(wchar_t), "str");
- /* don't know why this is +4, just duplicating load_editText() */
- cu->strinfo = MEM_callocN((len + 4) * sizeof(CharInfo), "strinfo");
+ cu->str = MEM_mallocN(len_bytes + sizeof(wchar_t), "str");
+ cu->strinfo = MEM_callocN((len_chars + 4) * sizeof(CharInfo), "strinfo");
- /*BLI_strncpy_wchar_as_utf8(cu->str, value, len + 1); *//* value is not wchar_t */
- BLI_strncpy(cu->str, value, len + 1);
+ BLI_strncpy(cu->str, value, len_bytes + 1);
}
static void rna_Nurb_update_cyclic_u(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -1021,7 +1022,7 @@ static void rna_def_font(BlenderRNA *UNUSED(brna), StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
prop = RNA_def_property(srna, "body_format", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "strinfo", "len");
+ RNA_def_property_collection_sdna(prop, NULL, "strinfo", "len_wchar");
RNA_def_property_struct_type(prop, "TextCharacterFormat");
RNA_def_property_ui_text(prop, "Character Info", "Stores the style of each character");