[Libreoffice-commits] core.git: filter/source sw/qa sw/source
Szymon Kłos
szymon.klos at collabora.com
Sun Nov 5 19:53:37 UTC 2017
filter/source/msfilter/msdffimp.cxx | 8 ++++----
sw/qa/extras/ww8export/ww8export2.cxx | 6 +++++-
sw/source/core/edit/edfcol.cxx | 20 +++++++++++++++-----
3 files changed, 24 insertions(+), 10 deletions(-)
New commits:
commit 1e6abe31eb8f7c12c725f7e1267a7cedfcd3d157
Author: Szymon Kłos <szymon.klos at collabora.com>
Date: Thu Nov 2 17:22:03 2017 +0100
tdf#113037 create Watermark with correct ratio
Change-Id: I17ab8d98a618cff6e38dad344f4096dc520cce43
Reviewed-on: https://gerrit.libreoffice.org/44228
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index fdc3f1e3a5dd..1fc80da83cb8 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -4419,13 +4419,13 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
OutputDevice* pOut = Application::GetDefaultDevice();
vcl::Font aFont( pOut->GetFont() );
aFont.SetFamilyName( aFontName );
- auto nTextWidth = pOut->GetTextWidth( aObjectText );
+ tools::Rectangle aBoundingRect;
+ pOut->GetTextBoundRect( aBoundingRect, aObjectText );
OUString aObjName = GetPropertyString(DFF_Prop_wzName, rSt);
- if ( nTextWidth && aObjData.eShapeType == mso_sptTextPlainText && aObjName.match("PowerPlusWaterMarkObject"))
+ if ( aBoundingRect.GetWidth() && aObjData.eShapeType == mso_sptTextPlainText && aObjName.match( "PowerPlusWaterMarkObject" ) )
{
- fRatio = aFont.GetFontSize().Height();
- fRatio /= nTextWidth;
+ fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
sal_Int32 nNewHeight = fRatio * aObjData.aBoundRect.getWidth();
sal_Int32 nPaddingY = aObjData.aBoundRect.getHeight() - nNewHeight;
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)));
More information about the Libreoffice-commits
mailing list