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