@@ -67,6 +67,16 @@ class TextRenderer : public nbl::core::IReferenceCounted
67
67
68
68
class FontFace : public nbl ::core::IReferenceCounted
69
69
{
70
+
71
+ protected:
72
+
73
+ FontFace (core::smart_refctd_ptr<TextRenderer>&& textRenderer, FT_Face face, size_t hash)
74
+ {
75
+ m_textRenderer = std::move (textRenderer);
76
+ m_ftFace = face;
77
+ m_hash = hash;
78
+ }
79
+
70
80
public:
71
81
72
82
// Face Global Metrics/Settings
@@ -90,14 +100,14 @@ class FontFace : public nbl::core::IReferenceCounted
90
100
float64_t2 size;
91
101
};
92
102
93
- FontFace (core::smart_refctd_ptr<TextRenderer>&& textRenderer, const std::string& path)
103
+ static core::smart_refctd_ptr< FontFace> create (core::smart_refctd_ptr<TextRenderer>&& textRenderer, const std::string& path)
94
104
{
95
- m_textRenderer = std::move (textRenderer) ;
96
-
97
- auto error = FT_New_Face (m_textRenderer-> m_ftLibrary , path. c_str (), 0 , &m_ftFace);
98
- assert (!error) ;
99
-
100
- m_hash = std::hash< std::string>{}(path );
105
+ FT_Face face ;
106
+ FT_Error res = FT_New_Face (textRenderer-> m_ftLibrary , path. c_str (), 0 , &face);
107
+ if (res != 0 )
108
+ return nullptr ;
109
+ size_t hash = std::hash<std::string>{}(path);
110
+ return core::smart_refctd_ptr<FontFace>( new FontFace ( std::move (textRenderer), face, hash), core::dont_grab );
101
111
}
102
112
103
113
~FontFace ()
@@ -140,11 +150,10 @@ class FontFace : public nbl::core::IReferenceCounted
140
150
assert (!error);
141
151
return m_ftFace->glyph ;
142
152
}
143
- FT_Face& getFreetypeFace () { return m_ftFace; }
153
+ FT_Face getFreetypeFace () { return m_ftFace; }
144
154
msdfgen::Shape generateGlyphShape (uint32_t glyphId);
145
155
146
156
protected:
147
-
148
157
core::smart_refctd_ptr<TextRenderer> m_textRenderer;
149
158
FT_Face m_ftFace;
150
159
size_t m_hash;
@@ -213,5 +222,4 @@ class GlyphShapeBuilder {
213
222
}
214
223
}
215
224
}
216
-
217
225
#endif
0 commit comments