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. --- src/ui/text.c | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'src/ui/text.c') 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); -- cgit v1.2.3