[Bf-blender-cvs] [651b7e9] temp-blf-wordwrap: word wrap and vert-align support for sequencer text
Campbell Barton
noreply at git.blender.org
Fri Sep 18 10:01:49 CEST 2015
Commit: 651b7e9f497185622217cb07c1c88c1050b3c6b5
Author: Campbell Barton
Date: Fri Sep 18 17:55:03 2015 +1000
Branches: temp-blf-wordwrap
https://developer.blender.org/rB651b7e9f497185622217cb07c1c88c1050b3c6b5
word wrap and vert-align support for sequencer text
===================================================================
M release/scripts/startup/bl_ui/space_sequencer.py
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenkernel/intern/seqeffects.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 5991ed5..5bf095d 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -638,8 +638,10 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel):
col.prop(strip, "text")
col.prop(strip, "font_size")
col.prop(strip, "use_shadow")
- col.prop(strip, "align")
+ col.prop(strip, "align_x")
+ col.prop(strip, "align_y")
col.prop(strip, "location")
+ col.prop(strip, "wrap_width")
layout.operator("sequencer.export_subtitles")
col = layout.column(align=True)
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 27a6685..edb9825 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -676,7 +676,7 @@ static void blf_font_wrap_apply(
struct WordWrapVars {
int wrap_width;
size_t start, last[2];
- } wrap = {font->wrap_width, 0, {0, 0}};
+ } wrap = {font->wrap_width != -1 ? font->wrap_width : INT_MAX, 0, {0, 0}};
blf_font_ensure_ascii_table(font);
// printf("%s wrapping (%d, %d) `%s`:\n", __func__, len, strlen(str), str);
diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index c7ff238..6d666aa 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -38,6 +38,7 @@
#include "BLI_math.h" /* windows needs for M_PI */
#include "BLI_utildefines.h"
+#include "BLI_rect.h"
#include "BLI_string.h"
#include "DNA_scene_types.h"
@@ -2893,7 +2894,8 @@ static void init_text_effect(Sequence *seq)
BLI_strncpy(data->text, "Text", sizeof(data->text));
data->loc[0] = 0.5f;
- data->align = SEQ_TEXT_ALIGN_CENTER;
+ data->align = SEQ_TEXT_ALIGN_X_CENTER;
+ data->align_y = SEQ_TEXT_ALIGN_Y_BOTTOM;
}
static int num_inputs_text(void)
@@ -2920,6 +2922,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
struct ColorManagedDisplay *display;
const char *display_device;
const int mono = blf_mono_font_render; // XXX
+ int line_height;
int y_ofs, x, y;
float proxy_size_comp;
@@ -2942,24 +2945,44 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
BLF_enable(mono, BLF_WORD_WRAP);
+ /* use max width to enable newlines only */
+ BLF_wordwrap(mono, (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);
+ line_height = BLF_height_max(mono);
+
y_ofs = -BLF_descender(mono);
x = (data->loc[0] * width);
y = (data->loc[1] * height) + y_ofs;
- if (data->align == SEQ_TEXT_ALIGN_LEFT) {
+ if ((data->align == SEQ_TEXT_ALIGN_X_LEFT) &&
+ (data->align_y == SEQ_TEXT_ALIGN_Y_TOP))
+ {
/* pass */
}
else {
- const int w = BLF_width(mono, data->text, sizeof(data->text));
+ /* vars for calculating wordwrap */
+ struct {
+ struct ResultBLF info;
+ rctf rect;
+ } wrap;
+
+ BLF_boundbox_ex(mono, data->text, sizeof(data->text), &wrap.rect, &wrap.info);
+
+ if (data->align == SEQ_TEXT_ALIGN_X_RIGHT) {
+ x -= BLI_rctf_size_x(&wrap.rect);
+ }
+ else if (data->align == SEQ_TEXT_ALIGN_X_CENTER) {
+ x -= BLI_rctf_size_x(&wrap.rect) / 2;
+ }
- if (data->align == SEQ_TEXT_ALIGN_RIGHT) {
- x -= w;
+ if (data->align_y == SEQ_TEXT_ALIGN_Y_BOTTOM) {
+ y += (wrap.info.lines - 1) * line_height;
}
- else { /* SEQ_TEXT_ALIGN_CENTER */
- x -= w / 2;
+ else if (data->align_y == SEQ_TEXT_ALIGN_Y_CENTER) {
+ y += (((wrap.info.lines - 1) / 2) * line_height) - (line_height / 2);
}
}
@@ -2967,7 +2990,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context, Sequence *seq, float
if (data->flag & SEQ_TEXT_SHADOW) {
int fontx, fonty;
fontx = BLF_width_max(mono);
- fonty = BLF_height_max(mono);
+ fonty = line_height;
BLF_position(mono, x + max_ii(fontx / 25, 1), y + max_ii(fonty / 25, 1), 0.0f);
BLF_buffer_col(mono, 0.0f, 0.0f, 0.0f, 1.0f);
BLF_draw_buffer(mono, data->text, sizeof(data->text));
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 3f3bfdf..69e7fb4 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -275,9 +275,10 @@ typedef struct TextVars {
char text[512];
int text_size;
float loc[2];
- short flag;
- char align;
- char pad;
+ float wrap_width;
+ char flag;
+ char align, align_y;
+ char pad[5];
} TextVars;
/* TextVars.flag */
@@ -287,9 +288,16 @@ enum {
/* TextVars.align */
enum {
- SEQ_TEXT_ALIGN_LEFT = 0,
- SEQ_TEXT_ALIGN_CENTER = 1,
- SEQ_TEXT_ALIGN_RIGHT = 2,
+ SEQ_TEXT_ALIGN_X_LEFT = 0,
+ SEQ_TEXT_ALIGN_X_CENTER = 1,
+ SEQ_TEXT_ALIGN_X_RIGHT = 2,
+};
+
+/* TextVars.align_y */
+enum {
+ SEQ_TEXT_ALIGN_Y_TOP = 0,
+ SEQ_TEXT_ALIGN_Y_CENTER = 1,
+ SEQ_TEXT_ALIGN_Y_BOTTOM = 2,
};
/* ***************** Sequence modifiers ****************** */
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index bfb6239..82e67bb 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -2307,10 +2307,16 @@ static void rna_def_gaussian_blur(StructRNA *srna)
static void rna_def_text(StructRNA *srna)
{
- static EnumPropertyItem text_align_items[] = {
- {SEQ_TEXT_ALIGN_LEFT, "LEFT", 0, "Left", ""},
- {SEQ_TEXT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
- {SEQ_TEXT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
+ static EnumPropertyItem text_align_x_items[] = {
+ {SEQ_TEXT_ALIGN_X_LEFT, "LEFT", 0, "Left", ""},
+ {SEQ_TEXT_ALIGN_X_CENTER, "CENTER", 0, "Center", ""},
+ {SEQ_TEXT_ALIGN_X_RIGHT, "RIGHT", 0, "Right", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem text_align_y_items[] = {
+ {SEQ_TEXT_ALIGN_Y_TOP, "TOP", 0, "Top", ""},
+ {SEQ_TEXT_ALIGN_Y_CENTER, "CENTER", 0, "Center", ""},
+ {SEQ_TEXT_ALIGN_Y_BOTTOM, "BOTTOM", 0, "Bottom", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -2331,10 +2337,23 @@ static void rna_def_text(StructRNA *srna)
RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1);
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
- prop = RNA_def_property(srna, "align", PROP_ENUM, PROP_NONE);
+ prop = RNA_def_property(srna, "wrap_width", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "wrap_width");
+ RNA_def_property_ui_text(prop, "Wrap Width", "Word wrap width as factor, 0 disables");
+ RNA_def_property_range(prop, 0, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1);
+ RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
+
+ prop = RNA_def_property(srna, "align_x", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "align");
- RNA_def_property_enum_items(prop, text_align_items);
- RNA_def_property_ui_text(prop, "Align", "");
+ RNA_def_property_enum_items(prop, text_align_x_items);
+ RNA_def_property_ui_text(prop, "Align X", "");
+ RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
+
+ prop = RNA_def_property(srna, "align_y", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "align_y");
+ RNA_def_property_enum_items(prop, text_align_y_items);
+ RNA_def_property_ui_text(prop, "Align Y", "");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update");
prop = RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
More information about the Bf-blender-cvs
mailing list