aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--include/ResourceLoader.hpp1
-rw-r--r--src/QuickMedia.cpp6
-rw-r--r--src/ResourceLoader.cpp59
4 files changed, 63 insertions, 13 deletions
diff --git a/README.md b/README.md
index 753de99..5db0713 100644
--- a/README.md
+++ b/README.md
@@ -29,16 +29,17 @@ If you are running arch linux then you can install QuickMedia from aur (https://
### Executables
`curl`
### Fonts
-`noto-fonts`
+`noto-fonts` (when `QM_USE_SYSTEM_FONTS` is not set to `1`)
### Optional
-`noto-fonts-cjk` needs to be installed to view chinese, japanese and korean characters.\
+`noto-fonts-cjk` needs to be installed to view chinese, japanese and korean characters (when `QM_USE_SYSTEM_FONTS` is not set to `1`).\
`mpv` needs to be installed to play videos.\
`youtube-dl` needs to be installed to play/download xxx videos.\
-`libnotify` which provides `notify-send` needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system).\
+`notify-send` (which is part of `libnotify`) needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system).\
[automedia](https://git.dec05eba.com/AutoMedia/) needs to be installed when tracking manga with `Ctrl + T`.\
`waifu2x-ncnn-vulkan` needs to be installed when using the `--upscale-images` or `--upscale-images-always` option.\
`xdg-utils` which provides `xdg-open` needs to be installed when downloading torrents with `nyaa.si` plugin.\
-`ffmpeg (and ffprobe which is included in ffmpeg)` needs to be installed to display webp thumbnails, to upload videos with thumbnails on matrix or to merge video and audio when downloading youtube videos.
+`ffmpeg (and ffprobe which is included in ffmpeg)` needs to be installed to display webp thumbnails, to upload videos with thumbnails on matrix or to merge video and audio when downloading youtube videos.\
+`fc-match` (which is part of `fontconfig`) needs to be installed when `QM_USE_SYSTEM_FONTS` is set to `1`.
## Controls
### General control
Type text and then wait and QuickMedia will automatically search.\
@@ -151,6 +152,7 @@ Type text and then wait and QuickMedia will automatically search.\
Set `QM_THEME` to one of the following: `default, nord` to change the theme.\
Set `QM_SCALE` to scale UI.\
Set `QM_FONT_SCALE` to scale fonts.\
+Set `QM_USE_SYSTEM_FONTS` to `1` to use system fonts instead of noto fonts.
If `xdg-open` is not installed then the `BROWSER` environment variable is used to open links in a browser.\
Set `QM_PHONE_FACTOR=1` to disable the room list side panel in matrix.
## UI scaling
diff --git a/include/ResourceLoader.hpp b/include/ResourceLoader.hpp
index 29efa91..52f4975 100644
--- a/include/ResourceLoader.hpp
+++ b/include/ResourceLoader.hpp
@@ -8,6 +8,7 @@ namespace sf {
namespace QuickMedia {
void set_resource_loader_root_path(const char *resource_root);
const char* get_resource_loader_root_path();
+ void set_use_system_fonts(bool use);
}
namespace QuickMedia::FontLoader {
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8ef16c4..fe3e53c 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -603,6 +603,11 @@ namespace QuickMedia {
return focused_monitor_center;
}
+ static bool config_use_system_fonts() {
+ char *qm_use_system_fonts = getenv("QM_USE_SYSTEM_FONTS");
+ return qm_use_system_fonts && qm_use_system_fonts[0] == '1';
+ }
+
void Program::init(Window parent_window, std::string &program_path) {
disp = XOpenDisplay(NULL);
if (!disp) {
@@ -668,6 +673,7 @@ namespace QuickMedia {
}
set_resource_loader_root_path(resources_root.c_str());
+ set_use_system_fonts(config_use_system_fonts());
init_themes();
if(!is_touch_enabled()) {
diff --git a/src/ResourceLoader.cpp b/src/ResourceLoader.cpp
index fbcbe39..2725898 100644
--- a/src/ResourceLoader.cpp
+++ b/src/ResourceLoader.cpp
@@ -1,4 +1,7 @@
#include "../include/ResourceLoader.hpp"
+#include "../include/Program.hpp"
+#include "../include/Path.hpp"
+#include "../include/StringUtils.hpp"
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <array>
@@ -9,6 +12,7 @@
static std::string resource_root;
static std::array<std::unique_ptr<sf::Font>, 4> font_cache;
static std::unordered_map<std::string, std::unique_ptr<sf::Texture>> texture_cache;
+static bool use_system_fonts = false;
namespace QuickMedia {
void set_resource_loader_root_path(const char *new_resource_root) {
@@ -18,9 +22,21 @@ 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 {
+ static int accumulate_string(char *data, int size, void *userdata) {
+ std::string *str = (std::string*)userdata;
+ if(str->size() + size > 1024 * 1024 * 100) // 100mb sane limit, TODO: make configurable
+ return 1;
+ str->append(data, size);
+ return 0;
+ }
+
sf::Font* get_font(FontType font_type) {
sf::Font *font = font_cache[(size_t)font_type].get();
if(!font) {
@@ -29,24 +45,49 @@ namespace QuickMedia::FontLoader {
std::string font_file_name;
switch(font_type) {
case FontType::LATIN: {
- noto_directories.push_back("/usr/share/fonts/noto");
- noto_directories.push_back("/usr/share/fonts/truetype/noto");
- font_file_name = "NotoSans-Regular.ttf";
+ 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) {
+ 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";
+ }
break;
}
case FontType::LATIN_BOLD: {
- noto_directories.push_back("/usr/share/fonts/noto");
- noto_directories.push_back("/usr/share/fonts/truetype/noto");
- font_file_name = "NotoSans-Bold.ttf";
+ 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) {
+ 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";
+ }
break;
}
case FontType::CJK: {
- noto_directories.push_back("/usr/share/fonts/noto-cjk");
- noto_directories.push_back("/usr/share/fonts/opentype/noto");
- font_file_name = "NotoSansCJK-Regular.ttc";
+ 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) {
+ 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";
+ }
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";