summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-11-02 17:22:03 +0100
committerAndras Timar <andras.timar@collabora.com>2017-12-07 12:53:10 +0100
commitfec53ea4c33b012ef76d971d0b154d766c8e5759 (patch)
tree94985498aff57596914c31ce769bfaf7cf62eb39
parent0f685ee5a0913cab5826eec737f25328fabf256d (diff)
tdf#113037 create Watermark with correct ratio
Reviewed-on: https://gerrit.libreoffice.org/44228 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> (cherry picked from commit 1e6abe31eb8f7c12c725f7e1267a7cedfcd3d157) Change-Id: I17ab8d98a618cff6e38dad344f4096dc520cce43 Reviewed-on: https://gerrit.libreoffice.org/45994 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--filter/source/msfilter/msdffimp.cxx8
-rw-r--r--sw/qa/extras/ww8export/ww8export2.cxx6
-rw-r--r--sw/source/core/edit/edfcol.cxx20
3 files changed, 24 insertions, 10 deletions
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index 98427c6ebab6..36a3f59c3787 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -4414,13 +4414,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 );
+ 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 fb58fbcb47dc..5ef42cae4886 100644
--- a/sw/qa/extras/ww8export/ww8export2.cxx
+++ b/sw/qa/extras/ww8export/ww8export2.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/text/VertOrientation.hpp>
#include <pagedesc.hxx>
+#include <editeng/unoprnms.hxx>
class Test : public SwModelTestBase
{
@@ -112,7 +113,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 2201ada112c3..4df109045209 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -396,14 +396,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)
+
+ 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.
@@ -428,7 +436,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);
@@ -468,6 +477,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)));