简体   繁体   English

帮助与GetGlyphOutline函数(WinAPI)

[英]Help with GetGlyphOutline function(WinAPI)

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. 我想我必须用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." “字形轮廓返回为由TTPOLYGONHEADER结构定义的一系列一个或多个轮廓,后接一个或多个曲线。轮廓中的每个曲线均由TTPOLYCURVE结构定义,后跟多个POINTFX数据点。POINTFX点是绝对的位置的起始位置,而不是相对的移动位置;轮廓的起始点由TTPOLYGONHEADER结构的pfxStart成员给出;每条曲线的起始点是上一条曲线的末尾或轮廓的起始点。曲线中的轮廓存储在TTPOLYCURVE结构的cpfx成员中,缓冲区中每个轮廓的大小(以字节为单位)存储在TTPOLYGONHEADER结构的cb成员中。按照前面的轮廓填充到缓冲区中。缓冲区包含的轮廓与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 谢谢

I have never used this API myself, but after reading the MSDN documentation I would think it works like this: 我自己从未使用过此API,但是在阅读MSDN文档后,我认为它的工作方式如下:

First you have to call GetGlyphOutline with the lpvBuffer parameter set to NULL . 首先,您必须将lpvBuffer参数设置为NULL来调用GetGlyphOutline 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. 然后,您必须分配一个具有该大小的缓冲区,然后在将lpvBuffer设置为新创建的缓冲区的情况下再次调用该函数。
If you take a look at the documentation for TTPOLYGONHEADER it says: 如果您查看TTPOLYGONHEADER的文档,它会显示:

Each TTPOLYGONHEADER structure is followed by one or more TTPOLYCURVE structures. 每个TTPOLYGONHEADER结构后面都有一个或多个TTPOLYCURVE结构。

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. 然后,检查包含POINTFX结构数量的pPolyCurve->cpfx成员。 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. 由于TTPOLYGONHEADER不会告诉您缓冲区中有多少个TTPOLYCURVE结构,我想您必须自己从缓冲区大小中减去各个结构的大小来跟踪自己,并继续进行直到达到0 。

Please excuse any potential errors as I didn't test this myself :) 请原谅任何潜在的错误,因为我自己并未对此进行测试:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM