7f0ae838d7
This changes the font plugin from using a font file to using a specific installed system font, which is searched for on each specific system and associated with the font file. It now uses a font property instead of a path property, and font size has been removed because the font property now handles that. When the module is first loaded, it will build up a list of system fonts in order to be usable by Freetype. It was quite painful to program this because font files can contain multiple localized versions of their face names, and then there was the issue where windows likes to mangle custom style types to the font name. Regardless, it all seems to have worked out pretty well. Minor issues: - Truetype/Opentype fonts sometimes do not automatically have italic and/or bold styles available, it seems that the system applies transformations manually in those cases. We don't do this yet, however, so right now a user might select a font with italic/bold only to discover that italic/bold doesn't always work. Not entirely sure what to do about this yet. There's probably a freetype function to do something like that somehow, This also requires that iconv be used for non-windows systems to be able to look up localized font names within font files. Windows will use the win32 API and code page IDs to translate font names.
93 lines
2.7 KiB
C
93 lines
2.7 KiB
C
/******************************************************************************
|
|
Copyright (C) 2014 by Nibbles
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
******************************************************************************/
|
|
|
|
#include <obs-module.h>
|
|
#include <ft2build.h>
|
|
|
|
#define num_cache_slots 65535
|
|
#define src_glyph srcdata->cacheglyphs[glyph_index]
|
|
|
|
struct glyph_info {
|
|
float u, v, u2, v2;
|
|
int32_t w, h, xoff, yoff;
|
|
int32_t xadv;
|
|
};
|
|
|
|
struct ft2_source {
|
|
char *font_name;
|
|
char *font_style;
|
|
uint16_t font_size;
|
|
uint32_t font_flags;
|
|
|
|
char *text_file;
|
|
wchar_t *text;
|
|
time_t m_timestamp;
|
|
uint64_t last_checked;
|
|
|
|
uint32_t cx, cy, max_h, custom_width;
|
|
uint32_t texbuf_x, texbuf_y;
|
|
uint32_t color[2];
|
|
uint32_t *colorbuf;
|
|
|
|
int32_t cur_scroll, scroll_speed;
|
|
|
|
gs_texture_t tex;
|
|
|
|
struct glyph_info *cacheglyphs[num_cache_slots];
|
|
|
|
FT_Face font_face;
|
|
|
|
uint32_t *texbuf;
|
|
gs_vertbuffer_t vbuf;
|
|
|
|
gs_effect_t draw_effect;
|
|
bool outline_text, drop_shadow;
|
|
bool log_mode, word_wrap;
|
|
|
|
obs_source_t src;
|
|
};
|
|
|
|
extern FT_Library ft2_lib;
|
|
|
|
static void *ft2_source_create(obs_data_t settings, obs_source_t source);
|
|
static void ft2_source_destroy(void *data);
|
|
static void ft2_source_update(void *data, obs_data_t settings);
|
|
static void ft2_source_render(void *data, gs_effect_t effect);
|
|
static void ft2_video_tick(void *data, float seconds);
|
|
|
|
void draw_outlines(struct ft2_source *srcdata);
|
|
void draw_drop_shadow(struct ft2_source *srcdata);
|
|
|
|
static uint32_t ft2_source_get_width(void *data);
|
|
static uint32_t ft2_source_get_height(void *data);
|
|
|
|
static obs_properties_t ft2_source_properties(void);
|
|
|
|
static const char *ft2_source_get_name(void);
|
|
|
|
uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata);
|
|
|
|
time_t get_modified_timestamp(char *filename);
|
|
void load_text_from_file(struct ft2_source *srcdata, const char *filename);
|
|
void read_from_end(struct ft2_source *srcdata, const char *filename);
|
|
|
|
void cache_standard_glyphs(struct ft2_source *srcdata);
|
|
void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs);
|
|
|
|
void set_up_vertex_buffer(struct ft2_source *srcdata);
|
|
void fill_vertex_buffer(struct ft2_source *srcdata);
|