SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Toggle main menu visibility
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
8
using namespace
sourcepp
;
9
using namespace
vtfpp
;
10
11
VBF::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
if
(
const
auto
glyphIndex = glyphLUT[i]; glyphIndex < glyphCount) {
41
this->
glyphs
[i] = glyphList[glyphIndex];
42
}
43
}
44
}
45
46
VBF::VBF
(
const
std::filesystem::path& vbfPath)
47
:
VBF
(
fs
::readFileBuffer(vbfPath)) {}
48
49
VBF::operator bool()
const
{
50
return
this->
version
== 3;
51
}
52
53
math::Vec2ui16
VBF::getPageSize
()
const
{
54
return
this->
pageSize
;
55
}
56
57
math::Vec2ui16
VBF::getMaxGlyphSize
()
const
{
58
return
this->
maxGlyphSize
;
59
}
60
61
VBF::Flags
VBF::getFlags
()
const
{
62
return
this->
flags
;
63
}
64
65
uint16_t
VBF::getAscent
()
const
{
66
return
this->
ascent
;
67
}
68
69
const
std::array<VBF::Glyph, 256>&
VBF::getGlyphs
()
const
{
70
return
this->
glyphs
;
71
}
FS.h
VBF.h
vtfpp::VBF::maxGlyphSize
sourcepp::math::Vec2ui16 maxGlyphSize
Definition
VBF.h:53
vtfpp::VBF::getFlags
Flags getFlags() const
Definition
VBF.cpp:61
vtfpp::VBF::getPageSize
sourcepp::math::Vec2ui16 getPageSize() const
Definition
VBF.cpp:53
vtfpp::VBF::Flags
Flags
Definition
VBF.h:16
vtfpp::VBF::ascent
uint16_t ascent
Definition
VBF.h:55
vtfpp::VBF::getMaxGlyphSize
sourcepp::math::Vec2ui16 getMaxGlyphSize() const
Definition
VBF.cpp:57
vtfpp::VBF::glyphs
std::array< Glyph, 256 > glyphs
Definition
VBF.h:56
vtfpp::VBF::pageSize
sourcepp::math::Vec2ui16 pageSize
Definition
VBF.h:52
vtfpp::VBF::version
uint32_t version
Definition
VBF.h:51
vtfpp::VBF::getGlyphs
const std::array< Glyph, 256 > & getGlyphs() const
Definition
VBF.cpp:69
vtfpp::VBF::getAscent
uint16_t getAscent() const
Definition
VBF.cpp:65
vtfpp::VBF::VBF
VBF(std::span< const std::byte > vbfData)
Definition
VBF.cpp:11
vtfpp::VBF::flags
Flags flags
Definition
VBF.h:54
sourcepp::fs
Definition
FS.h:9
sourcepp
Definition
LZMA.h:11
vtfpp
Definition
DistanceMapping.h:8
vtfpp::VBF_SIGNATURE
constexpr uint32_t VBF_SIGNATURE
Definition
VBF.h:12
src
vtfpp
VBF.cpp
Generated on
for SourcePP by
1.18.0