bitmap_font_adv.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*************************************************************************/
  2. /* bitmap_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 BITMAP_FONT_ADV_H
  31. #define BITMAP_FONT_ADV_H
  32. #include "font_adv.h"
  33. void hb_bmp_create_font_funcs();
  34. void hb_bmp_free_font_funcs();
  35. struct BitmapFontDataAdvanced : public FontDataAdvanced {
  36. _THREAD_SAFE_CLASS_
  37. private:
  38. Vector<Ref<Texture2D>> textures;
  39. struct Character {
  40. int texture_idx = 0;
  41. Rect2 rect;
  42. Vector2 align;
  43. Vector2 advance = Vector2(-1, -1);
  44. };
  45. struct KerningPairKey {
  46. union {
  47. struct {
  48. uint32_t A, B;
  49. };
  50. uint64_t pair = 0;
  51. };
  52. _FORCE_INLINE_ bool operator<(const KerningPairKey &p_r) const { return pair < p_r.pair; }
  53. };
  54. HashMap<uint32_t, Character> char_map;
  55. Map<KerningPairKey, int> kerning_map;
  56. Map<float, hb_font_t *> cache;
  57. float height = 0.f;
  58. float ascent = 0.f;
  59. float base_size = 0.f;
  60. bool distance_field_hint = false;
  61. public:
  62. virtual void clear_cache() override{};
  63. virtual Error load_from_file(const String &p_filename, int p_base_size) override;
  64. virtual Error load_from_memory(const uint8_t *p_data, size_t p_size, int p_base_size) override;
  65. virtual float get_height(int p_size) const override;
  66. virtual float get_ascent(int p_size) const override;
  67. virtual float get_descent(int p_size) const override;
  68. virtual float get_underline_position(int p_size) const override;
  69. virtual float get_underline_thickness(int p_size) const override;
  70. virtual void set_antialiased(bool p_antialiased) override{};
  71. virtual bool get_antialiased() const override { return false; };
  72. virtual void set_hinting(TextServer::Hinting p_hinting) override{};
  73. virtual TextServer::Hinting get_hinting() const override { return TextServer::HINTING_NONE; };
  74. virtual void set_distance_field_hint(bool p_distance_field) override;
  75. virtual bool get_distance_field_hint() const override;
  76. virtual void set_force_autohinter(bool p_enabeld) override{};
  77. virtual bool get_force_autohinter() const override { return false; };
  78. virtual bool has_outline() const override { return false; };
  79. virtual float get_base_size() const override;
  80. virtual hb_font_t *get_hb_handle(int p_size) override;
  81. virtual bool has_char(char32_t p_char) const override;
  82. virtual String get_supported_chars() const override;
  83. virtual Vector2 get_advance(uint32_t p_char, int p_size) const override;
  84. Vector2 get_align(uint32_t p_char, int p_size) const;
  85. Vector2 get_size(uint32_t p_char, int p_size) const;
  86. virtual Vector2 get_kerning(uint32_t p_char, uint32_t p_next, int p_size) const override;
  87. virtual uint32_t get_glyph_index(char32_t p_char, char32_t p_variation_selector) const override { return (uint32_t)p_char; };
  88. virtual Vector2 draw_glyph(RID p_canvas, int p_size, const Vector2 &p_pos, uint32_t p_index, const Color &p_color) const override;
  89. 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 override;
  90. virtual ~BitmapFontDataAdvanced();
  91. };
  92. #endif // BITMAP_FONT_ADV_H