xref: /aoo42x/main/svtools/source/filter/wmf/wmf.cxx (revision 2925bb56)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include "winmtf.hxx"
28 #include "emfwr.hxx"
29 #include "wmfwr.hxx"
30 #include <svtools/wmf.hxx>
31 #include <vcl/gdimetafiletools.hxx>
32 
33 // -----------------------------------------------------------------------------
34 
ConvertWMFToGDIMetaFile(SvStream & rStreamWMF,GDIMetaFile & rGDIMetaFile,FilterConfigItem * pConfigItem)35 sal_Bool ConvertWMFToGDIMetaFile( SvStream & rStreamWMF, GDIMetaFile & rGDIMetaFile, FilterConfigItem* pConfigItem )
36 {
37 	sal_uInt32 nMetaType;
38 	sal_uInt32 nOrgPos = rStreamWMF.Tell();
39 	sal_uInt16 nOrigNumberFormat = rStreamWMF.GetNumberFormatInt();
40 	rStreamWMF.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
41 	rStreamWMF.Seek( 0x28 );
42 	rStreamWMF >> nMetaType;
43 	rStreamWMF.Seek( nOrgPos );
44 	if ( nMetaType == 0x464d4520 )
45 	{
46 		if ( EnhWMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadEnhWMF() == sal_False )
47 			rStreamWMF.SetError( SVSTREAM_FILEFORMAT_ERROR );
48 	}
49 	else
50 	{
51 		WMFReader( rStreamWMF, rGDIMetaFile, pConfigItem ).ReadWMF();
52 	}
53 
54 #ifdef DBG_UTIL
55     // #123216# allow a look at CheckSum and ByteSize for debugging
56     const sal_uLong aC(rGDIMetaFile.GetChecksum());
57     const sal_uLong aB(rGDIMetaFile.GetSizeBytes());
58 #endif
59 
60 	rStreamWMF.SetNumberFormatInt( nOrigNumberFormat );
61 	return !rStreamWMF.GetError();
62 }
63 
64 // -----------------------------------------------------------------------------
65 
ReadWindowMetafile(SvStream & rStream,GDIMetaFile & rMTF,FilterConfigItem * pFilterConfigItem)66 sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pFilterConfigItem )
67 {
68 	sal_uInt32 nMetaType;
69 	sal_uInt32 nOrgPos = rStream.Tell();
70 	sal_uInt16 nOrigNumberFormat = rStream.GetNumberFormatInt();
71 	rStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
72 	rStream.Seek( 0x28 );
73 	rStream >> nMetaType;
74 	rStream.Seek( nOrgPos );
75 	if ( nMetaType == 0x464d4520 )
76 	{
77 		if ( EnhWMFReader( rStream, rMTF, NULL ).ReadEnhWMF() == sal_False )
78 			rStream.SetError( SVSTREAM_FILEFORMAT_ERROR );
79 	}
80 	else
81 	{
82 		WMFReader( rStream, rMTF, pFilterConfigItem ).ReadWMF();
83 	}
84 	rStream.SetNumberFormatInt( nOrigNumberFormat );
85 	return !rStream.GetError();
86 }
87 
88 // -----------------------------------------------------------------------------
89 
ConvertGDIMetaFileToWMF(const GDIMetaFile & rMTF,SvStream & rTargetStream,FilterConfigItem * pConfigItem,sal_Bool bPlaceable)90 sal_Bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
91 							  FilterConfigItem* pConfigItem, sal_Bool bPlaceable)
92 {
93 	WMFWriter aWMFWriter;
94     GDIMetaFile aGdiMetaFile(rMTF);
95 
96     if(usesClipActions(aGdiMetaFile))
97     {
98         // #121267# It is necessary to prepare the metafile since the export does *not* support
99         // clip regions. This tooling method clips the geometry content of the metafile internally
100         // against it's own clip regions, so that the export is safe to ignore clip regions
101         clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
102     }
103 
104     return aWMFWriter.WriteWMF( aGdiMetaFile, rTargetStream, pConfigItem, bPlaceable );
105 }
106 
107 // -----------------------------------------------------------------------------
108 
ConvertGDIMetaFileToEMF(const GDIMetaFile & rMTF,SvStream & rTargetStream,FilterConfigItem * pConfigItem)109 sal_Bool ConvertGDIMetaFileToEMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
110 							  FilterConfigItem* pConfigItem )
111 {
112 	EMFWriter aEMFWriter;
113     GDIMetaFile aGdiMetaFile(rMTF);
114 
115     if(usesClipActions(aGdiMetaFile))
116     {
117         // #121267# It is necessary to prepare the metafile since the export does *not* support
118         // clip regions. This tooling method clips the geometry content of the metafile internally
119         // against it's own clip regions, so that the export is safe to ignore clip regions
120         clipMetafileContentAgainstOwnRegions(aGdiMetaFile);
121     }
122 
123     return aEMFWriter.WriteEMF( aGdiMetaFile, rTargetStream, pConfigItem );
124 }
125 
126 // -----------------------------------------------------------------------------
127 
WriteWindowMetafile(SvStream & rStream,const GDIMetaFile & rMTF)128 sal_Bool WriteWindowMetafile( SvStream& rStream, const GDIMetaFile& rMTF )
129 {
130 	return WMFWriter().WriteWMF( rMTF, rStream, NULL );
131 }
132 
133 // -----------------------------------------------------------------------------
134 
WriteWindowMetafileBits(SvStream & rStream,const GDIMetaFile & rMTF)135 sal_Bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF )
136 {
137 	return WMFWriter().WriteWMF( rMTF, rStream, NULL, sal_False );
138 }
139