1 | |
---|
2 | #include "resource_font.h" |
---|
3 | #include "substring.h" |
---|
4 | #include "multi_type.h" |
---|
5 | #include "debug.h" |
---|
6 | |
---|
7 | |
---|
8 | ResourceFont::ResourceFont(const std::string& fontName, unsigned int renderSize, const Resources::KeepLevel& keepLevel) |
---|
9 | : Font(), Resource(&ResourceFont::type) |
---|
10 | { |
---|
11 | assert(!fontName.empty()); |
---|
12 | Resources::StorePointer* ptr = this->acquireResource(fontName + ',' + MultiType((int)renderSize).getString()); |
---|
13 | |
---|
14 | if (ptr) |
---|
15 | { |
---|
16 | PRINTF(5)("FOUND FONT: %s\n", fontName.c_str()); |
---|
17 | this->Font::acquireData(static_cast<ResourceFont::FontResourcePointer*>(ptr)->ptr()); |
---|
18 | } |
---|
19 | else |
---|
20 | { |
---|
21 | PRINTF(5)("NOT FOUND FONT: %s\n", fontName.c_str()); |
---|
22 | std::string fileName = this->Resource::locateFile(fontName); |
---|
23 | |
---|
24 | this->Font::loadFontFromTTF(fileName, renderSize); |
---|
25 | this->Resource::addResource(new ResourceFont::FontResourcePointer(fontName + ',' + MultiType((int)renderSize).getString(), keepLevel, this->Font::dataPointer())); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | ResourceFont ResourceFont::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel) |
---|
30 | { |
---|
31 | SubString loadValues(loadString, ','); |
---|
32 | std::string fontName; |
---|
33 | unsigned int renderSize = 20; |
---|
34 | if (loadValues.size() > 0) |
---|
35 | fontName = loadValues[0]; |
---|
36 | if (loadValues.size() > 1) |
---|
37 | renderSize = (unsigned int)MultiType(loadValues[2]).getInt(); |
---|
38 | |
---|
39 | return ResourceFont(fontName, renderSize, keepLevel); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | Resources::tType<ResourceFont> ResourceFont::type("Font"); |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | ResourceFont::FontResourcePointer::FontResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const FontData::Pointer& data) |
---|
51 | : Resources::StorePointer(loadString, keepLevel) , pointer(data) |
---|
52 | {} |
---|
53 | |
---|
54 | |
---|