[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Thu Mar 5 07:39:16 UTC 2020
include/vcl/gfxlink.hxx | 4 --
vcl/inc/TypeSerializer.hxx | 4 ++
vcl/source/gdi/TypeSerializer.cxx | 71 ++++++++++++++++++++++++++++++++++++++
vcl/source/gdi/gfxlink.cxx | 71 --------------------------------------
vcl/source/gdi/impgraph.cxx | 7 ++-
vcl/source/gdi/metaact.cxx | 4 +-
6 files changed, 82 insertions(+), 79 deletions(-)
New commits:
commit bdfd0feefe3785e1ea68bf1f1f987147c8fe9335
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Mar 4 16:51:27 2020 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Mar 5 08:38:40 2020 +0100
vcl: move read and write to/from GfxLink to TypeSerializer
Change-Id: Ie99d00ea54296f5f3a909ade7115d9a9251f688e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89983
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx
index 33f1321b6953..0376149f7025 100644
--- a/include/vcl/gfxlink.hxx
+++ b/include/vcl/gfxlink.hxx
@@ -103,10 +103,6 @@ public:
bool ExportNative( SvStream& rOStream ) const;
bool IsEMF() const; // WMF & EMF stored under the same type (NativeWmf)
-public:
-
- friend SvStream& WriteGfxLink( SvStream& rOStream, const GfxLink& rGfxLink );
- friend SvStream& ReadGfxLink( SvStream& rIStream, GfxLink& rGfxLink );
};
#endif
diff --git a/vcl/inc/TypeSerializer.hxx b/vcl/inc/TypeSerializer.hxx
index 861da5681178..76842aeee3d2 100644
--- a/vcl/inc/TypeSerializer.hxx
+++ b/vcl/inc/TypeSerializer.hxx
@@ -23,6 +23,7 @@
#include <vcl/dllapi.h>
#include <tools/GenericTypeSerializer.hxx>
#include <vcl/gradient.hxx>
+#include <vcl/gfxlink.hxx>
class TypeSerializer : public tools::GenericTypeSerializer
{
@@ -31,6 +32,9 @@ public:
void readGradient(Gradient& rGradient);
void writeGradient(const Gradient& rGradient);
+
+ void readGfxLink(GfxLink& rGfxLink);
+ void writeGfxLink(const GfxLink& rGfxLink);
};
#endif
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index a54f3558c7ef..ad2f1400da85 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -19,6 +19,7 @@
#include <TypeSerializer.hxx>
#include <tools/vcompat.hxx>
+#include <sal/log.hxx>
TypeSerializer::TypeSerializer(SvStream& rStream)
: GenericTypeSerializer(rStream)
@@ -78,3 +79,73 @@ void TypeSerializer::writeGradient(const Gradient& rGradient)
mrStream.WriteUInt16(rGradient.GetEndIntensity());
mrStream.WriteUInt16(rGradient.GetSteps());
}
+
+void TypeSerializer::readGfxLink(GfxLink& rGfxLink)
+{
+ sal_uInt16 nType = 0;
+ sal_uInt32 nDataSize = 0;
+ sal_uInt32 nUserId = 0;
+
+ Size aSize;
+ MapMode aMapMode;
+ bool bMapAndSizeValid = false;
+
+ {
+ VersionCompat aCompat(mrStream, StreamMode::READ);
+
+ // Version 1
+ mrStream.ReadUInt16(nType);
+ mrStream.ReadUInt32(nDataSize);
+ mrStream.ReadUInt32(nUserId);
+
+ if (aCompat.GetVersion() >= 2)
+ {
+ readSize(aSize);
+ ReadMapMode(mrStream, aMapMode);
+ bMapAndSizeValid = true;
+ }
+ }
+
+ auto nRemainingData = mrStream.remainingSize();
+ if (nDataSize > nRemainingData)
+ {
+ SAL_WARN("vcl", "graphic link stream is smaller than requested size");
+ nDataSize = nRemainingData;
+ }
+
+ std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nDataSize]);
+ mrStream.ReadBytes(pBuffer.get(), nDataSize);
+
+ rGfxLink = GfxLink(std::move(pBuffer), nDataSize, static_cast<GfxLinkType>(nType));
+ rGfxLink.SetUserId(nUserId);
+
+ if (bMapAndSizeValid)
+ {
+ rGfxLink.SetPrefSize(aSize);
+ rGfxLink.SetPrefMapMode(aMapMode);
+ }
+}
+
+void TypeSerializer::writeGfxLink(const GfxLink& rGfxLink)
+{
+ {
+ VersionCompat aCompat(mrStream, StreamMode::WRITE, 2);
+
+ // Version 1
+ mrStream.WriteUInt16(sal_uInt16(rGfxLink.GetType()));
+ mrStream.WriteUInt32(rGfxLink.GetDataSize());
+ mrStream.WriteUInt32(rGfxLink.GetUserId());
+
+ // Version 2
+ writeSize(rGfxLink.GetPrefSize());
+ WriteMapMode(mrStream, rGfxLink.GetPrefMapMode());
+ }
+
+ if (rGfxLink.GetDataSize())
+ {
+ if (rGfxLink.GetData())
+ mrStream.WriteBytes(rGfxLink.GetData(), rGfxLink.GetDataSize());
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/gfxlink.cxx b/vcl/source/gdi/gfxlink.cxx
index 186961c2ac7d..785d86d3be7f 100644
--- a/vcl/source/gdi/gfxlink.cxx
+++ b/vcl/source/gdi/gfxlink.cxx
@@ -24,8 +24,6 @@
#include <vcl/gfxlink.hxx>
#include <vcl/graphicfilter.hxx>
#include <memory>
-#include <TypeSerializer.hxx>
-
GfxLink::GfxLink()
: meType(GfxLinkType::NONE)
@@ -147,75 +145,6 @@ bool GfxLink::ExportNative( SvStream& rOStream ) const
return ( rOStream.GetError() == ERRCODE_NONE );
}
-SvStream& WriteGfxLink( SvStream& rOStream, const GfxLink& rGfxLink )
-{
- std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStream, StreamMode::WRITE, 2 ));
- TypeSerializer aSerializer(rOStream);
-
- // Version 1
- rOStream.WriteUInt16( static_cast<sal_uInt16>(rGfxLink.GetType()) ).WriteUInt32( rGfxLink.GetDataSize() ).WriteUInt32( rGfxLink.GetUserId() );
-
- // Version 2
- aSerializer.writeSize(rGfxLink.GetPrefSize());
- WriteMapMode( rOStream, rGfxLink.GetPrefMapMode() );
-
- pCompat.reset(); // destructor writes stuff into the header
-
- if( rGfxLink.GetDataSize() )
- {
- auto pData = rGfxLink.GetSwapInData();
- if (pData)
- rOStream.WriteBytes( pData.get(), rGfxLink.mnSwapInDataSize );
- }
-
- return rOStream;
-}
-
-SvStream& ReadGfxLink( SvStream& rIStream, GfxLink& rGfxLink)
-{
- Size aSize;
- MapMode aMapMode;
- bool bMapAndSizeValid( false );
- std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rIStream, StreamMode::READ ));
-
- TypeSerializer aSerializer(rIStream);
-
- // Version 1
- sal_uInt16 nType(0);
- sal_uInt32 nSize(0), nUserId(0);
- rIStream.ReadUInt16(nType).ReadUInt32(nSize).ReadUInt32(nUserId);
-
- if( pCompat->GetVersion() >= 2 )
- {
- aSerializer.readSize(aSize);
- ReadMapMode( rIStream, aMapMode );
- bMapAndSizeValid = true;
- }
-
- pCompat.reset(); // destructor writes stuff into the header
-
- auto nRemainingData = rIStream.remainingSize();
- if (nSize > nRemainingData)
- {
- SAL_WARN("vcl", "graphic link stream is smaller than requested size");
- nSize = nRemainingData;
- }
-
- std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ nSize ]);
- rIStream.ReadBytes( pBuf.get(), nSize );
-
- rGfxLink = GfxLink( std::move(pBuf), nSize, static_cast<GfxLinkType>(nType) );
- rGfxLink.SetUserId( nUserId );
-
- if( bMapAndSizeValid )
- {
- rGfxLink.SetPrefSize( aSize );
- rGfxLink.SetPrefMapMode( aMapMode );
- }
-
- return rIStream;
-}
-
std::shared_ptr<sal_uInt8> GfxLink::GetSwapInData() const
{
return mpSwapInData;
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index df736a274d87..90582919c785 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1678,7 +1678,9 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
{
VersionCompat aCompat( rIStm, StreamMode::READ );
}
- ReadGfxLink( rIStm, aLink );
+
+ TypeSerializer aSerializer(rIStm);
+ aSerializer.readGfxLink(aLink);
// set dummy link to avoid creation of additional link after filtering;
// we set a default link to avoid unnecessary swapping of native data
@@ -1855,7 +1857,8 @@ void WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic)
}
rImpGraphic.mpGfxLink->SetPrefMapMode( rImpGraphic.ImplGetPrefMapMode() );
rImpGraphic.mpGfxLink->SetPrefSize( rImpGraphic.ImplGetPrefSize() );
- WriteGfxLink( rOStm, *rImpGraphic.mpGfxLink );
+ TypeSerializer aSerializer(rOStm);
+ aSerializer.writeGfxLink(*rImpGraphic.mpGfxLink);
}
else
{
diff --git a/vcl/source/gdi/metaact.cxx b/vcl/source/gdi/metaact.cxx
index bf4902fb9222..0f55e2fbe00d 100644
--- a/vcl/source/gdi/metaact.cxx
+++ b/vcl/source/gdi/metaact.cxx
@@ -3064,8 +3064,8 @@ void MetaEPSAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
MetaAction::Write(rOStm, pData);
VersionCompat aCompat(rOStm, StreamMode::WRITE, 1);
- WriteGfxLink( rOStm, maGfxLink );
TypeSerializer aSerializer(rOStm);
+ aSerializer.writeGfxLink(maGfxLink);
aSerializer.writePoint(maPoint);
aSerializer.writeSize(maSize);
maSubst.Write( rOStm );
@@ -3074,8 +3074,8 @@ void MetaEPSAction::Write( SvStream& rOStm, ImplMetaWriteData* pData )
void MetaEPSAction::Read( SvStream& rIStm, ImplMetaReadData* )
{
VersionCompat aCompat(rIStm, StreamMode::READ);
- ReadGfxLink( rIStm, maGfxLink );
TypeSerializer aSerializer(rIStm);
+ aSerializer.readGfxLink(maGfxLink);
aSerializer.readPoint(maPoint);
aSerializer.readSize(maSize);
ReadGDIMetaFile( rIStm, maSubst );
More information about the Libreoffice-commits
mailing list