[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] Vertical offset at font-rendering
From: |
Erik Unger |
Subject: |
[ft] Vertical offset at font-rendering |
Date: |
Wed, 20 Dec 2006 13:31:53 +0100 |
User-agent: |
Thunderbird 1.5.0.8 (Windows/20061025) |
Hi,
I want to render a font into a 256*256 pixel texture,
using a grid for 16*16 glyphs.
My renderGlyph() function receives a pointer to the
upper left corner of the grid-position, so I have to
move this "pen-position" by glyph->bitmap_top and glyph->bitmap_left
to align the glyph-bitmaps to the baseline of the grid:
void Font::renderGlyph(char32 character, uint8 * pixels, int
lineStrideInBytes)
{
// ...
const FT_Bitmap& glyphBitmap = face->glyph->bitmap;
const int left = face->glyph->bitmap_left;
const int top = size - face->glyph->bitmap_top - 4;
pixels = &pixels[top * lineStrideInBytes + left];
for (int y = 0; y < glyphBitmap.rows; ++y)
{
for (int x = 0; x < glyphBitmap.width; ++x)
{
pixels[y * lineStrideInBytes + x] =
offset_cast<uint8>(glyphBitmap.buffer, y * glyphBitmap.pitch + x);
}
}
-> Notice the "- 4". For the Arial-Font under Windows with
a font-size of 16, it seams that all glyph-bitmaps have to
be moved 4 pixels up. If I don't move them up, the last row
of glyphs in my grid exceeds the border of the texture.
So where do this 4 pixel offset come from?
There is also something strange with bitmap_left:
It's -1 for 'A'. If 'A' would be the first glyph in
the 16*16 grid, some pixels would be written before the
texture-memory.
Thanks in advance,
-Erik
- [ft] Vertical offset at font-rendering,
Erik Unger <=