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>
23 #include <vcl/gdimetafiletools.hxx>
24 #include <vcl/graph.hxx>
25 
26 bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF )
27 {
28  // tdf#111484 Use new method to import Metafile. Take current StreamPos
29  // into account (used by SwWW8ImplReader::ReadGrafFile and by
30  // SwWw6ReadMetaStream, so do *not* ignore. OTOH XclImpDrawing::ReadWmf
31  // is nice enough to copy to an own MemStream to avoid that indirect
32  // parameter passing...)
33  const sal_uInt32 nStreamStart(rStream.Tell());
34  const sal_uInt32 nStreamEnd(rStream.TellEnd());
35 
36  if (nStreamStart >= nStreamEnd)
37  {
38  return false;
39  }
40 
41  // Read binary data to mem array
42  const sal_uInt32 nStreamLength(nStreamEnd - nStreamStart);
43  VectorGraphicDataArray aNewData(nStreamLength);
44  rStream.ReadBytes(aNewData.begin(), nStreamLength);
45  rStream.Seek(nStreamStart);
46 
47  if (rStream.good())
48  {
49  // Throw into VectorGraphicData to get the import. Do not care
50  // too much for type, this will be checked there. Also no path
51  // needed, it is a temporary object
52  VectorGraphicDataPtr aVectorGraphicDataPtr(
54  aNewData,
55  OUString(),
57 
58  // create a Graphic and grep Metafile from it
59  const Graphic aGraphic(aVectorGraphicDataPtr);
60 
61  // get the Metafile from it, done
62  rMTF = aGraphic.GetGDIMetaFile();
63  return true;
64  }
65 
66  return rStream.good();
67 }
68 
69 bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
70  FilterConfigItem const * pConfigItem, bool bPlaceable)
71 {
72  WMFWriter aWMFWriter;
73  GDIMetaFile aGdiMetaFile(rMTF);
74 
75  if(usesClipActions(aGdiMetaFile))
76  {
77  // #i121267# It is necessary to prepare the metafile since the export does *not* support
78  // clip regions. This tooling method clips the geometry content of the metafile internally
79  // against its own clip regions, so that the export is safe to ignore clip regions
81  }
82 
83  return aWMFWriter.WriteWMF( aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable );
84 }
85 
86 bool ConvertGDIMetaFileToEMF(const GDIMetaFile & rMTF, SvStream & rTargetStream)
87 {
88  EMFWriter aEMFWriter(rTargetStream);
89  GDIMetaFile aGdiMetaFile(rMTF);
90 
91  if(usesClipActions(aGdiMetaFile))
92  {
93  // #i121267# It is necessary to prepare the metafile since the export does *not* support
94  // clip regions. This tooling method clips the geometry content of the metafile internally
95  // against its own clip regions, so that the export is safe to ignore clip regions
97  }
98 
99  return aEMFWriter.WriteEMF(aGdiMetaFile);
100 }
101 
102 bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
103 {
104  return WMFWriter().WriteWMF( rMTF, rStream, nullptr, false );
105 }
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool WriteWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pFilterConfigItem, bool bPlaceable)
Definition: wmfwr.cxx:1678
bool ReadWindowMetafile(SvStream &rStream, GDIMetaFile &rMTF)
Definition: wmf.cxx:26
virtual sal_uInt64 TellEnd()
bool ConvertGDIMetaFileToWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)
Definition: wmf.cxx:69
bool usesClipActions(const GDIMetaFile &rSource)
sal_uInt64 Seek(sal_uInt64 nPos)
bool WriteWindowMetafileBits(SvStream &rStream, const GDIMetaFile &rMTF)
Definition: wmf.cxx:102
bool ConvertGDIMetaFileToEMF(const GDIMetaFile &rMTF, SvStream &rTargetStream)
Definition: wmf.cxx:86
const GDIMetaFile & GetGDIMetaFile() const
Definition: graph.cxx:359
void clipMetafileContentAgainstOwnRegions(GDIMetaFile &rSource)
bool WriteEMF(const GDIMetaFile &rMtf)
Definition: emfwr.cxx:239
std::size_t ReadBytes(void *pData, std::size_t nSize)
std::shared_ptr< VectorGraphicData > VectorGraphicDataPtr
css::uno::Sequence< sal_Int8 > VectorGraphicDataArray
sal_uInt64 Tell() const
bool good() const