[Libreoffice-commits] core.git: filter/source oox/source sw/qa sw/source

Szymon Kłos szymon.klos at collabora.com
Sat Dec 2 17:45:18 UTC 2017


 filter/source/msfilter/msdffimp.cxx        |   17 ++++++++++-------
 oox/source/vml/vmlshape.cxx                |   15 +++++++++------
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx |    3 ++-
 sw/source/core/edit/edfcol.cxx             |   29 ++++++++++++++++-------------
 4 files changed, 37 insertions(+), 27 deletions(-)

New commits:
commit 923ca4efe2095998e3da75c372cd7d716db9abb3
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Thu Nov 30 18:26:11 2017 +0100

    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 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 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 ea111d4c93cb..6e792d93157e 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>
@@ -1174,15 +1175,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)));


More information about the Libreoffice-commits mailing list