mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 09:33:45 +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 {
|
||||
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()
|
||||
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);
|
||||
return QSizeF(extents.x, extents.y);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue