MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / Load

Method Load

engine/Poseidon/Graphics/Rendering/Draw/Font.cpp:267–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265
266 auto renderer = std::make_unique<ui::FontRenderer>();
267 if (!renderer->LoadFontFromStream(stream))
268 return nullptr;
269 renderer->SetSyntheticOblique(syntheticOblique);
270 renderer->SetSyntheticBold(syntheticBold);
271
272 auto* ptr = renderer.get();
273 renderers[key] = std::move(renderer);
274 return ptr;
275}
276
277void Font::Load(const char* name)
278{
279 strcpy(_name, name);
280 strlwr(_name);
281
282 // strip directory prefix for mapping lookup
283 const char* baseName = strrchr(_name, '\\');
284 baseName = baseName ? baseName + 1 : _name;
285
286 // FreeType eligibility depends only on whether a slot mapping +
287 // TTF exists on disk — never on init-time order. Gating on
288 // FontSystem::IsAvailable() here meant fonts created before
289 // FontSystem::Initialize() ran (e.g. ProgressSystem's font during
290 // InitializeWorld, before InitializeSubsystems) were permanently
291 // routed through the .fxy bitmap atlas, which walks the input
292 // string byte-by-byte (fontDraw.cpp:86) — UTF-8 multibyte
293 // sequences then drew two glyphs per codepoint. Now Font::Load
294 // always tries FreeType first; the gate only controls log noise
295 // for apps that opted out of text rendering.
296 if (!AppConfig::Instance().NoFreeType())
297 {
298 auto* mapping = FindFontMapping(baseName);
299 if (mapping)
300 {
301 auto* renderer = GetOrCreateRenderer(mapping->ttfPath, mapping->syntheticOblique, mapping->syntheticBold);
302 if (renderer)
303 {
304 _isFreeType = true;
305 _ftRenderer = renderer;
306 _ftReferencePx = mapping->renderPx;
307 _maxHeight = mapping->bitmapMaxHeight;
308 _ftWidthScale = mapping->widthScale;
309 _ftBaselineOffset = mapping->baselineOffset;
310 _ftLetterSpacing = mapping->letterSpacing;
311 _nChars = 0;
312 return;
313 }
314 }
315 }
316
317 char fontName[256];
318 QIFStreamB f;
319 snprintf(fontName, sizeof(fontName), "%s.fxy", _name);
320 f.AutoOpen(fontName);
321 if (f.rest() > 0)
322 {
323 FXYData data = ParseFXY(f, _name);
324

Callers 13

GlobLoadTextureFunction · 0.45
DecodePAABufferFunction · 0.45
DecodePAAFileMipFunction · 0.45
LoadFontMethod · 0.45
RefreshAllFontsMethod · 0.45
DrawTextMethod · 0.45
DrawText3DMethod · 0.45
InitMethod · 0.45
CreateUnitFunction · 0.45
ObjLoadStatusFunction · 0.45
ObjLoadIdentityFunction · 0.45
CreateUserDialogFunction · 0.45

Calls 15

FindFontMappingFunction · 0.85
GetOrCreateRendererFunction · 0.85
ParseFXYFunction · 0.85
NoFreeTypeMethod · 0.80
AutoOpenMethod · 0.80
restMethod · 0.80
sizeMethod · 0.80
GetLangIDMethod · 0.80
SetLangIDMethod · 0.80
strlwrFunction · 0.50
ReallocMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected