tags:

views:

49

answers:

1

I want to use this function to get contours and within these contours, I want to get cubic bezier. I think I have to call it with GGO_BEZIER. What puzzles me is how the return buffer works.

"A glyph outline is returned as a series of one or more contours defined by a TTPOLYGONHEADER structure followed by one or more curves. Each curve in the contour is defined by a TTPOLYCURVE structure followed by a number of POINTFX data points. POINTFX points are absolute positions, not relative moves. The starting point of a contour is given by the pfxStart member of the TTPOLYGONHEADER structure. The starting point of each curve is the last point of the previous curve or the starting point of the contour. The count of data points in a curve is stored in the cpfx member of TTPOLYCURVE structure. The size of each contour in the buffer, in bytes, is stored in the cb member of TTPOLYGONHEADER structure. Additional curve definitions are packed into the buffer following preceding curves and additional contours are packed into the buffer following preceding contours. The buffer contains as many contours as fit within the buffer returned by GetGlyphOutline."

I'm really not sure how to access the contours. I know that I can change a pointer another type of pointer but i'm not sure how I go about getting the contours based on this documentation.

Thanks

A: 

I have never used this API myself, but after reading the MSDN documentation I would think it works like this:

First you have to call GetGlyphOutline with the lpvBuffer parameter set to NULL. Then the function will return the required size of the buffer. You'll then have to allocate a buffer with that size, then call the function again with lpvBuffer set to your newly created buffer.
If you take a look at the documentation for TTPOLYGONHEADER it says:

Each TTPOLYGONHEADER structure is followed by one or more TTPOLYCURVE structures.

So, basically you have to do something like this:

BYTE*              pMyBuffer   = NULL;
...
TTPOLYGONHEADER*    pPolyHdr    = reinterpret_cast<TTPOLYGONHEADER*>(pMyBuffer);
TTPOLYCURVE*        pPolyCurve  = reinterpret_cast<TTPOLYCURVE*>(pMyBuffer + sizeof(TTPOLYGONHEADER));

Then, check the pPolyCurve->cpfx member which contains the number of POINTFX structures. Then you can iterate all the points by doing something like this:

for (WORD i = 0; i < pPolyCurve->cpfx: ++i)
{
    pCurve->apfx[i].x;
    pCurve->apfx[i].y;
}

Since the TTPOLYGONHEADER doesn't tell you how many TTPOLYCURVE structures are in the buffer, I guess you'll have to keep track of that yourself by subtracting the size of the individual structures from the size of your buffer and keep going until you reach 0.

Please excuse any potential errors as I didn't test this myself :)

humbagumba
Thanks, Man does Microsoft over complicate things!
Milo