Line data Source code
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 "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>
26 :
27 0 : bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem, WMF_EXTERNALHEADER *pExtHeader )
28 : {
29 : sal_uInt32 nMetaType;
30 0 : sal_uInt32 nOrgPos = rStreamWMF.Tell();
31 0 : sal_uInt16 nOrigNumberFormat = rStreamWMF.GetNumberFormatInt();
32 0 : rStreamWMF.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
33 0 : rStreamWMF.Seek( 0x28 );
34 0 : rStreamWMF.ReadUInt32( nMetaType );
35 0 : rStreamWMF.Seek( nOrgPos );
36 0 : if ( nMetaType == 0x464d4520 )
37 : {
38 0 : if ( !EnhWMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadEnhWMF() )
39 0 : rStreamWMF.SetError( SVSTREAM_FILEFORMAT_ERROR );
40 : }
41 : else
42 : {
43 0 : WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem, pExtHeader ).ReadWMF( );
44 : }
45 :
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
51 :
52 0 : rStreamWMF.SetNumberFormatInt( nOrigNumberFormat );
53 0 : return !rStreamWMF.GetError();
54 : }
55 :
56 0 : bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pFilterConfigItem )
57 : {
58 0 : sal_uInt32 nMetaType(0);
59 0 : sal_uInt32 nOrgPos = rStream.Tell();
60 :
61 0 : sal_uInt16 nOrigNumberFormat = rStream.GetNumberFormatInt();
62 0 : rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
63 : //exception-safe reset nOrigNumberFormat at end of scope
64 : const ::comphelper::ScopeGuard aScopeGuard(
65 : boost::bind(&SvStream::SetNumberFormatInt, ::boost::ref(rStream),
66 0 : nOrigNumberFormat));
67 :
68 0 : rStream.Seek( 0x28 );
69 0 : rStream.ReadUInt32( nMetaType );
70 0 : rStream.Seek( nOrgPos );
71 :
72 0 : if (!rStream.good())
73 0 : return false;
74 :
75 0 : if ( nMetaType == 0x464d4520 )
76 : {
77 0 : if ( !EnhWMFReader( rStream, rMTF, NULL ).ReadEnhWMF() )
78 0 : rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
79 : }
80 : else
81 : {
82 0 : WMFReader( rStream, rMTF, pFilterConfigItem ).ReadWMF();
83 : }
84 :
85 0 : return rStream.good();
86 : }
87 :
88 0 : bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
89 : FilterConfigItem* pConfigItem, bool bPlaceable)
90 : {
91 0 : WMFWriter aWMFWriter;
92 0 : GDIMetaFile aGdiMetaFile(rMTF);
93 :
94 0 : if(usesClipActions(aGdiMetaFile))
95 : {
96 : // #i121267# It is necessary to prepare the metafile since the export does *not* support
97 : // clip regions. This tooling method clips the geometry content of the metafile internally
98 : // against it's own clip regions, so that the export is safe to ignore clip regions
99 0 : clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
100 : }
101 :
102 0 : return aWMFWriter.WriteWMF( aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable );
103 : }
104 :
105 0 : bool ConvertGDIMetaFileToEMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
106 : FilterConfigItem* pConfigItem )
107 : {
108 0 : EMFWriter aEMFWriter(rTargetStream);
109 0 : GDIMetaFile aGdiMetaFile(rMTF);
110 :
111 0 : if(usesClipActions(aGdiMetaFile))
112 : {
113 : // #i121267# It is necessary to prepare the metafile since the export does *not* support
114 : // clip regions. This tooling method clips the geometry content of the metafile internally
115 : // against it's own clip regions, so that the export is safe to ignore clip regions
116 0 : clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
117 : }
118 :
119 0 : return aEMFWriter.WriteEMF( aGdiMetaFile, pConfigItem );
120 : }
121 :
122 0 : bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
123 : {
124 0 : return WMFWriter().WriteWMF( rMTF, rStream, NULL, false );
125 3 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|