LibreOffice Module vcl (master) 1
wmf.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "emfwr.hxx"
21#include "wmfwr.hxx"
22#include <vcl/wmf.hxx>
24#include <vcl/graph.hxx>
25
26using namespace com::sun::star;
27
29{
30 // tdf#111484 Use new method to import Metafile. Take current StreamPos
31 // into account (used by SwWW8ImplReader::ReadGrafFile and by
32 // SwWw6ReadMetaStream, so do *not* ignore. OTOH XclImpDrawing::ReadWmf
33 // is nice enough to copy to an own MemStream to avoid that indirect
34 // parameter passing...)
35 const sal_uInt32 nStreamStart(rStream.Tell());
36 const sal_uInt32 nStreamEnd(rStream.TellEnd());
37
38 if (nStreamStart >= nStreamEnd)
39 {
40 return false;
41 }
42
43 // Read binary data to mem array
44 const sal_uInt32 nStreamLength(nStreamEnd - nStreamStart);
45 BinaryDataContainer aDataContainer(rStream, nStreamLength);
46 rStream.Seek(nStreamStart);
47
48 if (rStream.good())
49 {
50 // Throw into VectorGraphicData to get the import. Do not care
51 // too much for type, this will be checked there. Also no path
52 // needed, it is a temporary object
53 auto aVectorGraphicDataPtr =
54 std::make_shared<VectorGraphicData>(aDataContainer, VectorGraphicDataType::Emf);
55
56 // create a Graphic and grep Metafile from it
57 const Graphic aGraphic(aVectorGraphicDataPtr);
58
59 // get the Metafile from it, done
60 rMTF = aGraphic.GetGDIMetaFile();
61 return true;
62 }
63
64 return rStream.good();
65}
66
67bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
68 FilterConfigItem const * pConfigItem, bool bPlaceable)
69{
70 WMFWriter aWMFWriter;
71 GDIMetaFile aGdiMetaFile(rMTF);
72
73 if(usesClipActions(aGdiMetaFile))
74 {
75 // #i121267# It is necessary to prepare the metafile since the export does *not* support
76 // clip regions. This tooling method clips the geometry content of the metafile internally
77 // against its own clip regions, so that the export is safe to ignore clip regions
79 }
80
81 bool bRet = aWMFWriter.WriteWMF(aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable);
82 return bRet;
83}
84
85bool ConvertGraphicToWMF(const Graphic& rGraphic, SvStream& rTargetStream,
86 FilterConfigItem const* pConfigItem, bool bPlaceable)
87{
88 GfxLink aLink = rGraphic.GetGfxLink();
89 if (aLink.GetType() == GfxLinkType::NativeWmf && aLink.GetData() && aLink.GetDataSize())
90 {
91 if(!aLink.IsEMF()) // If WMF, just write directly.
92 return rTargetStream.WriteBytes(aLink.GetData(), aLink.GetDataSize()) == aLink.GetDataSize();
93
94 // This may be an EMF+ file. In EmfReader::ReadEnhWMF() we normally drop non-EMF commands
95 // when reading EMF+, so converting that to WMF is better done by re-parsing with EMF+ disabled.
96 auto & rDataContainer = aLink.getDataContainer();
97 auto aVectorGraphicData
98 = std::make_shared<VectorGraphicData>(rDataContainer, VectorGraphicDataType::Emf);
99 aVectorGraphicData->setEnableEMFPlus(false);
100 Graphic aGraphic(aVectorGraphicData);
101 bool bRet = ConvertGDIMetaFileToWMF(aGraphic.GetGDIMetaFile(), rTargetStream, pConfigItem,
102 bPlaceable);
103 return bRet;
104 }
105
106 bool bRet = ConvertGDIMetaFileToWMF(rGraphic.GetGDIMetaFile(), rTargetStream, pConfigItem,
107 bPlaceable);
108 return bRet;
109}
110
111bool ConvertGDIMetaFileToEMF(const GDIMetaFile & rMTF, SvStream & rTargetStream)
112{
113 EMFWriter aEMFWriter(rTargetStream);
114 GDIMetaFile aGdiMetaFile(rMTF);
115
116 if(usesClipActions(aGdiMetaFile))
117 {
118 // #i121267# It is necessary to prepare the metafile since the export does *not* support
119 // clip regions. This tooling method clips the geometry content of the metafile internally
120 // against its own clip regions, so that the export is safe to ignore clip regions
122 }
123
124 return aEMFWriter.WriteEMF(aGdiMetaFile);
125}
126
127bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
128{
129 return WMFWriter().WriteWMF( rMTF, rStream, nullptr, false );
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
bool WriteEMF(const GDIMetaFile &rMtf)
Definition: emfwr.cxx:239
const GDIMetaFile & GetGDIMetaFile() const
Definition: graph.cxx:340
GfxLink GetGfxLink() const
Definition: graph.cxx:510
sal_uInt64 Tell() const
bool good() const
virtual sal_uInt64 TellEnd()
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
bool WriteWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pFilterConfigItem, bool bPlaceable)
Definition: wmfwr.cxx:1677
bool usesClipActions(const GDIMetaFile &rSource)
void clipMetafileContentAgainstOwnRegions(GDIMetaFile &rSource)
bool ReadWindowMetafile(SvStream &rStream, GDIMetaFile &rMTF)
Definition: wmf.cxx:28
bool WriteWindowMetafileBits(SvStream &rStream, const GDIMetaFile &rMTF)
Definition: wmf.cxx:127
bool ConvertGDIMetaFileToWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
Definition: wmf.cxx:67
bool ConvertGraphicToWMF(const Graphic &rGraphic, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
Definition: wmf.cxx:85
bool ConvertGDIMetaFileToEMF(const GDIMetaFile &rMTF, SvStream &rTargetStream)
Definition: wmf.cxx:111