BsFont.h 3.6 KB

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