filter/source/msfilter/msdffimp.cxx | 17 ++++++++++------- oox/source/vml/vmlshape.cxx | 15 +++++++++------ sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 3 ++- sw/source/core/edit/edfcol.cxx | 29 ++++++++++++++++------------- 4 files changed, 37 insertions(+), 27 deletions(-)
New commits: commit b66435c3fcff5eb198f0037067294c1203ebcd76 Author: Szymon KÅos <szymon.k...@collabora.com> Date: Thu Nov 30 18:26:11 2017 +0100 tdf#113037 Unify Watermark in DOC & DOCX * use correct font for calculations Reviewed-on: https://gerrit.libreoffice.org/45698 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Szymon KÅos <szymon.k...@collabora.com> (cherry picked from commit 923ca4efe2095998e3da75c372cd7d716db9abb3) Change-Id: Idd370678c000bf22c460c3323bd55cd827ba7153 Reviewed-on: https://gerrit.libreoffice.org/45996 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 36a3f59c3787..b32c3d926f90 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -40,6 +40,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 @@ -4411,16 +4412,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 ); - 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 a9d31b26c82d..d82076315acb 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -22,6 +22,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> @@ -1134,15 +1135,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 ); - 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/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 9740bc954397..97a5098d2373 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -614,8 +614,9 @@ DECLARE_OOXMLEXPORT_TEST(testWatermarkSize, "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 4df109045209..1f14403f475b 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -397,21 +397,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); 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. @@ -443,7 +446,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); @@ -471,13 +474,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_THROUGHT)); 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)));
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits