2
0

BsFont.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsResource.h"
  4. #include "BsFontDesc.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Contains textures and data about every character for a bitmap font of a specific size.
  9. */
  10. struct BS_CORE_EXPORT FontBitmap : public IReflectable
  11. {
  12. /**
  13. * @brief Returns a character description for the character with the specified Unicode key.
  14. */
  15. const CHAR_DESC& getCharDesc(UINT32 charId) const;
  16. UINT32 size; /**< Font size for which the data is contained. */
  17. FONT_DESC fontDesc; /**< Font description containing per-character and general font data. */
  18. Vector<HTexture> texturePages; /**< Textures in which the character's pixels are stored. */
  19. /************************************************************************/
  20. /* SERIALIZATION */
  21. /************************************************************************/
  22. public:
  23. friend class FontBitmapRTTI;
  24. static RTTITypeBase* getRTTIStatic();
  25. virtual RTTITypeBase* getRTTI() const override;
  26. };
  27. // TODO - When saved on disk font currently stores a copy of the texture pages. This should be acceptable
  28. // if you import a new TrueType or OpenType font since the texture will be generated on the spot
  29. // but if you use a bitmap texture to initialize the font manually, then you will potentially have duplicate textures.
  30. // Also, changing the source texture will not automatically update the font because there is no direct link between them.
  31. // -- This is probably not a large problem, but it is something to keep an eye out.
  32. /**
  33. * @brief Font resource containing data about textual characters
  34. * and how to render text.
  35. */
  36. class BS_CORE_EXPORT Font : public Resource
  37. {
  38. public:
  39. virtual ~Font();
  40. /**
  41. * @brief Initializes the font with specified per-size font data.
  42. *
  43. * @note Internal method. Factory methods will call this automatically for you.
  44. */
  45. void initialize(const Vector<SPtr<FontBitmap>>& fontData);
  46. /**
  47. * @brief Returns font bitmap for a specific size if it exists, null otherwise.
  48. *
  49. * @param size Size of the bitmap in points.
  50. */
  51. SPtr<const FontBitmap> getBitmap(UINT32 size) const;
  52. /**
  53. * @brief Finds the available font bitmap size closest to the provided size.
  54. */
  55. INT32 getClosestSize(UINT32 size) const;
  56. /************************************************************************/
  57. /* STATICS */
  58. /************************************************************************/
  59. /**
  60. * @brief Creates a new font from the provided per-size font data.
  61. */
  62. static HFont create(const Vector<SPtr<FontBitmap>>& fontInitData);
  63. /**
  64. * @brief Creates a new font as a pointer instead of a resource handle.
  65. *
  66. * @note Internal method.
  67. */
  68. static FontPtr _createPtr(const Vector<SPtr<FontBitmap>>& fontInitData);
  69. protected:
  70. friend class FontManager;
  71. Font();
  72. /**
  73. * @copydoc Resource::getResourceDependencies
  74. */
  75. void getResourceDependencies(FrameVector<HResource>& dependencies) const override;
  76. /**
  77. * @copydoc CoreObject::getCoreDependencies
  78. */
  79. void getCoreDependencies(FrameVector<SPtr<CoreObject>>& dependencies) override;
  80. private:
  81. Map<UINT32, SPtr<FontBitmap>> mFontDataPerSize;
  82. /************************************************************************/
  83. /* SERIALIZATION */
  84. /************************************************************************/
  85. public:
  86. friend class FontRTTI;
  87. static RTTITypeBase* getRTTIStatic();
  88. virtual RTTITypeBase* getRTTI() const override;
  89. };
  90. }