Kaydet (Commit) a18c5517 authored tarafından Philippe Jung's avatar Philippe Jung

Better position for Toolbar name

The text is badly centered. Replaced GetTextHeight by GetTextBoundRect
and updated computation of text bounds.

Change-Id: I1e177a15787c6eddf2878a7d0254f71f3501ec34
Reviewed-on: https://gerrit.libreoffice.org/16354Reviewed-by: 's avatarPhilippe Jung <phil.jung@free.fr>
Tested-by: 's avatarPhilippe Jung <phil.jung@free.fr>
üst dc3d6214
...@@ -85,7 +85,7 @@ using namespace ::com::sun::star; ...@@ -85,7 +85,7 @@ using namespace ::com::sun::star;
using namespace vcl; using namespace vcl;
#define EXTRAITEMHEIGHT 4 #define EXTRAITEMHEIGHT 4
#define SPACE_AROUND_TITLE 2 #define SPACE_AROUND_TITLE 4
static bool ImplAccelDisabled() static bool ImplAccelDisabled()
{ {
...@@ -1631,16 +1631,21 @@ Size Menu::ImplCalcSize( vcl::Window* pWin ) ...@@ -1631,16 +1631,21 @@ Size Menu::ImplCalcSize( vcl::Window* pWin )
// Additional space for title // Additional space for title
nTitleHeight = 0; nTitleHeight = 0;
if (!IsMenuBar() && aTitleText.getLength() > 0) { if (!IsMenuBar() && aTitleText.getLength() > 0) {
// Vertically, one height of char + extra space for decoration // Set expected font
nTitleHeight = nFontHeight + 4 * SPACE_AROUND_TITLE ;
aSz.Height() += nTitleHeight;
// Horizontally, compute text width with bold font
pWin->Push(PushFlags::FONT); pWin->Push(PushFlags::FONT);
vcl::Font aFont = pWin->GetFont(); vcl::Font aFont = pWin->GetFont();
aFont.SetWeight(WEIGHT_BOLD); aFont.SetWeight(WEIGHT_BOLD);
pWin->SetFont(aFont); pWin->SetFont(aFont);
long nWidth = pWin->GetTextWidth( aTitleText ) + 4 * SPACE_AROUND_TITLE;
// Compute text bounding box
Rectangle aTextBoundRect;
pWin->GetTextBoundRect(aTextBoundRect, aTitleText);
// Vertically, one height of char + extra space for decoration
nTitleHeight = aTextBoundRect.GetSize().Height() + 4 * SPACE_AROUND_TITLE ;
aSz.Height() += nTitleHeight;
long nWidth = aTextBoundRect.GetSize().Width() + 4 * SPACE_AROUND_TITLE;
pWin->Pop(); pWin->Pop();
if ( nWidth > nMaxWidth ) if ( nWidth > nMaxWidth )
nMaxWidth = nWidth; nMaxWidth = nWidth;
...@@ -1784,10 +1789,12 @@ void Menu::ImplPaintMenuTitle(vcl::RenderContext& rRenderContext, const Rectangl ...@@ -1784,10 +1789,12 @@ void Menu::ImplPaintMenuTitle(vcl::RenderContext& rRenderContext, const Rectangl
rRenderContext.DrawRect(aBgRect); rRenderContext.DrawRect(aBgRect);
// Draw the text centered // Draw the text centered
Point aTextTopLeft(rRect.TopLeft()); Point aTextTopLeft(aBgRect.TopLeft());
long textWidth = rRenderContext.GetTextWidth(aTitleText); Rectangle aTextBoundRect;
aTextTopLeft.X() += (aBgRect.getWidth() - textWidth) / 2; rRenderContext.GetTextBoundRect( aTextBoundRect, aTitleText );
aTextTopLeft.Y() += SPACE_AROUND_TITLE; aTextTopLeft.X() += (aBgRect.getWidth() - aTextBoundRect.GetSize().Width()) / 2;
aTextTopLeft.Y() += (aBgRect.GetHeight() - aTextBoundRect.GetSize().Height()) / 2
- aTextBoundRect.TopLeft().Y();
rRenderContext.DrawText(aTextTopLeft, aTitleText, 0, aTitleText.getLength()); rRenderContext.DrawText(aTextTopLeft, aTitleText, 0, aTitleText.getLength());
// Restore // Restore
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment