mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 21:15:07 +02:00
Update TextOverlay::textSize to use new TextRenderer::getExtents
This commit is contained in:
parent
3e8f7dc3da
commit
d7e18d6f6d
1 changed files with 3 additions and 14 deletions
|
@ -165,19 +165,8 @@ QScriptValue TextOverlay::getProperty(const QString& property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF TextOverlay::textSize(const QString& text) const {
|
QSizeF TextOverlay::textSize(const QString& text) const {
|
||||||
|
auto textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT);
|
||||||
|
auto extents = textRenderer->computeExtent(text);
|
||||||
|
|
||||||
QFont font(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); // Same font properties as render()
|
return QSizeF(extents.x, extents.y);
|
||||||
QFontMetrics fontMetrics(font);
|
|
||||||
const int TEXT_HEIGHT_ADJUST = -2; // Experimentally determined for the specified font
|
|
||||||
|
|
||||||
QStringList lines = text.split(QRegExp("\r\n|\r|\n"));
|
|
||||||
|
|
||||||
int width = 0;
|
|
||||||
for (int i = 0; i < lines.count(); i += 1) {
|
|
||||||
width = std::max(width, fontMetrics.width(qPrintable(lines[i])));
|
|
||||||
}
|
|
||||||
|
|
||||||
int height = lines.count() * (fontMetrics.height() + TEXT_HEIGHT_ADJUST);
|
|
||||||
|
|
||||||
return QSizeF(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue