cui/source/dialogs/cuicharmap.cxx | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-)
New commits: commit eb1c8080016ee3d788a2eca6cbc6ba42ff7d362f Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 8 14:41:34 2013 +0100 Resolves: fdo#59246 shrink font to fit available width Change-Id: I74cabfcbbfe24e598e497cf6eb451bd9ab517c44 diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx index 0555942..ed42c14 100644 --- a/cui/source/dialogs/cuicharmap.cxx +++ b/cui/source/dialogs/cuicharmap.cxx @@ -191,11 +191,40 @@ void SvxShowText::Paint( const Rectangle& ) const String aText = GetText(); const Size aSize = GetOutputSizePixel(); - Point aPoint( 2, mnY ); - // adjust position using ink boundary if possible + long nAvailWidth = aSize.Width(); + long nWinHeight = GetOutputSizePixel().Height(); + + bool bGotBoundary = true; + bool bShrankFont = false; + Font aOrigFont(GetFont()); + Size aFontSize(aOrigFont.GetSize()); Rectangle aBoundRect; - if( !GetTextBoundRect( aBoundRect, aText ) || aBoundRect.IsEmpty() ) + + for (long nFontHeight = aFontSize.Height(); nFontHeight > 0; nFontHeight -= 5) + { + if( !GetTextBoundRect( aBoundRect, aText ) || aBoundRect.IsEmpty() ) + { + bGotBoundary = false; + break; + } + if (!mbCenter) + break; + //only shrink in the single glyph large view mode + long nTextWidth = aBoundRect.GetWidth(); + if (nAvailWidth > nTextWidth) + break; + Font aFont(aOrigFont); + aFontSize.Height() = nFontHeight; + aFont.SetSize(aFontSize); + Control::SetFont(aFont); + mnY = ( nWinHeight - GetTextHeight() ) / 2; + bShrankFont = true; + } + + Point aPoint( 2, mnY ); + // adjust position using ink boundary if possible + if( !bGotBoundary ) aPoint.X() = (aSize.Width() - GetTextWidth( aText )) / 2; else { @@ -230,6 +259,8 @@ void SvxShowText::Paint( const Rectangle& ) DrawText( aPoint, aText ); SetTextColor( aTextCol ); + if (bShrankFont) + Control::SetFont(aOrigFont); } // -----------------------------------------------------------------------
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits