Advertisement

Some questions about FreeType..

Started by July 20, 2012 08:11 AM
1 comment, last by FireInDark 12 years, 4 months ago
First:
FT_Render_Glyph(face->glyph,FT_Render_Mode::FT_RENDER_MODE_NORMAL);
After that how should I get every pixel mask as RGBA..
I realy don't know how to deal with th data with FT_Bitmap.buffer...

Next:
face->glyph->metrics.width ;
face->glyph->metrics.height;
face->glyph->metrics.horiBearingX;
face->glyph->metrics.horiAdvance;
FT_Bitmap bitmap;
bitmap.rows;
bitmap.width;

I think I've understand the member data of face->glyph->metrics;
But how should I understand bitmap.rows and the width;

Then I will express my question with a picture..[attachment=10145:GAME.png]
there are tow box ( a and b ,as you can see I write it with the mouse ) bounding the charactor "a" (ingore the "M"),wicth of the box really express the FT_Bitmap?

Thanks anyway.
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:

  1. glyph->bitmap.width is the width of the glyph bitmap in pixels.
  2. glyph->bitmap.height is the height of the glyph bitmap in pixels.
  3. glyph->bitmap.pitch is the size of one scanline of the glyph bitmap in bytes.
  4. glyph->left is the x-origin of the bitmap in pixels.
  5. glyph->top is the y-origin of the bitmap in pixels.
  6. 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.

Last but not least, you of course need glyph->bitmap.buffer which is the pointer to the top left corner of the glyph image data. When you render with FT_RENDER_NORMAL, you get an antialiased grey scale image. Thus, each pixel consists of one byte representing the grey scale level of the pixel.
Advertisement

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.


Thank you very much for your reply .
It's useful for me ...

This topic is closed to new replies.

Advertisement