[Bf-blender-cvs] [9c099985300] blender2.8: UI strings: Fix asserts in 'middle-splitting' fitting string code.
Bastien Montagne
noreply at git.blender.org
Wed Oct 3 16:28:19 CEST 2018
Commit: 9c09998530041744a183dfae3da435806272623b
Author: Bastien Montagne
Date: Wed Oct 3 16:22:10 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB9c09998530041744a183dfae3da435806272623b
UI strings: Fix asserts in 'middle-splitting' fitting string code.
The problem is that string width computing is performed in integers
(pixels), which can generate a rather annoying error (a few pixels)...
Simply work around that for now, by trimming an extra middle char when
needed.
===================================================================
M source/blender/editors/interface/interface_widgets.c
===================================================================
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 217893a4ecc..e738a3f6a6d 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1521,6 +1521,16 @@ float UI_text_clip_middle_ex(
memmove(str + l_end + sep_len, str + r_offset, r_len);
memcpy(str + l_end, sep, sep_len);
final_lpart_len = (size_t)(l_end + sep_len + r_len - 1); /* -1 to remove trailing '\0'! */
+
+ while (BLF_width(fstyle->uifont_id, str, max_len) > okwidth) {
+ /* This will happen because a lot of string width processing is done in integer pixels,
+ * which can introduce a rather high error in the end (about 2 pixels or so).
+ * Only one char removal shall ever be needed in real-life situation... */
+ r_len--;
+ final_lpart_len--;
+ char *c = str + l_end + sep_len;
+ memmove(c, c + 1, r_len);
+ }
}
}
More information about the Bf-blender-cvs
mailing list