text-freetype2.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. FT_Pos 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. int32_t cur_scroll, scroll_speed;
  42. gs_texture_t *tex;
  43. struct glyph_info *cacheglyphs[num_cache_slots];
  44. FT_Face font_face;
  45. uint8_t *texbuf;
  46. gs_vertbuffer_t *vbuf;
  47. gs_effect_t *draw_effect;
  48. bool outline_text, drop_shadow;
  49. bool log_mode, word_wrap;
  50. uint32_t log_lines;
  51. obs_source_t *src;
  52. };
  53. extern FT_Library ft2_lib;
  54. void draw_outlines(struct ft2_source *srcdata);
  55. void draw_drop_shadow(struct ft2_source *srcdata);
  56. uint32_t get_ft2_text_width(wchar_t *text, struct ft2_source *srcdata);
  57. time_t get_modified_timestamp(char *filename);
  58. void load_text_from_file(struct ft2_source *srcdata, const char *filename);
  59. void read_from_end(struct ft2_source *srcdata, const char *filename);
  60. void cache_standard_glyphs(struct ft2_source *srcdata);
  61. void cache_glyphs(struct ft2_source *srcdata, wchar_t *cache_glyphs);
  62. void set_up_vertex_buffer(struct ft2_source *srcdata);
  63. void fill_vertex_buffer(struct ft2_source *srcdata);