SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
VBF.cpp
Go to the documentation of this file.
1#include <vtfpp/VBF.h>
2
3#include <vector>
4
5#include <BufferStream.h>
6#include <sourcepp/FS.h>
7
8using namespace sourcepp;
9using namespace vtfpp;
10
11VBF::VBF(std::span<const std::byte> vbfData) {
12 BufferStreamReadOnly stream{vbfData};
13
14 if (stream.read<uint32_t>() != VBF_SIGNATURE) {
15 return;
16 }
17
18 stream >> this->version;
19 if (this->version != 3) {
20 this->version = 0;
21 return;
22 }
23
24 stream >> this->pageSize[0] >> this->pageSize[1];
25 stream >> this->maxGlyphSize[0] >> this->maxGlyphSize[1];
26 stream >> this->flags >> this->ascent;
27
28 const auto glyphCount = stream.read<uint16_t>();
29 const auto glyphLUT = stream.read<std::array<uint8_t, 256>>();
30
31 std::vector<Glyph> glyphList;
32 glyphList.reserve(glyphCount);
33 for (uint16_t i = 0; i < glyphCount; i++) {
34 auto& [position, size, abcSpacing] = glyphList.emplace_back();
35 stream >> position[0] >> position[1];
36 stream >> size[0] >> size[1];
37 stream >> abcSpacing[0] >> abcSpacing[1] >> abcSpacing[2];
38 }
39 for (int i = 0; i < this->glyphs.size(); i++) {
40 this->glyphs[i] = glyphList[glyphLUT[i]];
41 }
42}
43
44VBF::VBF(const std::filesystem::path& vbfPath)
45 : VBF(fs::readFileBuffer(vbfPath)) {}
46
47VBF::operator bool() const {
48 return this->version == 3;
49}
50
51math::Vec2ui16 VBF::getPageSize() const {
52 return this->pageSize;
53}
54
55math::Vec2ui16 VBF::getMaxGlyphSize() const {
56 return this->maxGlyphSize;
57}
58
60 return this->flags;
61}
62
63uint16_t VBF::getAscent() const {
64 return this->ascent;
65}
66
67const std::array<VBF::Glyph, 256>& VBF::getGlyphs() const {
68 return this->glyphs;
69}
sourcepp::math::Vec2ui16 maxGlyphSize
Definition VBF.h:53
Flags getFlags() const
Definition VBF.cpp:59
sourcepp::math::Vec2ui16 getPageSize() const
Definition VBF.cpp:51
uint16_t ascent
Definition VBF.h:55
sourcepp::math::Vec2ui16 getMaxGlyphSize() const
Definition VBF.cpp:55
std::array< Glyph, 256 > glyphs
Definition VBF.h:56
sourcepp::math::Vec2ui16 pageSize
Definition VBF.h:52
uint32_t version
Definition VBF.h:51
const std::array< Glyph, 256 > & getGlyphs() const
Definition VBF.cpp:67
uint16_t getAscent() const
Definition VBF.cpp:63
VBF(std::span< const std::byte > vbfData)
Definition VBF.cpp:11
Flags flags
Definition VBF.h:54
Definition HOT.h:11
constexpr uint32_t VBF_SIGNATURE
Definition VBF.h:12