From 684c6d25fc4465440d09f9ad14cf8876f2c3a0c2 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 11 Oct 2020 16:00:57 +0300 Subject: Added a preference for heading font Body and heading fonts can be selected separately. --- CMakeLists.txt | 3 +- res/fonts/EBGaramond-Medium.ttf | Bin 601412 -> 0 bytes res/fonts/Literata-LightItalic-opsz=10.ttf | Bin 0 -> 232220 bytes res/fonts/Literata-LightItalic-opsz=14.ttf | Bin 231988 -> 0 bytes src/app.c | 13 ++++++++ src/prefs.c | 1 + src/prefs.h | 1 + src/ui/text.c | 51 ++++++++++++++++++++--------- src/ui/text.h | 5 +-- src/ui/util.c | 29 ++++++++++++---- 10 files changed, 77 insertions(+), 26 deletions(-) delete mode 100644 res/fonts/EBGaramond-Medium.ttf create mode 100644 res/fonts/Literata-LightItalic-opsz=10.ttf delete mode 100644 res/fonts/Literata-LightItalic-opsz=14.ttf diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d0e087b..e69fe3cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,6 @@ set (EMBED_RESOURCES res/about/license.gmi res/about/version.gmi res/fonts/EBGaramond-Regular.ttf - res/fonts/EBGaramond-Medium.ttf res/fonts/EBGaramond-Italic.ttf res/fonts/EBGaramond-Bold.ttf res/fonts/FiraMono-Regular.ttf @@ -69,7 +68,7 @@ set (EMBED_RESOURCES res/fonts/Literata-Regular-opsz=14.ttf res/fonts/Literata-Bold-opsz=36.ttf res/fonts/Literata-ExtraLight-opsz=18.ttf - res/fonts/Literata-LightItalic-opsz=14.ttf + res/fonts/Literata-LightItalic-opsz=10.ttf res/fonts/NotoEmoji-Regular.ttf res/fonts/Nunito-ExtraBold.ttf res/fonts/Nunito-ExtraLight.ttf diff --git a/res/fonts/EBGaramond-Medium.ttf b/res/fonts/EBGaramond-Medium.ttf deleted file mode 100644 index b9d6964d..00000000 Binary files a/res/fonts/EBGaramond-Medium.ttf and /dev/null differ diff --git a/res/fonts/Literata-LightItalic-opsz=10.ttf b/res/fonts/Literata-LightItalic-opsz=10.ttf new file mode 100644 index 00000000..e07554b4 Binary files /dev/null and b/res/fonts/Literata-LightItalic-opsz=10.ttf differ diff --git a/res/fonts/Literata-LightItalic-opsz=14.ttf b/res/fonts/Literata-LightItalic-opsz=14.ttf deleted file mode 100644 index 4549f26e..00000000 Binary files a/res/fonts/Literata-LightItalic-opsz=14.ttf and /dev/null differ diff --git a/src/app.c b/src/app.c index 347e3661..ac93d511 100644 --- a/src/app.c +++ b/src/app.c @@ -169,6 +169,7 @@ static iString *serializePrefs_App_(const iApp *d) { appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar)); appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window)); appendFormat_String(str, "font.set arg:%d\n", d->prefs.font); + 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, "linewidth.set arg:%d\n", d->prefs.lineWidth); appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph); @@ -834,6 +835,14 @@ iBool handleCommand_App(const char *cmd) { postCommand_App("window.unfreeze"); return iTrue; } + else if (equal_Command(cmd, "headingfont.set")) { + setFreezeDraw_Window(get_Window(), iTrue); + d->prefs.headingFont = arg_Command(cmd); + setHeadingFont_Text(d->prefs.headingFont); + postCommand_App("font.changed"); + postCommand_App("window.unfreeze"); + return iTrue; + } else if (equal_Command(cmd, "zoom.set")) { setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */ d->prefs.zoomPercent = arg_Command(cmd); @@ -1015,6 +1024,10 @@ iBool handleCommand_App(const char *cmd) { setFlags_Widget(findChild_Widget(dlg, format_CStr("prefs.font.%d", d->prefs.font)), selected_WidgetFlag, iTrue); + setFlags_Widget( + findChild_Widget(dlg, format_CStr("prefs.headingfont.%d", d->prefs.headingFont)), + selected_WidgetFlag, + iTrue); setFlags_Widget( findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)), selected_WidgetFlag, diff --git a/src/prefs.c b/src/prefs.c index af481233..a36be6a0 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -7,6 +7,7 @@ void init_Prefs(iPrefs *d) { d->zoomPercent = 100; d->forceLineWrap = iFalse; d->font = nunito_TextFont; + d->headingFont = nunito_TextFont; d->lineWidth = 40; d->bigFirstParagraph = iTrue; d->sideIcon = iTrue; diff --git a/src/prefs.h b/src/prefs.h index 324fb6fd..53f5dfd7 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -20,6 +20,7 @@ struct Impl_Prefs { iString downloadDir; /* Content */ enum iTextFont font; + enum iTextFont headingFont; int lineWidth; iBool bigFirstParagraph; iBool forceLineWrap; diff --git a/src/ui/text.c b/src/ui/text.c index 8d8aa19c..5f915e3c 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -145,6 +145,7 @@ struct Impl_CacheRow { struct Impl_Text { enum iTextFont contentFont; + enum iTextFont headingFont; float contentFontSize; iFont fonts[max_FontId]; SDL_Renderer * render; @@ -164,28 +165,40 @@ static void initFonts_Text_(iText *d) { const float monoSize = fontSize_UI * d->contentFontSize / contentScale_Text_ * 0.866f; const iBlock *regularFont = &fontNunitoRegular_Embedded; const iBlock *italicFont = &fontNunitoLightItalic_Embedded; - const iBlock *boldFont = &fontNunitoExtraBold_Embedded; + const iBlock *h12Font = &fontNunitoExtraBold_Embedded; + const iBlock *h3Font = &fontNunitoExtraBold_Embedded; const iBlock *lightFont = &fontNunitoExtraLight_Embedded; float scaling = 1.0f; /* glyph scaling (<=1.0), for increasing line spacing */ + float h123Scaling = 1.0f; /* glyph scaling (<=1.0), for increasing line spacing */ if (d->contentFont == firaSans_TextFont) { regularFont = &fontFiraSansRegular_Embedded; - italicFont = &fontFiraSansItalic_Embedded; - boldFont = &fontFiraSansBold_Embedded; lightFont = &fontFiraSansLight_Embedded; + italicFont = &fontFiraSansItalic_Embedded; scaling = 0.85f; } else if (d->contentFont == ebGaramond_TextFont) { regularFont = &fontEBGaramondRegular_Embedded; + lightFont = &fontEBGaramondRegular_Embedded; italicFont = &fontEBGaramondItalic_Embedded; - boldFont = &fontEBGaramondBold_Embedded; - lightFont = &fontLiterataExtraLightopsz18_Embedded; } else if (d->contentFont == literata_TextFont) { regularFont = &fontLiterataRegularopsz14_Embedded; - italicFont = &fontLiterataLightItalicopsz14_Embedded; - boldFont = &fontLiterataBoldopsz36_Embedded; + italicFont = &fontLiterataLightItalicopsz10_Embedded; lightFont = &fontLiterataExtraLightopsz18_Embedded; } + if (d->headingFont == firaSans_TextFont) { + h12Font = &fontFiraSansBold_Embedded; + h3Font = &fontFiraSansRegular_Embedded; + h123Scaling = 0.85f; + } + else if (d->headingFont == ebGaramond_TextFont) { + h12Font = &fontEBGaramondBold_Embedded; + h3Font = &fontEBGaramondRegular_Embedded; + } + else if (d->headingFont == literata_TextFont) { + h12Font = &fontLiterataBoldopsz36_Embedded; + h3Font = &fontLiterataRegularopsz14_Embedded; + } const struct { const iBlock *ttf; int size; @@ -200,13 +213,13 @@ static void initFonts_Text_(iText *d) { { &fontFiraMonoRegular_Embedded, monoSize, 1.0f, monospaceSymbols_FontId }, { &fontFiraMonoRegular_Embedded, monoSize * 0.750f, 1.0f, monospaceSmallSymbols_FontId }, { regularFont, textSize * 1.200f, scaling, mediumSymbols_FontId }, - { regularFont, textSize * 1.333f, scaling, bigSymbols_FontId }, + { h3Font, textSize * 1.333f, scaling, bigSymbols_FontId }, { italicFont, textSize, scaling, symbols_FontId }, - { boldFont, textSize, scaling, symbols_FontId }, - { boldFont, textSize * 1.333f, scaling, mediumSymbols_FontId }, - { boldFont, textSize * 1.666f, scaling, largeSymbols_FontId }, - { boldFont, textSize * 2.000f, scaling, hugeSymbols_FontId }, - { lightFont, textSize * 1.666f, scaling, largeSymbols_FontId }, +// { boldFont, textSize, scaling, symbols_FontId }, +// { boldFont, textSize * 1.333f, h123Scaling, mediumSymbols_FontId }, + { h12Font, textSize * 1.666f, h123Scaling, largeSymbols_FontId }, + { h12Font, textSize * 2.000f, h123Scaling, hugeSymbols_FontId }, + { lightFont, textSize * 1.666f, scaling, largeSymbols_FontId }, /* symbol fonts */ { &fontSymbola_Embedded, fontSize_UI, 1.0f, defaultSymbols_FontId }, { &fontSymbola_Embedded, fontSize_UI * 1.125f, 1.0f, defaultMediumSymbols_FontId }, @@ -259,7 +272,7 @@ static void initFonts_Text_(iText *d) { font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId; font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId; font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId; - font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId; +// font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId; font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId; font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId; font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId; @@ -308,7 +321,8 @@ static void deinitCache_Text_(iText *d) { void init_Text(SDL_Renderer *render) { iText *d = &text_; d->contentFont = nunito_TextFont; - d->contentFontSize = contentScale_Text_; + d->headingFont = nunito_TextFont; + d->contentFontSize = contentScale_Text_; d->ansiEscape = new_RegExp("\\[([0-9;]+)m", 0); d->render = render; /* A grayscale palette for rasterized glyphs. */ { @@ -343,6 +357,13 @@ void setContentFont_Text(enum iTextFont font) { } } +void setHeadingFont_Text(enum iTextFont font) { + if (text_.headingFont != font) { + text_.headingFont = font; + resetFonts_Text(); + } +} + void setContentFontSize_Text(float fontSizeFactor) { fontSizeFactor *= contentScale_Text_; iAssert(fontSizeFactor > 0); diff --git a/src/ui/text.h b/src/ui/text.h index fe4ddef1..21256be5 100644 --- a/src/ui/text.h +++ b/src/ui/text.h @@ -40,8 +40,8 @@ enum iFontId { medium_FontId, big_FontId, italic_FontId, - bold_FontId, - bigBold_FontId, + /*bold_FontId,*/ /* TODO: Not used presently, but could be useful for Markdown for instance. */ + /*bigBold_FontId,*/ largeBold_FontId, hugeBold_FontId, largeLight_FontId, @@ -118,6 +118,7 @@ void init_Text (SDL_Renderer *); void deinit_Text (void); void setContentFont_Text (enum iTextFont font); +void setHeadingFont_Text (enum iTextFont font); void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */ void resetFonts_Text (void); diff --git a/src/ui/util.c b/src/ui/util.c index c061231d..67d34062 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -886,6 +886,18 @@ static void addRadioButton_(iWidget *parent, const char *id, const char *label, id); } +static void addFontButtons_(iWidget *parent, const char *id) { + const char *fontNames[] = { + "Nunito", "Fira Sans", "Literata", "EB Garamond" + }; + iForIndices(i, fontNames) { + addRadioButton_(parent, + format_CStr("prefs.%s.%u", id, i), + fontNames[i], + format_CStr("%s.set arg:%u", id, i)); + } +} + iWidget *makePreferences_Widget(void) { iWidget *dlg = makeSheet_Widget("prefs"); addChildFlags_Widget(dlg, @@ -920,15 +932,18 @@ iWidget *makePreferences_Widget(void) { } /* Layout. */ { appendTwoColumnPage_(tabs, "Style", '2', &headings, &values); - addChild_Widget(headings, iClob(makeHeading_Widget("Font:"))); - iWidget *fonts = new_Widget(); /* Fonts. */ { - addRadioButton_(fonts, "prefs.font.0", "Nunito", "font.set arg:0"); - addRadioButton_(fonts, "prefs.font.1", "Fira Sans", "font.set arg:1"); - addRadioButton_(fonts, "prefs.font.2", "Literata", "font.set arg:2"); - addRadioButton_(fonts, "prefs.font.3", "EB Garamond", "font.set arg:3"); + addChild_Widget(headings, iClob(makeHeading_Widget("Body font:"))); + iWidget *fonts = new_Widget(); + addFontButtons_(fonts, "font"); + addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); + addChild_Widget(headings, iClob(makeHeading_Widget("Heading font:"))); + fonts = new_Widget(); + addFontButtons_(fonts, "headingfont"); + addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); } - addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); + addChild_Widget(headings, iClob(makePadding_Widget(2 * gap_UI))); + addChild_Widget(values, iClob(makePadding_Widget(2 * gap_UI))); addChild_Widget(headings, iClob(makeHeading_Widget("Line width:"))); iWidget *widths = new_Widget(); /* Line widths. */ { -- cgit v1.2.3