summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-11-30 18:26:11 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2017-12-05 07:46:01 +0100
commit17a416759291426999d5b79eceeeb729ca95bc93 (patch)
treef46729c8025c16f86ecd1e0fa731aac840defbfb
parent29228e83df009cf76ac819ed024527be1092f065 (diff)
tdf#113037 Unify Watermark in DOC & DOCX
* use correct font for calculations Change-Id: Idd370678c000bf22c460c3323bd55cd827ba7153 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) Reviewed-on: https://gerrit.libreoffice.org/45824
-rw-r--r--filter/source/msfilter/msdffimp.cxx17
-rw-r--r--oox/source/vml/vmlshape.cxx15
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport10.cxx3
-rw-r--r--sw/source/core/edit/edfcol.cxx29
4 files changed, 37 insertions, 27 deletions
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index c2f77d7beb2b..38d7e5ed9e8d 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -41,6 +41,7 @@
#include <vcl/cvtgrf.hxx>
#include <vcl/wmf.hxx>
#include <vcl/settings.hxx>
+#include <vcl/vclptr.hxx>
#include "viscache.hxx"
// SvxItem-Mapping. Is needed to successfully include the SvxItem-Header
@@ -4424,16 +4425,18 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
aSet.Put(makeSdrTextAutoGrowWidthItem(false));
double fRatio = 0;
- OutputDevice* pOut = Application::GetDefaultDevice();
- vcl::Font aFont( pOut->GetFont() );
+ VclPtr<VirtualDevice> pDevice = VclPtr<VirtualDevice>::Create();
+ vcl::Font aFont = pDevice->GetFont();
aFont.SetFamilyName( aFontName );
- tools::Rectangle aBoundingRect;
- pOut->GetTextBoundRect( aBoundingRect, aObjectText );
+ aFont.SetFontSize( Size( 0, 96 ) );
+ pDevice->SetFont( aFont );
- OUString aObjName = GetPropertyString(DFF_Prop_wzName, rSt);
- if ( aBoundingRect.GetWidth() && aObjData.eShapeType == mso_sptTextPlainText && aObjName.match( "PowerPlusWaterMarkObject" ) )
+ auto nTextWidth = pDevice->GetTextWidth( aObjectText );
+ OUString aObjName = GetPropertyString( DFF_Prop_wzName, rSt );
+ if ( nTextWidth && aObjData.eShapeType == mso_sptTextPlainText
+ && aObjName.match( "PowerPlusWaterMarkObject" ) )
{
- fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
+ fRatio = (double)pDevice->GetTextHeight() / nTextWidth;
sal_Int32 nNewHeight = fRatio * aObjData.aBoundRect.getWidth();
sal_Int32 nPaddingY = aObjData.aBoundRect.getHeight() - nNewHeight;
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index f9fa58669c35..3a0736d8c53f 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -24,6 +24,7 @@
#include <oox/vml/vmlshape.hxx>
#include <vcl/wmf.hxx>
+#include <vcl/virdev.hxx>
#include <com/sun/star/beans/PropertyValues.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -1172,15 +1173,17 @@ sal_Int32 lcl_correctWatermarkRect( awt::Rectangle& rShapeRect, const OUString&
{
sal_Int32 nPaddingY = 0;
double fRatio = 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 );
- tools::Rectangle aBoundingRect;
- pOut->GetTextBoundRect( aBoundingRect, sText );
- if( aBoundingRect.GetWidth() )
+ auto nTextWidth = pDevice->GetTextWidth( sText );
+ if( nTextWidth )
{
- fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
+ fRatio = pDevice->GetTextHeight();
+ fRatio /= nTextWidth;
sal_Int32 nNewHeight = fRatio * rShapeRect.Width;
nPaddingY = rShapeRect.Height - nNewHeight;
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 24e57e21c369..9c29fd434dd9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1759,8 +1759,9 @@ DECLARE_OOXMLEXPORT_TEST(testWatermark, "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 61a4c15cc939..a4d4ddb0b00f 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -1464,21 +1464,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);
tools::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.
@@ -1510,7 +1513,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);
@@ -1538,13 +1541,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_THROUGH));
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)));