/*!
   Draw the text in a clipping rectangle

   \param painter Painter
   \param rect Clipping rectangle 
   \param flags Bitwise OR of the flags like in for QPainter::drawText
   \param text Text to be rendered
*/ 
void QwtMathMLTextEngine::draw(QPainter *painter, const QRectF &rect,
    int flags, const QString& text) const
{
    QwtMathMLDocument doc;
    doc.setContent(text);
    doc.setBaseFontPointSize(painter->font().pointSize());

    const QSizeF docSize = doc.size();

    QPointF pos = rect.topLeft();
    if ( rect.width() > docSize.width() )
    {
        if ( flags & Qt::AlignRight )
            pos.setX(rect.right() - docSize.width());
        if ( flags & Qt::AlignHCenter )
            pos.setX(rect.center().x() - docSize.width() / 2);
    }
    if ( rect.height() > docSize.height() )
    {
        if ( flags & Qt::AlignBottom )
            pos.setY(rect.bottom() - docSize.height());
        if ( flags & Qt::AlignVCenter )
            pos.setY(rect.center().y() - docSize.height() / 2);
    }

    doc.paint(painter, pos.toPoint());
}
/*!
  Returns the size, that is needed to render text

  \param font Font of the text
  \param flags Bitwise OR of the flags used like in QPainter::drawText
  \param text Text to be rendered

  \return Caluclated size
*/
QSizeF QwtMathMLTextEngine::textSize(const QFont &font,
    int, const QString& text) const
{
    static QString t;
    static QSize sz;

    if ( text != t )
    {
        QwtMathMLDocument doc;
        doc.setContent(text);
        doc.setBaseFontPointSize(font.pointSize());

        sz = doc.size();
        t = text;
    }

    return sz;
}
Exemple #3
0
void FormulaView::renderFormula( QPainter *painter ) const
{
    QwtMathMLDocument doc;
    doc.setContent( d_formula );
    doc.setBaseFontPointSize( d_fontSize );

    QRectF docRect;
    docRect.setSize( doc.size() );
    docRect.moveCenter( rect().center() );

    if ( d_transformation )
    {
        const double scaleF = d_scale ? 2.0 : 1.0;

        painter->save();

        painter->translate( docRect.center() );
        painter->rotate( d_rotation );
        painter->scale( scaleF, scaleF );
        painter->translate( docRect.topLeft() - docRect.center() );
        doc.paint( painter, QPointF( 0, 0 ) );

        painter->restore();
    }
    else
    {
        doc.paint( painter, docRect.topLeft().toPoint() );
    }
}