memononen / fontstash

Light-weight online font texture atlas builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why need to xadvance * 10.0f?

tailangjun opened this issue · comments

why need to xadvance * 10.0f?

glyph->xadv = (short)(scale * advance * 10.0f)
*x += (int)(glyph->xadv / 10.0f + 0.5f);

xadv is in kind of fixed point. the value type is short and there's need for more precision. I cannot remember why I used short instead of float for xadv. Maybe I wanted to save few bytes and the short fit better into the struct.

thank you very much!

Another question, I cannot understand the role of xoff and yoff. If has a pictures of glyph and texAtlas will be fine.

struct FONSglyph
{
unsigned int codepoint;
int index;
int next;
short size, blur;
short x0,y0,x1,y1;
short xadv,xoff,yoff;
};

Probably my understanding of stbtt_GetGlyphBitmapBox(..., x0, y0, x1, y1) is wrong.
Is x0 = bearingX, y0 = bearingY?

The (x0,y0) (x1,y1) is the bitmap inside the atlas. When rendering a glyph, the (0,0) is at the baseline. For example character y needs to move the bitmap down, and character ' higher up. xoff and yoff is that offset.

Also, note that the x0,y0,x1,y1 used by fons__tt_buildGlyphBitmap are different than the ones in * FONSglyph*. See: https://github.com/memononen/fontstash/blob/master/src/fontstash.h#L1053
The padding there is necessary so that when you render the glyphs the neighbour bitmap in atlas data will not leak.