diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2016-02-12 15:57:58 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2016-02-12 16:05:05 +0300 |
commit | a143aeaeae5fa52a8dff012b5e36d43f969c891e (patch) | |
tree | 8d8d36c49b5f32a3be88fd8927ceec4d1678e77d /source/blender/blenkernel/intern/font.c | |
parent | 9c21015c26564504fda20f09b510f2d81a51bbfc (diff) |
Integrate font objects copy/paste with system clipboard
When pasting text, the style (bold, material, ...) is maintained, if it was originally copied from Blender.
This fixes the issue of missing copy/paste options for font objects
(they were present back in Blender 2.49)
Reviewers: Severin, campbellbarton, brecht
Diffstat (limited to 'source/blender/blenkernel/intern/font.c')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index e8bfa27c662..0a887dcf676 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -1261,3 +1261,77 @@ bool BKE_vfont_to_curve(Main *bmain, Object *ob, int mode) return BKE_vfont_to_curve_ex(bmain, ob, mode, &cu->nurb, NULL, NULL, NULL, NULL); } + + +/* -------------------------------------------------------------------- */ + +/** \name VFont Clipboard + * \{ */ + +static struct { + wchar_t *text_buffer; + CharInfo *info_buffer; + size_t len_wchar; + size_t len_utf8; +} g_vfont_clipboard = {NULL}; + +void BKE_vfont_clipboard_free(void) +{ + MEM_SAFE_FREE(g_vfont_clipboard.text_buffer); + MEM_SAFE_FREE(g_vfont_clipboard.info_buffer); + g_vfont_clipboard.len_wchar = 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) +{ + wchar_t *text; + CharInfo *info; + + /* clean previous buffers*/ + BKE_vfont_clipboard_free(); + + text = MEM_mallocN((len + 1) * sizeof(wchar_t), __func__); + if (text == NULL) { + return; + } + + info = MEM_mallocN(len * sizeof(CharInfo), __func__); + if (info == NULL) { + MEM_freeN(text); + return; + } + + memcpy(text, text_buf, len * sizeof(wchar_t)); + text[len] = '\0'; + memcpy(info, info_buf, len * sizeof(CharInfo)); + + /* store new buffers */ + g_vfont_clipboard.text_buffer = text; + g_vfont_clipboard.info_buffer = info; + g_vfont_clipboard.len_utf8 = BLI_wstrlen_utf8(text); + g_vfont_clipboard.len_wchar = len; +} + +void BKE_vfont_clipboard_get( + wchar_t **r_text_buf, CharInfo **r_info_buf, + size_t *r_len_utf8, size_t *r_len_wchar) +{ + if (r_text_buf) { + *r_text_buf = g_vfont_clipboard.text_buffer; + } + + if (r_info_buf) { + *r_info_buf = g_vfont_clipboard.info_buffer; + } + + if (r_len_wchar) { + *r_len_wchar = g_vfont_clipboard.len_wchar; + } + + if (r_len_utf8) { + *r_len_utf8 = g_vfont_clipboard.len_utf8; + } +} + +/** \} */ |