1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Resources/BsResource.h"
7#include "Text/BsFontDesc.h"
8
9namespace bs
10{
11 /** @addtogroup Text
12 * @{
13 */
14
15 /** Contains textures and data about every character for a bitmap font of a specific size. */
16 struct BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:GUI_Engine) FontBitmap : public IReflectable
17 {
18 /** Returns a character description for the character with the specified Unicode key. */
19 BS_SCRIPT_EXPORT()
20 const CharDesc& getCharDesc(UINT32 charId) const;
21
22 /** Font size for which the data is contained. */
23 BS_SCRIPT_EXPORT()
24 UINT32 size;
25
26 /** Y offset to the baseline on which the characters are placed, in pixels. */
27 BS_SCRIPT_EXPORT()
28 INT32 baselineOffset;
29
30 /** Height of a single line of the font, in pixels. */
31 BS_SCRIPT_EXPORT()
32 UINT32 lineHeight;
33
34 /** Character to use when data for a character is missing. */
35 BS_SCRIPT_EXPORT()
36 CharDesc missingGlyph;
37
38 /** Width of a space in pixels. */
39 BS_SCRIPT_EXPORT()
40 UINT32 spaceWidth;
41
42 /** Textures in which the character's pixels are stored. */
43 BS_SCRIPT_EXPORT()
44 Vector<HTexture> texturePages;
45
46 /** All characters in the font referenced by character ID. */
47 Map<UINT32, CharDesc> characters;
48
49 /************************************************************************/
50 /* SERIALIZATION */
51 /************************************************************************/
52 public:
53 friend class FontBitmapRTTI;
54 static RTTITypeBase* getRTTIStatic();
55 RTTITypeBase* getRTTI() const override;
56 };
57
58 /**
59 * Font resource containing data about textual characters and how to render text. Contains one or multiple font
60 * bitmaps, each for a specific size.
61 */
62 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:GUI_Engine) Font : public Resource
63 {
64 public:
65 virtual ~Font() = default;
66
67 /**
68 * Returns font bitmap for a specific font size.
69 *
70 * @param[in] size Size of the bitmap in points.
71 * @return Bitmap object if it exists, false otherwise.
72 */
73 BS_SCRIPT_EXPORT()
74 SPtr<FontBitmap> getBitmap(UINT32 size) const;
75
76 /**
77 * Finds the available font bitmap size closest to the provided size.
78 *
79 * @param[in] size Size of the bitmap in points.
80 * @return Nearest available bitmap size.
81 */
82 BS_SCRIPT_EXPORT()
83 INT32 getClosestSize(UINT32 size) const;
84
85 /** Creates a new font from the provided per-size font data. */
86 static HFont create(const Vector<SPtr<FontBitmap>>& fontInitData);
87
88 public: // ***** INTERNAL ******
89 using Resource::initialize;
90
91 /** @name Internal
92 * @{
93 */
94
95 /**
96 * Initializes the font with specified per-size font data.
97 *
98 * @note Internal method. Factory methods will call this automatically for you.
99 */
100 void initialize(const Vector<SPtr<FontBitmap>>& fontData);
101
102 /** Creates a new font as a pointer instead of a resource handle. */
103 static SPtr<Font> _createPtr(const Vector<SPtr<FontBitmap>>& fontInitData);
104
105 /** Creates a Font without initializing it. */
106 static SPtr<Font> _createEmpty();
107
108 /** @} */
109
110 protected:
111 friend class FontManager;
112
113 Font();
114
115 /** @copydoc CoreObject::getCoreDependencies */
116 void getCoreDependencies(Vector<CoreObject*>& dependencies) override;
117
118 private:
119 Map<UINT32, SPtr<FontBitmap>> mFontDataPerSize;
120
121 /************************************************************************/
122 /* SERIALIZATION */
123 /************************************************************************/
124 public:
125 friend class FontRTTI;
126 static RTTITypeBase* getRTTIStatic();
127 RTTITypeBase* getRTTI() const override;
128 };
129
130 /** @} */
131}