Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void QPainterPath::addText ( const QPointF point,
const QFont font,
const QString text 

Adds the given text to this path as a set of closed subpaths created from the font supplied. The subpaths are positioned so that the left end of the text's baseline lies at the specified point.

100% qpainterpath-addtext.png doc/src/snippets/code/src.gui.painting.qpainterpath.cpp 6

See also:
QPainter::drawText(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1073 of file qpainterpath.cpp.

References addRect(), QTextLayout::beginLayout(), QTextLayout::createLine(), QFont::d, QTextLayout::endLayout(), QTextLayout::engine(), QString::isEmpty(), QTextLayout::setCacheEnabled(), QPointF::x(), and QPointF::y().

Referenced by addText(), BasicToolsPlugin::generateShape(), and Window::setupShapes().

    if (text.isEmpty())


    QTextLayout layout(text, f);
    QTextEngine *eng = layout.engine();
    QTextLine line = layout.createLine();
    const QScriptLine &sl = eng->lines[0];
    if (!sl.length || !eng->layoutData)

    int nItems = eng->layoutData->items.size();

    qreal x(point.x());
    qreal y(point.y());

    QVarLengthArray<int> visualOrder(nItems);
    QVarLengthArray<uchar> levels(nItems);
    for (int i = 0; i < nItems; ++i)
        levels[i] = eng->layoutData->items[i].analysis.bidiLevel;
    QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());

    for (int i = 0; i < nItems; ++i) {
        int item = visualOrder[i];
        QScriptItem &si = eng->layoutData->items[item];

        if (si.analysis.flags < QScriptAnalysis::TabOrObject) {
            QGlyphLayout *glyphs = eng->glyphs(&si);
            QFontEngine *fe = f.d->engineForScript(si.analysis.script);
            fe->addOutlineToPath(x, y, glyphs, si.num_glyphs, this,
                                 si.analysis.bidiLevel % 2
                                 ? QTextItem::RenderFlags(QTextItem::RightToLeft)
                                 : QTextItem::RenderFlags(0));

            const qreal lw = fe->lineThickness().toReal();
            if (f.d->underline) {
                qreal pos = fe->underlinePosition().toReal();
                addRect(x, y + pos, si.width.toReal(), lw);
            if (f.d->overline) {
                qreal pos = fe->ascent().toReal() + 1;
                addRect(x, y - pos, si.width.toReal(), lw);
            if (f.d->strikeOut) {
                qreal pos = fe->ascent().toReal() / 3;
                addRect(x, y - pos, si.width.toReal(), lw);
        x += si.width.toReal();

Generated by  Doxygen 1.6.0   Back to index