MCPcopy Create free account
hub / github.com/OpenMW/openmw / loadBitmapFont

Method loadBitmapFont

components/fontloader/fontloader.cpp:408–700  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406 } GlyphInfo;
407
408 void FontLoader::loadBitmapFont(FontId fontId, const VFS::Path::Normalized& path, std::istream& stream)
409 {
410 Log(Debug::Info) << "Loading bitmap font file " << path;
411
412 float fontSize;
413 stream.read(reinterpret_cast<char*>(&fontSize), sizeof(fontSize));
414 if (!stream.good())
415 fail(stream, path, "File too small to be a valid font");
416
417 int one;
418 stream.read(reinterpret_cast<char*>(&one), sizeof(one));
419 if (!stream.good())
420 fail(stream, path, "File too small to be a valid font");
421
422 if (one != 1)
423 fail(stream, path, "Unexpected value");
424
425 stream.read(reinterpret_cast<char*>(&one), sizeof(one));
426 if (!stream.good())
427 fail(stream, path, "File too small to be a valid font");
428
429 if (one != 1)
430 fail(stream, path, "Unexpected value");
431
432 char nameBuffer[284];
433 stream.read(nameBuffer, sizeof(nameBuffer));
434 if (!stream.good())
435 fail(stream, path, "File too small to be a valid font");
436
437 GlyphInfo data[256];
438 stream.read((char*)data, sizeof(data));
439 if (!stream.good())
440 fail(stream, path, "File too small to be a valid font");
441
442 // Create the font texture
443 const std::string name(nameBuffer);
444
445 constexpr VFS::Path::NormalizedView fonts("fonts");
446 constexpr VFS::Path::ExtensionView tex("tex");
447 const VFS::Path::Normalized bitmapPath = VFS::Path::join(fonts, name, tex);
448
449 Files::IStreamPtr bitmapFile = mVFS->get(bitmapPath);
450
451 int width;
452 bitmapFile->read(reinterpret_cast<char*>(&width), sizeof(int));
453
454 int height;
455 bitmapFile->read(reinterpret_cast<char*>(&height), sizeof(int));
456
457 if (!bitmapFile->good())
458 fail(*bitmapFile, bitmapPath, "File too small to be a valid bitmap");
459
460 if (width <= 0 || height <= 0)
461 fail(*bitmapFile, bitmapPath, "Width and height must be positive");
462
463 std::vector<char> textureData;
464 textureData.resize(width * height * 4);
465 bitmapFile->read(textureData.data(), width * height * 4);

Callers

nothing calls this directly

Calls 15

LogClass · 0.85
joinFunction · 0.85
getUnicodeFunction · 0.85
minFunction · 0.85
formatFunction · 0.85
createManualMethod · 0.80
emplaceMethod · 0.80
failFunction · 0.70
toStringFunction · 0.50
VersionClass · 0.50
readMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected