I scraped some code from *ft_smooth_render_generic* in *ftsmooth.c*.
It ignores the function parameter *const FT_Vector* origin.* I'm not sure
what it does, but don't think it's relevant for me.
Also, it assumes *FT_RENDER_MODE_LCD*, rather than *FT_RENDER_MODE_LCD_V.*
Aside from those two things, it seems to work, and the example below gives
matching results for precalculated and final size of the bitmap.
for(char c : sample)
{
FT_Load_Char(face, (int)c, FT_LOAD_TARGET_LCD);
FT_BBox cbox;
FT_Outline_Get_CBox(&face->glyph->outline, &cbox);
cbox.xMax += 21;
cbox.xMin -= 21;
cbox.xMin = FT_PIX_FLOOR(cbox.xMin);
cbox.yMin = FT_PIX_FLOOR(cbox.yMin);
cbox.xMax = FT_PIX_CEIL(cbox.xMax);
cbox.yMax = FT_PIX_CEIL(cbox.yMax);
FT_ULong width = (FT_ULong)(cbox.xMax - cbox.xMin) >> 6;
FT_ULong height = (FT_ULong)(cbox.yMax - cbox.yMin) >> 6;
FT_ULong pitch = width;
width *= 3;
pitch = FT_PAD_CEIL(width, 4);
cout << "precalc: "
<< width / 3 << " "
<< height << endl;
FT_Load_Char(face, (int)c, FT_LOAD_TARGET_LCD | FT_LOAD_RENDER);
cout << "rendered: "
<< (face->glyph->bitmap.width / 3) << " "
<< (face->glyph->bitmap.rows) << endl << endl;
}
On Tue, Sep 19, 2017 at 1:45 AM, Jan Alexander Steffens <
[email protected]> wrote:
>
>
> On Tue, Sep 19, 2017, 07:25 Nicolas Jinchereau <
> [email protected]> wrote:
>
>> Thanks for the quick responses.
>>
>> I've managed to render text correctly now using LCD filtering (the new
>> 2.8.1 version). I was able to do it by ignoring the glyph metrics and using
>> the bitmap size itself. This works well enough for now, and the text looks
>> great, but I would like to be able to retrieve final dimensions of the
>> bitmap without actually rendering/allocating anything, so I can calculate
>> the layout of a bitmap-font/texture-atlas, and blit the glyphs afterward.
>> I've been doing this for while and only ran into a problem when I tried the
>> new LCD filtering.
>>
>> I understand why the padding would be needed, but why wouldn't it be
>> included in the glyph metrics (width/height)?
>>
>
> Because the layout shouldn't change just because the glyphs got blurred.
> The bitmap_left and bitmap_top fields will tell you the offset of the
> bitmap from the pen position on the baseline. (The pen position is adjusted
> by the advance width of each glyph after drawing it, usually further
> modified by kerning from layers above FreeType.)
>
_______________________________________________
Freetype-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/freetype-devel