text-freetype2.h 3.0 KB

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