Resolves: fdo#59246 shrink font to fit available width
Change-Id: I74cabfcbbfe24e598e497cf6eb451bd9ab517c44
This commit is contained in:
parent
cf9bc834a4
commit
eb1c808001
@ -191,11 +191,40 @@ void SvxShowText::Paint( const Rectangle& )
|
|||||||
|
|
||||||
const String aText = GetText();
|
const String aText = GetText();
|
||||||
const Size aSize = GetOutputSizePixel();
|
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;
|
Rectangle aBoundRect;
|
||||||
|
|
||||||
|
for (long nFontHeight = aFontSize.Height(); nFontHeight > 0; nFontHeight -= 5)
|
||||||
|
{
|
||||||
if( !GetTextBoundRect( aBoundRect, aText ) || aBoundRect.IsEmpty() )
|
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;
|
aPoint.X() = (aSize.Width() - GetTextWidth( aText )) / 2;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -230,6 +259,8 @@ void SvxShowText::Paint( const Rectangle& )
|
|||||||
|
|
||||||
DrawText( aPoint, aText );
|
DrawText( aPoint, aText );
|
||||||
SetTextColor( aTextCol );
|
SetTextColor( aTextCol );
|
||||||
|
if (bShrankFont)
|
||||||
|
Control::SetFont(aOrigFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user