text-freetype2.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. bool file_load_failed;
  29. bool from_file;
  30. char *text_file;
  31. wchar_t *text;
  32. time_t m_timestamp;
  33. uint64_t last_checked;
  34. uint32_t cx, cy, max_h, custom_width;
  35. uint32_t texbuf_x, texbuf_y;
  36. uint32_t color[2];
  37. uint32_t *colorbuf;
  38. int32_t cur_scroll, scroll_speed;
  39. gs_texture_t *tex;
  40. struct glyph_info *cacheglyphs[num_cache_slots];
  41. FT_Face font_face;
  42. uint8_t *texbuf;
  43. gs_vertbuffer_t *vbuf;
  44. gs_effect_t *draw_effect;
  45. bool outline_text, drop_shadow;
  46. bool log_mode, word_wrap;
  47. obs_source_t *src;
  48. };
  49. extern FT_Library ft2_lib;
  50. static void *ft2_source_create(obs_data_t *settings, obs_source_t *source);
  51. static void ft2_source_destroy(void *data);
  52. static void ft2_source_update(void *data, obs_data_t *settings);
  53. static void ft2_source_render(void *data, gs_effect_t *effect);
  54. static void ft2_video_tick(void *data, float seconds);
  55. void draw_outlines(struct ft2_source *srcdata);
  56. void draw_drop_shadow(struct ft2_source *srcdata);
  57. static uint32_t ft2_source_get_width(void *data);
  58. static uint32_t ft2_source_get_height(void *data);
  59. static obs_properties_t *ft2_source_properties(void *unused);
  60. static const char *ft2_source_get_name(void *unused);
  61. uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata);
  62. time_t get_modified_timestamp(char *filename);
  63. void load_text_from_file(struct ft2_source *srcdata, const char *filename);
  64. void read_from_end(struct ft2_source *srcdata, const char *filename);
  65. void cache_standard_glyphs(struct ft2_source *srcdata);
  66. void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs);
  67. void set_up_vertex_buffer(struct ft2_source *srcdata);
  68. void fill_vertex_buffer(struct ft2_source *srcdata);