Update TextOverlay::textSize to use new TextRenderer::getExtents

This commit is contained in:
Ryan Huffman 2015-02-11 11:04:04 -08:00
parent 3e8f7dc3da
commit d7e18d6f6d

View file

@ -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);
}