1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2003 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
13
#if QT_VERSION >= 0x040000
17
#include "qwt_mathml_text_engine.h"
19
#include <qtmmlwidget.h>
22
QwtMathMLTextEngine::QwtMathMLTextEngine()
27
QwtMathMLTextEngine::~QwtMathMLTextEngine()
32
Find the height for a given width
34
\param font Font of the text
35
\param flags Bitwise OR of the flags used like in QPainter::drawText
36
\param text Text to be rendered
39
\return Calculated height
41
int QwtMathMLTextEngine::heightForWidth(const QFont& font, int flags,
42
const QString& text, int) const
44
return textSize(font, flags, text).height();
48
Returns the size, that is needed to render text
50
\param font Font of the text
51
\param flags Bitwise OR of the flags used like in QPainter::drawText
52
\param text Text to be rendered
54
\return Caluclated size
56
QSize QwtMathMLTextEngine::textSize(const QFont &font,
57
int, const QString& text) const
66
doc.setBaseFontPointSize(font.pointSize());
76
Return margins around the texts
81
\param bottom Return 0
83
void QwtMathMLTextEngine::textMargins(const QFont &, const QString &,
84
int &left, int &right, int &top, int &bottom) const
86
left = right = top = bottom = 0;
90
Draw the text in a clipping rectangle
92
\param painter Painter
93
\param rect Clipping rectangle
94
\param flags Bitwise OR of the flags like in for QPainter::drawText
95
\param text Text to be rendered
97
void QwtMathMLTextEngine::draw(QPainter *painter, const QRect &rect,
98
int flags, const QString& text) const
101
doc.setContent(text);
102
doc.setBaseFontPointSize(painter->font().pointSize());
104
const QSize docSize = doc.size();
106
QPoint pos = rect.topLeft();
107
if ( rect.width() > docSize.width() )
109
if ( flags & Qt::AlignRight )
110
pos.setX(rect.right() - docSize.width());
111
if ( flags & Qt::AlignHCenter )
112
pos.setX(rect.center().x() - docSize.width() / 2);
114
if ( rect.height() > docSize.height() )
116
if ( flags & Qt::AlignBottom )
117
pos.setY(rect.bottom() - docSize.height());
118
if ( flags & Qt::AlignVCenter )
119
pos.setY(rect.center().y() - docSize.height() / 2);
122
doc.paint(painter, pos);
126
Test if a string can be rendered by QwtMathMLTextEngine
128
\param text Text to be tested
129
\return true, if text begins with "<math>".
131
bool QwtMathMLTextEngine::mightRender(const QString &text) const
133
return text.trimmed().startsWith("<math");
136
#endif // QT_VERSION < 0x040000