/
FontLoader.cpp
69 lines (54 loc) · 1.47 KB
/
FontLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "FontLoader.h"
#include "os/path.h"
#include "string/convert.h"
#include <regex>
#include "itextstream.h"
#include "FontManager.h"
namespace fonts
{
void FontLoader::loadFont(const vfs::FileInfo& fileInfo)
{
// Construct the full VFS path
std::string fullPath = fileInfo.fullPath();
std::regex expr("^/?(.*)/.*_(\\d{2})\\.dat$", std::regex::icase);
std::smatch matches;
if (std::regex_match(fileInfo.name, matches, expr))
{
// Get the font name and resolution from the match
std::string fontname = matches[1];
std::string resolutionStr = matches[2];
int r = string::convert<int>(resolutionStr);
Resolution resolution = NumResolutions;
switch (r)
{
case 12:
resolution = Resolution12;
break;
case 24:
resolution = Resolution24;
break;
case 48:
resolution = Resolution48;
break;
};
if (resolution != NumResolutions)
{
// Create the font (if not done yet), acquire the info structure
auto font = _manager.findOrCreateFontInfo(fontname);
// Load the DAT file and create the glyph info
font->glyphSets[resolution] = GlyphSet::createFromDatFile(
fullPath, fontname, _manager.getCurLanguage(), resolution
);
}
else
{
rWarning() << "FontLoader: ignoring DAT: " << fileInfo.name << std::endl;
}
}
}
void FontLoader::loadFonts()
{
loadFiles(std::bind(&FontLoader::loadFont, this, std::placeholders::_1));
rMessage() << _manager.getNumFonts() << " fonts registered." << std::endl;
}
} // namespace fonts