summaryrefslogtreecommitdiff
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
parent52cb8a8d24408e21101dfe9465cf28eaaf287c13 (diff)
Added a preference for heading font
Body and heading fonts can be selected separately.
-rw-r--r--CMakeLists.txt3
-rw-r--r--res/fonts/EBGaramond-Medium.ttfbin601412 -> 0 bytes
-rw-r--r--res/fonts/Literata-LightItalic-opsz=10.ttfbin0 -> 232220 bytes
-rw-r--r--res/fonts/Literata-LightItalic-opsz=14.ttfbin231988 -> 0 bytes
-rw-r--r--src/app.c13
-rw-r--r--src/prefs.c1
-rw-r--r--src/prefs.h1
-rw-r--r--src/ui/text.c51
-rw-r--r--src/ui/text.h5
-rw-r--r--src/ui/util.c29
10 files changed, 77 insertions, 26 deletions
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
57 res/about/license.gmi 57 res/about/license.gmi
58 res/about/version.gmi 58 res/about/version.gmi
59 res/fonts/EBGaramond-Regular.ttf 59 res/fonts/EBGaramond-Regular.ttf
60 res/fonts/EBGaramond-Medium.ttf
61 res/fonts/EBGaramond-Italic.ttf 60 res/fonts/EBGaramond-Italic.ttf
62 res/fonts/EBGaramond-Bold.ttf 61 res/fonts/EBGaramond-Bold.ttf
63 res/fonts/FiraMono-Regular.ttf 62 res/fonts/FiraMono-Regular.ttf
@@ -69,7 +68,7 @@ set (EMBED_RESOURCES
69 res/fonts/Literata-Regular-opsz=14.ttf 68 res/fonts/Literata-Regular-opsz=14.ttf
70 res/fonts/Literata-Bold-opsz=36.ttf 69 res/fonts/Literata-Bold-opsz=36.ttf
71 res/fonts/Literata-ExtraLight-opsz=18.ttf 70 res/fonts/Literata-ExtraLight-opsz=18.ttf
72 res/fonts/Literata-LightItalic-opsz=14.ttf 71 res/fonts/Literata-LightItalic-opsz=10.ttf
73 res/fonts/NotoEmoji-Regular.ttf 72 res/fonts/NotoEmoji-Regular.ttf
74 res/fonts/Nunito-ExtraBold.ttf 73 res/fonts/Nunito-ExtraBold.ttf
75 res/fonts/Nunito-ExtraLight.ttf 74 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
--- a/res/fonts/EBGaramond-Medium.ttf
+++ /dev/null
Binary files 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
--- /dev/null
+++ b/res/fonts/Literata-LightItalic-opsz=10.ttf
Binary files 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
--- a/res/fonts/Literata-LightItalic-opsz=14.ttf
+++ /dev/null
Binary files 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) {
169 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar)); 169 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar));
170 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window)); 170 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window));
171 appendFormat_String(str, "font.set arg:%d\n", d->prefs.font); 171 appendFormat_String(str, "font.set arg:%d\n", d->prefs.font);
172 appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont);
172 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent); 173 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
173 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); 174 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth);
174 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph); 175 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph);
@@ -834,6 +835,14 @@ iBool handleCommand_App(const char *cmd) {
834 postCommand_App("window.unfreeze"); 835 postCommand_App("window.unfreeze");
835 return iTrue; 836 return iTrue;
836 } 837 }
838 else if (equal_Command(cmd, "headingfont.set")) {
839 setFreezeDraw_Window(get_Window(), iTrue);
840 d->prefs.headingFont = arg_Command(cmd);
841 setHeadingFont_Text(d->prefs.headingFont);
842 postCommand_App("font.changed");
843 postCommand_App("window.unfreeze");
844 return iTrue;
845 }
837 else if (equal_Command(cmd, "zoom.set")) { 846 else if (equal_Command(cmd, "zoom.set")) {
838 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */ 847 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */
839 d->prefs.zoomPercent = arg_Command(cmd); 848 d->prefs.zoomPercent = arg_Command(cmd);
@@ -1016,6 +1025,10 @@ iBool handleCommand_App(const char *cmd) {
1016 selected_WidgetFlag, 1025 selected_WidgetFlag,
1017 iTrue); 1026 iTrue);
1018 setFlags_Widget( 1027 setFlags_Widget(
1028 findChild_Widget(dlg, format_CStr("prefs.headingfont.%d", d->prefs.headingFont)),
1029 selected_WidgetFlag,
1030 iTrue);
1031 setFlags_Widget(
1019 findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)), 1032 findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)),
1020 selected_WidgetFlag, 1033 selected_WidgetFlag,
1021 iTrue); 1034 iTrue);
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) {
7 d->zoomPercent = 100; 7 d->zoomPercent = 100;
8 d->forceLineWrap = iFalse; 8 d->forceLineWrap = iFalse;
9 d->font = nunito_TextFont; 9 d->font = nunito_TextFont;
10 d->headingFont = nunito_TextFont;
10 d->lineWidth = 40; 11 d->lineWidth = 40;
11 d->bigFirstParagraph = iTrue; 12 d->bigFirstParagraph = iTrue;
12 d->sideIcon = iTrue; 13 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 {
20 iString downloadDir; 20 iString downloadDir;
21 /* Content */ 21 /* Content */
22 enum iTextFont font; 22 enum iTextFont font;
23 enum iTextFont headingFont;
23 int lineWidth; 24 int lineWidth;
24 iBool bigFirstParagraph; 25 iBool bigFirstParagraph;
25 iBool forceLineWrap; 26 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 {
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);
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 {
40 medium_FontId, 40 medium_FontId,
41 big_FontId, 41 big_FontId,
42 italic_FontId, 42 italic_FontId,
43 bold_FontId, 43 /*bold_FontId,*/ /* TODO: Not used presently, but could be useful for Markdown for instance. */
44 bigBold_FontId, 44 /*bigBold_FontId,*/
45 largeBold_FontId, 45 largeBold_FontId,
46 hugeBold_FontId, 46 hugeBold_FontId,
47 largeLight_FontId, 47 largeLight_FontId,
@@ -118,6 +118,7 @@ void init_Text (SDL_Renderer *);
118void deinit_Text (void); 118void deinit_Text (void);
119 119
120void setContentFont_Text (enum iTextFont font); 120void setContentFont_Text (enum iTextFont font);
121void setHeadingFont_Text (enum iTextFont font);
121void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */ 122void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */
122void resetFonts_Text (void); 123void resetFonts_Text (void);
123 124
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,
886 id); 886 id);
887} 887}
888 888
889static void addFontButtons_(iWidget *parent, const char *id) {
890 const char *fontNames[] = {
891 "Nunito", "Fira Sans", "Literata", "EB Garamond"
892 };
893 iForIndices(i, fontNames) {
894 addRadioButton_(parent,
895 format_CStr("prefs.%s.%u", id, i),
896 fontNames[i],
897 format_CStr("%s.set arg:%u", id, i));
898 }
899}
900
889iWidget *makePreferences_Widget(void) { 901iWidget *makePreferences_Widget(void) {
890 iWidget *dlg = makeSheet_Widget("prefs"); 902 iWidget *dlg = makeSheet_Widget("prefs");
891 addChildFlags_Widget(dlg, 903 addChildFlags_Widget(dlg,
@@ -920,15 +932,18 @@ iWidget *makePreferences_Widget(void) {
920 } 932 }
921 /* Layout. */ { 933 /* Layout. */ {
922 appendTwoColumnPage_(tabs, "Style", '2', &headings, &values); 934 appendTwoColumnPage_(tabs, "Style", '2', &headings, &values);
923 addChild_Widget(headings, iClob(makeHeading_Widget("Font:")));
924 iWidget *fonts = new_Widget();
925 /* Fonts. */ { 935 /* Fonts. */ {
926 addRadioButton_(fonts, "prefs.font.0", "Nunito", "font.set arg:0"); 936 addChild_Widget(headings, iClob(makeHeading_Widget("Body font:")));
927 addRadioButton_(fonts, "prefs.font.1", "Fira Sans", "font.set arg:1"); 937 iWidget *fonts = new_Widget();
928 addRadioButton_(fonts, "prefs.font.2", "Literata", "font.set arg:2"); 938 addFontButtons_(fonts, "font");
929 addRadioButton_(fonts, "prefs.font.3", "EB Garamond", "font.set arg:3"); 939 addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
940 addChild_Widget(headings, iClob(makeHeading_Widget("Heading font:")));
941 fonts = new_Widget();
942 addFontButtons_(fonts, "headingfont");
943 addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
930 } 944 }
931 addChildFlags_Widget(values, iClob(fonts), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag); 945 addChild_Widget(headings, iClob(makePadding_Widget(2 * gap_UI)));
946 addChild_Widget(values, iClob(makePadding_Widget(2 * gap_UI)));
932 addChild_Widget(headings, iClob(makeHeading_Widget("Line width:"))); 947 addChild_Widget(headings, iClob(makeHeading_Widget("Line width:")));
933 iWidget *widths = new_Widget(); 948 iWidget *widths = new_Widget();
934 /* Line widths. */ { 949 /* Line widths. */ {