fontstash icon indicating copy to clipboard operation
fontstash copied to clipboard

why need to xadvance * 10.0f?

Open tailangjun opened this issue 8 years ago • 6 comments
trafficstars

why need to xadvance * 10.0f?

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

tailangjun avatar Jul 19 '17 02:07 tailangjun

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.

memononen avatar Jul 19 '17 03:07 memononen

thank you very much!

tailangjun avatar Jul 19 '17 03:07 tailangjun

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; };

tailangjun avatar Jul 19 '17 03:07 tailangjun

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

tailangjun avatar Jul 19 '17 03:07 tailangjun

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.

memononen avatar Jul 19 '17 06:07 memononen

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.

memononen avatar Jul 19 '17 06:07 memononen