freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Determining pixel dimensions for bitmap


From: Marco Wertz
Subject: Re: [ft] Determining pixel dimensions for bitmap
Date: Tue, 4 Nov 2014 23:17:45 +0100

> > The problem for me is that I'm not using the glyph API but the
> > FT_Stroker and FT_Outline APIs directly. Of course I can detect an
> > empty row or column on my own, but if I want to have a bitmap that
> > doesn't contain any empty rows or columns, I'm forced to copy the
> > pixels to another bitmap because the current APIs don't give me the
> > chance to allocate a bitmap of the *exact* dimensions before drawing
> > to it.
> 
> Just to be sure: You have an outline, you apply FT_Stroker stuff, then
> you want to get the exact dimensions of the outline for a given
> resolution, right?

Actually, I first create an FT_Stroker, begin a subpath on it, add several
cubic splines using FT_Stroker_CubicTo(), close the subpath and then
export it into an FT_Outline using FT_Stroker_Export().

Now I want to be able to get the exact dimensions of the outline
in pixels.

> 
> My guess is that `FT_Outline_Get_BBox' + rounding as described above
> should deliver exact results in almost all cases.

Unfortunately not. Taking Alexei's feedback into account, I'm
now calculating the pixel dimensions for the bitmap like this:
(xyMin is rounded down, xyMax is rounded up)

        int xmin = bbox.xMin >> 6, ymin = bbox.yMin >> 6;
        int xmax = bbox.xMax >> 6, ymax = bbox.yMax >> 6;
                        
        if(bbox.xMax & 0x3f) xmax++;
        if(bbox.yMax & 0x3f) ymax++;

        pixelwidth = xmax - xmin;
        pixelheight = ymax - ymin;

This calculation gives me an exact fit only if I don't apply any
rotation to the shape using FT_Outline_Transform(). As soon as I
apply a transformation matrix on my FT_Outline, it happens very
often that either the very first row is empty or the very last
column is empty.

Also note that I do a

        FT_Outline_Translate(&outline, -bbox.xMin, -bbox.yMin);

before calling FT_Outline_Get_Bitmap().

Marco



reply via email to

[Prev in Thread] Current Thread [Next in Thread]