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 data about font characters of a specific size. Contains
  9. * textures in which the characters are located and information
  10. * about each individual character.
  11. */
  12. struct BS_CORE_EXPORT FontData : public IReflectable
  13. {
  14. /**
  15. * @brief Returns a character description for the character with the specified ID.
  16. */
  17. const CHAR_DESC& getCharDesc(UINT32 charId) const;
  18. UINT32 size; /**< Font size for which the data is contained. */
  19. FONT_DESC fontDesc; /**< Font description containing per-character and general font data. */
  20. Vector<HTexture> texturePages; /**< Textures in which the characters are stored. */
  21. /************************************************************************/
  22. /* SERIALIZATION */
  23. /************************************************************************/
  24. public:
  25. friend class FontDataRTTI;
  26. static RTTITypeBase* getRTTIStatic();
  27. virtual RTTITypeBase* getRTTI() const override;
  28. };
  29. // TODO - When saved on disk font currently stores a copy of the texture pages. This should be acceptable
  30. // if you import a new TrueType or OpenType font since the texture will be generated on the spot
  31. // but if you use a bitmap texture to initialize the font manually, then you will potentially have duplicate textures.
  32. // Also, changing the source texture will not automatically update the font because there is no direct link between them.
  33. // -- This is probably not a large problem, but it is something to keep an eye out.
  34. /**
  35. * @brief Font resource containing data about textual characters
  36. * and how to render text.
  37. */
  38. class BS_CORE_EXPORT Font : public Resource
  39. {
  40. public:
  41. virtual ~Font();
  42. /**
  43. * @brief Initializes the font with specified per-size font data.
  44. *
  45. * @note Internal method. Factory methods will call this automatically for you.
  46. */
  47. void initialize(const Vector<FontData>& fontData);
  48. /**
  49. * @brief Returns font data for a specific size if it exists, null otherwise.
  50. */
  51. const FontData* getFontDataForSize(UINT32 size) const;
  52. /**
  53. * @brief Attempts to find nearest available size next to the provided size.
  54. */
  55. INT32 getClosestAvailableSize(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<FontData>& fontInitData);
  63. /**
  64. * @brief Creates a new font pointer.
  65. *
  66. * @note Internal method.
  67. */
  68. static FontPtr _createPtr(const Vector<FontData>& 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(Vector<SPtr<CoreObject>>& dependencies) override;
  80. private:
  81. Map<UINT32, FontData> mFontDataPerSize;
  82. /************************************************************************/
  83. /* SERIALIZATION */
  84. /************************************************************************/
  85. public:
  86. friend class FontRTTI;
  87. static RTTITypeBase* getRTTIStatic();
  88. virtual RTTITypeBase* getRTTI() const;
  89. };
  90. }