BsFont.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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;
  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. private:
  73. Map<UINT32, FontData> mFontDataPerSize;
  74. /************************************************************************/
  75. /* SERIALIZATION */
  76. /************************************************************************/
  77. public:
  78. friend class FontRTTI;
  79. static RTTITypeBase* getRTTIStatic();
  80. virtual RTTITypeBase* getRTTI() const;
  81. };
  82. }