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:
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index cbf656289b5..2ee8cf088aa 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -33,6 +33,7 @@
#include "BLI_path_util.h"
#include "BLI_rect.h"
#include "BLI_string.h"
+#include "BLI_string_cursor_utf8.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
@@ -973,9 +974,16 @@ size_t blf_str_offset_from_cursor_position(struct FontBLF *font,
.r_offset = (size_t)-1,
};
blf_font_boundbox_foreach_glyph(font, str, str_len, blf_cursor_position_foreach_glyph, &data);
+
if (data.r_offset == (size_t)-1) {
+ /* We are to the right of the string, so return position of null terminator. */
data.r_offset = BLI_strnlen(str, str_len);
}
+ else if (BLI_str_utf8_char_width(&str[data.r_offset]) < 1) {
+ /* This is a combining character (or invalid), so move to previous visible valid char. */
+ BLI_str_cursor_step_prev_utf8(str, str_len, (int *)&data.r_offset);
+ }
+
return data.r_offset;
}