New upstream version 24.0.1+dfsg1
This commit is contained in:
parent
b14f9eae6d
commit
5a730d6ec3
842 changed files with 42245 additions and 33385 deletions
|
|
@ -23,8 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "text-freetype2.h"
|
||||
#include "obs-convenience.h"
|
||||
|
||||
float offsets[16] = { -2.0f, 0.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f,
|
||||
0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f };
|
||||
float offsets[16] = {-2.0f, 0.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f,
|
||||
0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f};
|
||||
|
||||
extern uint32_t texbuf_w, texbuf_h;
|
||||
|
||||
|
|
@ -44,10 +44,10 @@ void draw_outlines(struct ft2_source *srcdata)
|
|||
gs_matrix_push();
|
||||
for (int32_t i = 0; i < 8; i++) {
|
||||
gs_matrix_translate3f(offsets[i * 2], offsets[(i * 2) + 1],
|
||||
0.0f);
|
||||
0.0f);
|
||||
draw_uv_vbuffer(srcdata->vbuf, srcdata->tex,
|
||||
srcdata->draw_effect,
|
||||
(uint32_t)wcslen(srcdata->text) * 6);
|
||||
srcdata->draw_effect,
|
||||
(uint32_t)wcslen(srcdata->text) * 6);
|
||||
}
|
||||
gs_matrix_identity();
|
||||
gs_matrix_pop();
|
||||
|
|
@ -70,8 +70,8 @@ void draw_drop_shadow(struct ft2_source *srcdata)
|
|||
|
||||
gs_matrix_push();
|
||||
gs_matrix_translate3f(4.0f, 4.0f, 0.0f);
|
||||
draw_uv_vbuffer(srcdata->vbuf, srcdata->tex,
|
||||
srcdata->draw_effect, (uint32_t)wcslen(srcdata->text) * 6);
|
||||
draw_uv_vbuffer(srcdata->vbuf, srcdata->tex, srcdata->draw_effect,
|
||||
(uint32_t)wcslen(srcdata->text) * 6);
|
||||
gs_matrix_identity();
|
||||
gs_matrix_pop();
|
||||
|
||||
|
|
@ -105,16 +105,19 @@ void set_up_vertex_buffer(struct ft2_source *srcdata)
|
|||
return;
|
||||
}
|
||||
|
||||
srcdata->vbuf = create_uv_vbuffer((uint32_t)wcslen(srcdata->text) * 6,
|
||||
true);
|
||||
srcdata->vbuf =
|
||||
create_uv_vbuffer((uint32_t)wcslen(srcdata->text) * 6, true);
|
||||
|
||||
if (srcdata->custom_width <= 100) goto skip_word_wrap;
|
||||
if (!srcdata->word_wrap) goto skip_word_wrap;
|
||||
if (srcdata->custom_width <= 100)
|
||||
goto skip_word_wrap;
|
||||
if (!srcdata->word_wrap)
|
||||
goto skip_word_wrap;
|
||||
|
||||
len = wcslen(srcdata->text);
|
||||
|
||||
for (uint32_t i = 0; i <= len; i++) {
|
||||
if (i == wcslen(srcdata->text)) goto eos_check;
|
||||
if (i == wcslen(srcdata->text))
|
||||
goto eos_check;
|
||||
|
||||
if (srcdata->text[i] != L' ' && srcdata->text[i] != L'\n')
|
||||
goto next_char;
|
||||
|
|
@ -125,7 +128,8 @@ void set_up_vertex_buffer(struct ft2_source *srcdata)
|
|||
srcdata->text[space_pos] = L'\n';
|
||||
x = 0;
|
||||
}
|
||||
if (i == wcslen(srcdata->text)) goto eos_skip;
|
||||
if (i == wcslen(srcdata->text))
|
||||
goto eos_skip;
|
||||
|
||||
x += word_width;
|
||||
word_width = 0;
|
||||
|
|
@ -134,8 +138,8 @@ void set_up_vertex_buffer(struct ft2_source *srcdata)
|
|||
if (srcdata->text[i] == L' ')
|
||||
space_pos = i;
|
||||
next_char:;
|
||||
glyph_index = FT_Get_Char_Index(srcdata->font_face,
|
||||
srcdata->text[i]);
|
||||
glyph_index =
|
||||
FT_Get_Char_Index(srcdata->font_face, srcdata->text[i]);
|
||||
word_width += src_glyph->xadv;
|
||||
eos_skip:;
|
||||
}
|
||||
|
|
@ -148,7 +152,8 @@ skip_word_wrap:;
|
|||
void fill_vertex_buffer(struct ft2_source *srcdata)
|
||||
{
|
||||
struct gs_vb_data *vdata = gs_vertexbuffer_get_data(srcdata->vbuf);
|
||||
if (vdata == NULL || !srcdata->text) return;
|
||||
if (vdata == NULL || !srcdata->text)
|
||||
return;
|
||||
|
||||
struct vec2 *tvarray = (struct vec2 *)vdata->tvarray[0].array;
|
||||
uint32_t *col = (uint32_t *)vdata->colors;
|
||||
|
|
@ -163,28 +168,35 @@ void fill_vertex_buffer(struct ft2_source *srcdata)
|
|||
bfree(srcdata->colorbuf);
|
||||
srcdata->colorbuf = NULL;
|
||||
}
|
||||
srcdata->colorbuf = bzalloc(sizeof(uint32_t)*wcslen(srcdata->text) * 6);
|
||||
srcdata->colorbuf =
|
||||
bzalloc(sizeof(uint32_t) * wcslen(srcdata->text) * 6);
|
||||
for (size_t i = 0; i < len * 6; i++) {
|
||||
srcdata->colorbuf[i] = 0xFF000000;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
add_linebreak:;
|
||||
if (srcdata->text[i] != L'\n') goto draw_glyph;
|
||||
dx = 0; i++;
|
||||
if (srcdata->text[i] != L'\n')
|
||||
goto draw_glyph;
|
||||
dx = 0;
|
||||
i++;
|
||||
dy += srcdata->max_h + 4;
|
||||
if (i == wcslen(srcdata->text)) goto skip_glyph;
|
||||
if (srcdata->text[i] == L'\n') goto add_linebreak;
|
||||
if (i == wcslen(srcdata->text))
|
||||
goto skip_glyph;
|
||||
if (srcdata->text[i] == L'\n')
|
||||
goto add_linebreak;
|
||||
draw_glyph:;
|
||||
// Skip filthy dual byte Windows line breaks
|
||||
if (srcdata->text[i] == L'\r') goto skip_glyph;
|
||||
if (srcdata->text[i] == L'\r')
|
||||
goto skip_glyph;
|
||||
|
||||
glyph_index = FT_Get_Char_Index(srcdata->font_face,
|
||||
srcdata->text[i]);
|
||||
glyph_index =
|
||||
FT_Get_Char_Index(srcdata->font_face, srcdata->text[i]);
|
||||
if (src_glyph == NULL)
|
||||
goto skip_glyph;
|
||||
|
||||
if (srcdata->custom_width < 100) goto skip_custom_width;
|
||||
if (srcdata->custom_width < 100)
|
||||
goto skip_custom_width;
|
||||
|
||||
if (dx + src_glyph->xadv > srcdata->custom_width) {
|
||||
dx = 0;
|
||||
|
|
@ -194,18 +206,13 @@ void fill_vertex_buffer(struct ft2_source *srcdata)
|
|||
skip_custom_width:;
|
||||
|
||||
set_v3_rect(vdata->points + (cur_glyph * 6),
|
||||
(float)dx + (float)src_glyph->xoff,
|
||||
(float)dy - (float)src_glyph->yoff,
|
||||
(float)src_glyph->w,
|
||||
(float)src_glyph->h);
|
||||
set_v2_uv(tvarray + (cur_glyph * 6),
|
||||
src_glyph->u,
|
||||
src_glyph->v,
|
||||
src_glyph->u2,
|
||||
src_glyph->v2);
|
||||
set_rect_colors2(col + (cur_glyph * 6),
|
||||
srcdata->color[0],
|
||||
srcdata->color[1]);
|
||||
(float)dx + (float)src_glyph->xoff,
|
||||
(float)dy - (float)src_glyph->yoff,
|
||||
(float)src_glyph->w, (float)src_glyph->h);
|
||||
set_v2_uv(tvarray + (cur_glyph * 6), src_glyph->u, src_glyph->v,
|
||||
src_glyph->u2, src_glyph->v2);
|
||||
set_rect_colors2(col + (cur_glyph * 6), srcdata->color[0],
|
||||
srcdata->color[1]);
|
||||
dx += src_glyph->xadv;
|
||||
if (dy - (float)src_glyph->yoff + src_glyph->h > max_y)
|
||||
max_y = dy - src_glyph->yoff + src_glyph->h;
|
||||
|
|
@ -228,12 +235,12 @@ void cache_standard_glyphs(struct ft2_source *srcdata)
|
|||
srcdata->texbuf_x = 0;
|
||||
srcdata->texbuf_y = 0;
|
||||
|
||||
cache_glyphs(srcdata, L"abcdefghijklmnopqrstuvwxyz" \
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" \
|
||||
L"!@#$%^&*()-_=+,<.>/?\\|[]{}`~ \'\"\0");
|
||||
cache_glyphs(srcdata, L"abcdefghijklmnopqrstuvwxyz"
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
L"!@#$%^&*()-_=+,<.>/?\\|[]{}`~ \'\"\0");
|
||||
}
|
||||
|
||||
#define glyph_pos x + (y*slot->bitmap.pitch)
|
||||
#define glyph_pos x + (y * slot->bitmap.pitch)
|
||||
#define buf_pos (dx + x) + ((dy + y) * texbuf_w)
|
||||
|
||||
void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs)
|
||||
|
|
@ -252,8 +259,8 @@ void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs)
|
|||
size_t len = wcslen(cache_glyphs);
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
glyph_index = FT_Get_Char_Index(srcdata->font_face,
|
||||
cache_glyphs[i]);
|
||||
glyph_index =
|
||||
FT_Get_Char_Index(srcdata->font_face, cache_glyphs[i]);
|
||||
|
||||
if (src_glyph != NULL)
|
||||
goto skip_glyph;
|
||||
|
|
@ -264,7 +271,8 @@ void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs)
|
|||
uint32_t g_w = slot->bitmap.width;
|
||||
uint32_t g_h = slot->bitmap.rows;
|
||||
|
||||
if (srcdata->max_h < g_h) srcdata->max_h = g_h;
|
||||
if (srcdata->max_h < g_h)
|
||||
srcdata->max_h = g_h;
|
||||
|
||||
if (dx + g_w >= texbuf_w) {
|
||||
dx = 0;
|
||||
|
|
@ -272,7 +280,8 @@ void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs)
|
|||
}
|
||||
|
||||
if (dy + g_h >= texbuf_h) {
|
||||
blog(LOG_WARNING, "Out of space trying to render glyphs");
|
||||
blog(LOG_WARNING,
|
||||
"Out of space trying to render glyphs");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -317,8 +326,9 @@ void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs)
|
|||
gs_texture_destroy(tmp_texture);
|
||||
}
|
||||
|
||||
srcdata->tex = gs_texture_create(texbuf_w, texbuf_h,
|
||||
GS_A8, 1, (const uint8_t **)&srcdata->texbuf, 0);
|
||||
srcdata->tex = gs_texture_create(
|
||||
texbuf_w, texbuf_h, GS_A8, 1,
|
||||
(const uint8_t **)&srcdata->texbuf, 0);
|
||||
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
|
@ -336,7 +346,7 @@ time_t get_modified_timestamp(char *filename)
|
|||
return stats.st_mtime;
|
||||
}
|
||||
|
||||
static void remove_cr(wchar_t* source)
|
||||
static void remove_cr(wchar_t *source)
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; source[i] != '\0'; ++i) {
|
||||
|
|
@ -393,9 +403,9 @@ void load_text_from_file(struct ft2_source *srcdata, const char *filename)
|
|||
bfree(srcdata->text);
|
||||
srcdata->text = NULL;
|
||||
}
|
||||
srcdata->text = bzalloc((strlen(tmp_read) + 1)*sizeof(wchar_t));
|
||||
os_utf8_to_wcs(tmp_read, strlen(tmp_read),
|
||||
srcdata->text, (strlen(tmp_read) + 1));
|
||||
srcdata->text = bzalloc((strlen(tmp_read) + 1) * sizeof(wchar_t));
|
||||
os_utf8_to_wcs(tmp_read, strlen(tmp_read), srcdata->text,
|
||||
(strlen(tmp_read) + 1));
|
||||
|
||||
remove_cr(srcdata->text);
|
||||
bfree(tmp_read);
|
||||
|
|
@ -431,16 +441,17 @@ void read_from_end(struct ft2_source *srcdata, const char *filename)
|
|||
log_lines = srcdata->log_lines;
|
||||
|
||||
while (line_breaks <= log_lines && cur_pos != 0) {
|
||||
if (!utf16) cur_pos--;
|
||||
else cur_pos -= 2;
|
||||
if (!utf16)
|
||||
cur_pos--;
|
||||
else
|
||||
cur_pos -= 2;
|
||||
fseek(tmp_file, cur_pos, SEEK_SET);
|
||||
|
||||
if (!utf16) {
|
||||
bytes_read = fread(&bvalue, 1, 1, tmp_file);
|
||||
if (bytes_read == 1 && bvalue == '\n')
|
||||
line_breaks++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bytes_read = fread(&value, 2, 1, tmp_file);
|
||||
if (bytes_read == 2 && value == L'\n')
|
||||
line_breaks++;
|
||||
|
|
@ -458,8 +469,8 @@ void read_from_end(struct ft2_source *srcdata, const char *filename)
|
|||
srcdata->text = NULL;
|
||||
}
|
||||
srcdata->text = bzalloc(filesize - cur_pos);
|
||||
bytes_read = fread(srcdata->text, (filesize - cur_pos), 1,
|
||||
tmp_file);
|
||||
bytes_read =
|
||||
fread(srcdata->text, (filesize - cur_pos), 1, tmp_file);
|
||||
|
||||
remove_cr(srcdata->text);
|
||||
bfree(tmp_read);
|
||||
|
|
@ -476,9 +487,9 @@ void read_from_end(struct ft2_source *srcdata, const char *filename)
|
|||
bfree(srcdata->text);
|
||||
srcdata->text = NULL;
|
||||
}
|
||||
srcdata->text = bzalloc((strlen(tmp_read) + 1)*sizeof(wchar_t));
|
||||
os_utf8_to_wcs(tmp_read, strlen(tmp_read),
|
||||
srcdata->text, (strlen(tmp_read) + 1));
|
||||
srcdata->text = bzalloc((strlen(tmp_read) + 1) * sizeof(wchar_t));
|
||||
os_utf8_to_wcs(tmp_read, strlen(tmp_read), srcdata->text,
|
||||
(strlen(tmp_read) + 1));
|
||||
|
||||
remove_cr(srcdata->text);
|
||||
bfree(tmp_read);
|
||||
|
|
@ -499,10 +510,12 @@ uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata)
|
|||
glyph_index = FT_Get_Char_Index(srcdata->font_face, text[i]);
|
||||
FT_Load_Glyph(srcdata->font_face, glyph_index, FT_LOAD_DEFAULT);
|
||||
|
||||
if (text[i] == L'\n') w = 0;
|
||||
if (text[i] == L'\n')
|
||||
w = 0;
|
||||
else {
|
||||
w += slot->advance.x >> 6;
|
||||
if (w > max_w) max_w = w;
|
||||
if (w > max_w)
|
||||
max_w = w;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue