From fe81b27b9cdeedd895a4b7c70875b96d18d9e103 Mon Sep 17 00:00:00 2001 From: kcleal Date: Thu, 12 Sep 2024 11:43:08 +0100 Subject: [PATCH] v1.1.0. Added --command option to CLI. Added sorting by POS. Fixed backspace-key segfault. Better drawing of mods when zoomed out. Font creation debug options. Other small bug fixes --- .gw.ini | 2 +- include/defaultIni.hpp | 2 +- src/themes.cpp | 60 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/.gw.ini b/.gw.ini index 041a5b1..a69f51e 100644 --- a/.gw.ini +++ b/.gw.ini @@ -36,7 +36,7 @@ threads=4 pad=500 scroll_speed=0.15 tabix_track_height=0.3 -font=Menlo +font=Default font_size=14 sv_arcs=true mods=false diff --git a/include/defaultIni.hpp b/include/defaultIni.hpp index 43db382..56d049c 100644 --- a/include/defaultIni.hpp +++ b/include/defaultIni.hpp @@ -47,7 +47,7 @@ namespace DefaultIni { "pad=500\n" "scroll_speed=0.15\n" "tabix_track_height=0.15\n" - "font=Menlo\n" + "font=Default\n" "font_size=14\n" "sv_arcs=true\n" "mods=false\n" diff --git a/src/themes.cpp b/src/themes.cpp index 91433a2..6c7a519 100644 --- a/src/themes.cpp +++ b/src/themes.cpp @@ -8,6 +8,8 @@ #include "defaultIni.hpp" #include "ankerl_unordered_dense.h" +#include "include/core/SkFontMgr.h" + #if !defined(__EMSCRIPTEN__) #include #include @@ -987,6 +989,30 @@ namespace Themes { file.generate(seshIni, true); } + void printAvailableFonts() { + sk_sp fontManager = SkFontMgr::RefDefault(); + int familyCount = fontManager->countFamilies(); + + std::cout << "Available font families:" << std::endl; + + std::vector fontFamilies; + for (int i = 0; i < familyCount; ++i) { + SkString familyName; + fontManager->getFamilyName(i, &familyName); + fontFamilies.push_back(familyName.c_str()); + } + + // Sort the font families alphabetically + std::sort(fontFamilies.begin(), fontFamilies.end()); + + // Print the sorted list + for (const auto& family : fontFamilies) { + std::cout << family << std::endl; + } + + std::cout << "Total font families: " << familyCount << std::endl; + } + const SkGlyphID glyphs[1] = {100}; EXPORT Fonts::Fonts() { @@ -997,11 +1023,37 @@ namespace Themes { } void Fonts::setTypeface(std::string &fontStr, int size) { - face = SkTypeface::MakeFromName(fontStr.c_str(), SkFontStyle::Normal()); - if (face && face->uniqueID() != 0) { - std::cerr << "Warning: font '" << fontStr << "' could not be initialised, falling back to 'Arial'\n"; - face = SkTypeface::MakeFromName("Arial", SkFontStyle::Normal()); + + if (fontStr == "Default") { + face = SkTypeface::MakeDefault(); + if (!face) { + std::cerr << "Error: failes to create font\n"; + } + } else { + const char * font_c = fontStr.c_str(); + face = SkTypeface::MakeFromName(font_c, SkFontStyle::Normal()); + if (!face) { + face = SkTypeface::MakeDefault(); + SkString familyName; + face->getFamilyName(&familyName); + std::cerr << "\nWarning: font '" << fontStr << "' could not be loaded, using system default instead '" << familyName.c_str() << ". et GW_DEBUG=1 to display available fonts.\n"; + char *val = getenv("GW_DEBUG"); + if (val) { + printAvailableFonts(); + } + } else { + SkString familyName; + face->getFamilyName(&familyName); + if (familyName.c_str() != fontStr) { + std::cerr << "\nWarning: font '" << fontStr << "' could not be loaded, swapped for '" << familyName.c_str() << " instead. Set GW_DEBUG=1 to display available fonts.\n"; + char *val = getenv("GW_DEBUG"); + if (val) { + printAvailableFonts(); + } + } + } } + SkScalar ts = size; fonty.setSize(ts); fonty.setTypeface(face);