NDEVR
API Documentation
TextConstructor.h
1
32#pragma once
33#include <NDEVR/Model.h>
34#include <NDEVR/Geometry.h>
35#include <NDEVR/Font.h>
36#include <NDEVR/Pointer.h>
37#if NDEVR_TEXT_MODEL
38struct FT_LibraryRec_;
39struct FT_FaceRec_;
40struct FT_Vector_;
41namespace NDEVR
42{
43 class Font;
48 struct NDEVR_DESIGN_API FreeTypeLibrary
49 {
51 FreeTypeLibrary();
52
54 ~FreeTypeLibrary();
55
56 FT_LibraryRec_* library;
57 };
73 struct NDEVR_DESIGN_API FreeTypeFace
74 {
76 FreeTypeFace();
77
81 FreeTypeFace(const FreeTypeLibrary &library, const Font& font);
82
85 FreeTypeFace(FreeTypeFace&& face);
86
88 ~FreeTypeFace();
89
93 FreeTypeFace& operator=(FreeTypeFace&& face) noexcept;
94
95 FT_FaceRec_* face;
96 };
97
101 class NDEVR_DESIGN_API TextConstructor
102 {
103 private:
105 TextConstructor();
106
110 TextConstructor(const StringView& app_font, bool cache_font_geometry = true);
111
115 TextConstructor(const Font& font, bool cache_font_geometry = true);
116 public:
118 ~TextConstructor();
119
124 Geometry getCharMesh(Model& parent, wchar symbol) const;
125
128 void ensureCharExists(wchar symbol);
129
132 fltp08 fontHeight() const;
133
136 fltp08 curveLength() const;
137
139 void cacheIfNeeded();
140
144 Vector<2, fltp08> symbolAdvance(wchar symbol) const;
145
151 Vector<2, fltp08> symbolAdvance(wchar symbol_a, wchar symbol_b) const;
152
155 Vector<2, fltp08> fontSize() const;
156
160 void setFont(Font font, bool cache_font_geometry = true);
161
164 const Font& currentFont() const { return m_font; }
165
168 bool canConstructGeometry() const;
169
171 void cacheFont();
172
176 const Font& fontForChar(wchar_t symbol) const;
177
183 static ConstPointer<TextConstructor> DefaultConstructor(const Font& font, const StringView& chars_to_ensure_exist);
184 private:
188 bool loadGlyph(wchar symbol);
189
193 bool OutlineExists() const;
194
197 void ExtractOutline();
198
201 void computeViewBox(Geometry& geo);
202
207 static int MoveToFunction(const FT_Vector_ *to, void *user);
208
213 static int LineToFunction(const FT_Vector_ *to, void *user);
214
220 static int ConicToFunction(const FT_Vector_ *control, const FT_Vector_ *to, void *user);
221
228 static int CubicToFunction(const FT_Vector_ *controlOne, const FT_Vector_ *controlTwo, const FT_Vector_ *to, void *user);
229
232 Geometry currentMesh();
233
234 private:
238 UUID textUUID(wchar symbol) const;
239
240 Font m_font;
241 FreeTypeLibrary m_library;
242 FreeTypeFace m_face;
243 fltp08 m_curve_length = 10.0;
244 DynamicPointer<Model> m_font_model;
245 mutable Dictionary<UUID, Dictionary<UUID, uint04>> m_model_copy;
246 Dictionary<UUID, Geometry> m_geometry;
247 Dictionary<wchar_t, Font> m_fallback_fonts;
248 wchar m_current_char = '\0';
249 Vector<2, fltp08> m_last_point;
250 bool m_needs_recache = false;
251
252 };
253
254}
255#endif
256
257
Information for how to display text data.
Definition Font.h:46
The primary namespace for the NDEVR SDK.
double fltp08
Defines an alias representing an 8 byte floating-point number.
wchar_t wchar
Allias for wchar_t, a value that represents a character of two bytes in size.