BsFont.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /** @cond INTERNAL */
  39. /**
  40. * Initializes the font with specified per-size font data.
  41. *
  42. * @note Internal method. Factory methods will call this automatically for you.
  43. */
  44. void initialize(const Vector<SPtr<FontBitmap>>& fontData);
  45. /** @endcond */
  46. /**
  47. * Returns font bitmap for a specific size if it exists, null otherwise.
  48. *
  49. * @param[in] size Size of the bitmap in points.
  50. */
  51. SPtr<const FontBitmap> getBitmap(UINT32 size) const;
  52. /** Finds the available font bitmap size closest to the provided size. */
  53. INT32 getClosestSize(UINT32 size) const;
  54. /** Creates a new font from the provided per-size font data. */
  55. static HFont create(const Vector<SPtr<FontBitmap>>& fontInitData);
  56. /** @cond INTERNAL */
  57. /** Creates a new font as a pointer instead of a resource handle. */
  58. static FontPtr _createPtr(const Vector<SPtr<FontBitmap>>& fontInitData);
  59. /** @endcond */
  60. protected:
  61. friend class FontManager;
  62. Font();
  63. /** @copydoc Resource::getResourceDependencies */
  64. void getResourceDependencies(FrameVector<HResource>& dependencies) const override;
  65. /** @copydoc CoreObject::getCoreDependencies */
  66. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  67. private:
  68. Map<UINT32, SPtr<FontBitmap>> mFontDataPerSize;
  69. /************************************************************************/
  70. /* SERIALIZATION */
  71. /************************************************************************/
  72. public:
  73. friend class FontRTTI;
  74. static RTTITypeBase* getRTTIStatic();
  75. virtual RTTITypeBase* getRTTI() const override;
  76. };
  77. /** @} */
  78. }