text_server_fb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*************************************************************************/
  2. /* text_server_fb.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 TEXT_SERVER_FALLBACK_H
  31. #define TEXT_SERVER_FALLBACK_H
  32. /*************************************************************************/
  33. /* Fallback Text Server provides simplified TS functionality, without */
  34. /* BiDi, shaping and advanced font features support. */
  35. /*************************************************************************/
  36. #include "servers/text_server.h"
  37. #include "core/templates/rid_owner.h"
  38. #include "scene/resources/texture.h"
  39. #include "font_fb.h"
  40. class TextServerFallback : public TextServer {
  41. GDCLASS(TextServerFallback, TextServer);
  42. _THREAD_SAFE_CLASS_
  43. float oversampling = 1.f;
  44. mutable RID_PtrOwner<FontDataFallback> font_owner;
  45. mutable RID_PtrOwner<ShapedTextData> shaped_owner;
  46. static String interface_name;
  47. static uint32_t interface_features;
  48. protected:
  49. static void _bind_methods(){};
  50. void full_copy(ShapedTextData *p_shaped);
  51. void invalidate(ShapedTextData *p_shaped);
  52. public:
  53. virtual bool has_feature(Feature p_feature) override;
  54. virtual String get_name() const override;
  55. virtual void free(RID p_rid) override;
  56. virtual bool has(RID p_rid) override;
  57. virtual bool load_support_data(const String &p_filename) override;
  58. #ifdef TOOLS_ENABLED
  59. virtual String get_support_data_filename() override { return ""; };
  60. virtual String get_support_data_info() override { return "Not supported"; };
  61. virtual bool save_support_data(const String &p_filename) override;
  62. #endif
  63. virtual bool is_locale_right_to_left(const String &p_locale) override;
  64. /* Font interface */
  65. virtual RID create_font_system(const String &p_name, int p_base_size = 16) override;
  66. virtual RID create_font_resource(const String &p_filename, int p_base_size = 16) override;
  67. virtual RID create_font_memory(const uint8_t *p_data, size_t p_size, const String &p_type, int p_base_size = 16) override;
  68. virtual float font_get_height(RID p_font, int p_size) const override;
  69. virtual float font_get_ascent(RID p_font, int p_size) const override;
  70. virtual float font_get_descent(RID p_font, int p_size) const override;
  71. virtual float font_get_underline_position(RID p_font, int p_size) const override;
  72. virtual float font_get_underline_thickness(RID p_font, int p_size) const override;
  73. virtual int font_get_spacing_space(RID p_font) const override;
  74. virtual void font_set_spacing_space(RID p_font, int p_value) override;
  75. virtual int font_get_spacing_glyph(RID p_font) const override;
  76. virtual void font_set_spacing_glyph(RID p_font, int p_value) override;
  77. virtual void font_set_antialiased(RID p_font, bool p_antialiased) override;
  78. virtual bool font_get_antialiased(RID p_font) const override;
  79. virtual void font_set_hinting(RID p_font, Hinting p_hinting) override;
  80. virtual Hinting font_get_hinting(RID p_font) const override;
  81. virtual void font_set_force_autohinter(RID p_font, bool p_enabeld) override;
  82. virtual bool font_get_force_autohinter(RID p_font) const override;
  83. virtual bool font_has_char(RID p_font, char32_t p_char) const override;
  84. virtual String font_get_supported_chars(RID p_font) const override;
  85. virtual void font_set_distance_field_hint(RID p_font, bool p_distance_field) override;
  86. virtual bool font_get_distance_field_hint(RID p_font) const override;
  87. virtual bool font_has_outline(RID p_font) const override;
  88. virtual float font_get_base_size(RID p_font) const override;
  89. virtual bool font_is_language_supported(RID p_font, const String &p_language) const override;
  90. virtual void font_set_language_support_override(RID p_font, const String &p_language, bool p_supported) override;
  91. virtual bool font_get_language_support_override(RID p_font, const String &p_language) override;
  92. virtual void font_remove_language_support_override(RID p_font, const String &p_language) override;
  93. Vector<String> font_get_language_support_overrides(RID p_font) override;
  94. virtual bool font_is_script_supported(RID p_font, const String &p_script) const override;
  95. virtual void font_set_script_support_override(RID p_font, const String &p_script, bool p_supported) override;
  96. virtual bool font_get_script_support_override(RID p_font, const String &p_script) override;
  97. virtual void font_remove_script_support_override(RID p_font, const String &p_script) override;
  98. Vector<String> font_get_script_support_overrides(RID p_font) override;
  99. virtual uint32_t font_get_glyph_index(RID p_font, char32_t p_char, char32_t p_variation_selector = 0x0000) const override;
  100. virtual Vector2 font_get_glyph_advance(RID p_font, uint32_t p_index, int p_size) const override;
  101. virtual Vector2 font_get_glyph_kerning(RID p_font, uint32_t p_index_a, uint32_t p_index_b, int p_size) const override;
  102. virtual Vector2 font_draw_glyph(RID p_font, RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
  103. virtual Vector2 font_draw_glyph_outline(RID p_font, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color = Color(1, 1, 1)) const override;
  104. virtual float font_get_oversampling() const override;
  105. virtual void font_set_oversampling(float p_oversampling) override;
  106. virtual Vector<String> get_system_fonts() const override;
  107. /* Shaped text buffer interface */
  108. virtual RID create_shaped_text(Direction p_direction = DIRECTION_AUTO, Orientation p_orientation = ORIENTATION_HORIZONTAL) override;
  109. virtual void shaped_text_clear(RID p_shaped) override;
  110. virtual void shaped_text_set_direction(RID p_shaped, Direction p_direction = DIRECTION_AUTO) override;
  111. virtual Direction shaped_text_get_direction(RID p_shaped) const override;
  112. virtual void shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) override;
  113. virtual void shaped_text_set_orientation(RID p_shaped, Orientation p_orientation = ORIENTATION_HORIZONTAL) override;
  114. virtual Orientation shaped_text_get_orientation(RID p_shaped) const override;
  115. virtual void shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) override;
  116. virtual bool shaped_text_get_preserve_invalid(RID p_shaped) const override;
  117. virtual void shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) override;
  118. virtual bool shaped_text_get_preserve_control(RID p_shaped) const override;
  119. virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "") override;
  120. virtual bool shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align = VALIGN_CENTER, int p_length = 1) override;
  121. virtual bool shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, VAlign p_inline_align = VALIGN_CENTER) override;
  122. virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override;
  123. virtual RID shaped_text_get_parent(RID p_shaped) const override;
  124. virtual float shaped_text_fit_to_width(RID p_shaped, float p_width, uint8_t /*JustificationFlag*/ p_jst_flags = JUSTIFICATION_WORD_BOUND | JUSTIFICATION_KASHIDA) override;
  125. virtual float shaped_text_tab_align(RID p_shaped, const Vector<float> &p_tab_stops) override;
  126. virtual bool shaped_text_shape(RID p_shaped) override;
  127. virtual bool shaped_text_update_breaks(RID p_shaped) override;
  128. virtual bool shaped_text_update_justification_ops(RID p_shaped) override;
  129. virtual bool shaped_text_is_ready(RID p_shaped) const override;
  130. virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override;
  131. virtual Vector2i shaped_text_get_range(RID p_shaped) const override;
  132. virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override;
  133. virtual Array shaped_text_get_objects(RID p_shaped) const override;
  134. virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override;
  135. virtual Size2 shaped_text_get_size(RID p_shaped) const override;
  136. virtual float shaped_text_get_ascent(RID p_shaped) const override;
  137. virtual float shaped_text_get_descent(RID p_shaped) const override;
  138. virtual float shaped_text_get_width(RID p_shaped) const override;
  139. virtual float shaped_text_get_underline_position(RID p_shaped) const override;
  140. virtual float shaped_text_get_underline_thickness(RID p_shaped) const override;
  141. static TextServer *create_func(Error &r_error, void *p_user_data);
  142. static void register_server();
  143. TextServerFallback(){};
  144. ~TextServerFallback(){};
  145. };
  146. #endif // TEXT_SERVER_FALLBACK_H