summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-25 16:22:29 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-25 16:22:29 +0300
commitf99a9111170f2ff28383fd3172fdaf4b9a1ba069 (patch)
treea4c5b801298a569c5043ba69a1b9a6c010a9234c /src/ui/text.c
parente84b1a4a13ee1932c609e9d9d64b0915fbf468b9 (diff)
parentd06c19e7fdd07ffc52ca4d4903fecf5b539f85ea (diff)
Merge branch 'dev' into work/v1.6
# Conflicts: # CMakeLists.txt
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 ae1248a7..edbc6583 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);
@@ -1131,14 +1141,26 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1131 const iChar next = nextChar_(&peek, args->text.end); 1141 const iChar next = nextChar_(&peek, args->text.end);
1132 if (enableKerning_Text && !d->manualKernOnly && next) { 1142 if (enableKerning_Text && !d->manualKernOnly && next) {
1133 const uint32_t nextGlyphIndex = glyphIndex_Font_(glyph->font, next); 1143 const uint32_t nextGlyphIndex = glyphIndex_Font_(glyph->font, next);
1134 const int kern = stbtt_GetGlyphKernAdvance( 1144 int kern = stbtt_GetGlyphKernAdvance(
1135 &glyph->font->font, glyph->glyphIndex, nextGlyphIndex); 1145 &glyph->font->font, glyph->glyphIndex, nextGlyphIndex);
1146 /* Nunito needs some kerning fixes. */
1147 if (glyph->font->family == nunito_TextFont) {
1148 if (ch == 'W' && (next == 'i' || next == 'h')) {
1149 kern = -30;
1150 }
1151 else if (ch == 'T' && next == 'h') {
1152 kern = -15;
1153 }
1154 else if (ch == 'V' && next == 'i') {
1155 kern = -15;
1156 }
1157 }
1136 if (kern) { 1158 if (kern) {
1137// printf("%lc(%u) -> %lc(%u): kern %d (%f)\n", ch, glyph->glyphIndex, next, 1159// printf("%lc(%u) -> %lc(%u): kern %d (%f)\n", ch, glyph->glyphIndex, next,
1138// nextGlyphIndex, 1160// nextGlyphIndex,
1139// kern, d->xScale * kern); 1161// kern, d->xScale * kern);
1140 xpos += d->xScale * kern; 1162 xpos += glyph->font->xScale * kern;
1141 xposExtend += d->xScale * kern; 1163 xposExtend += glyph->font->xScale * kern;
1142 } 1164 }
1143 } 1165 }
1144 } 1166 }