BsFont.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsResource.h"
  7. #include "BsFontDesc.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Contains data about font characters of a specific size. Contains
  12. * textures in which the characters are located and information
  13. * about each individual character.
  14. */
  15. struct BS_CORE_EXPORT FontData : public IReflectable
  16. {
  17. /**
  18. * @brief Returns a character description for the character with the specified ID.
  19. */
  20. const CHAR_DESC& getCharDesc(UINT32 charId) const;
  21. UINT32 size; /**< Font size for which the data is contained. */
  22. FONT_DESC fontDesc; /**< Font description containing per-character and general font data. */
  23. Vector<HTexture> texturePages; /**< Textures in which the characters are stored. */
  24. /************************************************************************/
  25. /* SERIALIZATION */
  26. /************************************************************************/
  27. public:
  28. friend class FontDataRTTI;
  29. static RTTITypeBase* getRTTIStatic();
  30. virtual RTTITypeBase* getRTTI() const;
  31. };
  32. // TODO - When saved on disk font currently stores a copy of the texture pages. This should be acceptable
  33. // if you import a new TrueType or OpenType font since the texture will be generated on the spot
  34. // but if you use a bitmap texture to initialize the font manually, then you will potentially have duplicate textures.
  35. // Also, changing the source texture will not automatically update the font because there is no direct link between them.
  36. // -- This is probably not a large problem, but it is something to keep an eye out.
  37. /**
  38. * @brief Font resource containing data about textual characters
  39. * and how to render text.
  40. */
  41. class BS_CORE_EXPORT Font : public Resource
  42. {
  43. public:
  44. virtual ~Font();
  45. /**
  46. * @brief Initializes the font with specified per-size font data.
  47. *
  48. * @note Internal method. Factory methods will call this automatically for you.
  49. */
  50. void initialize(const Vector<FontData>& fontData);
  51. /**
  52. * @brief Returns font data for a specific size if it exists, null otherwise.
  53. */
  54. const FontData* getFontDataForSize(UINT32 size) const;
  55. /**
  56. * @brief Attempts to find nearest available size next to the provided size.
  57. */
  58. INT32 getClosestAvailableSize(UINT32 size) const;
  59. /************************************************************************/
  60. /* STATICS */
  61. /************************************************************************/
  62. /**
  63. * @brief Creates a new font from the provided per-size font data.
  64. */
  65. static HFont create(const Vector<FontData>& fontInitData);
  66. /**
  67. * @brief Creates a new font pointer.
  68. *
  69. * @note Internal method.
  70. */
  71. static FontPtr _createPtr(const Vector<FontData>& fontInitData);
  72. protected:
  73. friend class FontManager;
  74. Font();
  75. private:
  76. Map<UINT32, FontData> mFontDataPerSize;
  77. /************************************************************************/
  78. /* SERIALIZATION */
  79. /************************************************************************/
  80. public:
  81. friend class FontRTTI;
  82. static RTTITypeBase* getRTTIStatic();
  83. virtual RTTITypeBase* getRTTI() const;
  84. };
  85. }