diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-06 12:16:43 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-06 12:16:43 +0300 |
commit | 61a3dc017067be43472dadb7909094aa04d1fe9d (patch) | |
tree | 18b87895489844b4e516f79cd1588038f1d49494 /src/ui/text.h | |
parent | f6a54d5375aab9c41af3f7c8a5e8fcbd1e0c9287 (diff) |
Revised runtime font management
The built-in fonts are loaded via FontPack, and the font table is now constructed dynamically based on available fonts.
A full set of variants (style, size) are prepared for each font, but some of the data gets allocated lazily when needed.
GmRun needed a larger allocation for fonts, so now all the fields are combined into a single bit field.
TODO: Glyph scaling, vertical offsets, and symbol lookup are still not fully working.
Diffstat (limited to 'src/ui/text.h')
-rw-r--r-- | src/ui/text.h | 131 |
1 files changed, 72 insertions, 59 deletions
diff --git a/src/ui/text.h b/src/ui/text.h index 1b3200d4..f76c8125 100644 --- a/src/ui/text.h +++ b/src/ui/text.h | |||
@@ -31,79 +31,92 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
31 | 31 | ||
32 | /* Content sizes: regular (1x) -> medium (1.2x) -> big (1.33x) -> large (1.67x) -> huge (2x) */ | 32 | /* Content sizes: regular (1x) -> medium (1.2x) -> big (1.33x) -> large (1.67x) -> huge (2x) */ |
33 | 33 | ||
34 | #define FONT_ID(name, style, size) ((name) + ((style) * max_FontSize) + (size)) | ||
35 | |||
34 | enum iFontId { | 36 | enum iFontId { |
35 | /* UI fonts: normal weight (1x, 1.125x, 1.33x, 1.67x) */ | 37 | default_FontId = 0, /* default is always the first font */ |
36 | default_FontId = 0, | 38 | monospace_FontId = maxVariants_Fonts, /* 2nd font is always the monospace font */ |
37 | defaultMedium_FontId, | 39 | documentBody_FontId = maxVariants_Fonts * 2, /* 3rd font is the body font */ |
38 | defaultBig_FontId, | 40 | documentHeading_FontId = maxVariants_Fonts * 3, /* heading font */ |
39 | defaultLarge_FontId, | 41 | auxiliary_FontId = maxVariants_Fonts * 4, /* the first auxiliary font (e.g., symbols) */ |
40 | defaultTiny_FontId, | 42 | |
41 | defaultSmall_FontId, | 43 | // defaultMedium_FontId, |
44 | // defaultBig_FontId, | ||
45 | // defaultLarge_FontId, | ||
46 | // defaultTiny_FontId, | ||
47 | // defaultSmall_FontId, | ||
42 | /* UI fonts: bold weight */ | 48 | /* UI fonts: bold weight */ |
43 | defaultBold_FontId, | 49 | // defaultBold_FontId, |
44 | defaultMediumBold_FontId, | 50 | // defaultMediumBold_FontId, |
45 | defaultBigBold_FontId, | 51 | // defaultBigBold_FontId, |
46 | defaultLargeBold_FontId, | 52 | // defaultLargeBold_FontId, |
47 | /* content fonts */ | 53 | /* content fonts */ |
48 | regular_FontId, | 54 | // bold_FontId, |
49 | bold_FontId, | 55 | // italic_FontId, |
50 | italic_FontId, | 56 | // medium_FontId, |
51 | medium_FontId, | 57 | // big_FontId, |
52 | big_FontId, | 58 | // largeBold_FontId, |
53 | largeBold_FontId, | 59 | // largeLight_FontId, |
54 | largeLight_FontId, | 60 | // hugeBold_FontId, |
55 | hugeBold_FontId, | 61 | // monospaceSmall_FontId, |
56 | monospaceSmall_FontId, | ||
57 | monospace_FontId, | ||
58 | /* extra content fonts */ | 62 | /* extra content fonts */ |
59 | defaultContentRegular_FontId, /* UI font but sized to regular_FontId */ | 63 | // defaultContentRegular_FontId, /* UI font but sized to regular_FontId */ |
60 | defaultContentSmall_FontId, /* UI font but sized smaller */ | 64 | // defaultContentSmall_FontId, /* UI font but sized smaller */ |
61 | /* symbols and scripts */ | 65 | /* symbols and scripts */ |
62 | userSymbols_FontId, | 66 | // userSymbols_FontId, |
63 | iosevka_FontId = userSymbols_FontId + max_FontSize, | 67 | // iosevka_FontId = userSymbols_FontId + max_FontSize, |
64 | symbols_FontId = iosevka_FontId + max_FontSize, | 68 | // symbols_FontId = iosevka_FontId + max_FontSize, |
65 | symbols2_FontId = symbols_FontId + max_FontSize, | 69 | // symbols2_FontId = symbols_FontId + max_FontSize, |
66 | smolEmoji_FontId = symbols2_FontId + max_FontSize, | 70 | // smolEmoji_FontId = symbols2_FontId + max_FontSize, |
67 | notoEmoji_FontId = smolEmoji_FontId + max_FontSize, | 71 | // notoEmoji_FontId = smolEmoji_FontId + max_FontSize, |
68 | japanese_FontId = notoEmoji_FontId + max_FontSize, | 72 | // japanese_FontId = notoEmoji_FontId + max_FontSize, |
69 | chineseSimplified_FontId = japanese_FontId + max_FontSize, | 73 | // chineseSimplified_FontId = japanese_FontId + max_FontSize, |
70 | korean_FontId = chineseSimplified_FontId + max_FontSize, | 74 | // korean_FontId = chineseSimplified_FontId + max_FontSize, |
71 | arabic_FontId = korean_FontId + max_FontSize, | 75 | // arabic_FontId = korean_FontId + max_FontSize, |
72 | max_FontId = arabic_FontId + max_FontSize, | 76 | // max_FontId = arabic_FontId + max_FontSize, |
73 | 77 | ||
74 | /* Meta: */ | 78 | /* Meta: */ |
75 | mask_FontId = 0xffff, | 79 | mask_FontId = 0x0000ffff, /* font IDs are 16-bit; see GmRun's packing */ |
76 | alwaysVariableFlag_FontId = 0x10000, | 80 | alwaysVariableFlag_FontId = 0x00010000, |
77 | 81 | ||
78 | /* UI fonts: */ | 82 | /* UI fonts: */ |
79 | uiLabel_FontId = default_FontId, | 83 | uiLabelTiny_FontId = FONT_ID(default_FontId, semiBold_FontStyle, uiTiny_FontSize), |
80 | uiLabelBold_FontId = defaultBold_FontId, | 84 | uiLabelSmall_FontId = FONT_ID(default_FontId, regular_FontStyle, uiSmall_FontSize), |
81 | uiLabelLarge_FontId = defaultLarge_FontId, | 85 | uiLabel_FontId = FONT_ID(default_FontId, regular_FontStyle, uiNormal_FontSize), |
82 | uiLabelLargeBold_FontId = defaultLargeBold_FontId, | 86 | uiLabelMedium_FontId = FONT_ID(default_FontId, regular_FontStyle, uiMedium_FontSize), |
83 | uiShortcuts_FontId = default_FontId, | 87 | uiLabelMediumBold_FontId = FONT_ID(default_FontId, bold_FontStyle, uiMedium_FontSize), |
84 | uiInput_FontId = defaultMedium_FontId, | 88 | uiLabelBig_FontId = FONT_ID(default_FontId, regular_FontStyle, uiBig_FontSize), |
85 | uiContent_FontId = defaultMedium_FontId, | 89 | uiLabelBold_FontId = FONT_ID(default_FontId, bold_FontStyle, uiNormal_FontSize), |
86 | uiContentBold_FontId = defaultMediumBold_FontId, | 90 | uiLabelBigBold_FontId = FONT_ID(default_FontId, bold_FontStyle, uiBig_FontSize), |
87 | uiContentSymbols_FontId = symbols_FontId + uiMedium_FontSize, | 91 | uiLabelLarge_FontId = FONT_ID(default_FontId, regular_FontStyle, uiLarge_FontSize), |
92 | uiLabelLargeBold_FontId = FONT_ID(default_FontId, bold_FontStyle, uiLarge_FontSize), | ||
93 | uiLabelSymbols_FontId = FONT_ID(auxiliary_FontId, regular_FontStyle, uiNormal_FontSize), | ||
94 | uiShortcuts_FontId = FONT_ID(default_FontId, regular_FontStyle, uiNormal_FontSize), | ||
95 | uiInput_FontId = FONT_ID(default_FontId, regular_FontStyle, uiMedium_FontSize), | ||
96 | uiContent_FontId = FONT_ID(default_FontId, regular_FontStyle, uiMedium_FontSize), | ||
97 | uiContentBold_FontId = FONT_ID(default_FontId, bold_FontStyle, uiMedium_FontSize), | ||
98 | uiContentSymbols_FontId = FONT_ID(auxiliary_FontId, regular_FontStyle, uiMedium_FontSize), | ||
88 | /* Document fonts: */ | 99 | /* Document fonts: */ |
89 | paragraph_FontId = regular_FontId, | 100 | paragraph_FontId = FONT_ID(documentBody_FontId, regular_FontStyle, contentRegular_FontSize), |
90 | firstParagraph_FontId = medium_FontId, | 101 | bold_FontId = FONT_ID(documentBody_FontId, semiBold_FontStyle, contentRegular_FontSize), |
91 | preformatted_FontId = monospace_FontId, | 102 | firstParagraph_FontId = FONT_ID(documentBody_FontId, regular_FontStyle, contentMedium_FontSize), |
92 | preformattedSmall_FontId = monospaceSmall_FontId, | 103 | preformatted_FontId = FONT_ID(monospace_FontId, regular_FontStyle, contentMono_FontSize), |
93 | quote_FontId = italic_FontId, | 104 | preformattedSmall_FontId = FONT_ID(monospace_FontId, regular_FontStyle, contentMonoSmall_FontSize), |
94 | heading1_FontId = hugeBold_FontId, | 105 | quote_FontId = FONT_ID(documentBody_FontId, italic_FontStyle, contentRegular_FontSize), |
95 | heading2_FontId = largeBold_FontId, | 106 | heading1_FontId = FONT_ID(documentHeading_FontId, bold_FontStyle, contentHuge_FontSize), |
96 | heading3_FontId = big_FontId, | 107 | heading2_FontId = FONT_ID(documentHeading_FontId, bold_FontStyle, contentLarge_FontSize), |
97 | banner_FontId = largeLight_FontId, | 108 | heading3_FontId = FONT_ID(documentHeading_FontId, regular_FontStyle, contentBig_FontSize), |
98 | regularMonospace_FontId = iosevka_FontId + contentRegular_FontSize | 109 | banner_FontId = FONT_ID(documentHeading_FontId, light_FontStyle, contentLarge_FontSize), |
110 | regularMonospace_FontId = FONT_ID(monospace_FontId, regular_FontStyle, contentRegular_FontSize), | ||
99 | }; | 111 | }; |
100 | 112 | ||
101 | iLocalDef iBool isJapanese_FontId(enum iFontId id) { | 113 | //iLocalDef iBool isJapanese_FontId(enum iFontId id) { |
102 | return id >= japanese_FontId && id < japanese_FontId + max_FontSize; | 114 | // return id >= japanese_FontId && id < japanese_FontId + max_FontSize; |
103 | } | 115 | //} |
104 | 116 | ||
105 | #define emojiVariationSelector_Char ((iChar) 0xfe0f) | 117 | #define emojiVariationSelector_Char ((iChar) 0xfe0f) |
106 | 118 | ||
119 | /* TODO: get rid of this; configure using font ID strings, check RTL from FontFile flags */ | ||
107 | enum iTextFont { | 120 | enum iTextFont { |
108 | undefined_TextFont = -1, | 121 | undefined_TextFont = -1, |
109 | nunito_TextFont = 0, | 122 | nunito_TextFont = 0, |
@@ -127,7 +140,7 @@ void deinit_Text (iText *); | |||
127 | 140 | ||
128 | void setCurrent_Text (iText *); | 141 | void setCurrent_Text (iText *); |
129 | 142 | ||
130 | void loadUserFonts_Text (void); /* based on Prefs */ | 143 | //void loadUserFonts_Text (void); /* based on Prefs */ |
131 | 144 | ||
132 | void setContentFont_Text (iText *, enum iTextFont font); | 145 | void setContentFont_Text (iText *, enum iTextFont font); |
133 | void setHeadingFont_Text (iText *, enum iTextFont font); | 146 | void setHeadingFont_Text (iText *, enum iTextFont font); |