Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
backport Ryg fix for vertical shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
ponce committed Apr 28, 2015
1 parent a821beb commit 826b2e3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions image/gfm/image/stb_truetype.d
Expand Up @@ -745,15 +745,25 @@ void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)

void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
{
int x0,y0,x1,y1;
if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1))
x0=y0=x1=y1=0; // e.g. space character
// now move to integral bboxes (treating pixels as little squares, what pixels get touched)?
if (ix0) *ix0 = ifloor(x0 * scale_x + shift_x);
if (iy0) *iy0 = -iceil (y1 * scale_y + shift_y);
if (ix1) *ix1 = iceil (x1 * scale_x + shift_x);
if (iy1) *iy1 = -ifloor(y0 * scale_y + shift_y);
int x0, y0, x1, y1;
if (!stbtt_GetGlyphBox(font, glyph, &x0, &y0, &x1, &y1))
{
// e.g. space character
if (ix0) *ix0 = 0;
if (iy0) *iy0 = 0;
if (ix1) *ix1 = 0;
if (iy1) *iy1 = 0;
}
else
{
// move to integral bboxes (treating pixels as little squares, what pixels get touched)?
if (ix0) *ix0 = ifloor( x0 * scale_x + shift_x);
if (iy0) *iy0 = ifloor(-y1 * scale_y + shift_y);
if (ix1) *ix1 = iceil( x1 * scale_x + shift_x);
if (iy1) *iy1 = iceil(-y0 * scale_y + shift_y);
}
}

void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
{
stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);
Expand Down Expand Up @@ -1009,9 +1019,9 @@ void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int
a=j,b=k;
}
e[n].x0 = p[a].x * scale_x + shift_x;
e[n].y0 = p[a].y * y_scale_inv * vsubsample + shift_y;
e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample;
e[n].x1 = p[b].x * scale_x + shift_x;
e[n].y1 = p[b].y * y_scale_inv * vsubsample + shift_y;
e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample;
++n;
}
}
Expand Down

0 comments on commit 826b2e3

Please sign in to comment.