Skip to content

Commit

Permalink
v1.1.0. Added --command option to CLI. Added sorting by POS. Fixed ba…
Browse files Browse the repository at this point in the history
…ckspace-key segfault. Better drawing of mods when zoomed out. Font creation debug options. Other small bug fixes
  • Loading branch information
kcleal committed Sep 12, 2024
1 parent c441607 commit fe81b27
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/defaultIni.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 56 additions & 4 deletions src/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "defaultIni.hpp"
#include "ankerl_unordered_dense.h"

#include "include/core/SkFontMgr.h"

#if !defined(__EMSCRIPTEN__)
#include <curl/curl.h>
#include <curl/easy.h>
Expand Down Expand Up @@ -987,6 +989,30 @@ namespace Themes {
file.generate(seshIni, true);
}

void printAvailableFonts() {
sk_sp<SkFontMgr> fontManager = SkFontMgr::RefDefault();
int familyCount = fontManager->countFamilies();

std::cout << "Available font families:" << std::endl;

std::vector<std::string> 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() {
Expand All @@ -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);
Expand Down

0 comments on commit fe81b27

Please sign in to comment.