[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/Library_vcl.mk vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 16 11:20:09 UTC 2019


 include/vcl/gradient.hxx          |    3 -
 vcl/Library_vcl.mk                |    1 
 vcl/inc/TypeSerializer.hxx        |   38 ++++++++++++++++++
 vcl/source/gdi/TypeSerializer.cxx |   80 ++++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/gradient.cxx       |   41 -------------------
 vcl/source/gdi/metaact.cxx        |   20 ++++++---
 vcl/source/gdi/svmconverter.cxx   |    7 ++-
 vcl/source/gdi/wall.cxx           |   14 ++++--
 8 files changed, 148 insertions(+), 56 deletions(-)

New commits:
commit c7ca124efd08097a1005ea56773d4def87efebcb
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Sep 13 16:29:07 2019 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Sep 16 13:19:28 2019 +0200

    move WriteGradient and ReadGradient to the TypeSerializer class
    
    Change-Id: I40f72470c2a5a4a9ffff45ccc3295e7a8f1f3584
    Reviewed-on: https://gerrit.libreoffice.org/78876
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/gradient.hxx b/include/vcl/gradient.hxx
index b3b2d1a9abef..92facb33dd19 100644
--- a/include/vcl/gradient.hxx
+++ b/include/vcl/gradient.hxx
@@ -103,9 +103,6 @@ public:
     bool            operator==( const Gradient& rGradient ) const;
     bool            operator!=( const Gradient& rGradient ) const
                         { return !(Gradient::operator==( rGradient )); }
-
-    friend VCL_DLLPUBLIC SvStream& ReadGradient( SvStream& rIStm, Gradient& rGradient );
-    friend VCL_DLLPUBLIC SvStream& WriteGradient( SvStream& rOStm, const Gradient& rGradient );
 };
 
 #endif // INCLUDED_VCL_GRADIENT_HXX
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index c33dfbdbd987..0ebd4dd35c64 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -314,6 +314,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/gdi/wall \
     vcl/source/gdi/scrptrun \
     vcl/source/gdi/CommonSalLayout \
+    vcl/source/gdi/TypeSerializer \
     vcl/source/graphic/GraphicLoader \
     vcl/source/graphic/GraphicObject \
     vcl/source/graphic/GraphicObject2 \
diff --git a/vcl/inc/TypeSerializer.hxx b/vcl/inc/TypeSerializer.hxx
new file mode 100644
index 000000000000..99d4609d5d2a
--- /dev/null
+++ b/vcl/inc/TypeSerializer.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_TYPESERIALIZER_HXX
+#define INCLUDED_VCL_INC_TYPESERIALIZER_HXX
+
+#include <vcl/dllapi.h>
+#include <tools/GenericTypeSerializer.hxx>
+#include <vcl/gradient.hxx>
+
+class VCL_DLLPUBLIC TypeSerializer : public tools::GenericTypeSerializer
+{
+public:
+    TypeSerializer(SvStream& rStream);
+
+    void readGradient(Gradient& rGradient);
+    void writeGradient(Gradient& rGradient);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
new file mode 100644
index 000000000000..264a25096756
--- /dev/null
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <TypeSerializer.hxx>
+#include <tools/vcompat.hxx>
+
+TypeSerializer::TypeSerializer(SvStream& rStream)
+    : GenericTypeSerializer(rStream)
+{
+}
+
+void TypeSerializer::readGradient(Gradient& rGradient)
+{
+    VersionCompat aCompat(mrStream, StreamMode::READ);
+
+    sal_uInt16 nStyle;
+    Color aStartColor;
+    Color aEndColor;
+    sal_uInt16 nAngle;
+    sal_uInt16 nBorder;
+    sal_uInt16 nOffsetX;
+    sal_uInt16 nOffsetY;
+    sal_uInt16 nIntensityStart;
+    sal_uInt16 nIntensityEnd;
+    sal_uInt16 nStepCount;
+
+    mrStream.ReadUInt16(nStyle);
+    readColor(aStartColor);
+    readColor(aEndColor);
+    mrStream.ReadUInt16(nAngle);
+    mrStream.ReadUInt16(nBorder);
+    mrStream.ReadUInt16(nOffsetX);
+    mrStream.ReadUInt16(nOffsetY);
+    mrStream.ReadUInt16(nIntensityStart);
+    mrStream.ReadUInt16(nIntensityEnd);
+    mrStream.ReadUInt16(nStepCount);
+
+    rGradient.SetStyle(static_cast<GradientStyle>(nStyle));
+    rGradient.SetStartColor(aStartColor);
+    rGradient.SetEndColor(aEndColor);
+    rGradient.SetAngle(nAngle);
+    rGradient.SetBorder(nBorder);
+    rGradient.SetOfsX(nOffsetX);
+    rGradient.SetOfsY(nOffsetY);
+    rGradient.SetStartIntensity(nIntensityStart);
+    rGradient.SetEndIntensity(nIntensityEnd);
+    rGradient.SetSteps(nStepCount);
+}
+
+void TypeSerializer::writeGradient(Gradient& rGradient)
+{
+    VersionCompat aCompat(mrStream, StreamMode::WRITE, 1);
+
+    mrStream.WriteUInt16(static_cast<sal_uInt16>(rGradient.GetStyle()));
+    writeColor(rGradient.GetStartColor());
+    writeColor(rGradient.GetEndColor());
+    mrStream.WriteUInt16(rGradient.GetAngle());
+    mrStream.WriteUInt16(rGradient.GetBorder());
+    mrStream.WriteUInt16(rGradient.GetOfsX());
+    mrStream.WriteUInt16(rGradient.GetOfsY());
+    mrStream.WriteUInt16(rGradient.GetStartIntensity());
+    mrStream.WriteUInt16(rGradient.GetEndIntensity());
+    mrStream.WriteUInt16(rGradient.GetSteps());
+}
diff --git a/vcl/source/gdi/gradient.cxx b/vcl/source/gdi/gradient.cxx
index 4c13bb423134..1c79d6c9fc7f 100644
--- a/vcl/source/gdi/gradient.cxx
+++ b/vcl/source/gdi/gradient.cxx
@@ -21,6 +21,7 @@
 #include <tools/vcompat.hxx>
 #include <tools/gen.hxx>
 #include <tools/GenericTypeSerializer.hxx>
+#include <TypeSerializer.hxx>
 #include <vcl/gradient.hxx>
 
 Impl_Gradient::Impl_Gradient() :
@@ -219,44 +220,4 @@ bool Gradient::operator==( const Gradient& rGradient ) const
     return mpImplGradient == rGradient.mpImplGradient;
 }
 
-SvStream& ReadGradient( SvStream& rIStm, Gradient& rGradient )
-{
-    VersionCompat   aCompat( rIStm, StreamMode::READ );
-    sal_uInt16          nTmp16;
-
-    rIStm.ReadUInt16( nTmp16 ); rGradient.mpImplGradient->meStyle = static_cast<GradientStyle>(nTmp16);
-
-    tools::GenericTypeSerializer aSerializer(rIStm);
-    aSerializer.readColor(rGradient.mpImplGradient->maStartColor);
-    aSerializer.readColor(rGradient.mpImplGradient->maEndColor);
-    rIStm.ReadUInt16( rGradient.mpImplGradient->mnAngle )
-         .ReadUInt16( rGradient.mpImplGradient->mnBorder )
-         .ReadUInt16( rGradient.mpImplGradient->mnOfsX )
-         .ReadUInt16( rGradient.mpImplGradient->mnOfsY )
-         .ReadUInt16( rGradient.mpImplGradient->mnIntensityStart )
-         .ReadUInt16( rGradient.mpImplGradient->mnIntensityEnd )
-         .ReadUInt16( rGradient.mpImplGradient->mnStepCount );
-
-    return rIStm;
-}
-
-SvStream& WriteGradient( SvStream& rOStm, const Gradient& rGradient )
-{
-    VersionCompat aCompat( rOStm, StreamMode::WRITE, 1 );
-
-    rOStm.WriteUInt16( static_cast<sal_uInt16>(rGradient.mpImplGradient->meStyle) );
-    tools::GenericTypeSerializer aSerializer(rOStm);
-    aSerializer.writeColor(rGradient.mpImplGradient->maStartColor);
-    aSerializer.writeColor(rGradient.mpImplGradient->maEndColor);
-    rOStm.WriteUInt16( rGradient.mpImplGradient->mnAngle )
-         .WriteUInt16( rGradient.mpImplGradient->mnBorder )
-         .WriteUInt16( rGradient.mpImplGradient->mnOfsX )
-         .WriteUInt16( rGradient.mpImplGradient->mnOfsY )
-         .WriteUInt16( rGradient.mpImplGradient->mnIntensityStart )
-         .WriteUInt16( rGradient.mpImplGradient->mnIntensityEnd )
-         .WriteUInt16( rGradient.mpImplGradient->mnStepCount );
-
-    return rOStm;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx
index 63ab44c607bf..a59824d8841b 100644
--- a/vcl/source/gdi/metaact.cxx
+++ b/vcl/source/gdi/metaact.cxx
@@ -29,6 +29,7 @@
 #include <vcl/metaact.hxx>
 #include <vcl/graphictools.hxx>
 #include <unotools/fontdefs.hxx>
+#include <TypeSerializer.hxx>
 
 namespace
 {
@@ -1987,14 +1988,16 @@ void MetaGradientAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
     MetaAction::Write(rOStm, pData);
     VersionCompat aCompat(rOStm, StreamMode::WRITE, 1);
     WriteRectangle( rOStm, maRect );
-    WriteGradient( rOStm, maGradient );
+    TypeSerializer aSerializer(rOStm);
+    aSerializer.writeGradient(maGradient);
 }
 
 void MetaGradientAction::Read( SvStream& rIStm, ImplMetaReadData* )
 {
     VersionCompat aCompat(rIStm, StreamMode::READ);
     ReadRectangle( rIStm, maRect );
-    ReadGradient( rIStm, maGradient );
+    TypeSerializer aSerializer(rIStm);
+    aSerializer.readGradient(maGradient);
 }
 
 MetaGradientExAction::MetaGradientExAction() :
@@ -2044,14 +2047,16 @@ void MetaGradientExAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
     maPolyPoly.AdaptiveSubdivide(aNoCurvePolyPolygon);
 
     WritePolyPolygon( rOStm, aNoCurvePolyPolygon );
-    WriteGradient( rOStm, maGradient );
+    TypeSerializer aSerializer(rOStm);
+    aSerializer.writeGradient(maGradient);
 }
 
 void MetaGradientExAction::Read( SvStream& rIStm, ImplMetaReadData* )
 {
     VersionCompat aCompat(rIStm, StreamMode::READ);
     ReadPolyPolygon( rIStm, maPolyPoly );
-    ReadGradient( rIStm, maGradient );
+    TypeSerializer aSerializer(rIStm);
+    aSerializer.readGradient(maGradient);
 }
 
 MetaHatchAction::MetaHatchAction() :
@@ -2947,7 +2952,9 @@ void MetaFloatTransparentAction::Write( SvStream& rOStm, ImplMetaWriteData* pDat
     maMtf.Write( rOStm );
     WritePair( rOStm,  maPoint );
     WritePair( rOStm, maSize );
-    WriteGradient( rOStm, maGradient );
+
+    TypeSerializer aSerializer(rOStm);
+    aSerializer.writeGradient(maGradient);
 }
 
 void MetaFloatTransparentAction::Read(SvStream& rIStm, ImplMetaReadData* pData)
@@ -2956,7 +2963,8 @@ void MetaFloatTransparentAction::Read(SvStream& rIStm, ImplMetaReadData* pData)
     ReadGDIMetaFile(rIStm, maMtf, pData);
     ReadPair( rIStm, maPoint );
     ReadPair( rIStm, maSize );
-    ReadGradient( rIStm, maGradient );
+    TypeSerializer aSerializer(rIStm);
+    aSerializer.readGradient(maGradient);
 }
 
 MetaEPSAction::MetaEPSAction() :
diff --git a/vcl/source/gdi/svmconverter.cxx b/vcl/source/gdi/svmconverter.cxx
index 6611d8fa5d2e..1c8d7af76324 100644
--- a/vcl/source/gdi/svmconverter.cxx
+++ b/vcl/source/gdi/svmconverter.cxx
@@ -30,6 +30,7 @@
 #include <sal/log.hxx>
 #include <osl/diagnose.h>
 
+#include <TypeSerializer.hxx>
 #include <svmconverter.hxx>
 #include <memory>
 #include <stack>
@@ -1080,7 +1081,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                 ReadGDIMetaFile( rIStm, aMtf );
                 ReadPair( rIStm, aPos );
                 ReadPair( rIStm, aSize );
-                ReadGradient( rIStm, aGradient );
+                TypeSerializer aSerializer(rIStm);
+                aSerializer.readGradient(aGradient);
                 rIStm.ReadInt32( nFollowingActionCount );
                 ImplSkipActions( rIStm, nFollowingActionCount );
                 rMtf.AddAction( new MetaFloatTransparentAction( aMtf, aPos, aSize, aGradient ) );
@@ -1169,7 +1171,8 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
                 sal_Int32 nFollowingActionCount(0);
 
                 ReadPolyPolygon( rIStm, aPolyPoly );
-                ReadGradient( rIStm, aGradient );
+                TypeSerializer aSerializer(rIStm);
+                aSerializer.readGradient(aGradient);
                 rIStm.ReadInt32( nFollowingActionCount );
                 ImplSkipActions( rIStm, nFollowingActionCount );
                 rMtf.AddAction( new MetaGradientExAction( aPolyPoly, aGradient ) );
diff --git a/vcl/source/gdi/wall.cxx b/vcl/source/gdi/wall.cxx
index fb0efd16ffa3..81f7bc61bb4d 100644
--- a/vcl/source/gdi/wall.cxx
+++ b/vcl/source/gdi/wall.cxx
@@ -28,6 +28,8 @@
 #include <vcl/dibtools.hxx>
 #include <vcl/settings.hxx>
 
+#include <TypeSerializer.hxx>
+
 ImplWallpaper::ImplWallpaper() :
     maColor( COL_TRANSPARENT ), meStyle( WallpaperStyle::NONE )
 {
@@ -62,7 +64,7 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
     rImplWallpaper.mpBitmap.reset();
 
     // version 1
-    tools::GenericTypeSerializer aSerializer(rIStm);
+    TypeSerializer aSerializer(rIStm);
     aSerializer.readColor(rImplWallpaper.maColor);
     sal_uInt16 nTmp16(0);
     rIStm.ReadUInt16(nTmp16);
@@ -84,7 +86,7 @@ SvStream& ReadImplWallpaper( SvStream& rIStm, ImplWallpaper& rImplWallpaper )
         if( bGrad )
         {
             rImplWallpaper.mpGradient = std::make_unique<Gradient>();
-            ReadGradient( rIStm, *rImplWallpaper.mpGradient );
+            aSerializer.readGradient(*rImplWallpaper.mpGradient);
         }
 
         if( bBmp )
@@ -112,7 +114,7 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
     bool            bDummy = false;
 
     // version 1
-    tools::GenericTypeSerializer aSerializer(rOStm);
+    TypeSerializer aSerializer(rOStm);
     aSerializer.writeColor(rImplWallpaper.maColor);
 
     rOStm.WriteUInt16( static_cast<sal_uInt16>(rImplWallpaper.meStyle) );
@@ -123,8 +125,10 @@ SvStream& WriteImplWallpaper( SvStream& rOStm, const ImplWallpaper& rImplWallpap
     if( bRect )
         WriteRectangle( rOStm, *rImplWallpaper.mpRect );
 
-    if( bGrad )
-        WriteGradient( rOStm, *rImplWallpaper.mpGradient );
+    if (bGrad)
+    {
+        aSerializer.writeGradient(*rImplWallpaper.mpGradient);
+    }
 
     if( bBmp )
         WriteDIBBitmapEx(*rImplWallpaper.mpBitmap, rOStm);


More information about the Libreoffice-commits mailing list