static qreal fitFontSizeToGeometry( const QString& text, const QFont& font, const QRectF& geometry, const TextAttributes& ta ) { QFont f = font; const qreal origResult = f.pointSizeF(); qreal result = origResult; const QSizeF mySize = geometry.size(); if ( mySize.isNull() ) return result; const QString t = text; QFontMetrics fm( f ); while ( true ) { const QSizeF textSize = rotatedRect( fm.boundingRect( t ), ta.rotation() ).normalized().size(); if ( textSize.height() <= mySize.height() && textSize.width() <= mySize.width() ) return result; result -= 0.5; if ( result <= 0.0 ) return origResult; f.setPointSizeF( result ); fm = QFontMetrics( f ); } }
bool TextAttributes::operator==( const TextAttributes& r ) const { // the following works around a bug in gcc 4.3.2 // causing StyleHint to be set to Zero when copying a QFont const QFont myFont( font() ); QFont r_font( r.font() ); r_font.setStyleHint( myFont.styleHint(), myFont.styleStrategy() ); return ( isVisible() == r.isVisible() && myFont == r_font && fontSize() == r.fontSize() && minimalFontSize() == r.minimalFontSize() && autoRotate() == r.autoRotate() && autoShrink() == r.autoShrink() && rotation() == r.rotation() && pen() == r.pen() && textDocument() == r.textDocument() ); }