History

fix kerning

Sigrid Haflínudóttir committed 6 years ago

Commit ca125ec1 parent 700a47c1 file · +8 −4Browse files

Unified · Split

test.c+8−4
@@ -226,7 +226,7 @@ static void · 225 unmodified lines
226226 prepare(Sfont *f, char *s)
227227 {
228228 int i, base, n, map, x0, y0;
229− int glyph, prevglyph, adv, kern, leftb;
229+ int glyph, prevglyph, adv, leftb;
230230 float x, shift, subx, suby;
231231 Rune r;
232232 Rectangle rect, o;
@@ -243,10 +243,14 @@ prepare(Sfont *f, char *s) · 10 unmodified lines
243243 base = 0;
244244
245245 for(i = 0; s[i]; i += n){
246− shift = x - floor(x);
247246 n = chartorune(&r, s+i);
248247 map = r >> 16;
249248 glyph = f->u2g[map][r&0xffff];
249+
250+ if(prevglyph > 0 && glyph > 0 && r != '\n')
251+ x += stbtt_GetGlyphKernAdvance(&f->fi, prevglyph, glyph) * f->scale;
252+ shift = x - floor(x);
253+
250254 if(r != '\n' && glyph > 0){
251255 memfillcolor(f->g, DBlack);
252256 stbtt_MakeGlyphBitmapSubpixelPrefilter(
@@ -271,13 +275,13 @@ prepare(Sfont *f, char *s) · 18 unmodified lines
271275 o.min.y = base + f->asc*f->scale + y0;
272276 memimagedraw(mi, o, f->white, ZP, f->g, ZP, DoutS);
273277 stbtt_GetGlyphHMetrics(&f->fi, glyph, &adv, &leftb);
274− kern = prevglyph ? stbtt_GetGlyphKernAdvance(&f->fi, prevglyph, glyph) : 0;
275− x += (adv + kern)*f->scale;
278+ x += adv * f->scale;
276279 }else
277280 glyph = 0;
278281 prevglyph = glyph;
279282 if(r == '\n'){
280283 x = x0 = 0;
284+ prevglyph = 0;
281285 base += ceil(f->scale * f->lineh);
282286 }
283287 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t