7
7
8
8
#include " nabla.h"
9
9
10
- #include " nbl/video/utilities/CPropertyPool.h"
11
10
#include < msdfgen/msdfgen.h>
12
11
#include < ft2build.h>
13
12
#include < nbl/builtin/hlsl/cpp_compat.hlsl>
@@ -43,6 +42,12 @@ class TextRenderer : public nbl::core::IReferenceCounted
43
42
auto error = FT_Init_FreeType (&m_ftLibrary);
44
43
assert (!error);
45
44
}
45
+
46
+ ~TextRenderer ()
47
+ {
48
+ auto error = FT_Done_FreeType (m_ftLibrary);
49
+ assert (!error);
50
+ }
46
51
47
52
// TODO: Remove these here, it's only used for customized tests such as building shapes for hatches
48
53
const FT_Library& getFreetypeLibrary () const { return m_ftLibrary; }
@@ -56,11 +61,23 @@ class TextRenderer : public nbl::core::IReferenceCounted
56
61
class FontFace : public nbl ::core::IReferenceCounted
57
62
{
58
63
public:
64
+
65
+ // Face Global Metrics/Settings
66
+ struct Metrics
67
+ {
68
+ // This value is the vertical distance between two consecutive baselines, expressed in font units. It is always positive.
69
+ float64_t height;
70
+ // The distance from the baseline to the highest or upper grid coordinate used to place an outline point. It is a positive value.
71
+ float64_t ascent;
72
+ // The distance from the baseline to the lowest grid coordinate used to place an outline point. this is almost always a negative value.
73
+ float64_t descent;
74
+ };
75
+
59
76
struct GlyphMetrics
60
77
{
61
78
// Offset that should be applied to the current baseline after this glyph is placed
62
79
float64_t2 advance;
63
- // Offset that the image of the glyph should be placed from the current baseline start, horizontal refers to horizonral LTR or RTL Languages
80
+ // Offset of the glyph's top left from the current baseline start, horizontal refers to horizonral LTR or RTL Languages
64
81
float64_t2 horizontalBearing;
65
82
// Size of the glyph in the text line
66
83
float64_t2 size;
@@ -76,6 +93,12 @@ class FontFace : public nbl::core::IReferenceCounted
76
93
m_hash = std::hash<std::string>{}(path);
77
94
}
78
95
96
+ ~FontFace ()
97
+ {
98
+ auto error = FT_Done_Face (m_ftFace);
99
+ assert (!error);
100
+ }
101
+
79
102
static constexpr uint32_t InvalidGlyphIndex = ~0u ;
80
103
81
104
uint32_t getGlyphIndex (wchar_t unicode)
@@ -88,7 +111,9 @@ class FontFace : public nbl::core::IReferenceCounted
88
111
return FT_Get_Char_Index (m_ftFace, unicode);
89
112
}
90
113
91
- GlyphMetrics getGlyphMetricss (uint32_t glyphId);
114
+ Metrics getMetrics () const ;
115
+
116
+ GlyphMetrics getGlyphMetrics (uint32_t glyphId);
92
117
93
118
// returns the cpu buffer for the generated MSDF texture with "TextRenderer::MSDFTextureFormat" format
94
119
// it will place the glyph in the center of msdfExtents considering the margin of msdfPixelRange
0 commit comments