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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-09-18 13:37:53 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-09-18 13:44:06 +0300
commit910aaa3951c9443dade9516510762718b21171de (patch)
tree49efaab46df2bc25ce0c24cd63d41a2ddf94839f
parent0aa0a1a966d317a42da46bb43719f25688a8beeb (diff)
Image Stamp: word-wrap support for 'note' text
-rw-r--r--source/blender/blenkernel/intern/image.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index b6645a35b60..4a76c704130 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1872,12 +1872,23 @@ void BKE_image_stamp_buf(
struct ColorManagedDisplay *display;
const char *display_device;
+ /* vars for calculating wordwrap */
+ struct {
+ struct ResultBLF info;
+ rctf rect;
+ } wrap;
+
/* this could be an argument if we want to operate on non linear float imbuf's
* for now though this is only used for renders which use scene settings */
#define TEXT_SIZE_CHECK(str, w, h) \
((str[0]) && ((void)(h = h_fixed), (w = BLF_width(mono, str, sizeof(str)))))
+ /* must enable BLF_WORD_WRAP before using */
+#define TEXT_SIZE_CHECK_WORD_WRAP(str, w, h) \
+ ((str[0]) && (BLF_boundbox_ex(mono, str, sizeof(str), &wrap.rect, &wrap.info), \
+ (void)(h = h_fixed * wrap.info.lines), (w = BLI_rctf_size_x(&wrap.rect))))
+
#define BUFF_MARGIN_X 2
#define BUFF_MARGIN_Y 1
@@ -1895,6 +1906,7 @@ void BKE_image_stamp_buf(
/* set before return */
BLF_size(mono, scene->r.stamp_font_id, 72);
+ BLF_wordwrap(mono, width - (BUFF_MARGIN_X * 2));
BLF_buffer(mono, rectf, rect, width, height, channels, display);
BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
@@ -1924,7 +1936,7 @@ void BKE_image_stamp_buf(
}
/* Top left corner, below File */
- if (TEXT_SIZE_CHECK(stamp_data.note, w, h)) {
+ if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) {
y -= h;
/* and space for background. */
@@ -1932,14 +1944,14 @@ 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_STR_DUMMY_MAX);
+ BLF_draw_buffer(mono, stamp_data.date, BLF_DRAW_STR_DUMMY_MAX);
/* the extra pixel for background. */
y -= BUFF_MARGIN_Y * 2;
}
- /* Top left corner, below File (or Note) */
- if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) {
+ /* Top left corner, below File, Date */
+ if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) {
y -= h;
/* and space for background. */
@@ -1947,23 +1959,25 @@ 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_STR_DUMMY_MAX);
+ BLF_draw_buffer(mono, stamp_data.rendertime, BLF_DRAW_STR_DUMMY_MAX);
/* the extra pixel for background. */
y -= BUFF_MARGIN_Y * 2;
}
- /* Top left corner, below File, Date or Note */
- if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) {
+ /* Top left corner, below File, Date, Rendertime */
+ BLF_enable(mono, BLF_WORD_WRAP);
+ if (TEXT_SIZE_CHECK_WORD_WRAP(stamp_data.note, w, h)) {
y -= h;
/* and space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
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_STR_DUMMY_MAX);
+ BLF_position(mono, x, y + y_ofs + (h - h_fixed), 0.0);
+ BLF_draw_buffer(mono, stamp_data.note, BLF_DRAW_STR_DUMMY_MAX);
}
+ BLF_disable(mono, BLF_WORD_WRAP);
x = 0;
y = 0;
@@ -2063,8 +2077,10 @@ void BKE_image_stamp_buf(
/* cleanup the buffer. */
BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL);
+ BLF_wordwrap(mono, 0);
#undef TEXT_SIZE_CHECK
+#undef TEXT_SIZE_CHECK_WORD_WRAP
#undef BUFF_MARGIN_X
#undef BUFF_MARGIN_Y
}