diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 14:57:08 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 14:57:08 +0300 |
commit | b8bcbb2cf26f7217099076e17d69088e690c0790 (patch) | |
tree | 76e1a5fdb64df47197cb28f3e8b0dd8da7b263e7 /source/blender/blenkernel/intern/text.c | |
parent | fcf6177b0d156a07d8975387be9abe1cef4a0fed (diff) |
Refactor: move Text .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bde9b9ab9b8..c1f2c66badb 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -55,6 +55,8 @@ #include "BKE_node.h" #include "BKE_text.h" +#include "BLO_read_write.h" + #ifdef WITH_PYTHON # include "BPY_extern.h" #endif @@ -167,6 +169,72 @@ static void text_free_data(ID *id) #endif } +static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Text *text = (Text *)id; + + /* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ + if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { + text->flags &= ~TXT_ISEXT; + } + + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + text->compiled = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, Text, id_address, &text->id); + BKE_id_blend_write(writer, &text->id); + + if (text->filepath) { + BLO_write_string(writer, text->filepath); + } + + if (!(text->flags & TXT_ISEXT)) { + /* now write the text data, in two steps for optimization in the readfunction */ + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_struct(writer, TextLine, tmp); + } + + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_raw(writer, tmp->len + 1, tmp->line); + } + } +} + +static void text_blend_read_data(BlendDataReader *reader, ID *id) +{ + Text *text = (Text *)id; + BLO_read_data_address(reader, &text->filepath); + + text->compiled = NULL; + +#if 0 + if (text->flags & TXT_ISEXT) { + BKE_text_reload(text); + } + /* else { */ +#endif + + BLO_read_list(reader, &text->lines); + + BLO_read_data_address(reader, &text->curl); + BLO_read_data_address(reader, &text->sell); + + LISTBASE_FOREACH (TextLine *, ln, &text->lines) { + BLO_read_data_address(reader, &ln->line); + ln->format = NULL; + + if (ln->len != (int)strlen(ln->line)) { + printf("Error loading text, line lengths differ\n"); + ln->len = strlen(ln->line); + } + } + + text->flags = (text->flags) & ~TXT_ISEXT; + + id_us_ensure_real(&text->id); +} + IDTypeInfo IDType_ID_TXT = { .id_code = ID_TXT, .id_filter = FILTER_ID_TXT, @@ -184,8 +252,8 @@ IDTypeInfo IDType_ID_TXT = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = text_blend_write, + .blend_read_data = text_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; |