summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c28
1 files changed, 25 insertions, 3 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 }