summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpanoskorovesis <panoskorovesis@outlook.com>2021-07-14 12:21:34 +0300
committerpanoskorovesis <panoskorovesis@outlook.com>2021-07-14 12:21:34 +0300
commit3aba4bdeb00f1c39d8131e8cee2634e5387a10f7 (patch)
tree95410479ce1a34215c726a2be0f9d8fea73d3927
parentAdd Handler for ClipRegion Read (diff)
downloadcore-3aba4bdeb00f1c39d8131e8cee2634e5387a10f7.tar.gz
core-3aba4bdeb00f1c39d8131e8cee2634e5387a10f7.zip
Create SvmWriter Class
This is the initial form of the SvmWriter Class. It's job will be to separate MetaFile write functionality from metaact.hxx Change-Id: I59f437850d355ccd1f64a6bd5decd2c52e354d81
-rw-r--r--include/vcl/filter/SvmWriter.hxx43
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/qa/cppunit/svm/svmtest.cxx4
-rw-r--r--vcl/source/filter/svm/SvmWriter.cxx106
4 files changed, 153 insertions, 1 deletions
diff --git a/include/vcl/filter/SvmWriter.hxx b/include/vcl/filter/SvmWriter.hxx
new file mode 100644
index 000000000000..5b57d969b80b
--- /dev/null
+++ b/include/vcl/filter/SvmWriter.hxx
@@ -0,0 +1,43 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <memory>
+#include <vcl/gdimtf.hxx>
+#include <vcl/metaact.hxx>
+
+class SvStream;
+
+class VCL_DLLPUBLIC SvmWriter
+{
+private:
+ SvStream& mrStream;
+
+protected:
+ void WriteColor(::Color aColor);
+
+public:
+ SvmWriter(SvStream& rIStm);
+
+ SvStream& Write(GDIMetaFile& rMetaFile);
+ void MetaActionHandler(MetaAction* pAct, ImplMetaWriteData* pData);
+ void ActionHandler(MetaActionType nType);
+ void PixelHandler(MetaPixelAction* pAct);
+}; \ No newline at end of file
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index d3f1adcd9b37..483c51980fe8 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -455,6 +455,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/filter/jpeg/JpegWriter \
vcl/source/filter/jpeg/JpegTransform \
vcl/source/filter/svm/SvmReader \
+ vcl/source/filter/svm/SvmWriter \
vcl/source/filter/wmf/emfwr \
vcl/source/filter/wmf/wmf \
vcl/source/filter/wmf/wmfexternal \
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 7a1f4b8f0dba..a32cbd44b6f2 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -23,6 +23,7 @@
#include <tools/fract.hxx>
#include <vcl/metaact.hxx>
#include <vcl/filter/SvmReader.hxx>
+#include <vcl/filter/SvmWriter.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <bitmap/BitmapWriteAccess.hxx>
@@ -325,7 +326,8 @@ GDIMetaFile SvmTest::writeAndReadStream(GDIMetaFile& rMetaFile, std::u16string_v
writeToFile(rMetaFile, rName);
SvMemoryStream aStream;
- rMetaFile.Write(aStream);
+ SvmWriter aWriter(aStream);
+ aWriter.Write(rMetaFile);
aStream.Seek(STREAM_SEEK_TO_BEGIN);
GDIMetaFile aResultMetafile;
diff --git a/vcl/source/filter/svm/SvmWriter.cxx b/vcl/source/filter/svm/SvmWriter.cxx
new file mode 100644
index 000000000000..b4c373a16946
--- /dev/null
+++ b/vcl/source/filter/svm/SvmWriter.cxx
@@ -0,0 +1,106 @@
+/* -*- 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 <vcl/filter/SvmWriter.hxx>
+#include <vcl/TypeSerializer.hxx>
+
+#include <tools/stream.hxx>
+#include <tools/vcompat.hxx>
+
+SvmWriter::SvmWriter(SvStream& rIStm)
+ : mrStream(rIStm)
+{
+}
+
+void SvmWriter::WriteColor(::Color aColor)
+{
+ mrStream.WriteUInt32(static_cast<sal_uInt32>(aColor));
+}
+
+SvStream& SvmWriter::Write(GDIMetaFile& rMetaFile)
+{
+ const SvStreamCompressFlags nStmCompressMode = mrStream.GetCompressMode();
+ SvStreamEndian nOldFormat = mrStream.GetEndian();
+
+ mrStream.SetEndian(SvStreamEndian::LITTLE);
+ mrStream.WriteBytes("VCLMTF", 6);
+
+ {
+ VersionCompatWrite aCompat(mrStream, 1);
+
+ mrStream.WriteUInt32(static_cast<sal_uInt32>(nStmCompressMode));
+ TypeSerializer aSerializer(mrStream);
+ aSerializer.writeMapMode(rMetaFile.GetPrefMapMode());
+ aSerializer.writeSize(rMetaFile.GetPrefSize());
+ mrStream.WriteUInt32(rMetaFile.GetActionSize());
+ } // VersionCompatWrite dtor writes stuff into the header
+
+ ImplMetaWriteData aWriteData;
+
+ aWriteData.meActualCharSet = mrStream.GetStreamCharSet();
+
+ MetaAction* pAct = rMetaFile.FirstAction();
+ while (pAct)
+ {
+ // pAct->Write( mrStream, &aWriteData );
+ MetaActionHandler(pAct, &aWriteData);
+ pAct = rMetaFile.NextAction();
+ }
+
+ mrStream.SetEndian(nOldFormat);
+
+ return mrStream;
+}
+
+void SvmWriter::MetaActionHandler(MetaAction* pAct, ImplMetaWriteData* pData)
+{
+ MetaActionType nType = static_cast<MetaActionType>(pAct->GetType());
+
+ switch (nType)
+ {
+ case MetaActionType::NONE:
+ {
+ ActionHandler(pAct->GetType());
+ }
+ break;
+ case MetaActionType::PIXEL:
+ {
+ auto* pMetaAction = static_cast<MetaPixelAction*>(pAct);
+ PixelHandler(pMetaAction);
+ }
+ break;
+ default:
+ pAct->Write(mrStream, pData);
+ }
+}
+
+void SvmWriter::ActionHandler(MetaActionType nType)
+{
+ mrStream.WriteUInt16(static_cast<sal_uInt16>(nType));
+}
+
+void SvmWriter::PixelHandler(MetaPixelAction* pAct)
+{
+ ActionHandler(pAct->GetType());
+ VersionCompatWrite aCompat(mrStream, 1);
+ TypeSerializer aSerializer(mrStream);
+ aSerializer.writePoint(pAct->GetPoint());
+ WriteColor(pAct->GetColor());
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */