[Libreoffice-commits] core.git: Branch 'private/tvajngerl/staging' - include/vcl vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 1 03:57:35 UTC 2021


Rebased ref, commits from common ancestor:
commit 4a36766b2cae049f4b51e0135a4519a793b98429
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Mar 31 19:13:17 2021 +0900
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Apr 1 12:56:55 2021 +0900

    vcl: move MapMode reading adn writing to TypeSerializer
    
    remove usage of ReadMapMode and WriteMapMode and add tests
    
    Change-Id: I40e1da8aea5c2171d9dbb6343fbf61912e5b3367

diff --git a/include/vcl/TypeSerializer.hxx b/include/vcl/TypeSerializer.hxx
index 7be2f54198e7..e85b25b1cfe3 100644
--- a/include/vcl/TypeSerializer.hxx
+++ b/include/vcl/TypeSerializer.hxx
@@ -50,6 +50,9 @@ public:
 
     void readGraphic(Graphic& rGraphic);
     void writeGraphic(const Graphic& rGraphic);
+
+    void readMapMode(MapMode& rMapMode);
+    void writeMapMode(MapMode const& rMapMode);
 };
 
 #endif
diff --git a/include/vcl/mapmod.hxx b/include/vcl/mapmod.hxx
index e6c96048c90c..9af61f8b7e69 100644
--- a/include/vcl/mapmod.hxx
+++ b/include/vcl/mapmod.hxx
@@ -59,20 +59,20 @@ public:
     MapMode&        operator=( MapMode&& rMapMode );
     bool            operator==( const MapMode& rMapMode ) const;
     bool            operator!=( const MapMode& rMapMode ) const
-                        { return !(MapMode::operator==( rMapMode )); }
+    {
+        return !(MapMode::operator==( rMapMode ));
+    }
     bool            IsDefault() const;
 
-    friend SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode );
-    friend SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode );
-
     // tdf#117984 needs to be thread-safe due to being used e.g. in Bitmaps
     // vcl::ScopedBitmapAccess in parallelized 3D renderer
     typedef o3tl::cow_wrapper< ImplMapMode, o3tl::ThreadSafeRefCountingPolicy > ImplType;
 
+    // If only the map unit is set.
+    bool IsSimple() const;
+
 private:
     ImplType        mpImplMapMode;
-
-    SAL_DLLPRIVATE bool IsSimple() const;
 };
 
 template<typename charT, typename traits>
diff --git a/vcl/qa/cppunit/TypeSerializerTest.cxx b/vcl/qa/cppunit/TypeSerializerTest.cxx
index f8de4e9ce3a2..5d7b72b0f560 100644
--- a/vcl/qa/cppunit/TypeSerializerTest.cxx
+++ b/vcl/qa/cppunit/TypeSerializerTest.cxx
@@ -24,6 +24,7 @@
 #include <comphelper/hash.hxx>
 #include <tools/vcompat.hxx>
 #include <comphelper/fileformat.h>
+#include <tools/fract.hxx>
 
 #include <vcl/TypeSerializer.hxx>
 
@@ -67,6 +68,7 @@ private:
     void testGraphic_Bitmap_NoGfxLink();
     void testGraphic_Animation();
     void testGraphic_GDIMetaFile();
+    void testMapMode();
 
     CPPUNIT_TEST_SUITE(TypeSerializerTest);
     CPPUNIT_TEST(testGradient);
@@ -74,6 +76,7 @@ private:
     CPPUNIT_TEST(testGraphic_Bitmap_NoGfxLink);
     CPPUNIT_TEST(testGraphic_Animation);
     CPPUNIT_TEST(testGraphic_GDIMetaFile);
+    CPPUNIT_TEST(testMapMode);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -345,6 +348,42 @@ void TypeSerializerTest::testGraphic_GDIMetaFile()
     }
 }
 
+void TypeSerializerTest::testMapMode()
+{
+    { // "simple" case - only map unit is set, IsSimple = true
+        MapMode aMapMode(MapUnit::Map100thMM);
+
+        SvMemoryStream aStream;
+        TypeSerializer aSerializer(aStream);
+        aSerializer.writeMapMode(aMapMode);
+        aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+        MapMode aReadMapMode;
+        aSerializer.readMapMode(aReadMapMode);
+        CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aReadMapMode.GetMapUnit());
+        CPPUNIT_ASSERT_EQUAL(true, aReadMapMode.IsSimple());
+    }
+    { // "complex" case - map unit, origin and scale are set, IsSimple = false
+        MapMode aMapMode(MapUnit::MapTwip, Point(5, 10), Fraction(1, 2), Fraction(2, 3));
+
+        SvMemoryStream aStream;
+        TypeSerializer aSerializer(aStream);
+        aSerializer.writeMapMode(aMapMode);
+        aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+        MapMode aReadMapMode;
+        aSerializer.readMapMode(aReadMapMode);
+        CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aReadMapMode.GetMapUnit());
+        CPPUNIT_ASSERT_EQUAL(tools::Long(5), aReadMapMode.GetOrigin().X());
+        CPPUNIT_ASSERT_EQUAL(tools::Long(10), aReadMapMode.GetOrigin().Y());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aReadMapMode.GetScaleX().GetNumerator());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadMapMode.GetScaleX().GetDenominator());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadMapMode.GetScaleY().GetNumerator());
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aReadMapMode.GetScaleY().GetDenominator());
+        CPPUNIT_ASSERT_EQUAL(false, aReadMapMode.IsSimple());
+    }
+}
+
 } // namespace
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TypeSerializerTest);
diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx
index 2b66d2d29395..5666497ce08f 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -1062,10 +1062,9 @@ bool GraphicDescriptor::ImpDetectSVM( SvStream& rStm, bool bExtendedInfo )
                 if( bExtendedInfo )
                 {
                     MapMode aMapMode;
-
                     rStm.SeekRel( 0x06 );
-                    ReadMapMode( rStm, aMapMode );
                     TypeSerializer aSerializer(rStm);
+                    aSerializer.readMapMode(aMapMode);
                     aSerializer.readSize(aLogSize);
                     aLogSize = OutputDevice::LogicToLogic( aLogSize, aMapMode, MapMode( MapUnit::Map100thMM ) );
                 }
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index fb354d7f3dd0..7f0609e01826 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -19,6 +19,7 @@
 
 #include <vcl/TypeSerializer.hxx>
 #include <tools/vcompat.hxx>
+#include <tools/fract.hxx>
 #include <sal/log.hxx>
 #include <comphelper/fileformat.h>
 #include <vcl/gdimtf.hxx>
@@ -109,7 +110,7 @@ void TypeSerializer::readGfxLink(GfxLink& rGfxLink)
         if (aCompat.GetVersion() >= 2)
         {
             readSize(aSize);
-            ReadMapMode(mrStream, aMapMode);
+            readMapMode(aMapMode);
             bMapAndSizeValid = true;
         }
     }
@@ -146,7 +147,7 @@ void TypeSerializer::writeGfxLink(const GfxLink& rGfxLink)
 
         // Version 2
         writeSize(rGfxLink.GetPrefSize());
-        WriteMapMode(mrStream, rGfxLink.GetPrefMapMode());
+        writeMapMode(rGfxLink.GetPrefMapMode());
     }
 
     if (rGfxLink.GetDataSize())
@@ -415,4 +416,37 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
     }
 }
 
+void TypeSerializer::readMapMode(MapMode& rMapMode)
+{
+    VersionCompatRead aCompat(mrStream);
+    sal_uInt16 nTmp16;
+    Point aOrigin;
+    Fraction aScaleX;
+    Fraction aScaleY;
+    bool bSimple;
+
+    mrStream.ReadUInt16(nTmp16);
+    MapUnit eUnit = static_cast<MapUnit>(nTmp16);
+    readPoint(aOrigin);
+    ReadFraction(mrStream, aScaleX);
+    ReadFraction(mrStream, aScaleY);
+    mrStream.ReadCharAsBool(bSimple);
+
+    if (bSimple)
+        rMapMode = MapMode(eUnit);
+    else
+        rMapMode = MapMode(eUnit, aOrigin, aScaleX, aScaleY);
+}
+
+void TypeSerializer::writeMapMode(MapMode const& rMapMode)
+{
+    VersionCompatWrite aCompat(mrStream, 1);
+
+    mrStream.WriteUInt16(sal_uInt16(rMapMode.GetMapUnit()));
+    writePoint(rMapMode.GetOrigin());
+    WriteFraction(mrStream, rMapMode.GetScaleX());
+    WriteFraction(mrStream, rMapMode.GetScaleY());
+    mrStream.WriteBool(rMapMode.IsSimple());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx
index 9d329439de80..7ef6c73ce47b 100644
--- a/vcl/source/gdi/gdimtf.cxx
+++ b/vcl/source/gdi/gdimtf.cxx
@@ -2667,8 +2667,8 @@ SvStream& ReadGDIMetaFile(SvStream& rIStm, GDIMetaFile& rGDIMetaFile, ImplMetaRe
             std::unique_ptr<VersionCompatRead> pCompat(new VersionCompatRead(rIStm));
 
             rIStm.ReadUInt32( nStmCompressMode );
-            ReadMapMode( rIStm, rGDIMetaFile.m_aPrefMapMode );
             TypeSerializer aSerializer(rIStm);
+            aSerializer.readMapMode(rGDIMetaFile.m_aPrefMapMode);
             aSerializer.readSize(rGDIMetaFile.m_aPrefSize);
             rIStm.ReadUInt32( nCount );
 
@@ -2752,8 +2752,8 @@ SvStream& GDIMetaFile::Write( SvStream& rOStm )
         VersionCompatWrite aCompat(rOStm, 1);
 
         rOStm.WriteUInt32(static_cast<sal_uInt32>(nStmCompressMode));
-        WriteMapMode(rOStm, m_aPrefMapMode);
         TypeSerializer aSerializer(rOStm);
+        aSerializer.writeMapMode(m_aPrefMapMode);
         aSerializer.writeSize(m_aPrefSize);
         rOStm.WriteUInt32(GetActionSize());
     } // VersionCompatWrite dtor writes stuff into the header
diff --git a/vcl/source/gdi/mapmod.cxx b/vcl/source/gdi/mapmod.cxx
index 2ce154ae08e3..925732a66e39 100644
--- a/vcl/source/gdi/mapmod.cxx
+++ b/vcl/source/gdi/mapmod.cxx
@@ -133,38 +133,6 @@ bool MapMode::IsDefault() const
     return mpImplMapMode.same_object(theGlobalDefault::get());
 }
 
-SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode )
-{
-    VersionCompatRead aCompat(rIStm);
-    sal_uInt16    nTmp16;
-
-    TypeSerializer aSerializer(rIStm);
-
-    rIStm.ReadUInt16( nTmp16 ); rMapMode.mpImplMapMode->meUnit = static_cast<MapUnit>(nTmp16);
-    aSerializer.readPoint(rMapMode.mpImplMapMode->maOrigin);
-    ReadFraction( rIStm, rMapMode.mpImplMapMode->maScaleX );
-    ReadFraction( rIStm, rMapMode.mpImplMapMode->maScaleY );
-    rIStm.ReadCharAsBool( rMapMode.mpImplMapMode->mbSimple );
-
-    return rIStm;
-}
-
-SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode )
-{
-    VersionCompatWrite aCompat(rOStm, 1);
-
-    TypeSerializer aSerializer(rOStm);
-
-    rOStm.WriteUInt16( static_cast<sal_uInt16>(rMapMode.mpImplMapMode->meUnit) );
-    aSerializer.writePoint(rMapMode.mpImplMapMode->maOrigin);
-    WriteFraction( rOStm, rMapMode.mpImplMapMode->maScaleX );
-    WriteFraction( rOStm, rMapMode.mpImplMapMode->maScaleY );
-    rOStm.WriteBool( rMapMode.mpImplMapMode->mbSimple );
-
-    return rOStm;
-}
-
-
 MapUnit MapMode::GetMapUnit() const { return mpImplMapMode->meUnit; }
 
 const Point& MapMode::GetOrigin() const { return mpImplMapMode->maOrigin; }
diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx
index 02fce9554f14..cc95892240d6 100644
--- a/vcl/source/gdi/metaact.cxx
+++ b/vcl/source/gdi/metaact.cxx
@@ -2735,13 +2735,15 @@ void MetaMapModeAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
 {
     MetaAction::Write(rOStm, pData);
     VersionCompatWrite aCompat(rOStm, 1);
-    WriteMapMode( rOStm, maMapMode );
+    TypeSerializer aSerializer(rOStm);
+    aSerializer.writeMapMode(maMapMode);
 }
 
 void MetaMapModeAction::Read( SvStream& rIStm, ImplMetaReadData* )
 {
     VersionCompatRead aCompat(rIStm);
-    ReadMapMode( rIStm, maMapMode );
+    TypeSerializer aSerializer(rIStm);
+    aSerializer.readMapMode(maMapMode);
 }
 
 MetaFontAction::MetaFontAction() :


More information about the Libreoffice-commits mailing list