include/vcl/filter/SvmWriter.hxx | 42 +++++++++++++++++ vcl/Library_vcl.mk | 1 vcl/qa/cppunit/svm/svmtest.cxx | 4 + vcl/source/filter/svm/SvmWriter.cxx | 87 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-)
New commits: commit 5e020c43668c9e11188ba48bf57de4bd7e9cc501 Author: panoskorovesis <panoskorove...@outlook.com> AuthorDate: Tue Jul 27 10:40:58 2021 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Jul 31 08:45:09 2021 +0200 Create SvmWriter class This class will separate Write functionality from metaact.hxx with the use of handlers for each metaact subclass Change-Id: I7c74ec183f08b62d713457e4e971ea5b0b67cde2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119541 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/filter/SvmWriter.hxx b/include/vcl/filter/SvmWriter.hxx new file mode 100644 index 000000000000..644cb55f9aff --- /dev/null +++ b/include/vcl/filter/SvmWriter.hxx @@ -0,0 +1,42 @@ +/* -*- 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* pAction, ImplMetaWriteData* pData); + void ActionHandler(MetaAction* pAction); +}; \ No newline at end of file diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 8a150e0ad1ca..9fb2e352bdea 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -454,6 +454,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 5f9a4bced6a4..84978a6e9c67 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..8c07bffe5d53 --- /dev/null +++ b/vcl/source/filter/svm/SvmWriter.cxx @@ -0,0 +1,87 @@ +/* -*- 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/vcompat.hxx> + +SvmWriter::SvmWriter(SvStream& rIStm) + : mrStream(rIStm) +{ +} + +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) + { + MetaActionHandler(pAct, &aWriteData); + pAct = rMetaFile.NextAction(); + } + + mrStream.SetEndian(nOldFormat); + + return mrStream; +} + +void SvmWriter::MetaActionHandler(MetaAction* pAction, ImplMetaWriteData* pData) +{ + MetaActionType nType = pAction->GetType(); + + switch (nType) + { + case MetaActionType::NONE: + { + ActionHandler(pAction); + } + break; + + /* default case prevents test failure and will be + removed once all the handlers are completed */ + default: + pAction->Write(mrStream, pData); + } +} + +void SvmWriter::ActionHandler(MetaAction* pAction) +{ + mrStream.WriteUInt16(static_cast<sal_uInt16>(pAction->GetType())); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */