Commit: b3dbe17658fe8ca5115abab642cc0f1680d1f0d5
Author: Richard Antalik
Date:   Sun Jan 13 21:28:07 2019 -0800
Branches: master
https://developer.blender.org/rBb3dbe17658fe8ca5115abab642cc0f1680d1f0d5

Add font selection to VSE text strips

Allows users to select a font for text strips in the video sequence editor.

Related: 3610f1fc43d0 Sequencer: refactor clipboard copy to no longer increase 
user count.

Reviewed by: Brecht

Differential Revision: https://developer.blender.org/D3621

===================================================================

M       release/scripts/startup/bl_ui/space_sequencer.py
M       source/blender/blenfont/BLF_api.h
M       source/blender/blenfont/intern/blf.c
M       source/blender/blenfont/intern/blf_internal_types.h
M       source/blender/blenkernel/BKE_sequencer.h
M       source/blender/blenkernel/intern/library_query.c
M       source/blender/blenkernel/intern/seqeffects.c
M       source/blender/blenkernel/intern/sequencer.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/interface/interface_templates.c
M       source/blender/makesdna/DNA_sequence_types.h
M       source/blender/makesrna/intern/rna_sequencer.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_sequencer.py 
b/release/scripts/startup/bl_ui/space_sequencer.py
index 57bb73ae707..1d1b857b2f1 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -786,6 +786,7 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel):
         elif strip.type == 'TEXT':
             col = layout.column()
             col.prop(strip, "text")
+            col.template_ID(strip, "font", open="font.open", 
unlink="font.unlink")
             col.prop(strip, "font_size")
 
             row = col.row()
diff --git a/source/blender/blenfont/BLF_api.h 
b/source/blender/blenfont/BLF_api.h
index 8a3728574f3..75afa0e3018 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -51,6 +51,7 @@ void BLF_batch_reset(void); /* call when changing opengl 
context. */
 
 void BLF_cache_clear(void);
 
+/* Loads a font, or returns an already loaded font and increments its 
reference count. */
 int BLF_load(const char *name) ATTR_NONNULL();
 int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) 
ATTR_NONNULL();
 
diff --git a/source/blender/blenfont/intern/blf.c 
b/source/blender/blenfont/intern/blf.c
index 70a7b862830..70478fd1d1c 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -198,7 +198,8 @@ int BLF_load(const char *name)
        /* check if we already load this font. */
        i = blf_search(name);
        if (i >= 0) {
-               /*font = global_font[i];*/ /*UNUSED*/
+               font = global_font[i];
+               font->reference_count++;
                return i;
        }
 
@@ -222,6 +223,7 @@ int BLF_load(const char *name)
                return -1;
        }
 
+       font->reference_count = 1;
        global_font[i] = font;
        return i;
 }
@@ -255,6 +257,7 @@ int BLF_load_unique(const char *name)
                return -1;
        }
 
+       font->reference_count = 1;
        global_font[i] = font;
        return i;
 }
@@ -296,6 +299,7 @@ int BLF_load_mem(const char *name, const unsigned char 
*mem, int mem_size)
                return -1;
        }
 
+       font->reference_count = 1;
        global_font[i] = font;
        return i;
 }
@@ -326,6 +330,7 @@ int BLF_load_mem_unique(const char *name, const unsigned 
char *mem, int mem_size
                return -1;
        }
 
+       font->reference_count = 1;
        global_font[i] = font;
        return i;
 }
@@ -339,8 +344,13 @@ void BLF_unload(const char *name)
                font = global_font[i];
 
                if (font && (STREQ(font->name, name))) {
-                       blf_font_free(font);
-                       global_font[i] = NULL;
+                       BLI_assert(font->reference_count > 0);
+                       font->reference_count--;
+
+                       if (font->reference_count == 0) {
+                               blf_font_free(font);
+                               global_font[i] = NULL;
+                       }
                }
        }
 }
@@ -349,8 +359,13 @@ void BLF_unload_id(int fontid)
 {
        FontBLF *font = blf_get(fontid);
        if (font) {
-               blf_font_free(font);
-               global_font[fontid] = NULL;
+               BLI_assert(font->reference_count > 0);
+               font->reference_count--;
+
+               if (font->reference_count == 0) {
+                       blf_font_free(font);
+                       global_font[fontid] = NULL;
+               }
        }
 }
 
diff --git a/source/blender/blenfont/intern/blf_internal_types.h 
b/source/blender/blenfont/intern/blf_internal_types.h
index 265835f4c75..14bc081cd10 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -194,6 +194,9 @@ typedef struct FontBLF {
        /* font name. */
        char *name;
 
+       /* # of times this font was loaded */
+       unsigned int reference_count;
+
        /* filename or NULL. */
        char *filename;
 
diff --git a/source/blender/blenkernel/BKE_sequencer.h 
b/source/blender/blenkernel/BKE_sequencer.h
index 62c56c0dc24..f5c917302ea 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -46,6 +46,7 @@ struct Sequence;
 struct SequenceModifierData;
 struct Stereo3dFormat;
 struct StripElem;
+struct TextVars;
 struct bSound;
 
 struct SeqIndexBuildContext;
@@ -145,7 +146,7 @@ struct SeqEffectHandle {
 
        /* load is called first time after readblenfile in
         * get_sequence_effect automatically */
-       void (*load)(struct Sequence *seq);
+       void (*load)(struct Sequence *seqconst);
 
        /* duplicate */
        void (*copy)(struct Sequence *dst, struct Sequence *src, const int 
flag);
@@ -301,6 +302,9 @@ void BKE_sequence_effect_speed_rebuild_map(struct Scene 
*scene, struct Sequence
 struct SeqEffectHandle BKE_sequence_get_effect(struct Sequence *seq);
 int BKE_sequence_effect_get_num_inputs(int seq_type);
 int BKE_sequence_effect_get_supports_mask(int seq_type);
+void BKE_sequencer_text_font_unload(struct TextVars *data, const bool 
do_id_user);
+void BKE_sequencer_text_font_load(struct TextVars *data, const bool 
do_id_user);
+
 
 /* **********************************************************************
  * Sequencer editing functions
diff --git a/source/blender/blenkernel/intern/library_query.c 
b/source/blender/blenkernel/intern/library_query.c
index c902aa8c5d5..b3ddb186fa5 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -425,6 +425,11 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, 
LibraryIDLinkCallback call
                                                for (SequenceModifierData *smd 
= seq->modifiers.first; smd; smd = smd->next) {
                                                        
CALLBACK_INVOKE(smd->mask_id, IDWALK_CB_USER);
                                                }
+
+                                               if (seq->type == SEQ_TYPE_TEXT 
&& seq->effectdata) {
+                                                       TextVars *text_data = 
seq->effectdata;
+                                                       
CALLBACK_INVOKE(text_data->text_font, IDWALK_CB_USER);
+                                               }
                                        } SEQ_END;
                                }
 
diff --git a/source/blender/blenkernel/intern/seqeffects.c 
b/source/blender/blenkernel/intern/seqeffects.c
index 193db2b623f..7203691d7dc 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -37,8 +37,10 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math.h" /* windows needs for M_PI */
+#include "BLI_threads.h"
 #include "BLI_utildefines.h"
 #include "BLI_rect.h"
+#include "BLI_path_util.h"
 #include "BLI_string.h"
 
 #include "DNA_scene_types.h"
@@ -47,6 +49,8 @@
 #include "DNA_space_types.h"
 
 #include "BKE_fcurve.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_sequencer.h"
 
 #include "IMB_imbuf_types.h"
@@ -3357,6 +3361,7 @@ static ImBuf *do_gaussian_blur_effect(
 }
 
 /*********************** text *************************/
+
 static void init_text_effect(Sequence *seq)
 {
        TextVars *data;
@@ -3365,6 +3370,8 @@ static void init_text_effect(Sequence *seq)
                MEM_freeN(seq->effectdata);
 
        data = seq->effectdata = MEM_callocN(sizeof(TextVars), "textvars");
+       data->text_font = NULL;
+       data->text_blf_id = -1;
        data->text_size = 30;
 
        copy_v4_fl(data->color, 1.0f);
@@ -3377,6 +3384,64 @@ static void init_text_effect(Sequence *seq)
        data->align_y = SEQ_TEXT_ALIGN_Y_BOTTOM;
 }
 
+void BKE_sequencer_text_font_unload(TextVars *data, const bool do_id_user)
+{
+       if (data) {
+               /* Unlink the VFont */
+               if (do_id_user && data->text_font != NULL) {
+                       id_us_min(&data->text_font->id);
+                       data->text_font = NULL;
+               }
+
+               /* Unload the BLF font. */
+               if (data->text_blf_id >= 0) {
+                       BLF_unload_id(data->text_blf_id);
+               }
+       }
+}
+
+void BKE_sequencer_text_font_load(TextVars *data, const bool do_id_user)
+{
+       if (data->text_font != NULL) {
+               if (do_id_user) {
+                       id_us_plus(&data->text_font->id);
+               }
+
+               char path[FILE_MAX];
+               STRNCPY(path, data->text_font->name);
+               BLI_assert(BLI_thread_is_main());
+               BLI_path_abs(path, BKE_main_blendfile_path_from_global());
+
+               data->text_blf_id = BLF_load(path);
+       }
+}
+
+static void free_text_effect(Sequence *seq, const bool do_id_user)
+{
+       TextVars *data = seq->effectdata;
+       BKE_sequencer_text_font_unload(data, do_id_user);
+
+       if (data) {
+               MEM_freeN(data);
+               seq->effectdata = NULL;
+       }
+}
+
+static void load_text_effect(Sequence *seq)
+{
+       TextVars *data = seq->effectdata;
+       BKE_sequencer_text_font_load(data, false);
+}
+
+static void copy_text_effect(Sequence *dst, Sequence *src, const int flag)
+{
+       dst->effectdata = MEM_dupallocN(src->effectdata);
+       TextVars *data = dst->effectdata;
+
+       data->text_blf_id = -1;
+       BKE_sequencer_text_font_load(data, (flag & 
LIB_ID_CREATE_NO_USER_REFCOUNT) == 0);
+}
+
 static int num_inputs_text(void)
 {
        return 0;
@@ -3403,11 +3468,23 @@ static ImBuf *do_text_effect(
        int height = out->y;
        struct ColorManagedDisplay *display;
        const char *display_device;
-       const int mono = blf_mono_font_render; // XXX
+       int font = blf_mono_font_render;
        int line_height;
        int y_ofs, x, y;
        float proxy_size_comp;
 
+       if (data->text_blf_id == SEQ_FONT_NOT_LOADED) {
+               data->text_blf_id = -1;
+
+               if (data->text_font) {
+                       data->text_blf_id = BLF_load(data->text_font->name);
+               }
+       }
+
+       if (data->text_blf_id >= 0) {
+               font = data->text_blf_id;
+       }
+
        display_device = context->scene->display_settings.display_device;
        display = IMB_colormanagement_display_get_named(display_device);
 
@@ -3423,18 +3500,18 @@ static ImBuf *do_text_effect(
        }
 
        /* set before return */
-       BLF_size(mono, proxy_size_comp * data->text_size, 72);
+       BLF_size(font, proxy_size_comp * data->text_size, 72);
 
-       BLF_enable(mono, BLF_WORD_WRAP);
+       BLF_enable(font, BLF_WORD_WRAP);
 
        /* use max width to enable newlines only */
-       BLF_wordwrap(mono, (data->wrap_width != 0.0f) ? data->wrap_width * 
width : -1);
+       BLF_wordwrap(font, (data->wrap_width != 0.0f) ? data->wrap_width * 
width : -1);
 
-       BLF_buffer(mono, out->rect_float, (unsigned char *)out->rect, width, 
height, out->channels, display);
+       BLF_buffer(font, out->rect_float, (unsigned char *)out->rect, width, 
height, out->channels, display);
 
-       line_height = BLF_height_max(mono);
+       line_height = BLF_height_max(font);
 
-       y_ofs = -BLF_descender(mono);
+       y_ofs = -BLF_descender(font);
 
        x = (data->loc[0] * width);
        y = (data->loc[1] * height) + y_ofs;
@@ -3451,7 +3528,7 @@ static ImBuf *do_text_effect(
                        rctf rect;
                } wrap;
 
-               BLF_boundbox_ex(mono, data->text, sizeof(data->text), 
&wrap.rect, &wrap.info);
+               BLF_boundbox_ex(font, data->text, sizeof(data->text), 
&wrap.rect, &wrap.info);
 
                if (data->align == SEQ_TEXT_ALIGN_X_RIGHT) {
                        x -= BLI_rctf_size_x(&wrap.rect);
@@ -3474,19 +3551,20 @@ static ImBuf *do_text_effect(
        /* BLF_SHADOW won't work with buffers, instead use cheap shadow trick */
        if (d

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to