build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / filter / wmf / wmf.cxx
blobdabf950f37e7f3d65e786d73c3542bfd808783be
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 "winmtf.hxx"
21 #include "emfwr.hxx"
22 #include "wmfwr.hxx"
23 #include <vcl/wmf.hxx>
24 #include <vcl/gdimetafiletools.hxx>
25 #include <comphelper/scopeguard.hxx>
27 bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem, WMF_EXTERNALHEADER *pExtHeader )
29 sal_uInt32 nMetaType;
30 sal_uInt32 nOrgPos = rStreamWMF.Tell();
31 SvStreamEndian nOrigNumberFormat = rStreamWMF.GetEndian();
32 rStreamWMF.SetEndian( SvStreamEndian::LITTLE );
33 rStreamWMF.Seek( 0x28 );
34 rStreamWMF.ReadUInt32( nMetaType );
35 rStreamWMF.Seek( nOrgPos );
36 if ( nMetaType == 0x464d4520 )
38 if ( !EnhWMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadEnhWMF() )
39 rStreamWMF.SetError( SVSTREAM_FILEFORMAT_ERROR );
41 else
43 WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem, pExtHeader ).ReadWMF( );
46 #ifdef DBG_UTIL
47 // #i123216# allow a look at CheckSum and ByteSize for debugging
48 SAL_INFO("vcl.emf", "\t\t\tchecksum: 0x" << std::hex << rGDIMetaFile.GetChecksum() << std::dec);
49 SAL_INFO("vcl.emf", "\t\t\tsize: " << rGDIMetaFile.GetSizeBytes());
50 #endif
52 rStreamWMF.SetEndian( nOrigNumberFormat );
53 return !rStreamWMF.GetError();
56 bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF )
58 sal_uInt32 nMetaType(0);
59 sal_uInt32 nOrgPos = rStream.Tell();
61 SvStreamEndian nOrigNumberFormat = rStream.GetEndian();
62 rStream.SetEndian( SvStreamEndian::LITTLE );
63 //exception-safe reset nOrigNumberFormat at end of scope
64 const ::comphelper::ScopeGuard aScopeGuard( [&rStream, nOrigNumberFormat] () { rStream.SetEndian( nOrigNumberFormat ); } );
66 rStream.Seek( 0x28 );
67 rStream.ReadUInt32( nMetaType );
68 rStream.Seek( nOrgPos );
70 if (!rStream.good())
71 return false;
73 if ( nMetaType == 0x464d4520 )
75 if ( !EnhWMFReader( rStream, rMTF, nullptr ).ReadEnhWMF() )
76 rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
78 else
80 WMFReader( rStream, rMTF, nullptr ).ReadWMF();
83 return rStream.good();
86 bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
87 FilterConfigItem* pConfigItem, bool bPlaceable)
89 WMFWriter aWMFWriter;
90 GDIMetaFile aGdiMetaFile(rMTF);
92 if(usesClipActions(aGdiMetaFile))
94 // #i121267# It is necessary to prepare the metafile since the export does *not* support
95 // clip regions. This tooling method clips the geometry content of the metafile internally
96 // against its own clip regions, so that the export is safe to ignore clip regions
97 clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
100 return aWMFWriter.WriteWMF( aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable );
103 bool ConvertGDIMetaFileToEMF(const GDIMetaFile & rMTF, SvStream & rTargetStream)
105 EMFWriter aEMFWriter(rTargetStream);
106 GDIMetaFile aGdiMetaFile(rMTF);
108 if(usesClipActions(aGdiMetaFile))
110 // #i121267# It is necessary to prepare the metafile since the export does *not* support
111 // clip regions. This tooling method clips the geometry content of the metafile internally
112 // against its own clip regions, so that the export is safe to ignore clip regions
113 clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
116 return aEMFWriter.WriteEMF(aGdiMetaFile);
119 bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
121 return WMFWriter().WriteWMF( rMTF, rStream, nullptr, false );
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */