2

I am drawing an outline of a glyph for given character using:

QString myfname="FreeMono.ttf";
QRawFont *myfont=new QRawFont(myfname,324,QFont::PreferDefaultHinting);
QChar mychars[]={'Q','B'};
int numofchars=3;
quint32 myglyphindexes[3];
int numofglyphs;
myfont->glyphIndexesForChars(mychars,numofchars,myglyphindexes,&numofglyphs);
QPainterPath mypath=myfont->pathForGlyph(myglyphindexes[0]);

This path I am drawing on pixmap using

painter.drawPath(mypath)

I want to know how this path is drawn. I mean what type of curves or lines this outline contains. For this I tried this:

QPointF mypoints[49];
for(int i=0; i<mypath.elementAt(i); i++)
    {
        mypoints[i]=mypath.elementAt(i);
    }

This gives me array of points. But how these points are connected with each other like using a line or curve. How can I know that? Also is this a correct approach? What I need to improve?

4

2 回答 2

2

QPainterPath::elementAt()返回QPainterPath::Element类型的对象,而不是 a QPoint(它定义了 QPointF 运算符)。

你可以使用这样的代码:

const QPainterPath::Element &elem = path.elementAt(ii);

// You can use the type enum.
qDebug() << elem.type;

// Or you can use the functions.
if (elem.isCurveTo()) {
    qDebug() << "curve";
} else if (elem.isLineTo()) {
    qDebug() << "line";
} else if (elem.isMoveTo()) {
    qDebug() << "move";
}
于 2013-09-11T06:55:06.963 回答
1

sashoalm 是正确的,但我想补充一点,您可以使用它path.elementCount()来了解QPainterPath.

因此,它看起来像这样:

for(int i=0; i<mypath.elementCount(); i++)
{
    const QPainterPath::Element & elem = mypath.elementAt(i);
    qDebug() << elem.type;

    // Or you can use the functions.
    if (elem.isCurveTo()) {
        qDebug() << "curve";
    } else if (elem.isLineTo()) {
        qDebug() << "line";
    } else if (elem.isMoveTo()) {
        qDebug() << "move";
    }
}
于 2013-09-11T07:04:22.100 回答