BsFont.h 3.4 KB

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