MCPcopy Create free account
hub / github.com/Illation/ETEngine / LoadFnt

Method LoadFnt

Engine/source/EtRendering/GraphicsTypes/SpriteFont.cpp:379–514  ·  view source on GitHub ↗

--------------------------------- TextureAsset::LoadFnt Loads a Sprite font from an FNT file

Source from the content-addressed store, hash-verified

377// Loads a Sprite font from an FNT file
378//
379SpriteFont* FontAsset::LoadFnt(const std::vector<uint8>& binaryContent)
380{
381 auto pBinReader = new core::BinaryReader(); //Prevent memory leaks
382 pBinReader->Open(binaryContent);
383
384 if (!pBinReader->Exists())
385 {
386 delete pBinReader;
387 LOG("SpriteFont::Load > Failed to read the assetFile!", core::LogLevel::Warning);
388
389 return nullptr;
390 }
391 bool valid = false;
392 if (pBinReader->Read<char>() == 'B')
393 {
394 if (pBinReader->Read<char>() == 'M')
395 {
396 if (pBinReader->Read<char>() == 'F')
397 {
398 valid = true;
399 }
400 }
401 }
402 if (!valid)
403 {
404 LOG("Font file header invalid!", core::LogLevel::Warning);
405 return nullptr;
406 }
407 if (pBinReader->Read<char>() < 3)
408 {
409 LOG("Font version invalid!", core::LogLevel::Warning);
410 return nullptr;
411 }
412
413 SpriteFont* pFont = new SpriteFont();
414
415 //**********
416 // BLOCK 0 *
417 //**********
418 pBinReader->Read<char>();
419 auto Block0Size = pBinReader->Read<int32>();
420 int32 pos = pBinReader->GetBufferPosition();
421 pFont->m_FontSize = pBinReader->Read<int16>();
422 pBinReader->SetBufferPosition(pos + 14);
423 std::string fn;
424 char cur = pBinReader->Read<char>();
425 while (cur != '\0')
426 {
427 fn += cur;
428 cur = pBinReader->Read<char>();
429 }
430 pFont->m_FontName = fn;
431 pBinReader->SetBufferPosition(pos + Block0Size);
432 //**********
433 // BLOCK 1 *
434 //**********
435 pBinReader->Read<char>();
436 auto Block1Size = pBinReader->Read<int32>();

Callers

nothing calls this directly

Calls 6

HashStringClass · 0.85
GetBufferPositionMethod · 0.80
SetBufferPositionMethod · 0.80
IsCharValidMethod · 0.80
OpenMethod · 0.45
ExistsMethod · 0.45

Tested by

no test coverage detected