aboutsummaryrefslogtreecommitdiff
path: root/src/ResourceLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ResourceLoader.cpp')
-rw-r--r--src/ResourceLoader.cpp73
1 files changed, 52 insertions, 21 deletions
diff --git a/src/ResourceLoader.cpp b/src/ResourceLoader.cpp
index 9e8a884..50bb7b5 100644
--- a/src/ResourceLoader.cpp
+++ b/src/ResourceLoader.cpp
@@ -2,6 +2,7 @@
#include "../include/Program.hpp"
#include "../include/Path.hpp"
#include "../include/StringUtils.hpp"
+#include "../include/Config.hpp"
#include <mglpp/graphics/Font.hpp>
#include <mglpp/graphics/Texture.hpp>
#include <mglpp/system/MemoryMappedFile.hpp>
@@ -15,7 +16,6 @@ static std::array<std::unique_ptr<mgl::MemoryMappedFile>, 4> font_file_cache;
// font_cache[(unsigned int)font_type][character_size]
static std::array<std::unordered_map<unsigned int, std::unique_ptr<mgl::Font>>, 4> font_cache;
static std::unordered_map<std::string, std::unique_ptr<mgl::Texture>> texture_cache;
-static bool use_system_fonts = false;
namespace QuickMedia {
void set_resource_loader_root_path(const char *new_resource_root) {
@@ -25,10 +25,6 @@ namespace QuickMedia {
const char* get_resource_loader_root_path() {
return resource_root.c_str();
}
-
- void set_use_system_fonts(bool use) {
- use_system_fonts = use;
- }
}
namespace QuickMedia::FontLoader {
@@ -46,56 +42,91 @@ namespace QuickMedia::FontLoader {
mgl::MemoryMappedFile *mapped_file = font_file_cache[(unsigned int)font_type].get();
if(!mapped_file) {
- std::vector<std::string> noto_directories;
+ std::vector<std::string> noto_directories = {
+ "/usr/share/fonts/noto",
+ "/usr/share/fonts/truetype/noto",
+ "/usr/share/fonts/noto-cjk",
+ "/usr/share/fonts/truetype/noto-cjk",
+ "/usr/share/fonts/TTF",
+ };
+
std::string font_file_name;
switch(font_type) {
case FontType::LATIN: {
std::string output;
const char *args[] = { "fc-match", "sans:lang=en", "file", nullptr };
- if(use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
+ if(get_config().use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
Path path = strip(output.substr(6));
noto_directories.push_back(path.parent().data);
font_file_name = path.filename();
} else {
- noto_directories.push_back("/usr/share/fonts/noto");
- noto_directories.push_back("/usr/share/fonts/truetype/noto");
- font_file_name = "NotoSans-Regular.ttf";
+ Path font_path = get_config().font.latin;
+ if(font_path.data.empty())
+ font_path = "NotoSans-Regular.ttf";
+
+ if(font_path.data.find('/') == std::string::npos) {
+ font_file_name = std::move(font_path.data);
+ } else {
+ noto_directories.insert(noto_directories.begin(), font_path.parent().data);
+ font_file_name = font_path.filename();
+ }
}
break;
}
case FontType::LATIN_BOLD: {
std::string output;
const char *args[] = { "fc-match", "sans:bold:lang=en", "file", nullptr };
- if(use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
+ if(get_config().use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
Path path = strip(output.substr(6));
noto_directories.push_back(path.parent().data);
font_file_name = path.filename();
} else {
- noto_directories.push_back("/usr/share/fonts/noto");
- noto_directories.push_back("/usr/share/fonts/truetype/noto");
- font_file_name = "NotoSans-Bold.ttf";
+ Path font_path = get_config().font.latin_bold;
+ if(font_path.data.empty())
+ font_path = "NotoSans-Bold.ttf";
+
+ if(font_path.data.find('/') == std::string::npos) {
+ font_file_name = std::move(font_path.data);
+ } else {
+ noto_directories.insert(noto_directories.begin(), font_path.parent().data);
+ font_file_name = font_path.filename();
+ }
}
break;
}
case FontType::CJK: {
std::string output;
const char *args[] = { "fc-match", "sans:lang=ja", "file", nullptr };
- if(use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
+ if(get_config().use_system_fonts && exec_program(args, accumulate_string, &output) == 0 && output.size() > 6) {
Path path = strip(output.substr(6));
noto_directories.push_back(path.parent().data);
font_file_name = path.filename();
} else {
- noto_directories.push_back("/usr/share/fonts/noto-cjk");
- noto_directories.push_back("/usr/share/fonts/truetype/noto-cjk");
- font_file_name = "NotoSansCJK-Regular.ttc";
+ Path font_path = get_config().font.cjk;
+ if(font_path.data.empty())
+ font_path = "NotoSansCJK-Regular.ttc";
+
+ if(font_path.data.find('/') == std::string::npos) {
+ font_file_name = std::move(font_path.data);
+ } else {
+ noto_directories.insert(noto_directories.begin(), font_path.parent().data);
+ font_file_name = font_path.filename();
+ }
}
break;
}
case FontType::SYMBOLS: {
// TODO: Allow changing with system font setting
- noto_directories.push_back("/usr/share/fonts/noto");
- noto_directories.push_back("/usr/share/fonts/truetype/noto");
- font_file_name = "NotoSansSymbols2-Regular.ttf";
+ Path font_path = get_config().font.symbols;
+ if(font_path.data.empty())
+ font_path = "NotoSansSymbols2-Regular.ttf";
+
+ if(font_path.data.find('/') == std::string::npos) {
+ font_file_name = std::move(font_path.data);
+ } else {
+ noto_directories.insert(noto_directories.begin(), font_path.parent().data);
+ font_file_name = font_path.filename();
+ }
break;
}
}