@@ -67,6 +67,16 @@ class TextRenderer : public nbl::core::IReferenceCounted
6767
6868class FontFace : public nbl ::core::IReferenceCounted
6969{
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+
7080public:
7181
7282 // Face Global Metrics/Settings
@@ -90,14 +100,14 @@ class FontFace : public nbl::core::IReferenceCounted
90100 float64_t2 size;
91101 };
92102
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)
94104 {
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 );
101111 }
102112
103113 ~FontFace ()
@@ -140,11 +150,10 @@ class FontFace : public nbl::core::IReferenceCounted
140150 assert (!error);
141151 return m_ftFace->glyph ;
142152 }
143- FT_Face& getFreetypeFace () { return m_ftFace; }
153+ FT_Face getFreetypeFace () { return m_ftFace; }
144154 msdfgen::Shape generateGlyphShape (uint32_t glyphId);
145155
146156protected:
147-
148157 core::smart_refctd_ptr<TextRenderer> m_textRenderer;
149158 FT_Face m_ftFace;
150159 size_t m_hash;
@@ -213,5 +222,4 @@ class GlyphShapeBuilder {
213222}
214223}
215224}
216-
217225#endif
0 commit comments