From 4b50a09a4c835c23ff0ff389e976f2539d41f61b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 20 May 2021 14:30:24 +0300 Subject: Added a preference variable for UI animations Not yet in the UI, though. --- src/prefs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/prefs.h') diff --git a/src/prefs.h b/src/prefs.h index 0f604ee2..5c01ebda 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -47,6 +47,7 @@ struct Impl_Prefs { enum iColorAccent accent; iBool customFrame; /* when LAGRANGE_ENABLE_CUSTOM_FRAME is defined */ iBool retainWindowSize; + iBool uiAnimations; float uiScale; int zoomPercent; iBool sideIcon; -- cgit v1.2.3 From f53e6d34fbb8d2f2fb54aff8b746b1c5d06fe497 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 25 May 2021 18:25:40 +0300 Subject: Removed Symbola, replaced with other/new fonts Symbola's license is not permissive enough, so it has been removed. Added "Smol Emoji" with face emoticons and other UI characters for Lagrange. More symbols provided by Noto Sans Symbols and Noto Sans Symbols 2. The fallback fonts are now Iosevka, which has a pretty good coverage (although monospace), and the user's chosen TrueType font (which could still be a local copy of Symbola). Still a work in progress: some characters are missing. IssueID #283 --- CMakeLists.txt | 4 +- po/en.po | 3 + res/fonts/NotoSansSymbols-Regular.ttf | Bin 0 -> 168520 bytes res/fonts/NotoSansSymbols2-Regular.ttf | Bin 0 -> 583072 bytes res/fonts/SmolEmoji-Regular.ttf | Bin 0 -> 40384 bytes res/fonts/Symbola.ttf | Bin 3310696 -> 0 bytes res/lang/de.bin | Bin 20844 -> 20884 bytes res/lang/en.bin | Bin 19567 -> 19591 bytes res/lang/es.bin | Bin 21560 -> 21600 bytes res/lang/fi.bin | Bin 21534 -> 21574 bytes res/lang/fr.bin | Bin 22050 -> 22090 bytes res/lang/ia.bin | Bin 21751 -> 21791 bytes res/lang/ie.bin | Bin 20922 -> 20962 bytes res/lang/pl.bin | Bin 22555 -> 22595 bytes res/lang/ru.bin | Bin 32633 -> 32673 bytes res/lang/sr.bin | Bin 31212 -> 31252 bytes res/lang/tok.bin | Bin 19956 -> 19996 bytes res/lang/zh_Hans.bin | Bin 18715 -> 18755 bytes res/lang/zh_Hant.bin | Bin 18789 -> 18829 bytes src/app.c | 37 +++++++--- src/defs.h | 2 +- src/gmrequest.c | 4 +- src/prefs.c | 5 ++ src/prefs.h | 1 + src/ui/inputwidget.h | 5 ++ src/ui/keys.c | 8 +-- src/ui/root.c | 8 +-- src/ui/text.c | 127 +++++++++++++++++++++------------ src/ui/text.h | 16 +++-- src/ui/util.c | 2 + 30 files changed, 153 insertions(+), 69 deletions(-) create mode 100644 res/fonts/NotoSansSymbols-Regular.ttf create mode 100644 res/fonts/NotoSansSymbols2-Regular.ttf create mode 100644 res/fonts/SmolEmoji-Regular.ttf delete mode 100644 res/fonts/Symbola.ttf (limited to 'src/prefs.h') diff --git a/CMakeLists.txt b/CMakeLists.txt index 8429193a..f48d6fdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,17 +72,19 @@ set (EMBED_RESOURCES res/fonts/NotoSansArabicUI-Regular.ttf res/fonts/NotoSansJP-Regular.ttf res/fonts/NotoSansSC-Regular.ttf + res/fonts/NotoSansSymbols-Regular.ttf + res/fonts/NotoSansSymbols2-Regular.ttf res/fonts/Nunito-Bold.ttf res/fonts/Nunito-ExtraBold.ttf res/fonts/Nunito-ExtraLight.ttf res/fonts/Nunito-LightItalic.ttf res/fonts/Nunito-Regular.ttf + res/fonts/SmolEmoji-Regular.ttf res/fonts/SourceSans3-Bold.ttf res/fonts/SourceSans3-ExtraLight.ttf res/fonts/SourceSans3-It.ttf res/fonts/SourceSans3-Regular.ttf res/fonts/SourceSans3-Semibold.ttf - res/fonts/Symbola.ttf res/lang/de.bin res/lang/en.bin res/lang/es.bin diff --git a/po/en.po b/po/en.po index 7e9477ab..96f894d1 100644 --- a/po/en.po +++ b/po/en.po @@ -1210,6 +1210,9 @@ msgstr "On Dark" msgid "prefs.boldlink.light" msgstr "On Light" +msgid "prefs.userfont" +msgstr "Symbol font:" + msgid "prefs.linewidth" msgstr "Line width:" diff --git a/res/fonts/NotoSansSymbols-Regular.ttf b/res/fonts/NotoSansSymbols-Regular.ttf new file mode 100644 index 00000000..68847551 Binary files /dev/null and b/res/fonts/NotoSansSymbols-Regular.ttf differ diff --git a/res/fonts/NotoSansSymbols2-Regular.ttf b/res/fonts/NotoSansSymbols2-Regular.ttf new file mode 100644 index 00000000..79706435 Binary files /dev/null and b/res/fonts/NotoSansSymbols2-Regular.ttf differ diff --git a/res/fonts/SmolEmoji-Regular.ttf b/res/fonts/SmolEmoji-Regular.ttf new file mode 100644 index 00000000..de7cf07f Binary files /dev/null and b/res/fonts/SmolEmoji-Regular.ttf differ diff --git a/res/fonts/Symbola.ttf b/res/fonts/Symbola.ttf deleted file mode 100644 index f4bb1b7b..00000000 Binary files a/res/fonts/Symbola.ttf and /dev/null differ diff --git a/res/lang/de.bin b/res/lang/de.bin index d42d4cfc..41e5d121 100644 Binary files a/res/lang/de.bin and b/res/lang/de.bin differ diff --git a/res/lang/en.bin b/res/lang/en.bin index 4b7c1af3..c3ede7c0 100644 Binary files a/res/lang/en.bin and b/res/lang/en.bin differ diff --git a/res/lang/es.bin b/res/lang/es.bin index 815cc7b0..cdf6f4fe 100644 Binary files a/res/lang/es.bin and b/res/lang/es.bin differ diff --git a/res/lang/fi.bin b/res/lang/fi.bin index 6d1eaa78..83711d2f 100644 Binary files a/res/lang/fi.bin and b/res/lang/fi.bin differ diff --git a/res/lang/fr.bin b/res/lang/fr.bin index c18cbc99..0dc78464 100644 Binary files a/res/lang/fr.bin and b/res/lang/fr.bin differ diff --git a/res/lang/ia.bin b/res/lang/ia.bin index c47e3104..52af09ed 100644 Binary files a/res/lang/ia.bin and b/res/lang/ia.bin differ diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 974a1310..ccf95b6e 100644 Binary files a/res/lang/ie.bin and b/res/lang/ie.bin differ diff --git a/res/lang/pl.bin b/res/lang/pl.bin index dd047ff9..3f37675f 100644 Binary files a/res/lang/pl.bin and b/res/lang/pl.bin differ diff --git a/res/lang/ru.bin b/res/lang/ru.bin index ad2ad465..124a0a88 100644 Binary files a/res/lang/ru.bin and b/res/lang/ru.bin differ diff --git a/res/lang/sr.bin b/res/lang/sr.bin index 9c512c31..062d8c2f 100644 Binary files a/res/lang/sr.bin and b/res/lang/sr.bin differ diff --git a/res/lang/tok.bin b/res/lang/tok.bin index 24378b1c..ef0f2962 100644 Binary files a/res/lang/tok.bin and b/res/lang/tok.bin differ diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index c1a0d4f7..95be4c4f 100644 Binary files a/res/lang/zh_Hans.bin and b/res/lang/zh_Hans.bin differ diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index adeaceeb..f53edccc 100644 Binary files a/res/lang/zh_Hant.bin and b/res/lang/zh_Hant.bin differ diff --git a/src/app.c b/src/app.c index e22ee494..bb3afea6 100644 --- a/src/app.c +++ b/src/app.c @@ -204,6 +204,7 @@ static iString *serializePrefs_App_(const iApp *d) { appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window)); appendFormat_String(str, "prefs.dialogtab arg:%d\n", d->prefs.dialogTab); appendFormat_String(str, "font.set arg:%d\n", d->prefs.font); + appendFormat_String(str, "font.user path:%s\n", cstr_String(&d->prefs.symbolFontPath)); appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont); appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent); appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling); @@ -1555,24 +1556,25 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { isSelected_Widget(findChild_Widget(d, "prefs.imageloadscroll"))); postCommandf_App("hidetoolbarscroll arg:%d", isSelected_Widget(findChild_Widget(d, "prefs.hidetoolbarscroll"))); - postCommandf_App("ostheme arg:%d", - isSelected_Widget(findChild_Widget(d, "prefs.ostheme"))); + postCommandf_App("ostheme arg:%d", isSelected_Widget(findChild_Widget(d, "prefs.ostheme"))); + postCommandf_App("font.user path:%s", + cstrText_InputWidget(findChild_Widget(d, "prefs.userfont"))); postCommandf_App("decodeurls arg:%d", isSelected_Widget(findChild_Widget(d, "prefs.decodeurls"))); postCommandf_App("searchurl address:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.searchurl")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.searchurl"))); postCommandf_App("cachesize.set arg:%d", - toInt_String(text_InputWidget(findChild_Widget(d, "prefs.cachesize")))); + toInt_String(text_InputWidget(findChild_Widget(d, "prefs.cachesize")))); postCommandf_App("ca.file path:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.ca.file")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.ca.file"))); postCommandf_App("ca.path path:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.ca.path")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.ca.path"))); postCommandf_App("proxy.gemini address:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.gemini")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.proxy.gemini"))); postCommandf_App("proxy.gopher address:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.gopher")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.proxy.gopher"))); postCommandf_App("proxy.http address:%s", - cstr_String(text_InputWidget(findChild_Widget(d, "prefs.proxy.http")))); + cstrText_InputWidget(findChild_Widget(d, "prefs.proxy.http"))); const iWidget *tabs = findChild_Widget(d, "prefs.tabs"); if (tabs) { postCommandf_App("prefs.dialogtab arg:%u", @@ -1892,6 +1894,22 @@ iBool handleCommand_App(const char *cmd) { resetFonts_Text(); return iTrue; } + else if (equal_Command(cmd, "font.user")) { + const char *path = suffixPtr_Command(cmd, "path"); + if (cmp_String(&d->prefs.symbolFontPath, path)) { + if (!isFrozen) { + setFreezeDraw_Window(get_Window(), iTrue); + } + setCStr_String(&d->prefs.symbolFontPath, path); + loadUserFonts_Text(); + resetFonts_Text(); + if (!isFrozen) { + postCommand_App("font.changed"); + postCommand_App("window.unfreeze"); + } + } + return iTrue; + } else if (equal_Command(cmd, "font.set")) { if (!isFrozen) { setFreezeDraw_Window(get_Window(), iTrue); @@ -2332,6 +2350,7 @@ iBool handleCommand_App(const char *cmd) { setToggle_Widget(findChild_Widget(dlg, "prefs.archive.openindex"), d->prefs.openArchiveIndexPages); setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->prefs.useSystemTheme); setToggle_Widget(findChild_Widget(dlg, "prefs.customframe"), d->prefs.customFrame); + setText_InputWidget(findChild_Widget(dlg, "prefs.userfont"), &d->prefs.symbolFontPath); updatePrefsPinSplitButtons_(dlg, d->prefs.pinSplit); updateDropdownSelection_(findChild_Widget(dlg, "prefs.uilang"), cstr_String(&d->prefs.uiLanguage)); setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize); diff --git a/src/defs.h b/src/defs.h index 650f7e65..c19dd50e 100644 --- a/src/defs.h +++ b/src/defs.h @@ -62,7 +62,7 @@ enum iFileVersion { #define home_Icon "\U0001f3e0" #define edit_Icon "\u270e" #define delete_Icon "\u232b" -#define copy_Icon "\u2bba" +#define copy_Icon "\u2398" //"\u2bba" #define check_Icon "\u2714" #define ballotCheck_Icon "\U0001f5f9" #define inbox_Icon "\U0001f4e5" diff --git a/src/gmrequest.c b/src/gmrequest.c index 3dd92eec..1325c025 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c @@ -346,6 +346,7 @@ static const iBlock *replaceVariables_(const iBlock *block) { if (equal_Rangecc(name, "APP_VERSION")) { repl = range_CStr(LAGRANGE_APP_VERSION); } +#if 0 else if (startsWith_Rangecc(name, "BT:")) { /* block text */ repl = range_String(collect_String(renderBlockChars_Text( &fontFiraSansRegular_Embedded, @@ -356,12 +357,13 @@ static const iBlock *replaceVariables_(const iBlock *block) { } else if (startsWith_Rangecc(name, "ST:")) { /* shaded text */ repl = range_String(collect_String(renderBlockChars_Text( - &fontSymbola_Embedded, + &fontSmolEmojiRegular_Embedded, 20, shading_TextBlockMode, &(iString){ iBlockLiteral( name.start + 3, size_Range(&name) - 3, size_Range(&name) - 3) }))); } +#endif else if (equal_Rangecc(name, "ALT")) { #if defined (iPlatformApple) repl = range_CStr("\u2325"); diff --git a/src/prefs.c b/src/prefs.c index 96fa3c59..b29b33b5 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -68,6 +68,7 @@ void init_Prefs(iPrefs *d) { init_String(&d->httpProxy); init_String(&d->downloadDir); init_String(&d->searchUrl); + init_String(&d->symbolFontPath); /* TODO: Add some platform-specific common locations? */ if (fileExistsCStr_FileInfo("/etc/ssl/cert.pem")) { /* macOS */ setCStr_String(&d->caFile, "/etc/ssl/cert.pem"); @@ -75,9 +76,13 @@ void init_Prefs(iPrefs *d) { if (fileExistsCStr_FileInfo("/etc/ssl/certs")) { setCStr_String(&d->caPath, "/etc/ssl/certs"); } +#if defined (iPlatformAppleDesktop) + setCStr_String(&d->symbolFontPath, "/System/Library/Fonts/Apple Symbols.ttf"); +#endif } void deinit_Prefs(iPrefs *d) { + deinit_String(&d->symbolFontPath); deinit_String(&d->searchUrl); deinit_String(&d->geminiProxy); deinit_String(&d->gopherProxy); diff --git a/src/prefs.h b/src/prefs.h index 5c01ebda..7185c8f9 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -70,6 +70,7 @@ struct Impl_Prefs { iString gopherProxy; iString httpProxy; /* Style */ + iString symbolFontPath; enum iTextFont font; enum iTextFont headingFont; iBool monospaceGemini; diff --git a/src/ui/inputwidget.h b/src/ui/inputwidget.h index cb32a29c..5c39aae0 100644 --- a/src/ui/inputwidget.h +++ b/src/ui/inputwidget.h @@ -63,6 +63,11 @@ void setNotifyEdits_InputWidget (iInputWidget *, iBool notifyEdits); void setEatEscape_InputWidget (iInputWidget *, iBool eatEscape); const iString * text_InputWidget (const iInputWidget *); + +iLocalDef const char *cstrText_InputWidget(const iInputWidget *d) { + return cstr_String(text_InputWidget(d)); +} + iInputWidgetContentPadding contentPadding_InputWidget (const iInputWidget *); diff --git a/src/ui/keys.c b/src/ui/keys.c index 87a5fb88..17cc0e72 100644 --- a/src/ui/keys.c +++ b/src/ui/keys.c @@ -311,7 +311,10 @@ static iBinding *findCommand_Keys_(iKeys *d, const char *command) { static void updateLookup_Keys_(iKeys *d) { clear_PtrSet(&d->lookup); iConstForEach(Array, i, &d->bindings) { - insert_PtrSet(&d->lookup, i.value); + const iBinding *bind = i.value; + if (~bind->flags & noDirectTrigger_BindFlag) { + insert_PtrSet(&d->lookup, i.value); + } } } @@ -442,9 +445,6 @@ iBool processEvent_Keys(const SDL_Event *ev) { if (ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP) { const iBinding *bind = find_Keys_(d, ev->key.keysym.sym, keyMods_Sym(ev->key.keysym.mod)); if (bind) { - if (bind->flags & noDirectTrigger_BindFlag) { - return iFalse; - } if (ev->type == SDL_KEYUP) { if (bind->flags & argRelease_BindFlag) { postCommandf_Root(root, "%s release:1", cstr_String(&bind->command)); diff --git a/src/ui/root.c b/src/ui/root.c index 7a409a75..49925856 100644 --- a/src/ui/root.c +++ b/src/ui/root.c @@ -156,10 +156,10 @@ static const char *pageMenuCStr_ = midEllipsis_Icon; /* TODO: A preference for these, maybe? */ static const char *stopSeqCStr_[] = { /* Corners */ - uiTextCaution_ColorEscape "\U0000230c", - uiTextCaution_ColorEscape "\U0000230d", - uiTextCaution_ColorEscape "\U0000230f", - uiTextCaution_ColorEscape "\U0000230e", + uiTextCaution_ColorEscape "\U0000231c", + uiTextCaution_ColorEscape "\U0000231d", + uiTextCaution_ColorEscape "\U0000231f", + uiTextCaution_ColorEscape "\U0000231e", #if 0 /* Rotating arrow */ uiTextCaution_ColorEscape "\U00002b62", diff --git a/src/ui/text.c b/src/ui/text.c index b0c4f557..0e6a6d32 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include +#include #include #include #include @@ -124,10 +125,6 @@ struct Impl_Font { iBool isMonospaced; iBool manualKernOnly; enum iFontSize sizeId; /* used to look up different fonts of matching size */ -// enum iFontId -// enum iFontId japaneseFont; /* font to use for Japanese glyphs */ -// enum iFontId chineseFont; /* font to use for Simplified Chinese glyphs */ -// enum iFontId koreanFont; /* font to use for Korean glyphs */ uint32_t indexTable[128 - 32]; /* quick ASCII lookup */ }; @@ -155,13 +152,12 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale, d->xScale *= floorf(advance) / advance; } } - d->vertOffset = height * (1.0f - scale) / 2; - d->baseline = ascent * d->yScale; - d->sizeId = sizeId; -// d->symbolsFont = symbolsFont; -// d->japaneseFont = regularJapanese_FontId; -// d->chineseFont = regularChinese_FontId; -// d->koreanFont = regularKorean_FontId; + d->baseline = ascent * d->yScale; + d->vertOffset = height * (1.0f - scale) / 2; + if (scale > 1.0f) { + d->vertOffset /= 2; /* Tweak for Noto Sans Symbols */ + } + d->sizeId = sizeId; memset(d->indexTable, 0xff, sizeof(d->indexTable)); } @@ -215,7 +211,8 @@ struct Impl_Text { iRegExp * ansiEscape; }; -static iText text_; +static iText text_; +static iBlock *userFont_; static void initFonts_Text_(iText *d) { const float textSize = fontSize_UI * d->contentFontSize; @@ -321,27 +318,31 @@ static void initFonts_Text_(iText *d) { { &fontIosevkaTermExtended_Embedded, smallMonoSize, 1.0f, contentMonoSmall_FontSize }, { &fontIosevkaTermExtended_Embedded, monoSize, 1.0f, contentMono_FontSize }, /* extra content fonts */ - { &fontSourceSans3Regular_Embedded, textSize, scaling, contentRegular_FontSize }, - { &fontIosevkaTermExtended_Embedded, textSize, 0.866f, contentRegular_FontSize }, + { &fontSourceSans3Regular_Embedded, textSize, scaling, contentRegular_FontSize }, +// { &fontIosevkaTermExtended_Embedded, textSize, 0.866f, contentRegular_FontSize }, /* symbols and scripts */ -#define DEFINE_FONT_SET(data) \ - { &data, uiSize, 1.0f, uiNormal_FontSize }, \ - { &data, uiSize * 1.125f, 1.0f, uiMedium_FontSize }, \ - { &data, uiSize * 1.333f, 1.0f, uiBig_FontSize }, \ - { &data, uiSize * 1.666f, 1.0f, uiLarge_FontSize }, \ - { &data, textSize, 1.0f, contentRegular_FontSize }, \ - { &data, textSize * 1.200f, 1.0f, contentMedium_FontSize }, \ - { &data, textSize * 1.333f, 1.0f, contentBig_FontSize }, \ - { &data, textSize * 1.666f, 1.0f, contentLarge_FontSize }, \ - { &data, textSize * 2.000f, 1.0f, contentHuge_FontSize }, \ - { &data, smallMonoSize, 1.0f, contentMonoSmall_FontSize }, \ - { &data, monoSize, 1.0f, contentMono_FontSize } - DEFINE_FONT_SET(fontSymbola_Embedded), - DEFINE_FONT_SET(fontNotoEmojiRegular_Embedded), - DEFINE_FONT_SET(fontNotoSansJPRegular_Embedded), - DEFINE_FONT_SET(fontNotoSansSCRegular_Embedded), - DEFINE_FONT_SET(fontNanumGothicRegular_Embedded), /* TODO: should use Noto Sans here, too */ - DEFINE_FONT_SET(fontNotoSansArabicUIRegular_Embedded), +#define DEFINE_FONT_SET(data, glyphScale) \ + { (data), uiSize, glyphScale, uiNormal_FontSize }, \ + { (data), uiSize * 1.125f, glyphScale, uiMedium_FontSize }, \ + { (data), uiSize * 1.333f, glyphScale, uiBig_FontSize }, \ + { (data), uiSize * 1.666f, glyphScale, uiLarge_FontSize }, \ + { (data), textSize, glyphScale, contentRegular_FontSize }, \ + { (data), textSize * 1.200f, glyphScale, contentMedium_FontSize }, \ + { (data), textSize * 1.333f, glyphScale, contentBig_FontSize }, \ + { (data), textSize * 1.666f, glyphScale, contentLarge_FontSize }, \ + { (data), textSize * 2.000f, glyphScale, contentHuge_FontSize }, \ + { (data), smallMonoSize, glyphScale, contentMonoSmall_FontSize }, \ + { (data), monoSize, glyphScale, contentMono_FontSize } + DEFINE_FONT_SET(userFont_ ? userFont_ : &fontIosevkaTermExtended_Embedded, 1.0f), + DEFINE_FONT_SET(&fontIosevkaTermExtended_Embedded, 0.866f), + DEFINE_FONT_SET(&fontNotoSansSymbolsRegular_Embedded, 1.45f), + DEFINE_FONT_SET(&fontNotoSansSymbols2Regular_Embedded, 1.45f), + DEFINE_FONT_SET(&fontSmolEmojiRegular_Embedded, 1.0f), + DEFINE_FONT_SET(&fontNotoEmojiRegular_Embedded, 1.0f), + DEFINE_FONT_SET(&fontNotoSansJPRegular_Embedded, 1.0f), + DEFINE_FONT_SET(&fontNotoSansSCRegular_Embedded, 1.0f), + DEFINE_FONT_SET(&fontNanumGothicRegular_Embedded, 1.0f), /* TODO: should use Noto Sans here, too */ + DEFINE_FONT_SET(&fontNotoSansArabicUIRegular_Embedded, 1.0f), }; iForIndices(i, fontData) { iFont *font = &d->fonts[i]; @@ -401,8 +402,28 @@ static void deinitCache_Text_(iText *d) { SDL_DestroyTexture(d->cache); } +void loadUserFonts_Text(void) { + if (userFont_) { + delete_Block(userFont_); + userFont_ = NULL; + } + /* Load the system font. */ + const iPrefs *prefs = prefs_App(); + if (!isEmpty_String(&prefs->symbolFontPath)) { + iFile *f = new_File(&prefs->symbolFontPath); + if (open_File(f, readOnly_FileMode)) { + userFont_ = readAll_File(f); + } + else { + fprintf(stderr, "[Text] failed to open: %s\n", cstr_String(&prefs->symbolFontPath)); + } + iRelease(f); + } +} + void init_Text(SDL_Renderer *render) { iText *d = &text_; + loadUserFonts_Text(); d->contentFont = nunito_TextFont; d->headingFont = nunito_TextFont; d->contentFontSize = contentScale_Text_; @@ -542,14 +563,27 @@ static void allocate_Font_(iFont *d, iGlyph *glyph, int hoff) { } iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { + /* Smol Emoji overrides all other fonts. */ + if (ch != 0x20) { + iFont *smol = font_Text_(smolEmoji_FontId + d->sizeId); + if (smol != d && (*glyphIndex = glyphIndex_Font_(smol, ch)) != 0) { + return smol; + } + } if ((*glyphIndex = glyphIndex_Font_(d, ch)) != 0) { return d; } - /* Not defined in current font, try Noto Emoji (for selected characters). */ - if ((ch >= 0x1f300 && ch < 0x1f600) || (ch >= 0x1f680 && ch <= 0x1f6c5)) { - iFont *emoji = font_Text_(emoji_FontId + d->sizeId); - if (emoji != d && (*glyphIndex = glyphIndex_Font_(emoji, ch)) != 0) { - return emoji; + const int fallbacks[] = { + smolEmoji_FontId, + notoEmoji_FontId, + symbols2_FontId, + symbols_FontId + }; + /* First fallback is Smol Emoji. */ + iForIndices(i, fallbacks) { + iFont *fallback = font_Text_(fallbacks[i] + d->sizeId); + if (fallback != d && (*glyphIndex = glyphIndex_Font_(fallback, ch)) != 0) { + return fallback; } } /* Try Simplified Chinese. */ @@ -588,13 +622,18 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { return d; } #endif - /* Fall back to Symbola for anything else. */ - iFont *font = font_Text_(symbols_FontId + d->sizeId); - *glyphIndex = glyphIndex_Font_(font, ch); -// if (!*glyphIndex) { -// fprintf(stderr, "failed to find %08x (%lc)\n", ch, ch); fflush(stderr); -// } - return font; + /* User's symbols font. */ { + iFont *sys = font_Text_(userSymbols_FontId + d->sizeId); + if (sys != d && (*glyphIndex = glyphIndex_Font_(sys, ch)) != 0) { + return sys; + } + } +// iFont *font = font_Text_(iosevka_FontId + d->sizeId); +// *glyphIndex = glyphIndex_Font_(font, ch); + if (!*glyphIndex) { + fprintf(stderr, "failed to find %08x (%lc)\n", ch, (int)ch); fflush(stderr); + } + return d; } static iGlyph *glyph_Font_(iFont *d, iChar ch) { diff --git a/src/ui/text.h b/src/ui/text.h index 044ddd32..1bb60e8b 100644 --- a/src/ui/text.h +++ b/src/ui/text.h @@ -68,11 +68,14 @@ enum iFontId { monospace_FontId, /* extra content fonts */ defaultContentSized_FontId, /* UI font but sized to regular_FontId */ - regularMonospace_FontId, /* symbols and scripts */ - symbols_FontId, - emoji_FontId = symbols_FontId + max_FontSize, - japanese_FontId = emoji_FontId + max_FontSize, + userSymbols_FontId, + iosevka_FontId = userSymbols_FontId + max_FontSize, + symbols_FontId = iosevka_FontId + max_FontSize, + symbols2_FontId = symbols_FontId + max_FontSize, + smolEmoji_FontId = symbols2_FontId + max_FontSize, + notoEmoji_FontId = smolEmoji_FontId + max_FontSize, + japanese_FontId = notoEmoji_FontId + max_FontSize, chineseSimplified_FontId = japanese_FontId + max_FontSize, korean_FontId = chineseSimplified_FontId + max_FontSize, arabic_FontId = korean_FontId + max_FontSize, @@ -91,7 +94,7 @@ enum iFontId { uiInput_FontId = defaultMedium_FontId, uiContent_FontId = defaultMedium_FontId, uiContentBold_FontId = defaultMediumBold_FontId, - uiContentSymbols_FontId = symbols_FontId + uiMedium_FontSize, + uiContentSymbols_FontId = symbols_FontId + uiMedium_FontSize, /* Document fonts: */ paragraph_FontId = regular_FontId, firstParagraph_FontId = medium_FontId, @@ -102,6 +105,7 @@ enum iFontId { heading2_FontId = largeBold_FontId, heading3_FontId = big_FontId, banner_FontId = largeLight_FontId, + regularMonospace_FontId = iosevka_FontId + contentRegular_FontSize }; iLocalDef iBool isJapanese_FontId(enum iFontId id) { @@ -124,6 +128,8 @@ extern int gap_Text; /* affected by content font size */ void init_Text (SDL_Renderer *); void deinit_Text (void); +void loadUserFonts_Text (void); /* based on Prefs */ + void setContentFont_Text (enum iTextFont font); void setHeadingFont_Text (enum iTextFont font); void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */ diff --git a/src/ui/util.c b/src/ui/util.c index 6c87ba26..977eba9d 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -1525,6 +1525,7 @@ void updatePreferencesLayout_Widget(iWidget *prefs) { static const char *inputIds[] = { "prefs.searchurl", "prefs.downloads", + "prefs.userfont", "prefs.ca.file", "prefs.ca.path", "prefs.proxy.gemini", @@ -1786,6 +1787,7 @@ iWidget *makePreferences_Widget(void) { updateSize_LabelWidget((iLabelWidget *) tog); } addChildFlags_Widget(values, iClob(boldLink), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); + addPrefsInputWithHeading_(headings, values, "prefs.userfont", iClob(new_InputWidget(0))); } makeTwoColumnHeading_("${heading.prefs.paragraph}", headings, values); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.linewidth}"))); -- cgit v1.2.3