diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-11-30 18:26:11 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-12-07 13:27:39 +0100 |
commit | b66435c3fcff5eb198f0037067294c1203ebcd76 (patch) | |
tree | 4d60d1f4782dc772988cc1b3896b8fdeadb99755 /sw | |
parent | 3e4e3ee3dba7fa65263e71da0bc0091d4e950d33 (diff) |
tdf#113037 Unify Watermark in DOC & DOCX
* use correct font for calculations
Reviewed-on: https://gerrit.libreoffice.org/45698
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
(cherry picked from commit 923ca4efe2095998e3da75c372cd7d716db9abb3)
Change-Id: Idd370678c000bf22c460c3323bd55cd827ba7153
Reviewed-on: https://gerrit.libreoffice.org/45996
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/edit/edfcol.cxx | 29 |
2 files changed, 18 insertions, 14 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 9740bc954397..97a5098d2373 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -614,8 +614,9 @@ DECLARE_OOXMLEXPORT_TEST(testWatermarkSize, "watermark.docx") // Rounding errors sal_Int32 nDifference = 5198 - nTotalHeight; std::stringstream ss; - ss << "Difference: " << nDifference; + ss << "Difference: " << nDifference << " TotalHeight: " << nTotalHeight; CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 4df109045209..1f14403f475b 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -397,21 +397,24 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, // Calc the ratio. double fRatio = 0; double fRatioFrame = 0; - OutputDevice* pOut = Application::GetDefaultDevice(); - vcl::Font aFont(pOut->GetFont()); + + VclPtr<VirtualDevice> pDevice = VclPtr<VirtualDevice>::Create(); + vcl::Font aFont = pDevice->GetFont(); aFont.SetFamilyName(sFont); + aFont.SetFontSize(Size(0, 96)); + pDevice->SetFont(aFont); Rectangle aBoundingRect; - pOut->GetTextBoundRect(aBoundingRect, rWatermark.GetText()); + pDevice->GetTextBoundRect(aBoundingRect, rWatermark.GetText()); if (aBoundingRect.GetWidth()) { - fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth(); - auto nTextWidth = pOut->GetTextWidth(rWatermark.GetText()); - if (nTextWidth) - { - fRatioFrame = aFont.GetFontSize().Height(); - fRatioFrame /= nTextWidth; - } + fRatio = (double)aBoundingRect.getHeight() / aBoundingRect.getWidth(); + } + auto nTextWidth = pDevice->GetTextWidth(rWatermark.GetText()); + if (nTextWidth) + { + fRatioFrame = pDevice->GetTextHeight(); + fRatioFrame /= nTextWidth; } // Calc the size. @@ -443,7 +446,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY); basegfx::B2DHomMatrix aTransformation; aTransformation.identity(); - aTransformation.scale(nWidth, nHeight); + aTransformation.scale(nWidth, nFrameHeight); aTransformation.rotate(F_PI180 * -1 * nAngle); drawing::HomogenMatrix3 aMatrix; aMatrix.Line1.Column1 = aTransformation.get(0, 0); @@ -471,13 +474,13 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, xPropertySet->setPropertyValue(UNO_NAME_OPAQUE, uno::makeAny(false)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT, uno::makeAny(false)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_AUTOGROWWIDTH, uno::makeAny(false)); - xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEHEIGHT, uno::makeAny(nHeight)); + xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEHEIGHT, uno::makeAny(nFrameHeight)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGHT)); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::makeAny(static_cast<sal_Int16>(text::RelOrientation::PAGE_PRINT_AREA))); xPropertySet->setPropertyValue(UNO_NAME_CHAR_FONT_NAME, uno::makeAny(sFont)); xPropertySet->setPropertyValue(UNO_NAME_CHAR_HEIGHT, uno::makeAny(WATERMARK_AUTO_SIZE)); - xPropertySet->setPropertyValue(UNO_NAME_TEXT_UPPERDIST, uno::makeAny(sal_uInt32(nFrameHeight - nHeight))); + xPropertySet->setPropertyValue(UNO_NAME_TEXT_UPPERDIST, uno::makeAny(sal_Int32(nFrameHeight - nHeight))); xPropertySet->setPropertyValue("Transformation", uno::makeAny(aMatrix)); xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::HoriOrientation::CENTER))); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT, uno::makeAny(static_cast<sal_Int16>(text::VertOrientation::CENTER))); |