font_adv.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*************************************************************************/
  2. /* font_adv.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef FONT_ADV_H
  31. #define FONT_ADV_H
  32. #include "servers/text_server.h"
  33. #include <hb.h>
  34. struct FontDataAdvanced {
  35. Map<String, bool> lang_support_overrides;
  36. Map<String, bool> script_support_overrides;
  37. bool valid = false;
  38. int spacing_space = 0;
  39. int spacing_glyph = 0;
  40. virtual void clear_cache() = 0;
  41. virtual Error load_from_file(const String &p_filename, int p_base_size) = 0;
  42. virtual Error load_from_memory(const uint8_t *p_data, size_t p_size, int p_base_size) = 0;
  43. virtual float get_height(int p_size) const = 0;
  44. virtual float get_ascent(int p_size) const = 0;
  45. virtual float get_descent(int p_size) const = 0;
  46. virtual Dictionary get_feature_list() const { return Dictionary(); };
  47. virtual Dictionary get_variation_list() const { return Dictionary(); };
  48. virtual void set_variation(const String &p_name, double p_value){};
  49. virtual double get_variation(const String &p_name) const { return 0; };
  50. virtual float get_underline_position(int p_size) const = 0;
  51. virtual float get_underline_thickness(int p_size) const = 0;
  52. virtual int get_spacing_space() const { return spacing_space; };
  53. virtual void set_spacing_space(int p_value) {
  54. spacing_space = p_value;
  55. clear_cache();
  56. };
  57. virtual int get_spacing_glyph() const { return spacing_glyph; };
  58. virtual void set_spacing_glyph(int p_value) {
  59. spacing_glyph = p_value;
  60. clear_cache();
  61. };
  62. virtual void set_antialiased(bool p_antialiased) = 0;
  63. virtual bool get_antialiased() const = 0;
  64. virtual void set_hinting(TextServer::Hinting p_hinting) = 0;
  65. virtual TextServer::Hinting get_hinting() const = 0;
  66. virtual void set_distance_field_hint(bool p_distance_field) = 0;
  67. virtual bool get_distance_field_hint() const = 0;
  68. virtual void set_force_autohinter(bool p_enabeld) = 0;
  69. virtual bool get_force_autohinter() const = 0;
  70. virtual bool has_outline() const = 0;
  71. virtual float get_base_size() const = 0;
  72. virtual bool is_lang_supported(const String &p_lang) const { return false; };
  73. virtual bool is_script_supported(uint32_t p_script) const { return false; };
  74. virtual bool has_char(char32_t p_char) const = 0;
  75. virtual String get_supported_chars() const = 0;
  76. virtual float get_font_scale(int p_size) const { return 1.0f; };
  77. virtual hb_font_t *get_hb_handle(int p_size) = 0;
  78. virtual uint32_t get_glyph_index(char32_t p_char, char32_t p_variation_selector) const = 0;
  79. virtual Vector2 get_advance(uint32_t p_char, int p_size) const = 0;
  80. virtual Vector2 get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const = 0;
  81. virtual Vector2 draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const = 0;
  82. virtual Vector2 draw_glyph_outline(RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const = 0;
  83. virtual ~FontDataAdvanced(){};
  84. };
  85. #endif // FONT_ADV_H