[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - include/svx svx/source

Michael Stahl mstahl at redhat.com
Tue Sep 8 01:45:45 PDT 2015


 include/svx/CommonStylePreviewRenderer.hxx       |    2 
 svx/source/styles/CommonStylePreviewRenderer.cxx |   51 +++++++++++++----------
 2 files changed, 31 insertions(+), 22 deletions(-)

New commits:
commit 3a0d2c51021022233015c3318cfcf26aceb3b650
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Sep 7 16:40:20 2015 +0200

    svx: fix font rendering in the style preview
    
    If the style does not actually have any font items, as is the case for
    frame, page and number styles in Writer, the maFont will be
    default-initialized and the maPixelSize incorrect.
    Avoid using these variables.
    
    (cherry picked from commit 07df816d73884d094f0f56be022aa0b4eff00b2d)
    
    Change-Id: I084cd8faa90a3d53310ceec55e8dae3af3dd586c
    Reviewed-on: https://gerrit.libreoffice.org/18383
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/include/svx/CommonStylePreviewRenderer.hxx b/include/svx/CommonStylePreviewRenderer.hxx
index 1e7d54e..0a7dd89 100644
--- a/include/svx/CommonStylePreviewRenderer.hxx
+++ b/include/svx/CommonStylePreviewRenderer.hxx
@@ -22,7 +22,7 @@ namespace svx
 
 class SVX_DLLPUBLIC CommonStylePreviewRenderer : public sfx2::StylePreviewRenderer
 {
-    SvxFont maFont;
+    std::unique_ptr<SvxFont> m_pFont;
     Color maFontColor;
     Color maBackgroundColor;
     Size maPixelSize;
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx
index 67f9b89..fefd43b 100644
--- a/svx/source/styles/CommonStylePreviewRenderer.cxx
+++ b/svx/source/styles/CommonStylePreviewRenderer.cxx
@@ -47,7 +47,7 @@ CommonStylePreviewRenderer::CommonStylePreviewRenderer(
                                 const SfxObjectShell& rShell, OutputDevice& rOutputDev,
                                 SfxStyleSheetBase* pStyle, long nMaxHeight)
     : StylePreviewRenderer(rShell, rOutputDev, pStyle, nMaxHeight)
-    , maFont()
+    , m_pFont()
     , maFontColor(COL_AUTO)
     , maBackgroundColor(COL_AUTO)
     , maPixelSize()
@@ -60,53 +60,55 @@ CommonStylePreviewRenderer::~CommonStylePreviewRenderer()
 
 bool CommonStylePreviewRenderer::recalculate()
 {
-    maFont = SvxFont();
+    m_pFont.reset();
 
     std::unique_ptr<SfxItemSet> pItemSet(mpStyle->GetItemSetForPreview());
 
     if (!pItemSet) return false;
 
+    std::unique_ptr<SvxFont> pFont(new SvxFont);
+
     const SfxPoolItem* pItem;
 
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_WEIGHT)) != nullptr)
     {
-        maFont.SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight());
+        pFont->SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_POSTURE)) != nullptr)
     {
-        maFont.SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture());
+        pFont->SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CONTOUR)) != nullptr)
     {
-        maFont.SetOutline(static_cast< const SvxContourItem*>(pItem)->GetValue());
+        pFont->SetOutline(static_cast< const SvxContourItem*>(pItem)->GetValue());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_SHADOWED)) != nullptr)
     {
-        maFont.SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue());
+        pFont->SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_RELIEF)) != nullptr)
     {
-        maFont.SetRelief(static_cast<FontRelief>(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()));
+        pFont->SetRelief(static_cast<FontRelief>(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()));
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_UNDERLINE)) != nullptr)
     {
-        maFont.SetUnderline(static_cast< const SvxUnderlineItem*>(pItem)->GetLineStyle());
+        pFont->SetUnderline(static_cast< const SvxUnderlineItem*>(pItem)->GetLineStyle());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_OVERLINE)) != nullptr)
     {
-        maFont.SetOverline(static_cast<FontUnderline>(static_cast<const SvxOverlineItem*>(pItem)->GetValue()));
+        pFont->SetOverline(static_cast<FontUnderline>(static_cast<const SvxOverlineItem*>(pItem)->GetValue()));
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_STRIKEOUT)) != nullptr)
     {
-        maFont.SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout());
+        pFont->SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CASEMAP)) != nullptr)
     {
-        maFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
+        pFont->SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_EMPHASISMARK)) != nullptr)
     {
-        maFont.SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark());
+        pFont->SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark());
     }
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_COLOR)) != nullptr)
     {
@@ -131,8 +133,8 @@ bool CommonStylePreviewRenderer::recalculate()
     if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_FONT)) != nullptr)
     {
         const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(pItem);
-        maFont.SetName(pFontItem->GetFamilyName());
-        maFont.SetStyleName(pFontItem->GetStyleName());
+        pFont->SetName(pFontItem->GetFamilyName());
+        pFont->SetStyleName(pFontItem->GetStyleName());
     }
     else
     {
@@ -144,11 +146,11 @@ bool CommonStylePreviewRenderer::recalculate()
         const SvxFontHeightItem* pFontHeightItem = static_cast<const SvxFontHeightItem*>(pItem);
         Size aFontSize(0, pFontHeightItem->GetHeight());
         maPixelSize = Size(mrOutputDev.LogicToPixel(aFontSize, mrShell.GetMapUnit()));
-        maFont.SetSize(maPixelSize);
+        pFont->SetSize(maPixelSize);
 
         vcl::Font aOldFont(mrOutputDev.GetFont());
 
-        mrOutputDev.SetFont(maFont);
+        mrOutputDev.SetFont(*pFont);
         Rectangle aTextRect;
         mrOutputDev.GetTextBoundRect(aTextRect, mpStyle->GetName());
         if (aTextRect.Bottom() > mnMaxHeight)
@@ -156,7 +158,7 @@ bool CommonStylePreviewRenderer::recalculate()
             double ratio = double(mnMaxHeight) / aTextRect.Bottom();
             maPixelSize.Width() *= ratio;
             maPixelSize.Height() *= ratio;
-            maFont.SetSize(maPixelSize);
+            pFont->SetSize(maPixelSize);
         }
         mrOutputDev.SetFont(aOldFont);
     }
@@ -165,12 +167,14 @@ bool CommonStylePreviewRenderer::recalculate()
         return false;
     }
 
+    m_pFont = std::move(pFont);
     return true;
 }
 
 Size CommonStylePreviewRenderer::getRenderSize()
 {
-    maPixelSize = maFont.GetTextSize(&mrOutputDev, maStyleName);
+    assert(m_pFont);
+    maPixelSize = m_pFont->GetTextSize(&mrOutputDev, maStyleName);
     if (maPixelSize.Height() > mnMaxHeight)
         maPixelSize.Height() = mnMaxHeight;
     return maPixelSize;
@@ -189,13 +193,18 @@ bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle)
         mrOutputDev.DrawRect(aRectangle);
     }
 
-    mrOutputDev.SetFont(maFont);
+    if (m_pFont)
+    {
+        mrOutputDev.SetFont(*m_pFont);
+    }
     if (maFontColor != COL_AUTO)
         mrOutputDev.SetTextColor(maFontColor);
 
+    Size aPixelSize((m_pFont) ? maPixelSize : mrOutputDev.GetFont().GetSize());
+
     Point aFontDrawPosition = aRectangle.TopLeft();
-    if (aRectangle.GetHeight() > maPixelSize.Height())
-        aFontDrawPosition.Y() += ( aRectangle.GetHeight() - maPixelSize.Height() ) / 2;
+    if (aRectangle.GetHeight() > aPixelSize.Height())
+        aFontDrawPosition.Y() += (aRectangle.GetHeight() - aPixelSize.Height()) / 2;
 
     mrOutputDev.DrawText(aFontDrawPosition, maStyleName);
 


More information about the Libreoffice-commits mailing list