summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-10-11 16:00:57 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-10-11 16:00:57 +0300
commit684c6d25fc4465440d09f9ad14cf8876f2c3a0c2 (patch)
treee6a6c576a3ca44d2d079687b860d413a298a88de /src/ui/text.c
parent52cb8a8d24408e21101dfe9465cf28eaaf287c13 (diff)
Added a preference for heading font
Body and heading fonts can be selected separately.
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c51
1 files changed, 36 insertions, 15 deletions
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 {
145 145
146struct Impl_Text { 146struct Impl_Text {
147 enum iTextFont contentFont; 147 enum iTextFont contentFont;
148 enum iTextFont headingFont;
148 float contentFontSize; 149 float contentFontSize;
149 iFont fonts[max_FontId]; 150 iFont fonts[max_FontId];
150 SDL_Renderer * render; 151 SDL_Renderer * render;
@@ -164,28 +165,40 @@ static void initFonts_Text_(iText *d) {
164 const float monoSize = fontSize_UI * d->contentFontSize / contentScale_Text_ * 0.866f; 165 const float monoSize = fontSize_UI * d->contentFontSize / contentScale_Text_ * 0.866f;
165 const iBlock *regularFont = &fontNunitoRegular_Embedded; 166 const iBlock *regularFont = &fontNunitoRegular_Embedded;
166 const iBlock *italicFont = &fontNunitoLightItalic_Embedded; 167 const iBlock *italicFont = &fontNunitoLightItalic_Embedded;
167 const iBlock *boldFont = &fontNunitoExtraBold_Embedded; 168 const iBlock *h12Font = &fontNunitoExtraBold_Embedded;
169 const iBlock *h3Font = &fontNunitoExtraBold_Embedded;
168 const iBlock *lightFont = &fontNunitoExtraLight_Embedded; 170 const iBlock *lightFont = &fontNunitoExtraLight_Embedded;
169 float scaling = 1.0f; /* glyph scaling (<=1.0), for increasing line spacing */ 171 float scaling = 1.0f; /* glyph scaling (<=1.0), for increasing line spacing */
172 float h123Scaling = 1.0f; /* glyph scaling (<=1.0), for increasing line spacing */
170 if (d->contentFont == firaSans_TextFont) { 173 if (d->contentFont == firaSans_TextFont) {
171 regularFont = &fontFiraSansRegular_Embedded; 174 regularFont = &fontFiraSansRegular_Embedded;
172 italicFont = &fontFiraSansItalic_Embedded;
173 boldFont = &fontFiraSansBold_Embedded;
174 lightFont = &fontFiraSansLight_Embedded; 175 lightFont = &fontFiraSansLight_Embedded;
176 italicFont = &fontFiraSansItalic_Embedded;
175 scaling = 0.85f; 177 scaling = 0.85f;
176 } 178 }
177 else if (d->contentFont == ebGaramond_TextFont) { 179 else if (d->contentFont == ebGaramond_TextFont) {
178 regularFont = &fontEBGaramondRegular_Embedded; 180 regularFont = &fontEBGaramondRegular_Embedded;
181 lightFont = &fontEBGaramondRegular_Embedded;
179 italicFont = &fontEBGaramondItalic_Embedded; 182 italicFont = &fontEBGaramondItalic_Embedded;
180 boldFont = &fontEBGaramondBold_Embedded;
181 lightFont = &fontLiterataExtraLightopsz18_Embedded;
182 } 183 }
183 else if (d->contentFont == literata_TextFont) { 184 else if (d->contentFont == literata_TextFont) {
184 regularFont = &fontLiterataRegularopsz14_Embedded; 185 regularFont = &fontLiterataRegularopsz14_Embedded;
185 italicFont = &fontLiterataLightItalicopsz14_Embedded; 186 italicFont = &fontLiterataLightItalicopsz10_Embedded;
186 boldFont = &fontLiterataBoldopsz36_Embedded;
187 lightFont = &fontLiterataExtraLightopsz18_Embedded; 187 lightFont = &fontLiterataExtraLightopsz18_Embedded;
188 } 188 }
189 if (d->headingFont == firaSans_TextFont) {
190 h12Font = &fontFiraSansBold_Embedded;
191 h3Font = &fontFiraSansRegular_Embedded;
192 h123Scaling = 0.85f;
193 }
194 else if (d->headingFont == ebGaramond_TextFont) {
195 h12Font = &fontEBGaramondBold_Embedded;
196 h3Font = &fontEBGaramondRegular_Embedded;
197 }
198 else if (d->headingFont == literata_TextFont) {
199 h12Font = &fontLiterataBoldopsz36_Embedded;
200 h3Font = &fontLiterataRegularopsz14_Embedded;
201 }
189 const struct { 202 const struct {
190 const iBlock *ttf; 203 const iBlock *ttf;
191 int size; 204 int size;
@@ -200,13 +213,13 @@ static void initFonts_Text_(iText *d) {
200 { &fontFiraMonoRegular_Embedded, monoSize, 1.0f, monospaceSymbols_FontId }, 213 { &fontFiraMonoRegular_Embedded, monoSize, 1.0f, monospaceSymbols_FontId },
201 { &fontFiraMonoRegular_Embedded, monoSize * 0.750f, 1.0f, monospaceSmallSymbols_FontId }, 214 { &fontFiraMonoRegular_Embedded, monoSize * 0.750f, 1.0f, monospaceSmallSymbols_FontId },
202 { regularFont, textSize * 1.200f, scaling, mediumSymbols_FontId }, 215 { regularFont, textSize * 1.200f, scaling, mediumSymbols_FontId },
203 { regularFont, textSize * 1.333f, scaling, bigSymbols_FontId }, 216 { h3Font, textSize * 1.333f, scaling, bigSymbols_FontId },
204 { italicFont, textSize, scaling, symbols_FontId }, 217 { italicFont, textSize, scaling, symbols_FontId },
205 { boldFont, textSize, scaling, symbols_FontId }, 218// { boldFont, textSize, scaling, symbols_FontId },
206 { boldFont, textSize * 1.333f, scaling, mediumSymbols_FontId }, 219// { boldFont, textSize * 1.333f, h123Scaling, mediumSymbols_FontId },
207 { boldFont, textSize * 1.666f, scaling, largeSymbols_FontId }, 220 { h12Font, textSize * 1.666f, h123Scaling, largeSymbols_FontId },
208 { boldFont, textSize * 2.000f, scaling, hugeSymbols_FontId }, 221 { h12Font, textSize * 2.000f, h123Scaling, hugeSymbols_FontId },
209 { lightFont, textSize * 1.666f, scaling, largeSymbols_FontId }, 222 { lightFont, textSize * 1.666f, scaling, largeSymbols_FontId },
210 /* symbol fonts */ 223 /* symbol fonts */
211 { &fontSymbola_Embedded, fontSize_UI, 1.0f, defaultSymbols_FontId }, 224 { &fontSymbola_Embedded, fontSize_UI, 1.0f, defaultSymbols_FontId },
212 { &fontSymbola_Embedded, fontSize_UI * 1.125f, 1.0f, defaultMediumSymbols_FontId }, 225 { &fontSymbola_Embedded, fontSize_UI * 1.125f, 1.0f, defaultMediumSymbols_FontId },
@@ -259,7 +272,7 @@ static void initFonts_Text_(iText *d) {
259 font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId; 272 font_Text_(monospace_FontId)->japaneseFont = monospaceJapanese_FontId;
260 font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId; 273 font_Text_(medium_FontId)->japaneseFont = mediumJapanese_FontId;
261 font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId; 274 font_Text_(big_FontId)->japaneseFont = bigJapanese_FontId;
262 font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId; 275// font_Text_(bigBold_FontId)->japaneseFont = bigJapanese_FontId;
263 font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId; 276 font_Text_(largeBold_FontId)->japaneseFont = largeJapanese_FontId;
264 font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId; 277 font_Text_(largeLight_FontId)->japaneseFont = largeJapanese_FontId;
265 font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId; 278 font_Text_(hugeBold_FontId)->japaneseFont = hugeJapanese_FontId;
@@ -308,7 +321,8 @@ static void deinitCache_Text_(iText *d) {
308void init_Text(SDL_Renderer *render) { 321void init_Text(SDL_Renderer *render) {
309 iText *d = &text_; 322 iText *d = &text_;
310 d->contentFont = nunito_TextFont; 323 d->contentFont = nunito_TextFont;
311 d->contentFontSize = contentScale_Text_; 324 d->headingFont = nunito_TextFont;
325 d->contentFontSize = contentScale_Text_;
312 d->ansiEscape = new_RegExp("\\[([0-9;]+)m", 0); 326 d->ansiEscape = new_RegExp("\\[([0-9;]+)m", 0);
313 d->render = render; 327 d->render = render;
314 /* A grayscale palette for rasterized glyphs. */ { 328 /* A grayscale palette for rasterized glyphs. */ {
@@ -343,6 +357,13 @@ void setContentFont_Text(enum iTextFont font) {
343 } 357 }
344} 358}
345 359
360void setHeadingFont_Text(enum iTextFont font) {
361 if (text_.headingFont != font) {
362 text_.headingFont = font;
363 resetFonts_Text();
364 }
365}
366
346void setContentFontSize_Text(float fontSizeFactor) { 367void setContentFontSize_Text(float fontSizeFactor) {
347 fontSizeFactor *= contentScale_Text_; 368 fontSizeFactor *= contentScale_Text_;
348 iAssert(fontSizeFactor > 0); 369 iAssert(fontSizeFactor > 0);