text-freetype2.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #pragma once
  15. #include <obs-module.h>
  16. #include <ft2build.h>
  17. #define num_cache_slots 65535
  18. #define src_glyph srcdata->cacheglyphs[glyph_index]
  19. struct glyph_info {
  20. float u, v, u2, v2;
  21. int32_t w, h, xoff, yoff;
  22. int32_t xadv;
  23. };
  24. struct ft2_source {
  25. char *font_name;
  26. char *font_style;
  27. uint16_t font_size;
  28. uint32_t font_flags;
  29. bool file_load_failed;
  30. bool from_file;
  31. char *text_file;
  32. wchar_t *text;
  33. time_t m_timestamp;
  34. bool update_file;
  35. uint64_t last_checked;
  36. uint32_t cx, cy, max_h, custom_width;
  37. uint32_t texbuf_x, texbuf_y;
  38. uint32_t color[2];
  39. uint32_t *colorbuf;
  40. int32_t cur_scroll, scroll_speed;
  41. gs_texture_t *tex;
  42. struct glyph_info *cacheglyphs[num_cache_slots];
  43. FT_Face font_face;
  44. uint8_t *texbuf;
  45. gs_vertbuffer_t *vbuf;
  46. gs_effect_t *draw_effect;
  47. bool outline_text, drop_shadow;
  48. bool log_mode, word_wrap;
  49. uint32_t log_lines;
  50. obs_source_t *src;
  51. };
  52. extern FT_Library ft2_lib;
  53. static void *ft2_source_create(obs_data_t *settings, obs_source_t *source);
  54. static void ft2_source_destroy(void *data);
  55. static void ft2_source_update(void *data, obs_data_t *settings);
  56. static void ft2_source_render(void *data, gs_effect_t *effect);
  57. static void ft2_video_tick(void *data, float seconds);
  58. void draw_outlines(struct ft2_source *srcdata);
  59. void draw_drop_shadow(struct ft2_source *srcdata);
  60. static uint32_t ft2_source_get_width(void *data);
  61. static uint32_t ft2_source_get_height(void *data);
  62. static obs_properties_t *ft2_source_properties(void *unused);
  63. static const char *ft2_source_get_name(void *unused);
  64. uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata);
  65. time_t get_modified_timestamp(char *filename);
  66. void load_text_from_file(struct ft2_source *srcdata, const char *filename);
  67. void read_from_end(struct ft2_source *srcdata, const char *filename);
  68. void cache_standard_glyphs(struct ft2_source *srcdata);
  69. void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs);
  70. void set_up_vertex_buffer(struct ft2_source *srcdata);
  71. void fill_vertex_buffer(struct ft2_source *srcdata);