MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / loadFromFile

Method loadFromFile

Source/Falcor/Utils/UI/Font.cpp:67–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65Font::~Font() = default;
66
67bool Font::loadFromFile(ref<Device> pDevice, const std::filesystem::path& path)
68{
69 std::filesystem::path texturePath = path;
70 texturePath.replace_extension(".dds");
71 std::filesystem::path dataPath = path;
72 dataPath.replace_extension(".bin");
73
74 if (!std::filesystem::exists(texturePath) || !std::filesystem::exists(dataPath))
75 return false;
76
77 // Load the data
78 std::ifstream data(dataPath, std::ios::binary);
79 FontFileHeader header;
80 // Read the header
81 data.read((char*)&header, sizeof(header));
82 bool valid = (header.structSize == sizeof(header));
83 valid = valid && (header.magicNumber == kFontMagicNumber);
84 valid = valid && (header.charDataSize == sizeof(FontCharData));
85 valid = valid && (header.charCount == mCharCount);
86
87 if (!valid)
88 return false;
89
90 mTabWidth = header.tabWidth;
91 mFontHeight = header.fontHeight;
92
93 mLetterSpacing = 0;
94 // Load the char data
95 for (uint32_t i = 0; i < mCharCount; i++)
96 {
97 FontCharData charData;
98 data.read((char*)&charData, sizeof(FontCharData));
99 if (charData.character != i + mFirstChar)
100 {
101 data.close();
102 return false;
103 }
104
105 mCharDesc[i].topLeft.x = charData.topLeftX;
106 mCharDesc[i].topLeft.y = charData.topLeftY;
107 mCharDesc[i].size.x = charData.width;
108 mCharDesc[i].size.y = charData.height;
109 mLetterSpacing = std::max(mLetterSpacing, charData.width);
110 }
111
112 // Load the texture
113 mpTexture = Texture::createFromFile(pDevice, texturePath, false, false);
114 return mpTexture != nullptr;
115}
116} // namespace Falcor

Callers

nothing calls this directly

Calls 3

maxFunction · 0.50
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected