diff --git a/src/fontstash.h b/src/fontstash.h index add81e6..94f5702 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -819,18 +819,15 @@ static struct FONSglyph* fons__getGlyph(struct FONScontext* stash, struct FONSfo dst[x + (gh-1)*stash->params.width] = 0; } - /* // Debug code to color the glyph background - int x,y; - unsigned char* fdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width]; +/* unsigned char* fdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width]; for (y = 0; y < gh; y++) { for (x = 0; x < gw; x++) { int a = (int)fdst[x+y*stash->params.width] + 20; if (a > 255) a = 255; fdst[x+y*stash->params.width] = a; } - } - */ + }*/ // Blur if (iblur > 0) { @@ -851,11 +848,11 @@ static void fons__getQuad(struct FONScontext* stash, struct FONSfont* font, struct FONSglyph* prevGlyph, struct FONSglyph* glyph, float scale, float spacing, float* x, float* y, struct FONSquad* q) { - int rx,ry,xoff,yoff,x0,y0,x1,y1; + float rx,ry,xoff,yoff,x0,y0,x1,y1; if (prevGlyph) { float adv = stbtt_GetGlyphKernAdvance(&font->font, prevGlyph->index, glyph->index) * scale; - *x += adv; + *x += (int)(adv + 0.5f); } // Each glyph has 2px border to allow good interpolation, diff --git a/src/nanovg.c b/src/nanovg.c index f4945fa..71af94e 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -1552,13 +1552,18 @@ void nvgFontFace(struct NVGcontext* ctx, const char* font) state->fontId = fonsGetFontByName(ctx->fs, font); } +static float nvg__quantize(float a, float d) +{ + return ((int)(a / d)) * d; +} + float nvgText(struct NVGcontext* ctx, float x, float y, const char* string, const char* end) { struct NVGstate* state = nvg__getState(ctx); struct FONStextIter iter; struct FONSquad q; struct NVGvertex* verts; - float scale = nvg__minf(nvg__getAverageScale(state->xform), 4.0f); + float scale = nvg__minf(nvg__quantize(nvg__getAverageScale(state->xform), 0.01f), 4.0f); float invscale = 1.0f / scale; int dirty[4]; int cverts = 0;