mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
calculate bounding rectangles via QTextLayout from QFontMetrics/QFontMetricsF
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
18ab4d967e
commit
ddc3af4962
1 changed files with 17 additions and 10 deletions
|
@ -560,13 +560,17 @@ int QFontMetrics::width(QChar ch) const
|
|||
*/
|
||||
QRect QFontMetrics::boundingRect(const QString &text) const
|
||||
{
|
||||
if (text.length() == 0)
|
||||
if (text.isEmpty())
|
||||
return QRect();
|
||||
|
||||
QTextEngine layout(text, d.data());
|
||||
layout.itemize();
|
||||
glyph_metrics_t gm = layout.boundingBox();
|
||||
return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
|
||||
QTextLayout textlayout(text, d.data());
|
||||
textlayout.beginLayout();
|
||||
QTextLine textline = textlayout.createLine();
|
||||
while (textline.isValid()) {
|
||||
textline = textlayout.createLine();
|
||||
}
|
||||
textlayout.endLayout();
|
||||
return textlayout.boundingRect().toRect();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1325,11 +1329,14 @@ QRectF QFontMetricsF::boundingRect(const QString &text) const
|
|||
if (text.isEmpty())
|
||||
return QRectF();
|
||||
|
||||
QTextEngine layout(text, d.data());
|
||||
layout.itemize();
|
||||
glyph_metrics_t gm = layout.boundingBox();
|
||||
return QRectF(gm.x.toReal(), gm.y.toReal(),
|
||||
gm.width.toReal(), gm.height.toReal());
|
||||
QTextLayout textlayout(text, d.data());
|
||||
textlayout.beginLayout();
|
||||
QTextLine textline = textlayout.createLine();
|
||||
while (textline.isValid()) {
|
||||
textline = textlayout.createLine();
|
||||
}
|
||||
textlayout.endLayout();
|
||||
return textlayout.boundingRect();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Add table
Reference in a new issue