Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/curve/editfont.c
| Show First 20 Lines • Show All 482 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Generic Paste Functions | /** \name Generic Paste Functions | ||||
| * \{ */ | * \{ */ | ||||
| /* text_update_edited(C, scene, obedit, 1, FO_EDIT); */ | /* text_update_edited(C, scene, obedit, 1, FO_EDIT); */ | ||||
| static bool font_paste_wchar(Object *obedit, | static bool font_paste_wchar(Object *obedit, | ||||
| const wchar_t *str, | const BLI_unicode *str, | ||||
| const size_t str_len, | const size_t str_len, | ||||
| /* optional */ | /* optional */ | ||||
| struct CharInfo *str_info) | struct CharInfo *str_info) | ||||
| { | { | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| int selend, selstart; | int selend, selstart; | ||||
| Show All 33 Lines | |||||
| static bool font_paste_utf8(bContext *C, const char *str, const size_t str_len) | static bool font_paste_utf8(bContext *C, const char *str, const size_t str_len) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| bool retval; | bool retval; | ||||
| int tmplen; | int tmplen; | ||||
| wchar_t *mem = MEM_mallocN((sizeof(wchar_t) * (str_len + 1)), __func__); | BLI_unicode *mem = MEM_mallocN((sizeof(*mem) * (str_len + 1)), __func__); | ||||
| tmplen = BLI_strncpy_wchar_from_utf8(mem, str, str_len + 1); | tmplen = BLI_str_utf8_as_unicode_array(mem, str, str_len + 1); | ||||
| retval = font_paste_wchar(obedit, mem, tmplen, NULL); | retval = font_paste_wchar(obedit, mem, tmplen, NULL); | ||||
| MEM_freeN(mem); | MEM_freeN(mem); | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | |||||
| static void copy_selection(Object *obedit) | static void copy_selection(Object *obedit) | ||||
| { | { | ||||
| int selstart, selend; | int selstart, selend; | ||||
| if (BKE_vfont_select_get(obedit, &selstart, &selend)) { | if (BKE_vfont_select_get(obedit, &selstart, &selend)) { | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| char *buf = NULL; | char *buf = NULL; | ||||
| wchar_t *text_buf; | BLI_unicode *text_buf; | ||||
| size_t len_utf8; | size_t len_utf8; | ||||
| /* internal clipboard (for style) */ | /* internal clipboard (for style) */ | ||||
| BKE_vfont_clipboard_set( | BKE_vfont_clipboard_set( | ||||
| ef->textbuf + selstart, ef->textbufinfo + selstart, selend - selstart + 1); | ef->textbuf + selstart, ef->textbufinfo + selstart, selend - selstart + 1); | ||||
| BKE_vfont_clipboard_get(&text_buf, NULL, &len_utf8, NULL); | BKE_vfont_clipboard_get(&text_buf, NULL, &len_utf8, NULL); | ||||
| /* system clipboard */ | /* system clipboard */ | ||||
| buf = MEM_mallocN(len_utf8 + 1, __func__); | buf = MEM_mallocN(len_utf8 + 1, __func__); | ||||
| if (buf) { | if (buf) { | ||||
| BLI_strncpy_wchar_as_utf8(buf, text_buf, len_utf8 + 1); | BLI_unicode_array_as_str_utf8(buf, text_buf, len_utf8 + 1); | ||||
| WM_clipboard_text_set(buf, false); | WM_clipboard_text_set(buf, false); | ||||
| MEM_freeN(buf); | MEM_freeN(buf); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int copy_text_exec(bContext *C, wmOperator *UNUSED(op)) | static int copy_text_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Paste Text Operator | /** \name Paste Text Operator | ||||
| * \{ */ | * \{ */ | ||||
| static bool paste_selection(Object *obedit, ReportList *reports) | static bool paste_selection(Object *obedit, ReportList *reports) | ||||
| { | { | ||||
| wchar_t *text_buf; | BLI_unicode *text_buf; | ||||
| CharInfo *info_buf; | CharInfo *info_buf; | ||||
| size_t len; | size_t len; | ||||
| BKE_vfont_clipboard_get(&text_buf, &info_buf, NULL, &len); | BKE_vfont_clipboard_get(&text_buf, &info_buf, NULL, &len); | ||||
| if (font_paste_wchar(obedit, text_buf, len, info_buf)) { | if (font_paste_wchar(obedit, text_buf, len, info_buf)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_report(reports, RPT_WARNING, "Text too long"); | BKE_report(reports, RPT_WARNING, "Text too long"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| static int paste_text_exec(bContext *C, wmOperator *op) | static int paste_text_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| int retval; | int retval; | ||||
| size_t len_utf8; | size_t len_utf8; | ||||
| wchar_t *text_buf; | BLI_unicode *text_buf; | ||||
| /* Store both clipboards as utf8 for comparison, | /* Store both clipboards as utf8 for comparison, | ||||
| * Give priority to the internal 'vfont' clipboard with its 'CharInfo' text styles | * Give priority to the internal 'vfont' clipboard with its 'CharInfo' text styles | ||||
| * as long as its synchronized with the systems clipboard. */ | * as long as its synchronized with the systems clipboard. */ | ||||
| struct { | struct { | ||||
| char *buf; | char *buf; | ||||
| int len; | int len; | ||||
| } clipboard_system = {NULL}, clipboard_vfont = {NULL}; | } clipboard_system = {NULL}, clipboard_vfont = {NULL}; | ||||
| Show All 9 Lines | static int paste_text_exec(bContext *C, wmOperator *op) | ||||
| if (text_buf) { | if (text_buf) { | ||||
| clipboard_vfont.buf = MEM_mallocN(len_utf8 + 1, __func__); | clipboard_vfont.buf = MEM_mallocN(len_utf8 + 1, __func__); | ||||
| if (clipboard_vfont.buf == NULL) { | if (clipboard_vfont.buf == NULL) { | ||||
| MEM_freeN(clipboard_system.buf); | MEM_freeN(clipboard_system.buf); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| BLI_strncpy_wchar_as_utf8(clipboard_vfont.buf, text_buf, len_utf8 + 1); | BLI_unicode_array_as_str_utf8(clipboard_vfont.buf, text_buf, len_utf8 + 1); | ||||
| } | } | ||||
| if (clipboard_vfont.buf && STREQ(clipboard_vfont.buf, clipboard_system.buf)) { | if (clipboard_vfont.buf && STREQ(clipboard_vfont.buf, clipboard_system.buf)) { | ||||
| retval = paste_selection(obedit, op->reports) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | retval = paste_selection(obedit, op->reports) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | else { | ||||
| if ((clipboard_system.len <= MAXTEXT) && | if ((clipboard_system.len <= MAXTEXT) && | ||||
| font_paste_utf8(C, clipboard_system.buf, clipboard_system.len)) { | font_paste_utf8(C, clipboard_system.buf, clipboard_system.len)) { | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | case LINE_END: | ||||
| } | } | ||||
| ef->pos++; | ef->pos++; | ||||
| } | } | ||||
| cursmove = FO_CURS; | cursmove = FO_CURS; | ||||
| break; | break; | ||||
| case PREV_WORD: { | case PREV_WORD: { | ||||
| int pos = ef->pos; | int pos = ef->pos; | ||||
| BLI_str_cursor_step_wchar( | BLI_str_cursor_step_unicode( | ||||
| ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); | ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); | ||||
| ef->pos = pos; | ef->pos = pos; | ||||
| cursmove = FO_CURS; | cursmove = FO_CURS; | ||||
| break; | break; | ||||
| } | } | ||||
| case NEXT_WORD: { | case NEXT_WORD: { | ||||
| int pos = ef->pos; | int pos = ef->pos; | ||||
| BLI_str_cursor_step_wchar( | BLI_str_cursor_step_unicode( | ||||
| ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); | ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); | ||||
| ef->pos = pos; | ef->pos = pos; | ||||
| cursmove = FO_CURS; | cursmove = FO_CURS; | ||||
| break; | break; | ||||
| } | } | ||||
| case PREV_CHAR: | case PREV_CHAR: | ||||
| ef->pos--; | ef->pos--; | ||||
| ▲ Show 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | case DEL_NEXT_CHAR: | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| range[0] = ef->pos; | range[0] = ef->pos; | ||||
| range[1] = ef->pos + 1; | range[1] = ef->pos + 1; | ||||
| break; | break; | ||||
| case DEL_NEXT_WORD: { | case DEL_NEXT_WORD: { | ||||
| int pos = ef->pos; | int pos = ef->pos; | ||||
| BLI_str_cursor_step_wchar( | BLI_str_cursor_step_unicode( | ||||
| ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); | ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); | ||||
| range[0] = ef->pos; | range[0] = ef->pos; | ||||
| range[1] = pos; | range[1] = pos; | ||||
| break; | break; | ||||
| } | } | ||||
| case DEL_PREV_WORD: { | case DEL_PREV_WORD: { | ||||
| int pos = ef->pos; | int pos = ef->pos; | ||||
| BLI_str_cursor_step_wchar( | BLI_str_cursor_step_unicode( | ||||
| ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); | ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); | ||||
| range[0] = pos; | range[0] = pos; | ||||
| range[1] = ef->pos; | range[1] = ef->pos; | ||||
| ef->pos = pos; | ef->pos = pos; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | void ED_curve_editfont_make(Object *obedit) | ||||
| if (ef == NULL) { | if (ef == NULL) { | ||||
| ef = cu->editfont = MEM_callocN(sizeof(EditFont), "editfont"); | ef = cu->editfont = MEM_callocN(sizeof(EditFont), "editfont"); | ||||
| ef->textbuf = MEM_callocN((MAXTEXT + 4) * sizeof(wchar_t), "texteditbuf"); | ef->textbuf = MEM_callocN((MAXTEXT + 4) * sizeof(wchar_t), "texteditbuf"); | ||||
| ef->textbufinfo = MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "texteditbufinfo"); | ef->textbufinfo = MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "texteditbufinfo"); | ||||
| } | } | ||||
| /* Convert the original text to wchar_t */ | /* Convert the original text to wchar_t */ | ||||
| len_wchar = BLI_strncpy_wchar_from_utf8(ef->textbuf, cu->str, MAXTEXT + 4); | len_wchar = BLI_str_utf8_as_unicode_array(ef->textbuf, cu->str, MAXTEXT + 4); | ||||
| BLI_assert(len_wchar == cu->len_wchar); | BLI_assert(len_wchar == cu->len_wchar); | ||||
| ef->len = len_wchar; | ef->len = len_wchar; | ||||
| BLI_assert(ef->len >= 0); | BLI_assert(ef->len >= 0); | ||||
| memcpy(ef->textbufinfo, cu->strinfo, ef->len * sizeof(CharInfo)); | memcpy(ef->textbufinfo, cu->strinfo, ef->len * sizeof(CharInfo)); | ||||
| ef->pos = cu->pos; | ef->pos = cu->pos; | ||||
| if (ef->pos > ef->len) { | if (ef->pos > ef->len) { | ||||
| Show All 15 Lines | void ED_curve_editfont_load(Object *obedit) | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| /* Free the old curve string */ | /* Free the old curve string */ | ||||
| MEM_freeN(cu->str); | MEM_freeN(cu->str); | ||||
| /* Calculate the actual string length in UTF-8 variable characters */ | /* Calculate the actual string length in UTF-8 variable characters */ | ||||
| cu->len_wchar = ef->len; | cu->len_wchar = ef->len; | ||||
| cu->len = BLI_wstrlen_utf8(ef->textbuf); | cu->len = BLI_unicode_array_utf8_len(ef->textbuf); | ||||
| /* Alloc memory for UTF-8 variable char length string */ | /* Alloc memory for UTF-8 variable char length string */ | ||||
| cu->str = MEM_mallocN(cu->len + sizeof(wchar_t), "str"); | cu->str = MEM_mallocN(cu->len + sizeof(wchar_t), "str"); | ||||
| /* Copy the wchar to UTF-8 */ | /* Copy the wchar to UTF-8 */ | ||||
| BLI_strncpy_wchar_as_utf8(cu->str, ef->textbuf, cu->len + 1); | BLI_unicode_array_as_str_utf8(cu->str, ef->textbuf, cu->len + 1); | ||||
| if (cu->strinfo) { | if (cu->strinfo) { | ||||
| MEM_freeN(cu->strinfo); | MEM_freeN(cu->strinfo); | ||||
| } | } | ||||
| cu->strinfo = MEM_callocN((cu->len_wchar + 4) * sizeof(CharInfo), "texteditinfo"); | cu->strinfo = MEM_callocN((cu->len_wchar + 4) * sizeof(CharInfo), "texteditinfo"); | ||||
| memcpy(cu->strinfo, ef->textbufinfo, cu->len_wchar * sizeof(CharInfo)); | memcpy(cu->strinfo, ef->textbufinfo, cu->len_wchar * sizeof(CharInfo)); | ||||
| /* Other vars */ | /* Other vars */ | ||||
| Show All 19 Lines | static const EnumPropertyItem case_items[] = { | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| static int set_case(bContext *C, int ccase) | static int set_case(bContext *C, int ccase) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| wchar_t *str; | BLI_unicode *str; | ||||
| int len; | int len; | ||||
| int selstart, selend; | int selstart, selend; | ||||
| if (BKE_vfont_select_get(obedit, &selstart, &selend)) { | if (BKE_vfont_select_get(obedit, &selstart, &selend)) { | ||||
| len = (selend - selstart) + 1; | len = (selend - selstart) + 1; | ||||
| str = &ef->textbuf[selstart]; | str = &ef->textbuf[selstart]; | ||||
| while (len) { | while (len) { | ||||
| if (*str >= 'a' && *str <= 'z') { | if (*str >= 'a' && *str <= 'z') { | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| /** \name Toggle Case Operator | /** \name Toggle Case Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int toggle_case_exec(bContext *C, wmOperator *UNUSED(op)) | static int toggle_case_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| wchar_t *str; | BLI_unicode *str; | ||||
| int len, ccase = CASE_UPPER; | int ccase = CASE_UPPER; | ||||
| len = wcslen(ef->textbuf); | |||||
| str = ef->textbuf; | str = ef->textbuf; | ||||
| while (len) { | while (*str) { | ||||
| if (*str >= 'a' && *str <= 'z') { | if (*str >= 'a' && *str <= 'z') { | ||||
| ccase = CASE_LOWER; | ccase = CASE_LOWER; | ||||
| break; | break; | ||||
| } | } | ||||
| len--; | |||||
| str++; | str++; | ||||
| } | } | ||||
| return set_case(C, ccase); | return set_case(C, ccase); | ||||
| } | } | ||||
| void FONT_OT_case_toggle(wmOperatorType *ot) | void FONT_OT_case_toggle(wmOperatorType *ot) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines | |||||