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
226prepare(Sfont *f, char *s)226prepare(Sfont *f, char *s)
227{227{
228 int i, base, n, map, x0, y0;228 int i, base, n, map, x0, y0;
229 int glyph, prevglyph, adv, kern, leftb;229 int glyph, prevglyph, adv, leftb;
230 float x, shift, subx, suby;230 float x, shift, subx, suby;
231 Rune r;231 Rune r;
232 Rectangle rect, o;232 Rectangle rect, o;
@@ -243,10 +243,14 @@ prepare(Sfont *f, char *s) · 10 unmodified lines
243 base = 0;243 base = 0;
244 244
245 for(i = 0; s[i]; i += n){245 for(i = 0; s[i]; i += n){
246 shift = x - floor(x);
247 n = chartorune(&r, s+i);246 n = chartorune(&r, s+i);
248 map = r >> 16;247 map = r >> 16;
249 glyph = f->u2g[map][r&0xffff];248 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
250 if(r != '\n' && glyph > 0){254 if(r != '\n' && glyph > 0){
251 memfillcolor(f->g, DBlack);255 memfillcolor(f->g, DBlack);
252 stbtt_MakeGlyphBitmapSubpixelPrefilter(256 stbtt_MakeGlyphBitmapSubpixelPrefilter(
@@ -271,13 +275,13 @@ prepare(Sfont *f, char *s) · 18 unmodified lines
271 o.min.y = base + f->asc*f->scale + y0;275 o.min.y = base + f->asc*f->scale + y0;
272 memimagedraw(mi, o, f->white, ZP, f->g, ZP, DoutS);276 memimagedraw(mi, o, f->white, ZP, f->g, ZP, DoutS);
273 stbtt_GetGlyphHMetrics(&f->fi, glyph, &adv, &leftb);277 stbtt_GetGlyphHMetrics(&f->fi, glyph, &adv, &leftb);
274 kern = prevglyph ? stbtt_GetGlyphKernAdvance(&f->fi, prevglyph, glyph) : 0;278 x += adv * f->scale;
275 x += (adv + kern)*f->scale;
276 }else279 }else
277 glyph = 0;280 glyph = 0;
278 prevglyph = glyph;281 prevglyph = glyph;
279 if(r == '\n'){282 if(r == '\n'){
280 x = x0 = 0;283 x = x0 = 0;
284 prevglyph = 0;
281 base += ceil(f->scale * f->lineh);285 base += ceil(f->scale * f->lineh);
282 }286 }
283 }287 }

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