diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-11-02 17:22:03 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2017-11-05 20:53:09 +0100 |
commit | 1e6abe31eb8f7c12c725f7e1267a7cedfcd3d157 (patch) | |
tree | 02a9ea7cf0da452330344a79ce25dcc05c5da727 /sw | |
parent | 1bacce999d7dad91b1f87baaf09b08e6b4629fad (diff) |
tdf#113037 create Watermark with correct ratio
Change-Id: I17ab8d98a618cff6e38dad344f4096dc520cce43
Reviewed-on: https://gerrit.libreoffice.org/44228
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ww8export/ww8export2.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/edit/edfcol.cxx | 20 |
2 files changed, 20 insertions, 6 deletions
diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index 94039067e58d..1c180173f11b 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -24,6 +24,7 @@ #include <ftninfo.hxx> #include <pagedesc.hxx> +#include <editeng/unoprnms.hxx> class Test : public SwModelTestBase { @@ -269,7 +270,10 @@ DECLARE_WW8EXPORT_TEST(testTdf91687, "tdf91687.doc") uno::Reference<drawing::XShape> xWatermark = getShape(1); uno::Reference<beans::XPropertySet> xWatermarkProperties(xWatermark, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL((sal_Int32)5172, xWatermark->getSize().Height); + 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)18105, xWatermark->getSize().Width); } diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 0e2fc36051bc..2b32ccfb9f0d 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -1307,14 +1307,22 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, // Calc the ratio. double fRatio = 0; + double fRatioFrame = 0; OutputDevice* pOut = Application::GetDefaultDevice(); vcl::Font aFont(pOut->GetFont()); aFont.SetFamilyName(sFont); - auto nTextWidth = pOut->GetTextWidth(rWatermark.GetText()); - if (nTextWidth) + + tools::Rectangle aBoundingRect; + pOut->GetTextBoundRect(aBoundingRect, rWatermark.GetText()); + if (aBoundingRect.GetWidth()) { - fRatio = aFont.GetFontSize().Height(); - fRatio /= nTextWidth; + fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth(); + auto nTextWidth = pOut->GetTextWidth(rWatermark.GetText()); + if (nTextWidth) + { + fRatioFrame = aFont.GetFontSize().Height(); + fRatioFrame /= nTextWidth; + } } // Calc the size. @@ -1339,7 +1347,8 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, xPageStyle->getPropertyValue(UNO_NAME_BOTTOM_MARGIN) >>= nBottomMargin; nWidth = aSize.Height - nTopMargin - nBottomMargin; } - sal_Int32 nHeight = nWidth * fRatio; + sal_Int32 nHeight = fRatio * nWidth; + sal_Int32 nFrameHeight = fRatioFrame * nWidth; // Create and insert the shape. uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY); @@ -1379,6 +1388,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, 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("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))); |