summaryrefslogtreecommitdiff
path: root/cui/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-04-08 14:41:34 +0100
committerCaolán McNamara <caolanm@redhat.com>2013-04-08 14:42:53 +0100
commiteb1c8080016ee3d788a2eca6cbc6ba42ff7d362f (patch)
tree3781357111d995b81a23c1ef0bb071eb1eeadfc7 /cui/source
parentcf9bc834a404d213234f7d9344318ca7342cbcde (diff)
Resolves: fdo#59246 shrink font to fit available width
Change-Id: I74cabfcbbfe24e598e497cf6eb451bd9ab517c44
Diffstat (limited to 'cui/source')
-rw-r--r--cui/source/dialogs/cuicharmap.cxx37
1 files changed, 34 insertions, 3 deletions
diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index 05559422f7dd..ed42c14c9931 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);
}
// -----------------------------------------------------------------------