BsFont.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 BS_SCRIPT_EXPORT(m:GUI_Engine) FontBitmap : public IReflectable
  14. {
  15. /** Returns a character description for the character with the specified Unicode key. */
  16. BS_SCRIPT_EXPORT()
  17. const CharDesc& getCharDesc(UINT32 charId) const;
  18. /** Font size for which the data is contained. */
  19. BS_SCRIPT_EXPORT()
  20. UINT32 size;
  21. /** Y offset to the baseline on which the characters are placed, in pixels. */
  22. BS_SCRIPT_EXPORT()
  23. INT32 baselineOffset;
  24. /** Height of a single line of the font, in pixels. */
  25. BS_SCRIPT_EXPORT()
  26. UINT32 lineHeight;
  27. /** Character to use when data for a character is missing. */
  28. BS_SCRIPT_EXPORT()
  29. CharDesc missingGlyph;
  30. /** Width of a space in pixels. */
  31. BS_SCRIPT_EXPORT()
  32. UINT32 spaceWidth;
  33. /** Textures in which the character's pixels are stored. */
  34. BS_SCRIPT_EXPORT()
  35. Vector<HTexture> texturePages;
  36. /** All characters in the font referenced by character ID. */
  37. Map<UINT32, CharDesc> characters;
  38. /************************************************************************/
  39. /* SERIALIZATION */
  40. /************************************************************************/
  41. public:
  42. friend class FontBitmapRTTI;
  43. static RTTITypeBase* getRTTIStatic();
  44. RTTITypeBase* getRTTI() const override;
  45. };
  46. /**
  47. * Font resource containing data about textual characters and how to render text. Contains one or multiple font
  48. * bitmaps, each for a specific size.
  49. */
  50. class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:GUI_Engine) Font : public Resource
  51. {
  52. public:
  53. virtual ~Font();
  54. /**
  55. * Returns font bitmap for a specific font size.
  56. *
  57. * @param[in] size Size of the bitmap in points.
  58. * @return Bitmap object if it exists, false otherwise.
  59. */
  60. BS_SCRIPT_EXPORT()
  61. SPtr<FontBitmap> getBitmap(UINT32 size) const;
  62. /**
  63. * Finds the available font bitmap size closest to the provided size.
  64. *
  65. * @param[in] size Size of the bitmap in points.
  66. * @return Nearest available bitmap size.
  67. */
  68. BS_SCRIPT_EXPORT()
  69. INT32 getClosestSize(UINT32 size) const;
  70. /** Creates a new font from the provided per-size font data. */
  71. static HFont create(const Vector<SPtr<FontBitmap>>& fontInitData);
  72. public: // ***** INTERNAL ******
  73. using Resource::initialize;
  74. /** @name Internal
  75. * @{
  76. */
  77. /**
  78. * Initializes the font with specified per-size font data.
  79. *
  80. * @note Internal method. Factory methods will call this automatically for you.
  81. */
  82. void initialize(const Vector<SPtr<FontBitmap>>& fontData);
  83. /** Creates a new font as a pointer instead of a resource handle. */
  84. static SPtr<Font> _createPtr(const Vector<SPtr<FontBitmap>>& fontInitData);
  85. /** @} */
  86. protected:
  87. friend class FontManager;
  88. Font();
  89. /** @copydoc Resource::getResourceDependencies */
  90. void getResourceDependencies(FrameVector<HResource>& dependencies) const override;
  91. /** @copydoc CoreObject::getCoreDependencies */
  92. void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
  93. private:
  94. Map<UINT32, SPtr<FontBitmap>> mFontDataPerSize;
  95. /************************************************************************/
  96. /* SERIALIZATION */
  97. /************************************************************************/
  98. public:
  99. friend class FontRTTI;
  100. static RTTITypeBase* getRTTIStatic();
  101. RTTITypeBase* getRTTI() const override;
  102. };
  103. /** @} */
  104. }