MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / SpriteFont

Method SpriteFont

src/Abyss/UI/SpriteFont.h:62–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61 public:
62 explicit SpriteFont(const std::string_view path, const DataTypes::Palette &palette) : _drawable(absl::StrCat(path, ".dc6")) {
63 Abyss::Common::Log::debug("Loading font {}...", path);
64
65 _drawable.setPalette(palette);
66
67 auto tableStream = Singletons::getFileProvider().loadFile(absl::StrCat(path, ".tbl"));
68 Streams::StreamReader sr(tableStream);
69 char signature[5] = {};
70 sr.readBytes(signature);
71 if (std::string_view(signature, 5) != "Woo!\x01")
72 throw std::runtime_error(absl::StrCat("Invalid font file signature: ", path));
73
74 tableStream.ignore(7); // skip unknown bytes
75
76 while (!tableStream.eof()) {
77 const auto code = sr.readUInt16();
78 auto &[glyphFrameIndex, glyphWidth, glyphHeight, glyphOffsetX, glyphOffsetY] = _glyphs[code];
79
80 tableStream.ignore(1); // Skip a byte for some reason
81
82 glyphWidth = sr.readUInt8();
83 glyphHeight = sr.readUInt8();
84
85 tableStream.ignore(3); // Skip 3 unknown bytes
86
87 glyphFrameIndex = sr.readUInt16();
88
89 if (glyphFrameIndex == 0xFFFF) {
90 // FIXME: do something about this.
91 glyphFrameIndex = 1;
92 }
93
94 if (glyphFrameIndex >= _drawable.getFrameCount())
95 throw std::runtime_error(absl::StrCat("Invalid font file: ", path));
96
97 _drawable.getFrameOffset(glyphFrameIndex, glyphOffsetX, glyphOffsetY);
98
99 tableStream.ignore(4); // More magic ignores, fun!
100 }
101 }
102};
103
104} // namespace Abyss::UI

Callers

nothing calls this directly

Calls 8

debugFunction · 0.85
readBytesMethod · 0.80
readUInt16Method · 0.80
readUInt8Method · 0.80
getFrameCountMethod · 0.80
getFrameOffsetMethod · 0.80
setPaletteMethod · 0.45
loadFileMethod · 0.45

Tested by

no test coverage detected