summaryrefslogtreecommitdiff
path: root/svx/source/styles
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-10-01 01:29:24 +0200
committerخالد حسني <khaled@aliftype.com>2022-10-01 13:29:50 +0200
commitb7e7ae77f55e41dae2231b04062cf037f7f9b13f (patch)
treed7793d3bfd46fcf764023f059ce4e9fc5c6b7c65 /svx/source/styles
parentd7083fe6dd383ac4144fbe53e300bc3d34f26ef6 (diff)
tdf#151114: Improve styles preview alignment
Change-Id: Iefe265584d710bd6cfc9e7ed0a656dd83d91c84c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140811 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
Diffstat (limited to 'svx/source/styles')
-rw-r--r--svx/source/styles/CommonStylePreviewRenderer.cxx29
1 files changed, 17 insertions, 12 deletions
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx
index bee9fb969f07..277948d3b6bc 100644
--- a/svx/source/styles/CommonStylePreviewRenderer.cxx
+++ b/svx/source/styles/CommonStylePreviewRenderer.cxx
@@ -15,6 +15,7 @@
#include <svl/style.hxx>
#include <svl/itemset.hxx>
#include <svl/itempool.hxx>
+#include <vcl/metric.hxx>
#include <vcl/outdev.hxx>
#include <com/sun/star/drawing/FillStyle.hpp>
@@ -54,6 +55,7 @@ CommonStylePreviewRenderer::CommonStylePreviewRenderer(
, maHighlightColor(COL_AUTO)
, maBackgroundColor(COL_AUTO)
, mnHeight(0)
+ , mnBaseLine(0)
, maStyleName(mpStyle->GetName())
{
}
@@ -78,6 +80,7 @@ static bool SetFont(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
rFont.SetPitch(rFontItem.GetPitch());
rFont.SetCharSet(rFontItem.GetCharSet());
rFont.SetStyleName(rFontItem.GetStyleName());
+ rFont.SetAlignment(ALIGN_BASELINE);
return true;
}
return false;
@@ -92,6 +95,8 @@ bool CommonStylePreviewRenderer::SetFontSize(const SfxItemSet& rSet, sal_uInt16
Size aFontSize(0, rFontHeightItem.GetHeight());
aFontSize = mrOutputDev.LogicToPixel(aFontSize, MapMode(mrShell.GetMapUnit()));
rFont.SetFontSize(aFontSize);
+ mrOutputDev.SetFont(rFont);
+ FontMetric aMetric(mrOutputDev.GetFontMetric());
return true;
}
return false;
@@ -228,9 +233,8 @@ void CommonStylePreviewRenderer::CalcRenderSize()
{
const OUString& rText = maStyleName;
- tools::Rectangle aTextRect;
- tools::Long nHeight = 0;
-
+ mnBaseLine = 0;
+ mnHeight = 0;
sal_uInt16 nScript;
sal_uInt16 nIdx = 0;
sal_Int32 nStart = 0;
@@ -258,23 +262,22 @@ void CommonStylePreviewRenderer::CalcRenderSize()
mrOutputDev.Push(vcl::PushFlags::FONT);
- Size aSize;
+ tools::Long nWidth;
if (oFont)
{
mrOutputDev.SetFont(*oFont);
- aSize = oFont->GetTextSize(mrOutputDev, rText, nStart, nEnd - nStart);
+ nWidth = oFont->GetTextSize(mrOutputDev, rText, nStart, nEnd - nStart).Width();
}
else
- aSize = Size(mrOutputDev.GetTextWidth(rText, nStart, nEnd - nStart), mrOutputDev.GetFont().GetFontHeight());
+ nWidth = mrOutputDev.GetTextWidth(rText, nStart, nEnd - nStart);
tools::Rectangle aRect;
mrOutputDev.GetTextBoundRect(aRect, rText, nStart, nStart, nEnd - nStart);
- aTextRect = aTextRect.Union(aRect);
mrOutputDev.Pop();
- auto nWidth = aSize.Width();
- nHeight = std::max(nHeight, aSize.Height());
+ mnBaseLine = std::max(mnBaseLine, -aRect.Top());
+ mnHeight = std::max(mnHeight, aRect.GetHeight());
if (nIdx >= maScriptChanges.size())
break;
@@ -292,10 +295,11 @@ void CommonStylePreviewRenderer::CalcRenderSize()
while(true);
double fRatio = 1;
- if (aTextRect.Bottom() > mnMaxHeight)
- fRatio = double(mnMaxHeight) / aTextRect.Bottom();
+ if (mnHeight > mnMaxHeight)
+ fRatio = double(mnMaxHeight) / mnHeight;
- mnHeight = std::min(tools::Long(nHeight * fRatio), mnMaxHeight);
+ mnHeight *= fRatio;
+ mnBaseLine *= fRatio;
if (fRatio != 1)
{
Size aFontSize;
@@ -340,6 +344,7 @@ bool CommonStylePreviewRenderer::render(const tools::Rectangle& aRectangle, Rend
mrOutputDev.SetTextFillColor(maHighlightColor);
Point aFontDrawPosition = aRectangle.TopLeft();
+ aFontDrawPosition.AdjustY(mnBaseLine);
if (eRenderAlign == RenderAlign::CENTER)
{
if (aRectangle.GetHeight() > mnHeight)