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
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-10 14:57:08 +0300
committerJacques Lucke <jacques@blender.org>2020-09-10 14:57:08 +0300
commitb8bcbb2cf26f7217099076e17d69088e690c0790 (patch)
tree76e1a5fdb64df47197cb28f3e8b0dd8da7b263e7 /source
parentfcf6177b0d156a07d8975387be9abe1cef4a0fed (diff)
Refactor: move Text .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/text.c72
-rw-r--r--source/blender/blenloader/intern/readfile.c51
-rw-r--r--source/blender/blenloader/intern/writefile.c34
3 files changed, 73 insertions, 84 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,
};
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index c41ed99167e..bb390320312 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3190,49 +3190,6 @@ static void direct_link_vfont(BlendDataReader *reader, VFont *vf)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Read ID: Text
- * \{ */
-
-static void lib_link_text(BlendLibReader *UNUSED(reader), Text *UNUSED(text))
-{
-}
-
-static void direct_link_text(BlendDataReader *reader, Text *text)
-{
- 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);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Read ID: Image
* \{ */
@@ -7481,9 +7438,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_VF:
direct_link_vfont(&reader, (VFont *)id);
break;
- case ID_TXT:
- direct_link_text(&reader, (Text *)id);
- break;
case ID_IP:
direct_link_ipo(&reader, (Ipo *)id);
break;
@@ -7558,6 +7512,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_AC:
case ID_NT:
case ID_LS:
+ case ID_TXT:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8211,9 +8166,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_SO:
lib_link_sound(&reader, (bSound *)id);
break;
- case ID_TXT:
- lib_link_text(&reader, (Text *)id);
- break;
case ID_CA:
lib_link_camera(&reader, (Camera *)id);
break;
@@ -8277,6 +8229,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_AC:
case ID_NT:
case ID_LS:
+ case ID_TXT:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 1adfb7a05c9..01ccb6823a1 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2416,36 +2416,6 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a
}
}
-static void write_text(BlendWriter *writer, Text *text, const void *id_address)
-{
- /* 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 write_speaker(BlendWriter *writer, Speaker *spk, const void *id_address)
{
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -3152,9 +3122,6 @@ static bool write_file_handle(Main *mainvar,
case ID_WO:
write_world(&writer, (World *)id_buffer, id);
break;
- case ID_TXT:
- write_text(&writer, (Text *)id_buffer, id);
- break;
case ID_SPK:
write_speaker(&writer, (Speaker *)id_buffer, id);
break;
@@ -3214,6 +3181,7 @@ static bool write_file_handle(Main *mainvar,
case ID_AC:
case ID_NT:
case ID_LS:
+ case ID_TXT:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: