summaryrefslogtreecommitdiffstats
path: root/gui/resources.cpp
diff options
context:
space:
mode:
authorVojtech Bocek <vbocek@gmail.com>2014-09-07 15:01:56 +0200
committerDees Troy <dees_troy@teamw.in>2014-10-14 15:06:56 +0200
commit76ee903d84d5b477016fb6ed6bdee1a21e237903 (patch)
treeb5e773d53ce727911db18ba12d1e96b690c78c54 /gui/resources.cpp
parentFix exfat-fuse handling (diff)
downloadandroid_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar.gz
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar.bz2
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar.lz
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar.xz
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.tar.zst
android_bootable_recovery-76ee903d84d5b477016fb6ed6bdee1a21e237903.zip
Diffstat (limited to 'gui/resources.cpp')
-rw-r--r--gui/resources.cpp67
1 files changed, 61 insertions, 6 deletions
diff --git a/gui/resources.cpp b/gui/resources.cpp
index 8d430b1ec..4fce0ca44 100644
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -65,27 +65,82 @@ FontResource::FontResource(xml_node<>* node, ZipArchive* pZip)
: Resource(node, pZip)
{
std::string file;
+ xml_attribute<>* attr;
mFont = NULL;
if (!node)
return;
- if (node->first_attribute("filename"))
- file = node->first_attribute("filename")->value();
+ attr = node->first_attribute("filename");
+ if (!attr)
+ return;
+
+ file = attr->value();
- if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
+#ifndef TW_DISABLE_TTF
+ if(file.size() >= 4 && file.compare(file.size()-4, 4, ".ttf") == 0)
{
- mFont = gr_loadFont(TMP_RESOURCE_NAME);
- unlink(TMP_RESOURCE_NAME);
+ m_type = TYPE_TTF;
+
+ attr = node->first_attribute("size");
+ if(!attr)
+ return;
+
+ int size = atoi(attr->value());
+ int dpi = 300;
+
+ attr = node->first_attribute("dpi");
+ if(attr)
+ dpi = atoi(attr->value());
+
+ if (ExtractResource(pZip, "fonts", file, "", TMP_RESOURCE_NAME) == 0)
+ {
+ mFont = gr_ttf_loadFont(TMP_RESOURCE_NAME, size, dpi);
+ unlink(TMP_RESOURCE_NAME);
+ }
+ else
+ {
+ file = std::string("/res/fonts/") + file;
+ mFont = gr_ttf_loadFont(file.c_str(), size, dpi);
+ }
}
else
+#endif
{
- mFont = gr_loadFont(file.c_str());
+ m_type = TYPE_TWRP;
+
+ if(file.size() >= 4 && file.compare(file.size()-4, 4, ".ttf") == 0)
+ {
+ attr = node->first_attribute("fallback");
+ if (!attr)
+ return;
+
+ file = attr->value();
+ }
+
+ if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0)
+ {
+ mFont = gr_loadFont(TMP_RESOURCE_NAME);
+ unlink(TMP_RESOURCE_NAME);
+ }
+ else
+ {
+ mFont = gr_loadFont(file.c_str());
+ }
}
}
FontResource::~FontResource()
{
+ if(mFont)
+ {
+#ifndef TW_DISABLE_TTF
+ if(m_type == TYPE_TTF)
+ gr_ttf_freeFont(mFont);
+ else
+#endif
+ gr_freeFont(mFont);
+ }
}
ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip)