QSize QwtText::textSize(const QFont &font) const { #if QT_VERSION < 0x040000 const QFont fnt(usedFont(font)); #else // We want to calculate in screen metrics. So // we need a font that uses screen metrics const QFont fnt(usedFont(font), QApplication::desktop()); #endif if ( !d_layoutCache->textSize.isValid() || d_layoutCache->font != fnt ) { d_layoutCache->textSize = d_data->textEngine->textSize( fnt, d_data->flags, d_data->text); d_layoutCache->font = fnt; } QSize sz = d_layoutCache->textSize; if ( d_data->layoutAttributes & MinimumLayout ) { int left, right, top, bottom; d_data->textEngine->textMargins(fnt, d_data->text, left, right, top, bottom); sz -= QSize(left + right, top + bottom); } const QwtMetricsMap map = QwtPainter::metricsMap(); sz = map.screenToLayout(sz); return sz; }
/*! Returns the size, that is needed to render text \param defaultFont Font of the text \return Caluclated size */ QSize QwtText::textSize(const QFont &defaultFont) const { #if QT_VERSION < 0x040000 const QFont font(usedFont(defaultFont)); #else // We want to calculate in screen metrics. So // we need a font that uses screen metrics const QFont font(usedFont(defaultFont), QApplication::desktop()); #endif if ( !d_layoutCache->textSize.isValid() || d_layoutCache->font != font ) { d_layoutCache->textSize = d_data->textEngine->textSize( font, d_data->renderFlags, d_data->text); d_layoutCache->font = font; } QSize sz = d_layoutCache->textSize; const QwtMetricsMap map = QwtPainter::metricsMap(); if ( d_data->layoutAttributes & MinimumLayout ) { int left, right, top, bottom; d_data->textEngine->textMargins(font, d_data->text, left, right, top, bottom); sz -= QSize(left + right, top + bottom); #if QT_VERSION >= 0x040000 if ( !map.isIdentity() ) { #ifdef __GNUC__ #warning Too small text size, when printing in high resolution #endif /* When printing in high resolution, the tick labels of are cut of. We need to find out why, but for the moment we add a couple of pixels instead. */ sz += QSize(3, 2); } #endif } sz = map.screenToLayout(sz); return sz; }