Add support to load .ttf files from the theme folder

This commit is contained in:
David Capello 2017-10-09 11:55:20 -03:00
parent bc541c776b
commit aa95ccde80
3 changed files with 12 additions and 9 deletions

View File

@ -14,12 +14,16 @@
namespace app {
std::string find_font(const std::string& filename)
std::string find_font(const std::string& firstDir,
const std::string& filename)
{
std::string fn = base::join_path(firstDir, filename);
if (base::is_file(fn))
return fn;
std::vector<std::string> fontDirs;
get_font_dirs(fontDirs);
std::string fn;
for (const std::string& dir : fontDirs) {
fn = base::join_path(dir, filename);
if (base::is_file(fn))

View File

@ -14,7 +14,8 @@
namespace app {
void get_font_dirs(std::vector<std::string>& fontDirs);
std::string find_font(const std::string& filename);
std::string find_font(const std::string& firstDir,
const std::string& filename);
} // namespace app

View File

@ -107,16 +107,14 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
xmlFilename.c_str());
std::string type(typeStr);
std::string xmlDir(base::get_file_path(xmlFilename));
base::UniquePtr<FontData> font(nullptr);
if (type == "spritesheet") {
const char* fileStr = xmlFont->Attribute("file");
if (fileStr) {
font.reset(new FontData(she::FontType::kSpriteSheet));
font->setFilename(
base::join_path(
base::get_file_path(xmlFilename),
fileStr));
font->setFilename(base::join_path(xmlDir, fileStr));
}
}
else if (type == "truetype") {
@ -138,9 +136,9 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
std::string fontFilename;
if (platformFileStr)
fontFilename = app::find_font(platformFileStr);
fontFilename = app::find_font(xmlDir, platformFileStr);
if (fileStr && fontFilename.empty())
fontFilename = app::find_font(fileStr);
fontFilename = app::find_font(xmlDir, fileStr);
// The filename can be empty if the font was not found, anyway we
// want to keep the font information (e.g. to use the fallback