text-freetype2.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /******************************************************************************
  2. Copyright (C) 2014 by Nibbles
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <obs-module.h>
  15. #include <ft2build.h>
  16. #define num_cache_slots 65535
  17. #define src_glyph srcdata->cacheglyphs[glyph_index]
  18. struct glyph_info {
  19. float u, v, u2, v2;
  20. int32_t w, h, xoff, yoff;
  21. int32_t xadv;
  22. };
  23. struct ft2_source {
  24. char *font_name;
  25. char *font_style;
  26. uint16_t font_size;
  27. uint32_t font_flags;
  28. char *text_file;
  29. wchar_t *text;
  30. time_t m_timestamp;
  31. uint64_t last_checked;
  32. uint32_t cx, cy, max_h, custom_width;
  33. uint32_t texbuf_x, texbuf_y;
  34. uint32_t color[2];
  35. uint32_t *colorbuf;
  36. int32_t cur_scroll, scroll_speed;
  37. gs_texture_t tex;
  38. struct glyph_info *cacheglyphs[num_cache_slots];
  39. FT_Face font_face;
  40. uint32_t *texbuf;
  41. gs_vertbuffer_t vbuf;
  42. gs_effect_t draw_effect;
  43. bool outline_text, drop_shadow;
  44. bool log_mode, word_wrap;
  45. obs_source_t src;
  46. };
  47. extern FT_Library ft2_lib;
  48. static void *ft2_source_create(obs_data_t settings, obs_source_t source);
  49. static void ft2_source_destroy(void *data);
  50. static void ft2_source_update(void *data, obs_data_t settings);
  51. static void ft2_source_render(void *data, gs_effect_t effect);
  52. static void ft2_video_tick(void *data, float seconds);
  53. void draw_outlines(struct ft2_source *srcdata);
  54. void draw_drop_shadow(struct ft2_source *srcdata);
  55. static uint32_t ft2_source_get_width(void *data);
  56. static uint32_t ft2_source_get_height(void *data);
  57. static obs_properties_t ft2_source_properties(void);
  58. static const char *ft2_source_get_name(void);
  59. uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata);
  60. time_t get_modified_timestamp(char *filename);
  61. void load_text_from_file(struct ft2_source *srcdata, const char *filename);
  62. void read_from_end(struct ft2_source *srcdata, const char *filename);
  63. void cache_standard_glyphs(struct ft2_source *srcdata);
  64. void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs);
  65. void set_up_vertex_buffer(struct ft2_source *srcdata);
  66. void fill_vertex_buffer(struct ft2_source *srcdata);