Jump to content
Posted 20 July 2012 - 02:11 AM
Posted 20 July 2012 - 03:11 AM
Posted 21 July 2012 - 09:48 PM
Thank you very much for your reply .
The bitmap structure is box b in your image. The following six values are needed to align and render the glyph bitmaps correctly on a horizontal baseline:
glyph->bitmap.width is the width of the glyph bitmap in pixels.
glyph->bitmap.height is the height of the glyph bitmap in pixels.
glyph->bitmap.pitch is the size of one scanline of the glyph bitmap in bytes.
glyph->left is the x-origin of the bitmap in pixels.
glyph->top is the y-origin of the bitmap in pixels.
glyph->advance.x is the horizontal advance in font units.
Point 1 and 2 is simply the size of the bitmap: loop over both width and height to access each pixel.
Point 3 is for row-alignment: each new row of the bitmap starts pitch bytes from the start of the previous row. Since each row may end with some extra bytes that are not part of the bitmap image itself, the pitch takes this into account but width does not.
Point 4 and 5 is the vertical and horizontal offsets you need to shift the bitmaps location on the screen by in order to correctly align it on the baseline. For example, a glyph like 'g' or 'j' extends below the baseline, so it has to be shifted down, you cannot align the bottom of the bitmap to the baseline in these cases.
Point 6 is determines how far along the baseline to advance the drawing position for each glyph you draw. This value is in font units and not pixels, and has to be converted to pixels. From what I remembered, "font units" was a very vague terms and could mean different things depending on the actual font you have loaded. My experience is that it's mostly a fixed point value with 6 fractional bits, so right-shift the advance.x value 6 bits to obtain a pixel value.