[Bf-blender-cvs] [eb54170] temp-blf-wordwrap: Add support for line wrapping bitmap buffers
Campbell Barton
noreply at git.blender.org
Thu Sep 17 20:46:44 CEST 2015
Commit: eb5417047fad2133e445bdae42d249c003ac17e2
Author: Campbell Barton
Date: Fri Sep 18 04:40:46 2015 +1000
Branches: temp-blf-wordwrap
https://developer.blender.org/rBeb5417047fad2133e445bdae42d249c003ac17e2
Add support for line wrapping bitmap buffers
===================================================================
M source/blender/blenfont/BLF_api.h
M source/blender/blenfont/intern/blf.c
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenfont/intern/blf_internal.h
M source/blender/blenfont/intern/blf_thumbs.c
M source/blender/blenkernel/intern/image.c
M source/blender/blenkernel/intern/image_gen.c
M source/blender/blenkernel/intern/seqeffects.c
===================================================================
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index aa8f221..9527c4e 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -179,7 +179,8 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a);
/* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_
* it's not necessary set both buffer, NULL is valid here.
*/
-void BLF_draw_buffer(int fontid, const char *str) ATTR_NONNULL();
+void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info) ATTR_NONNULL(2);
+void BLF_draw_buffer(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
/* Add a path to the font dir paths. */
void BLF_dir_add(const char *path) ATTR_NONNULL();
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 4a19474..1eb86c8 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -908,14 +908,26 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
}
}
-void BLF_draw_buffer(int fontid, const char *str)
+void BLF_draw_buffer_ex(
+ int fontid, const char *str, size_t len,
+ struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache && (font->buf_info.fbuf || font->buf_info.cbuf)) {
- blf_font_buffer(font, str);
+ if (font->flags & BLF_WORD_WRAP) {
+ blf_font_buffer__wrap(font, str, len, r_info);
+ }
+ else {
+ blf_font_buffer(font, str, len, r_info);
+ }
}
}
+void BLF_draw_buffer(
+ int fontid, const char *str, size_t len)
+{
+ BLF_draw_buffer_ex(fontid, str, len, NULL);
+}
#ifdef DEBUG
void BLF_state_print(int fontid)
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index fb9051e..69c6cd1 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -290,12 +290,15 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
}
/* Sanity checks are done by BLF_draw_buffer() */
-void blf_font_buffer(FontBLF *font, const char *str)
+static void blf_font_buffer_ex(
+ FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info,
+ int pen_y)
{
unsigned int c;
GlyphBLF *g, *g_prev = NULL;
FT_Vector delta;
- int pen_x = (int)font->pos[0], pen_y = 0;
+ int pen_x = (int)font->pos[0];
+ int pen_y_basis = (int)font->pos[1] + pen_y;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
@@ -325,7 +328,7 @@ void blf_font_buffer(FontBLF *font, const char *str)
srgb_to_linearrgb_v4(b_col_float, buf_info->col);
}
- while (str[i]) {
+ while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
if (UNLIKELY(c == BLI_UTF8_ERR))
@@ -336,13 +339,13 @@ void blf_font_buffer(FontBLF *font, const char *str)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
chx = pen_x + ((int)g->pos_x);
- chy = (int)font->pos[1] + g->height;
+ chy = pen_y_basis + g->height;
if (g->pitch < 0) {
- pen_y = (int)font->pos[1] + (g->height - (int)g->pos_y);
+ pen_y = pen_y_basis + (g->height - (int)g->pos_y);
}
else {
- pen_y = (int)font->pos[1] - (g->height - (int)g->pos_y);
+ pen_y = pen_y_basis - (g->height - (int)g->pos_y);
}
if ((chx + g->width) >= 0 && chx < buf_info->w && (pen_y + g->height) >= 0 && pen_y < buf_info->h) {
@@ -451,6 +454,16 @@ void blf_font_buffer(FontBLF *font, const char *str)
pen_x += g->advance_i;
g_prev = g;
}
+
+ if (r_info) {
+ r_info->lines = 1;
+ r_info->width = pen_x;
+ }
+}
+void blf_font_buffer(
+ FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+{
+ blf_font_buffer_ex(font, str, len, r_info, 0);
}
size_t blf_font_width_to_strlen(FontBLF *font, const char *str, size_t len, float width, float *r_width)
@@ -779,6 +792,16 @@ void blf_font_boundbox__wrap(FontBLF *font, const char *str, size_t len, rctf *b
blf_font_wrap_apply(font, str, len, r_info, blf_font_boundbox_wrap_cb, box);
}
+/* blf_font_buffer__wrap */
+static void blf_font_buffer__wrap_cb(FontBLF *font, const char *str, size_t len, int pen_y, void *UNUSED(userdata))
+{
+ blf_font_buffer_ex(font, str, len, NULL, pen_y);
+}
+void blf_font_buffer__wrap(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
+{
+ blf_font_wrap_apply(font, str, len, r_info, blf_font_buffer__wrap_cb, NULL);
+}
+
/** \} */
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 6bd620d..ce6e763 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -56,7 +56,8 @@ void blf_font_draw(struct FontBLF *font, const char *str, size_t len, struct Res
void blf_font_draw__wrap(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
-void blf_font_buffer(struct FontBLF *font, const char *str);
+void blf_font_buffer(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
+void blf_font_buffer__wrap(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
size_t blf_font_width_to_strlen(struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
size_t blf_font_width_to_rstrlen(struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
void blf_font_boundbox(struct FontBLF *font, const char *str, size_t len, struct rctf *r_box, struct ResultBLF *r_info);
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 4eea5d5..9b59eb4 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -110,10 +110,10 @@ void BLF_thumb_preview(
if (blf_font_count_missing_chars(
font, draw_str_i18n, draw_str_i18n_len, &draw_str_i18n_nbr) > (draw_str_i18n_nbr / 2))
{
- blf_font_buffer(font, draw_str[i]);
+ blf_font_buffer(font, draw_str[i], (size_t)draw_str_i18n_nbr, NULL);
}
else {
- blf_font_buffer(font, draw_str_i18n);
+ blf_font_buffer(font, draw_str_i18n, draw_str_i18n_len, NULL);
}
}
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 36aeb97..ec80ea1 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1917,7 +1917,7 @@ void BKE_image_stamp_buf(
/* and draw the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.file);
+ BLF_draw_buffer(mono, stamp_data.file, sizeof(stamp_data.file));
/* the extra pixel for background. */
y -= BUFF_MARGIN_Y * 2;
@@ -1932,7 +1932,7 @@ void BKE_image_stamp_buf(
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.note);
+ BLF_draw_buffer(mono, stamp_data.note, sizeof(stamp_data.note));
/* the extra pixel for background. */
y -= BUFF_MARGIN_Y * 2;
@@ -1947,7 +1947,7 @@ void BKE_image_stamp_buf(
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.date);
+ BLF_draw_buffer(mono, stamp_data.date, sizeof(stamp_data.date));
/* the extra pixel for background. */
y -= BUFF_MARGIN_Y * 2;
@@ -1962,7 +1962,7 @@ void BKE_image_stamp_buf(
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.rendertime);
+ BLF_draw_buffer(mono, stamp_data.rendertime, sizeof(stamp_data.rendertime));
}
x = 0;
@@ -1977,7 +1977,7 @@ void BKE_image_stamp_buf(
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.marker);
+ BLF_draw_buffer(mono, stamp_data.marker, sizeof(stamp_data.marker));
/* space width. */
x += w + pad;
@@ -1992,7 +1992,7 @@ void BKE_image_stamp_buf(
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.time);
+ BLF_draw_buffer(mono, stamp_data.time, sizeof(stamp_data.time));
/* space width. */
x += w + pad;
@@ -2006,7 +2006,7 @@ void BKE_image_stamp_buf(
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.frame);
+ BLF_draw_buffer(mono, stamp_data.frame, sizeof(stamp_data.frame));
/* space width. */
x += w + pad;
@@ -2018,7 +2018,7 @@ void BKE_image_stamp_buf(
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.camera);
+ BLF_draw_buffer(mono, stamp_data.camera, sizeof(stamp_data.camera));
/* space width. */
x += w + pad;
@@ -2030,7 +2030,7 @@ void BKE_image_stamp_buf(
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.cameralens);
+ BLF_draw_buffer(mono, stamp_data.cameralens, sizeof(stamp_data.cameralens));
}
if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) {
@@ -2044,7 +2044,7 @@ void BKE_image_stamp_buf(
/* and pad the text. */
BLF_position(mono, x, y + y_ofs, 0.0);
- BLF_draw_buffer(mono, stamp_data.scene);
+ BLF_draw_buffer(mono, stamp_data.scene, sizeof(stamp_data.scene));
}
if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) {
@@ -2058,7 +2058,7 @@ void BKE_image_stamp_buf(
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
BLF_position(mono, x, y + y_of
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list