diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-09-07 16:40:20 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-09-07 16:49:59 +0200 |
commit | 07df816d73884d094f0f56be022aa0b4eff00b2d (patch) | |
tree | 8cc2453315ec7a7867e4ee0291da988ddc9dc445 /svx/source | |
parent | 779b547ca6271156a59965569fa44fbeb3f63ce5 (diff) |
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.
Change-Id: I084cd8faa90a3d53310ceec55e8dae3af3dd586c
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/styles/CommonStylePreviewRenderer.cxx | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx index 19bce5f5ef63..21876e9db994 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; @@ -191,20 +195,25 @@ bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle, RenderAlign 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 (eRenderAlign == RenderAlign::CENTER) { - if (aRectangle.GetHeight() > maPixelSize.Height()) - aFontDrawPosition.Y() += (aRectangle.GetHeight() - maPixelSize.Height()) / 2; + if (aRectangle.GetHeight() > aPixelSize.Height()) + aFontDrawPosition.Y() += (aRectangle.GetHeight() - aPixelSize.Height()) / 2; } else if (eRenderAlign == RenderAlign::BOTTOM) { - if (aRectangle.GetHeight() > maPixelSize.Height()) - aFontDrawPosition.Y() += aRectangle.GetHeight() - maPixelSize.Height(); + if (aRectangle.GetHeight() > aPixelSize.Height()) + aFontDrawPosition.Y() += aRectangle.GetHeight() - aPixelSize.Height(); } mrOutputDev.DrawText(aFontDrawPosition, rText); |