Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/font.c
| Show All 31 Lines | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utf8.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BLI_vfontdata.h" | #include "BLI_vfontdata.h" | ||||
| #include "DNA_packedFile_types.h" | #include "DNA_packedFile_types.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "DNA_vfont_types.h" | #include "DNA_vfont_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| ▲ Show 20 Lines • Show All 637 Lines • ▼ Show 20 Lines | |||||
| #define ASCENT(vfd) ((vfd)->ascender * (vfd)->em_height) | #define ASCENT(vfd) ((vfd)->ascender * (vfd)->em_height) | ||||
| #define DESCENT(vfd) ((vfd)->em_height - ASCENT(vfd)) | #define DESCENT(vfd) ((vfd)->em_height - ASCENT(vfd)) | ||||
| static bool vfont_to_curve(Object *ob, | static bool vfont_to_curve(Object *ob, | ||||
| Curve *cu, | Curve *cu, | ||||
| int mode, | int mode, | ||||
| VFontToCurveIter *iter_data, | VFontToCurveIter *iter_data, | ||||
| ListBase *r_nubase, | ListBase *r_nubase, | ||||
| const wchar_t **r_text, | const BLI_unicode **r_text, | ||||
| int *r_text_len, | int *r_text_len, | ||||
| bool *r_text_free, | bool *r_text_free, | ||||
| struct CharTrans **r_chartransdata) | struct CharTrans **r_chartransdata) | ||||
| { | { | ||||
| EditFont *ef = cu->editfont; | EditFont *ef = cu->editfont; | ||||
| EditFontSelBox *selboxes = NULL; | EditFontSelBox *selboxes = NULL; | ||||
| VFont *vfont, *oldvfont; | VFont *vfont, *oldvfont; | ||||
| VFontData *vfd = NULL; | VFontData *vfd = NULL; | ||||
| CharInfo *info = NULL, *custrinfo; | CharInfo *info = NULL, *custrinfo; | ||||
| TextBox tb_scale; | TextBox tb_scale; | ||||
| bool use_textbox; | bool use_textbox; | ||||
| VChar *che; | VChar *che; | ||||
| struct CharTrans *chartransdata = NULL, *ct; | struct CharTrans *chartransdata = NULL, *ct; | ||||
| struct TempLineInfo *lineinfo; | struct TempLineInfo *lineinfo; | ||||
| float *f, xof, yof, xtrax, linedist; | float *f, xof, yof, xtrax, linedist; | ||||
| float twidth = 0, maxlen = 0; | float twidth = 0, maxlen = 0; | ||||
| int i, slen, j; | int i, slen, j; | ||||
| int curbox; | int curbox; | ||||
| int selstart, selend; | int selstart, selend; | ||||
| int cnr = 0, lnr = 0, wsnr = 0; | int cnr = 0, lnr = 0, wsnr = 0; | ||||
| const wchar_t *mem = NULL; | const BLI_unicode *mem = NULL; | ||||
| wchar_t ascii; | BLI_unicode ascii; | ||||
| bool ok = false; | bool ok = false; | ||||
| const float font_size = cu->fsize * iter_data->scale_to_fit; | const float font_size = cu->fsize * iter_data->scale_to_fit; | ||||
| const float xof_scale = cu->xof / font_size; | const float xof_scale = cu->xof / font_size; | ||||
| const float yof_scale = cu->yof / font_size; | const float yof_scale = cu->yof / font_size; | ||||
| int last_line = -1; | int last_line = -1; | ||||
| /* Length of the text disregarding \n breaks. */ | /* Length of the text disregarding \n breaks. */ | ||||
| float current_line_length = 0.0f; | float current_line_length = 0.0f; | ||||
| float longest_line_length = 0.0f; | float longest_line_length = 0.0f; | ||||
| Show All 29 Lines | #define MARGIN_Y_MIN (yof_scale + tb_scale.y) | ||||
| } | } | ||||
| if (ef) { | if (ef) { | ||||
| slen = ef->len; | slen = ef->len; | ||||
| mem = ef->textbuf; | mem = ef->textbuf; | ||||
| custrinfo = ef->textbufinfo; | custrinfo = ef->textbufinfo; | ||||
| } | } | ||||
| else { | else { | ||||
| wchar_t *mem_tmp; | BLI_unicode *mem_tmp; | ||||
| slen = cu->len_wchar; | slen = cu->len_wchar; | ||||
| /* Create unicode string */ | /* Create unicode string */ | ||||
| mem_tmp = MEM_malloc_arrayN((slen + 1), sizeof(wchar_t), "convertedmem"); | mem_tmp = MEM_malloc_arrayN((slen + 1), sizeof(*mem_tmp), "convertedmem"); | ||||
| if (!mem_tmp) { | if (!mem_tmp) { | ||||
| return ok; | return ok; | ||||
| } | } | ||||
| BLI_strncpy_wchar_from_utf8(mem_tmp, cu->str, slen + 1); | BLI_str_utf8_as_unicode_array(mem_tmp, cu->str, slen + 1); | ||||
| if (cu->strinfo == NULL) { /* old file */ | if (cu->strinfo == NULL) { /* old file */ | ||||
| cu->strinfo = MEM_calloc_arrayN((slen + 4), sizeof(CharInfo), "strinfo compat"); | cu->strinfo = MEM_calloc_arrayN((slen + 4), sizeof(CharInfo), "strinfo compat"); | ||||
| } | } | ||||
| custrinfo = cu->strinfo; | custrinfo = cu->strinfo; | ||||
| if (!custrinfo) { | if (!custrinfo) { | ||||
| return ok; | return ok; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 820 Lines • ▼ Show 20 Lines | |||||
| #undef DESCENT | #undef DESCENT | ||||
| #undef ASCENT | #undef ASCENT | ||||
| bool BKE_vfont_to_curve_ex(Object *ob, | bool BKE_vfont_to_curve_ex(Object *ob, | ||||
| Curve *cu, | Curve *cu, | ||||
| int mode, | int mode, | ||||
| ListBase *r_nubase, | ListBase *r_nubase, | ||||
| const wchar_t **r_text, | const BLI_unicode **r_text, | ||||
| int *r_text_len, | int *r_text_len, | ||||
| bool *r_text_free, | bool *r_text_free, | ||||
| struct CharTrans **r_chartransdata) | struct CharTrans **r_chartransdata) | ||||
| { | { | ||||
| VFontToCurveIter data = { | VFontToCurveIter data = { | ||||
| .iteraction = cu->totbox * FONT_TO_CURVE_SCALE_ITERATIONS, | .iteraction = cu->totbox * FONT_TO_CURVE_SCALE_ITERATIONS, | ||||
| .scale_to_fit = 1.0f, | .scale_to_fit = 1.0f, | ||||
| .ok = true, | .ok = true, | ||||
| Show All 27 Lines | bool BKE_vfont_to_curve(Object *ob, int mode) | ||||
| return BKE_vfont_to_curve_ex(ob, ob->data, mode, &cu->nurb, NULL, NULL, NULL, NULL); | return BKE_vfont_to_curve_ex(ob, ob->data, mode, &cu->nurb, NULL, NULL, NULL, NULL); | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name VFont Clipboard | /** \name VFont Clipboard | ||||
| * \{ */ | * \{ */ | ||||
| static struct { | static struct { | ||||
| wchar_t *text_buffer; | BLI_unicode *text_buffer; | ||||
| CharInfo *info_buffer; | CharInfo *info_buffer; | ||||
| size_t len_wchar; | size_t len_wchar; | ||||
| size_t len_utf8; | size_t len_utf8; | ||||
| } g_vfont_clipboard = {NULL}; | } g_vfont_clipboard = {NULL}; | ||||
| void BKE_vfont_clipboard_free(void) | void BKE_vfont_clipboard_free(void) | ||||
| { | { | ||||
| MEM_SAFE_FREE(g_vfont_clipboard.text_buffer); | MEM_SAFE_FREE(g_vfont_clipboard.text_buffer); | ||||
| MEM_SAFE_FREE(g_vfont_clipboard.info_buffer); | MEM_SAFE_FREE(g_vfont_clipboard.info_buffer); | ||||
| g_vfont_clipboard.len_wchar = 0; | g_vfont_clipboard.len_wchar = 0; | ||||
| g_vfont_clipboard.len_utf8 = 0; | g_vfont_clipboard.len_utf8 = 0; | ||||
| } | } | ||||
| void BKE_vfont_clipboard_set(const wchar_t *text_buf, const CharInfo *info_buf, const size_t len) | void BKE_vfont_clipboard_set(const BLI_unicode *text_buf, | ||||
| const CharInfo *info_buf, | |||||
| const size_t len) | |||||
| { | { | ||||
| wchar_t *text; | BLI_unicode *text; | ||||
| CharInfo *info; | CharInfo *info; | ||||
| /* clean previous buffers*/ | /* clean previous buffers*/ | ||||
| BKE_vfont_clipboard_free(); | BKE_vfont_clipboard_free(); | ||||
| text = MEM_malloc_arrayN((len + 1), sizeof(wchar_t), __func__); | text = MEM_malloc_arrayN((len + 1), sizeof(wchar_t), __func__); | ||||
| if (text == NULL) { | if (text == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| info = MEM_malloc_arrayN(len, sizeof(CharInfo), __func__); | info = MEM_malloc_arrayN(len, sizeof(CharInfo), __func__); | ||||
| if (info == NULL) { | if (info == NULL) { | ||||
| MEM_freeN(text); | MEM_freeN(text); | ||||
| return; | return; | ||||
| } | } | ||||
| memcpy(text, text_buf, len * sizeof(wchar_t)); | memcpy(text, text_buf, len * sizeof(*text)); | ||||
| text[len] = '\0'; | text[len] = '\0'; | ||||
| memcpy(info, info_buf, len * sizeof(CharInfo)); | memcpy(info, info_buf, len * sizeof(CharInfo)); | ||||
| /* store new buffers */ | /* store new buffers */ | ||||
| g_vfont_clipboard.text_buffer = text; | g_vfont_clipboard.text_buffer = text; | ||||
| g_vfont_clipboard.info_buffer = info; | g_vfont_clipboard.info_buffer = info; | ||||
| g_vfont_clipboard.len_utf8 = BLI_wstrlen_utf8(text); | g_vfont_clipboard.len_utf8 = BLI_unicode_array_utf8_len(text); | ||||
| g_vfont_clipboard.len_wchar = len; | g_vfont_clipboard.len_wchar = len; | ||||
| } | } | ||||
| void BKE_vfont_clipboard_get(wchar_t **r_text_buf, | void BKE_vfont_clipboard_get(BLI_unicode **r_text_buf, | ||||
| CharInfo **r_info_buf, | CharInfo **r_info_buf, | ||||
| size_t *r_len_utf8, | size_t *r_len_utf8, | ||||
| size_t *r_len_wchar) | size_t *r_len_wchar) | ||||
| { | { | ||||
| if (r_text_buf) { | if (r_text_buf) { | ||||
| *r_text_buf = g_vfont_clipboard.text_buffer; | *r_text_buf = g_vfont_clipboard.text_buffer; | ||||
| } | } | ||||
| Show All 14 Lines | |||||