summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ui/text.c28
-rw-r--r--src/ui/text.h3
2 files changed, 27 insertions, 4 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index db922715..51865654 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -116,6 +116,7 @@ iDefineTypeConstructionArgs(Glyph, (iChar ch), ch)
116 116
117struct Impl_Font { 117struct Impl_Font {
118 iBlock * data; 118 iBlock * data;
119 enum iTextFont family;
119 stbtt_fontinfo font; 120 stbtt_fontinfo font;
120 float xScale, yScale; 121 float xScale, yScale;
121 int vertOffset; /* offset due to scaling */ 122 int vertOffset; /* offset due to scaling */
@@ -134,6 +135,15 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale,
134 enum iFontSize sizeId, iBool isMonospaced) { 135 enum iFontSize sizeId, iBool isMonospaced) {
135 init_Hash(&d->glyphs); 136 init_Hash(&d->glyphs);
136 d->data = NULL; 137 d->data = NULL;
138 d->family = undefined_TextFont;
139 /* Note: We only use `family` currently for applying a kerning fix to Nunito. */
140 if (data == &fontNunitoRegular_Embedded ||
141 data == &fontNunitoBold_Embedded ||
142 data == &fontNunitoExtraBold_Embedded ||
143 data == &fontNunitoLightItalic_Embedded ||
144 data == &fontNunitoExtraLight_Embedded) {
145 d->family = nunito_TextFont;
146 }
137 d->isMonospaced = isMonospaced; 147 d->isMonospaced = isMonospaced;
138 d->height = height; 148 d->height = height;
139 iZap(d->font); 149 iZap(d->font);
@@ -1128,14 +1138,26 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1128 const iChar next = nextChar_(&peek, args->text.end); 1138 const iChar next = nextChar_(&peek, args->text.end);
1129 if (enableKerning_Text && !d->manualKernOnly && next) { 1139 if (enableKerning_Text && !d->manualKernOnly && next) {
1130 const uint32_t nextGlyphIndex = glyphIndex_Font_(glyph->font, next); 1140 const uint32_t nextGlyphIndex = glyphIndex_Font_(glyph->font, next);
1131 const int kern = stbtt_GetGlyphKernAdvance( 1141 int kern = stbtt_GetGlyphKernAdvance(
1132 &glyph->font->font, glyph->glyphIndex, nextGlyphIndex); 1142 &glyph->font->font, glyph->glyphIndex, nextGlyphIndex);
1143 /* Nunito needs some kerning fixes. */
1144 if (glyph->font->family == nunito_TextFont) {
1145 if (ch == 'W' && (next == 'i' || next == 'h')) {
1146 kern = -30;
1147 }
1148 else if (ch == 'T' && next == 'h') {
1149 kern = -15;
1150 }
1151 else if (ch == 'V' && next == 'i') {
1152 kern = -15;
1153 }
1154 }
1133 if (kern) { 1155 if (kern) {
1134// printf("%lc(%u) -> %lc(%u): kern %d (%f)\n", ch, glyph->glyphIndex, next, 1156// printf("%lc(%u) -> %lc(%u): kern %d (%f)\n", ch, glyph->glyphIndex, next,
1135// nextGlyphIndex, 1157// nextGlyphIndex,
1136// kern, d->xScale * kern); 1158// kern, d->xScale * kern);
1137 xpos += d->xScale * kern; 1159 xpos += glyph->font->xScale * kern;
1138 xposExtend += d->xScale * kern; 1160 xposExtend += glyph->font->xScale * kern;
1139 } 1161 }
1140 } 1162 }
1141 } 1163 }
diff --git a/src/ui/text.h b/src/ui/text.h
index 2f2bcf3a..768713ee 100644
--- a/src/ui/text.h
+++ b/src/ui/text.h
@@ -116,7 +116,8 @@ iLocalDef iBool isJapanese_FontId(enum iFontId id) {
116#define emojiVariationSelector_Char ((iChar) 0xfe0f) 116#define emojiVariationSelector_Char ((iChar) 0xfe0f)
117 117
118enum iTextFont { 118enum iTextFont {
119 nunito_TextFont, 119 undefined_TextFont = -1,
120 nunito_TextFont = 0,
120 firaSans_TextFont, 121 firaSans_TextFont,
121 literata_TextFont, 122 literata_TextFont,
122 tinos_TextFont, 123 tinos_TextFont,