18 #include <qtextobject.h> 19 #include <qtextdocument.h> 20 #include <qabstracttextdocumentlayout.h> 24 QString richText = text;
27 if ( flags & Qt::AlignJustify )
29 richText.prepend( QLatin1String(
"<div align=\"justify\">" ) );
30 richText.append( QLatin1String (
"</div>" ) );
32 else if ( flags & Qt::AlignRight )
34 richText.prepend( QLatin1String (
"<div align=\"right\">" ) );
35 richText.append( QLatin1String (
"</div>" ) );
37 else if ( flags & Qt::AlignHCenter )
39 richText.prepend( QLatin1String (
"<div align=\"center\">" ) );
40 richText.append( QLatin1String (
"</div>" ) );
51 setUndoRedoEnabled(
false );
52 setDefaultFont( font );
56 ( void )documentLayout();
58 QTextOption option = defaultTextOption();
59 if ( flags & Qt::TextWordWrap )
60 option.setWrapMode( QTextOption::WordWrap );
62 option.setWrapMode( QTextOption::NoWrap );
64 option.setAlignment( static_cast<Qt::Alignment>( flags ) );
65 setDefaultTextOption( option );
67 QTextFrame *root = rootFrame();
68 QTextFrameFormat fm = root->frameFormat();
72 fm.setBottomMargin( 0 );
73 fm.setLeftMargin( 0 );
74 root->setFrameFormat( fm );
85 const QString fontKey = font.key();
87 QMap<QString, int>::const_iterator it =
88 d_ascentCache.constFind( fontKey );
89 if ( it == d_ascentCache.constEnd() )
91 int ascent = findAscent( font );
92 it = d_ascentCache.insert( fontKey, ascent );
101 static const QString dummy(
"E" );
102 static const QColor white( Qt::white );
104 const QFontMetrics fm( font );
105 QPixmap pm( fm.width( dummy ), fm.height() );
110 p.drawText( 0, 0, pm.width(), pm.height(), 0, dummy );
113 const QImage img = pm.toImage();
116 for ( row = 0; row < img.height(); row++ )
118 const QRgb *line =
reinterpret_cast<const QRgb *
>(
119 img.scanLine( row ) );
121 const int w = pm.width();
122 for (
int col = 0; col < w; col++ )
124 if ( line[col] != white.rgb() )
125 return fm.ascent() - row + 1;
168 const QString& text,
double width )
const 170 const QFontMetricsF fm( font );
171 const QRectF rect = fm.boundingRect(
172 QRectF( 0, 0, width, QWIDGETSIZE_MAX ), flags, text );
174 return rect.height();
187 int flags,
const QString& text )
const 189 const QFontMetricsF fm( font );
190 const QRectF rect = fm.boundingRect(
191 QRectF( 0, 0, QWIDGETSIZE_MAX, QWIDGETSIZE_MAX ), flags, text );
206 double &left,
double &right,
double &top,
double &bottom )
const 208 left = right = top = 0;
210 const QFontMetricsF fm( font );
211 top = fm.ascent() - d_data->effectiveAscent( font );
212 bottom = fm.descent();
226 int flags,
const QString& text )
const 240 #ifndef QT_NO_RICHTEXT 258 const QString& text,
double width )
const 262 doc.setPageSize( QSizeF( width, QWIDGETSIZE_MAX ) );
263 return doc.documentLayout()->documentSize().height();
277 int flags,
const QString& text )
const 281 QTextOption option = doc.defaultTextOption();
282 if ( option.wrapMode() != QTextOption::NoWrap )
284 option.setWrapMode( QTextOption::NoWrap );
285 doc.setDefaultTextOption( option );
301 int flags,
const QString& text )
const 328 return Qt::mightBeRichText( text );
340 double &left,
double &right,
double &top,
double &bottom )
const 342 left = right = top = bottom = 0;
345 #endif // !QT_NO_RICHTEXT
QwtRichTextEngine()
Constructor.
virtual bool mightRender(const QString &) const
virtual void draw(QPainter *painter, const QRectF &rect, int flags, const QString &text) const
virtual QSizeF textSize(const QFont &font, int flags, const QString &text) const
static void drawText(QPainter *, double x, double y, const QString &)
Wrapper for QPainter::drawText()
virtual ~QwtPlainTextEngine()
Destructor.
static QString taggedRichText(const QString &text, int flags)
static void drawSimpleRichText(QPainter *, const QRectF &, int flags, const QTextDocument &)
virtual void textMargins(const QFont &, const QString &, double &left, double &right, double &top, double &bottom) const
virtual QSizeF textSize(const QFont &font, int flags, const QString &text) const
virtual double heightForWidth(const QFont &font, int flags, const QString &text, double width) const
virtual void draw(QPainter *painter, const QRectF &rect, int flags, const QString &text) const
Draw the text in a clipping rectangle.
QwtPlainTextEngine()
Constructor.
virtual void textMargins(const QFont &, const QString &, double &left, double &right, double &top, double &bottom) const
QwtRichTextDocument(const QString &text, int flags, const QFont &font)
TFSIMD_FORCE_INLINE const tfScalar & w() const
int effectiveAscent(const QFont &font) const
virtual bool mightRender(const QString &) const
static int findAscent(const QFont &font)
QString taggedText(const QString &, int flags) const
virtual double heightForWidth(const QFont &font, int flags, const QString &text, double width) const
QwtTextEngine()
Constructor.
QMap< QString, int > d_ascentCache
virtual ~QwtTextEngine()
Destructor.