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
|
QRect QFontMetrics::boundingRect(const QString &text) const
|
||||||
{
|
{
|
||||||
if (text.length() == 0)
|
if (text.isEmpty())
|
||||||
return QRect();
|
return QRect();
|
||||||
|
|
||||||
QTextEngine layout(text, d.data());
|
QTextLayout textlayout(text, d.data());
|
||||||
layout.itemize();
|
textlayout.beginLayout();
|
||||||
glyph_metrics_t gm = layout.boundingBox();
|
QTextLine textline = textlayout.createLine();
|
||||||
return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
|
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())
|
if (text.isEmpty())
|
||||||
return QRectF();
|
return QRectF();
|
||||||
|
|
||||||
QTextEngine layout(text, d.data());
|
QTextLayout textlayout(text, d.data());
|
||||||
layout.itemize();
|
textlayout.beginLayout();
|
||||||
glyph_metrics_t gm = layout.boundingBox();
|
QTextLine textline = textlayout.createLine();
|
||||||
return QRectF(gm.x.toReal(), gm.y.toReal(),
|
while (textline.isValid()) {
|
||||||
gm.width.toReal(), gm.height.toReal());
|
textline = textlayout.createLine();
|
||||||
|
}
|
||||||
|
textlayout.endLayout();
|
||||||
|
return textlayout.boundingRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Add table
Reference in a new issue