bitmap_font_fb.h 4.6 KB

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