tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / vcl / source / filter / wmf / wmf.cxx
blobdb615410c1dc6e49a6bc7455338e8e6792b2492a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "emfwr.hxx"
21 #include "wmfwr.hxx"
22 #include <vcl/wmf.hxx>
23 #include <vcl/gdimetafiletools.hxx>
24 #include <vcl/graph.hxx>
26 using namespace com::sun::star;
28 bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF )
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_uInt64 nStreamStart(rStream.Tell());
36 const sal_uInt64 nStreamEnd(rStream.TellEnd());
38 if (nStreamStart >= nStreamEnd)
40 return false;
43 // Read binary data to mem array
44 const sal_uInt64 nStreamLength(nStreamEnd - nStreamStart);
45 BinaryDataContainer aDataContainer(rStream, nStreamLength);
46 rStream.Seek(nStreamStart);
48 if (rStream.good())
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);
56 // create a Graphic and grep Metafile from it
57 const Graphic aGraphic(aVectorGraphicDataPtr);
59 // get the Metafile from it, done
60 rMTF = aGraphic.GetGDIMetaFile();
61 return true;
64 return rStream.good();
67 bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
68 FilterConfigItem const * pConfigItem, bool bPlaceable)
70 WMFWriter aWMFWriter;
71 GDIMetaFile aGdiMetaFile(rMTF);
73 if(usesClipActions(aGdiMetaFile))
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
78 clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
81 bool bRet = aWMFWriter.WriteWMF(aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable);
82 return bRet;
85 bool ConvertGraphicToWMF(const Graphic& rGraphic, SvStream& rTargetStream,
86 FilterConfigItem const* pConfigItem, bool bPlaceable)
88 GfxLink aLink = rGraphic.GetGfxLink();
89 if (aLink.GetType() == GfxLinkType::NativeWmf && aLink.GetData() && aLink.GetDataSize())
91 if(!aLink.IsEMF()) // If WMF, just write directly.
92 return rTargetStream.WriteBytes(aLink.GetData(), aLink.GetDataSize()) == aLink.GetDataSize();
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;
106 bool bRet = ConvertGDIMetaFileToWMF(rGraphic.GetGDIMetaFile(), rTargetStream, pConfigItem,
107 bPlaceable);
108 return bRet;
111 bool ConvertGDIMetaFileToEMF(const GDIMetaFile & rMTF, SvStream & rTargetStream)
113 EMFWriter aEMFWriter(rTargetStream);
114 GDIMetaFile aGdiMetaFile(rMTF);
116 if(usesClipActions(aGdiMetaFile))
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
121 clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
124 return aEMFWriter.WriteEMF(aGdiMetaFile);
127 bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
129 return WMFWriter().WriteWMF( rMTF, rStream, nullptr, false );
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */