From 570bffc282ee796cb66397defef7db5829f5f2f7 Mon Sep 17 00:00:00 2001 From: Kasin Sparks Date: Thu, 20 Aug 2020 18:20:24 -0400 Subject: [PATCH] text-freetype2: Fix x,y bounds for text outline and shadow --- plugins/text-freetype2/text-freetype2.c | 12 ++++++++++-- plugins/text-freetype2/text-freetype2.h | 1 + plugins/text-freetype2/text-functionality.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/text-freetype2/text-freetype2.c b/plugins/text-freetype2/text-freetype2.c index 900b5aedb..fec89b94a 100644 --- a/plugins/text-freetype2/text-freetype2.c +++ b/plugins/text-freetype2/text-freetype2.c @@ -125,14 +125,14 @@ static uint32_t ft2_source_get_width(void *data) { struct ft2_source *srcdata = data; - return srcdata->cx; + return srcdata->cx + srcdata->outline_width; } static uint32_t ft2_source_get_height(void *data) { struct ft2_source *srcdata = data; - return srcdata->cy; + return srcdata->cy + srcdata->outline_width; } static obs_properties_t *ft2_source_properties(void *unused) @@ -325,8 +325,16 @@ static void ft2_source_update(void *data, obs_data_t *settings) if (!font_obj) return; + srcdata->outline_width = 0; + srcdata->drop_shadow = obs_data_get_bool(settings, "drop_shadow"); srcdata->outline_text = obs_data_get_bool(settings, "outline"); + + if (srcdata->outline_text && srcdata->drop_shadow) + srcdata->outline_width = 6; + else if (srcdata->outline_text || srcdata->drop_shadow) + srcdata->outline_width = 4; + word_wrap = obs_data_get_bool(settings, "word_wrap"); color[0] = (uint32_t)obs_data_get_int(settings, "color1"); diff --git a/plugins/text-freetype2/text-freetype2.h b/plugins/text-freetype2/text-freetype2.h index 92cea8441..bae0cbb91 100644 --- a/plugins/text-freetype2/text-freetype2.h +++ b/plugins/text-freetype2/text-freetype2.h @@ -45,6 +45,7 @@ struct ft2_source { uint64_t last_checked; uint32_t cx, cy, max_h, custom_width; + uint32_t outline_width; uint32_t texbuf_x, texbuf_y; uint32_t color[2]; uint32_t *colorbuf; diff --git a/plugins/text-freetype2/text-functionality.c b/plugins/text-freetype2/text-functionality.c index fb64ba600..eab3583b5 100644 --- a/plugins/text-freetype2/text-functionality.c +++ b/plugins/text-freetype2/text-functionality.c @@ -162,8 +162,14 @@ void fill_vertex_buffer(struct ft2_source *srcdata) uint32_t dx = 0, dy = srcdata->max_h, max_y = dy; uint32_t cur_glyph = 0; + uint32_t offset = 0; size_t len = wcslen(srcdata->text); + if (srcdata->outline_text) { + offset = 2; + dx = offset; + } + if (srcdata->colorbuf != NULL) { bfree(srcdata->colorbuf); srcdata->colorbuf = NULL; @@ -178,7 +184,7 @@ void fill_vertex_buffer(struct ft2_source *srcdata) add_linebreak:; if (srcdata->text[i] != L'\n') goto draw_glyph; - dx = 0; + dx = offset; i++; dy += srcdata->max_h + 4; if (i == wcslen(srcdata->text)) @@ -199,7 +205,7 @@ void fill_vertex_buffer(struct ft2_source *srcdata) goto skip_custom_width; if (dx + src_glyph->xadv > srcdata->custom_width) { - dx = 0; + dx = offset; dy += srcdata->max_h + 4; }