BsFont.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "BsResource.h"
  6. #include "BsFontDesc.h"
  7. namespace BansheeEngine
  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. virtual 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. /** @cond INTERNAL */
  50. /**
  51. * Initializes the font with specified per-size font data.
  52. *
  53. * @note Internal method. Factory methods will call this automatically for you.
  54. */
  55. void initialize(const Vector<SPtr<FontBitmap>>& fontData);
  56. /** Creates a new font as a pointer instead of a resource handle. */
  57. static FontPtr _createPtr(const Vector<SPtr<FontBitmap>>& fontInitData);
  58. /** @endcond */
  59. protected:
  60. friend class FontManager;
  61. Font();
  62. /** @copydoc Resource::getResourceDependencies */
  63. void getResourceDependencies(FrameVector<HResource>& dependencies) const override;
  64. /** @copydoc CoreObject::getCoreDependencies */
  65. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  66. private:
  67. Map<UINT32, SPtr<FontBitmap>> mFontDataPerSize;
  68. /************************************************************************/
  69. /* SERIALIZATION */
  70. /************************************************************************/
  71. public:
  72. friend class FontRTTI;
  73. static RTTITypeBase* getRTTIStatic();
  74. virtual RTTITypeBase* getRTTI() const override;
  75. };
  76. /** @} */
  77. }