From 1aca81256407be27fd4a7e027e27c51486c2dc31 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Thu, 7 Dec 2017 16:09:47 +0100 Subject: tdf#114308 Export Watermark size as is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactoring * removed size hack * export/import "trim" attribute * DOC: export set of parameters to fit shape & frame Change-Id: Ib00654626ae1e10ac5110d22eada7528e03357e7 Reviewed-on: https://gerrit.libreoffice.org/46036 Tested-by: Jenkins Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/46154 Reviewed-by: Andras Timar Tested-by: Andras Timar --- sw/qa/extras/ooxmlexport/data/tdf114308.docx | Bin 0 -> 21487 bytes sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 21 ++++++++++++++++----- sw/qa/extras/ww8export/ww8export2.cxx | 6 +----- sw/source/core/edit/edfcol.cxx | 17 ++++------------- sw/source/filter/ww8/wrtw8esh.cxx | 10 ---------- 5 files changed, 21 insertions(+), 33 deletions(-) create mode 100755 sw/qa/extras/ooxmlexport/data/tdf114308.docx (limited to 'sw') diff --git a/sw/qa/extras/ooxmlexport/data/tdf114308.docx b/sw/qa/extras/ooxmlexport/data/tdf114308.docx new file mode 100755 index 000000000000..0796200fc5f4 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf114308.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 97a5098d2373..8d125bea4910 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -607,14 +607,25 @@ DECLARE_OOXMLEXPORT_TEST(testWatermarkSize, "watermark.docx") uno::Reference xShape(getShape(1), uno::UNO_QUERY); uno::Reference xPropertySet(xShape, uno::UNO_QUERY); - sal_Int32 nTotalHeight = 0; - xPropertySet->getPropertyValue(UNO_NAME_TEXT_UPPERDIST) >>= nTotalHeight; - nTotalHeight += xShape->getSize().Height; + sal_Int32 nHeight = xShape->getSize().Height; // Rounding errors - sal_Int32 nDifference = 5198 - nTotalHeight; + sal_Int32 nDifference = 5150 - nHeight; std::stringstream ss; - ss << "Difference: " << nDifference << " TotalHeight: " << nTotalHeight; + ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); + CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); +} + +DECLARE_OOXMLEXPORT_TEST(testWatermarkTrim, "tdf114308.docx") +{ + uno::Reference xShape(getShape(1), uno::UNO_QUERY); + + // Rounding errors + sal_Int32 nHeight = xShape->getSize().Height; + sal_Int32 nDifference = 8729 - nHeight; + std::stringstream ss; + ss << "Difference: " << nDifference << " TotalHeight: " << nHeight; CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4); CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference >= -4); } diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index 5ef42cae4886..0f2ed521d6d0 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -111,12 +111,8 @@ DECLARE_WW8EXPORT_TEST(testTdf91687, "tdf91687.doc") { // Exported Watermarks were resized uno::Reference xWatermark = getShape(1); - uno::Reference xWatermarkProperties(xWatermark, uno::UNO_QUERY); - sal_Int32 nHeight = 0; - xWatermarkProperties->getPropertyValue(UNO_NAME_TEXT_UPPERDIST) >>= nHeight; - - CPPUNIT_ASSERT_EQUAL((sal_Int32)5172, xWatermark->getSize().Height + nHeight); + CPPUNIT_ASSERT_EQUAL((sal_Int32)5172, xWatermark->getSize().Height); CPPUNIT_ASSERT_EQUAL((sal_Int32)18105, xWatermark->getSize().Width); } diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index e8c4c6bc6c04..ce41b3e7a064 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -396,7 +396,6 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, // Calc the ratio. double fRatio = 0; - double fRatioFrame = 0; VclPtr pDevice = VclPtr::Create(); vcl::Font aFont = pDevice->GetFont(); @@ -404,17 +403,11 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, aFont.SetFontSize(Size(0, 96)); pDevice->SetFont(aFont); - Rectangle aBoundingRect; - pDevice->GetTextBoundRect(aBoundingRect, rWatermark.GetText()); - if (aBoundingRect.GetWidth()) - { - fRatio = (double)aBoundingRect.getHeight() / aBoundingRect.getWidth(); - } auto nTextWidth = pDevice->GetTextWidth(rWatermark.GetText()); if (nTextWidth) { - fRatioFrame = pDevice->GetTextHeight(); - fRatioFrame /= nTextWidth; + fRatio = pDevice->GetTextHeight(); + fRatio /= nTextWidth; } // Calc the size. @@ -440,13 +433,12 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, nWidth = aSize.Height - nTopMargin - nBottomMargin; } sal_Int32 nHeight = fRatio * nWidth; - sal_Int32 nFrameHeight = fRatioFrame * nWidth; // Create and insert the shape. uno::Reference xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY); basegfx::B2DHomMatrix aTransformation; aTransformation.identity(); - aTransformation.scale(nWidth, nFrameHeight); + aTransformation.scale(nWidth, nHeight); aTransformation.rotate(F_PI180 * -1 * nAngle); drawing::HomogenMatrix3 aMatrix; aMatrix.Line1.Column1 = aTransformation.get(0, 0); @@ -473,14 +465,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(nFrameHeight)); + xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEHEIGHT, uno::makeAny(nHeight)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_MINFRAMEWIDTH, uno::makeAny(nWidth)); xPropertySet->setPropertyValue(UNO_NAME_TEXT_WRAP, uno::makeAny(text::WrapTextMode_THROUGHT)); xPropertySet->setPropertyValue(UNO_NAME_HORI_ORIENT_RELATION, uno::makeAny(static_cast(text::RelOrientation::PAGE_PRINT_AREA))); xPropertySet->setPropertyValue(UNO_NAME_VERT_ORIENT_RELATION, uno::makeAny(static_cast(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_Int32(nFrameHeight - nHeight))); xPropertySet->setPropertyValue("Transformation", uno::makeAny(aMatrix)); uno::Reference xTextRange(xShape, uno::UNO_QUERY); diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index 160616816a0a..9cb319a9ef52 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -690,16 +690,6 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const if (pObj) { aRect = pObj->GetLogicRect(); - - // We have to export Watermark original size with padding - if (pObj->GetName().match("PowerPlusWaterMarkObject")) - { - const SfxItemSet& rSet = pObj->GetMergedItemSet(); - long nHeight = aRect.GetHeight(); - if (const SdrMetricItem* pItem = static_cast(rSet.GetItem(SDRATTR_TEXT_UPPERDIST))) - nHeight += pItem->GetValue(); - aRect.SetSize(Size(aRect.GetWidth(), nHeight)); - } } } -- cgit