diff --git a/demo/font.png b/demo/font.png new file mode 100644 index 0000000..ad4b4ba Binary files /dev/null and b/demo/font.png differ diff --git a/src/animation.c b/src/animation.c index 01782d5..e6a799c 100644 --- a/src/animation.c +++ b/src/animation.c @@ -299,7 +299,9 @@ int viewportSave(const char *path) { int height = 0; unsigned char *pixels = NULL; if (!imageFromViewport(&width, &height, &pixels)) return FALSE; - return imageSave(path, width, height, pixels); + int result = imageSave(path, width, height, pixels); + free(pixels); + return result; } unsigned int pixelGet(const void *pixel) { diff --git a/src/font.c b/src/font.c index 9297f90..dfeca6d 100644 --- a/src/font.c +++ b/src/font.c @@ -157,9 +157,10 @@ static HeliGlyph* loadGlyph(HeliFontInstance *fi, int code) { unsigned char buffer[FONT_MAP_GLYPHSIZE*FONT_MAP_GLYPHSIZE] = {}; if (metrics->width > 0 && metrics->height > 0) { + FT_Pos size = metrics->width > metrics->height ? metrics->width : metrics->height; FT_Matrix matrix = {}; - matrix.xx = (FONT_MAP_GLYPHWORKSIZE-2)*64*65536/metrics->width; - matrix.yy = (FONT_MAP_GLYPHWORKSIZE-2)*64*65536/metrics->height; + matrix.xx = (FONT_MAP_GLYPHWORKSIZE-2)*64*65536/size; + matrix.yy = (FONT_MAP_GLYPHWORKSIZE-2)*64*65536/size; FT_Vector offset = {}; offset.x = 64 - metrics->horiBearingX; offset.y = -(64 + metrics->horiBearingY - metrics->height); @@ -535,7 +536,8 @@ void textLayoutDrawSubstr(TextLayout layout, double x, double y, int start, int const double borderK = 0.5*FONT_MAP_BORDERSIZE/FONT_MAP_GLYPHWORKSIZE; const double texStep = 1.0/FONT_MAP_CNT; - const double texOffset = -0.5*FONT_MAP_BORDERSIZE/FONT_MAP_TEXSIZE; + const double texBorder = 0.5*FONT_MAP_BORDERSIZE/FONT_MAP_TEXSIZE; + const double texGlyphSize = (double)FONT_MAP_GLYPHWORKSIZE/FONT_MAP_TEXSIZE; if (!heliGLIsIntegerClipping()) glEnable(GL_MULTISAMPLE); glPushMatrix(); @@ -583,18 +585,24 @@ void textLayoutDrawSubstr(TextLayout layout, double x, double y, int start, int glBegin(GL_QUADS); } - double dx = (cc->glyph->r - cc->glyph->l)*borderK; - double dy = (cc->glyph->b - cc->glyph->t)*borderK; + double gw = cc->glyph->r - cc->glyph->l; + double gh = cc->glyph->b - cc->glyph->t; + double gs = gw > gh ? gw : gh; + double dx = gs*borderK; + double dy = gs*borderK; double l = cc->x + cc->glyph->l - dx; double t = cc->y + cc->glyph->t - dy; double r = cc->x + cc->glyph->r + dx; double b = cc->y + cc->glyph->b + dy; + double ttx = gh > gw ? gw/gh : 1; + double tty = gw > gh ? gh/gw : 1; + int gi = cc->glyph - cc->glyph->map->glyphs; - double tl = (gi % FONT_MAP_CNT)*texStep + texOffset; - double tt = (gi / FONT_MAP_CNT)*texStep + texOffset; - double tr = tl + texStep; - double tb = tt + texStep; + double tl = (gi % FONT_MAP_CNT)*texStep - texBorder; + double tt = (gi / FONT_MAP_CNT)*texStep - texBorder; + double tr = tl + texGlyphSize*ttx + 2*texBorder; + double tb = tt + texGlyphSize*tty + 2*texBorder; glTexCoord2d(tl, tt); glVertex2d(l, t); glTexCoord2d(tr, tt); glVertex2d(r, t);