xref: /trunk/main/svtools/inc/svtools/filter.hxx (revision 01aa44aa)
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 #ifndef _FILTER_HXX
25 #define _FILTER_HXX
26 
27 #include <svtools/fltcall.hxx>
28 #include "svtools/svtdllapi.h"
29 #include <tools/stream.hxx>
30 #include <vcl/graph.hxx>
31 #include <tools/gen.hxx>
32 #include <tools/urlobj.hxx>
33 #include <vcl/field.hxx>
34 #include <com/sun/star/uno/Sequence.h>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 
37 // -----------------------
38 // - GraphicFilter-Types -
39 // -----------------------
40 
41 struct ImplDirEntryHelper
42 {
43 	static sal_Bool Exists( const INetURLObject& rObj );
44 	static void Kill( const String& rStr );
45 };
46 
47 class Window;
48 class Graphic;
49 
50 #define OPT_FILTERSECTION			"Graphic"
51 
52 #define GRFILTER_OK					0
53 #define GRFILTER_OPENERROR			1
54 #define GRFILTER_IOERROR			2
55 #define GRFILTER_FORMATERROR		3
56 #define GRFILTER_VERSIONERROR		4
57 #define GRFILTER_FILTERERROR		5
58 #define GRFILTER_ABORT				6
59 #define GRFILTER_TOOBIG				7
60 
61 #define GRFILTER_OUTHINT_GREY       1
62 
63 #define GRFILTER_FORMAT_NOTFOUND	((sal_uInt16)0xFFFF)
64 #define GRFILTER_FORMAT_DONTKNOW	((sal_uInt16)0xFFFF)
65 
66 #define GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG       00000001
67 #define GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG  00000002
68 #define GRFILTER_I_FLAGS_FOR_PREVIEW                00000004
69 #define GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD   00000010
70 
71 #define IMP_BMP					"SVBMP"
72 #define IMP_SVMETAFILE			"SVMETAFILE"
73 #define IMP_WMF					"SVWMF"
74 #define IMP_EMF					"SVEMF"
75 #define IMP_SVSGF				"SVSGF"
76 #define IMP_SVSGV				"SVSGV"
77 #define IMP_GIF					"SVIGIF"
78 #define IMP_PNG					"SVIPNG"
79 #define IMP_JPEG				"SVIJPEG"
80 #define IMP_XBM					"SVIXBM"
81 #define IMP_XPM					"SVIXPM"
82 #define IMP_SVG                 "SVISVG"
83 #define EXP_BMP					"SVBMP"
84 #define EXP_SVMETAFILE			"SVMETAFILE"
85 #define EXP_WMF					"SVWMF"
86 #define EXP_EMF					"SVEMF"
87 #define EXP_JPEG				"SVEJPEG"
88 #define EXP_SVG					"SVESVG"
89 #define EXP_PNG					"SVEPNG"
90 
91 #define BMP_SHORTNAME			"BMP"
92 #define GIF_SHORTNAME			"GIF"
93 #define JPG_SHORTNAME			"JPG"
94 #define MET_SHORTNAME			"MET"
95 #define PCT_SHORTNAME			"PCT"
96 #define PNG_SHORTNAME			"PNG"
97 #define SVM_SHORTNAME			"SVM"
98 #define TIF_SHORTNAME			"TIF"
99 #define WMF_SHORTNAME			"WMF"
100 #define EMF_SHORTNAME			"EMF"
101 #define SVG_SHORTNAME			"SVG"
102 
103 // ------------------------------------
104 // - Info-Klasse fuer alle von uns
105 //	unterstuetzten Grafik-Fileformate
106 // ------------------------------------
107 
108 #define	GFF_NOT	( (sal_uInt16)0x0000 )
109 #define	GFF_BMP	( (sal_uInt16)0x0001 )
110 #define	GFF_GIF	( (sal_uInt16)0x0002 )
111 #define	GFF_JPG	( (sal_uInt16)0x0003 )
112 #define	GFF_PCD	( (sal_uInt16)0x0004 )
113 #define	GFF_PCX	( (sal_uInt16)0x0005 )
114 #define	GFF_PNG	( (sal_uInt16)0x0006 )
115 #define	GFF_TIF	( (sal_uInt16)0x0007 )
116 #define	GFF_XBM	( (sal_uInt16)0x0008 )
117 #define	GFF_XPM	( (sal_uInt16)0x0009 )
118 #define	GFF_PBM	( (sal_uInt16)0x000a )
119 #define	GFF_PGM	( (sal_uInt16)0x000b )
120 #define	GFF_PPM	( (sal_uInt16)0x000c )
121 #define	GFF_RAS	( (sal_uInt16)0x000d )
122 #define	GFF_TGA	( (sal_uInt16)0x000e )
123 #define	GFF_PSD	( (sal_uInt16)0x000f )
124 #define	GFF_EPS	( (sal_uInt16)0x0010 )
125 #define	GFF_DXF	( (sal_uInt16)0x00f1 )
126 #define	GFF_MET	( (sal_uInt16)0x00f2 )
127 #define	GFF_PCT	( (sal_uInt16)0x00f3 )
128 #define	GFF_SGF	( (sal_uInt16)0x00f4 )
129 #define	GFF_SVM	( (sal_uInt16)0x00f5 )
130 #define	GFF_WMF	( (sal_uInt16)0x00f6 )
131 #define GFF_SGV	( (sal_uInt16)0x00f7 )
132 #define	GFF_EMF	( (sal_uInt16)0x00f8 )
133 #define	GFF_SVG	( (sal_uInt16)0x00f9 )
134 #define	GFF_XXX	( (sal_uInt16)0xffff )
135 
136 // ---------------------
137 // - GraphicDescriptor -
138 // ---------------------
139 
140 class SVT_DLLPUBLIC GraphicDescriptor
141 {
142 	SvStream*			pFileStm;
143 
144 	String				aPathExt;
145 	Size				aPixSize;
146 	Size				aLogSize;
147 	sal_uInt16				nBitsPerPixel;
148 	sal_uInt16				nPlanes;
149 	sal_uInt16				nFormat;
150 	sal_Bool				bCompressed;
151 	sal_Bool				bOwnStream;
152 
153 	void				ImpConstruct();
154 
155 	sal_Bool			ImpDetectBMP( SvStream& rStm, sal_Bool bExtendedInfo );
156 	sal_Bool			ImpDetectGIF( SvStream& rStm, sal_Bool bExtendedInfo );
157 	sal_Bool			ImpDetectJPG( SvStream& rStm, sal_Bool bExtendedInfo );
158 	sal_Bool			ImpDetectPCD( SvStream& rStm, sal_Bool bExtendedInfo );
159 	sal_Bool			ImpDetectPCX( SvStream& rStm, sal_Bool bExtendedInfo );
160 	sal_Bool			ImpDetectPNG( SvStream& rStm, sal_Bool bExtendedInfo );
161 	sal_Bool			ImpDetectTIF( SvStream& rStm, sal_Bool bExtendedInfo );
162 	sal_Bool			ImpDetectXBM( SvStream& rStm, sal_Bool bExtendedInfo );
163 	sal_Bool			ImpDetectXPM( SvStream& rStm, sal_Bool bExtendedInfo );
164 	sal_Bool			ImpDetectPBM( SvStream& rStm, sal_Bool bExtendedInfo );
165 	sal_Bool			ImpDetectPGM( SvStream& rStm, sal_Bool bExtendedInfo );
166 	sal_Bool			ImpDetectPPM( SvStream& rStm, sal_Bool bExtendedInfo );
167 	sal_Bool			ImpDetectRAS( SvStream& rStm, sal_Bool bExtendedInfo );
168 	sal_Bool			ImpDetectTGA( SvStream& rStm, sal_Bool bExtendedInfo );
169 	sal_Bool			ImpDetectPSD( SvStream& rStm, sal_Bool bExtendedInfo );
170 	sal_Bool			ImpDetectEPS( SvStream& rStm, sal_Bool bExtendedInfo );
171 	sal_Bool			ImpDetectDXF( SvStream& rStm, sal_Bool bExtendedInfo );
172 	sal_Bool			ImpDetectMET( SvStream& rStm, sal_Bool bExtendedInfo );
173 	sal_Bool			ImpDetectPCT( SvStream& rStm, sal_Bool bExtendedInfo );
174 	sal_Bool			ImpDetectSGF( SvStream& rStm, sal_Bool bExtendedInfo );
175 	sal_Bool			ImpDetectSVM( SvStream& rStm, sal_Bool bExtendedInfo );
176 	sal_Bool			ImpDetectWMF( SvStream& rStm, sal_Bool bExtendedInfo );
177 	sal_Bool			ImpDetectSGV( SvStream& rStm, sal_Bool bExtendedInfo );
178 	sal_Bool			ImpDetectEMF( SvStream& rStm, sal_Bool bExtendedInfo );
179 	sal_Bool			ImpDetectSVG( SvStream& rStm, sal_Bool bExtendedInfo );
180 
181 	GraphicDescriptor( const GraphicDescriptor& );
182 	GraphicDescriptor& operator=( const GraphicDescriptor& );
183 
184 public:
185 
186 	// Ctor, um einen Filenamen zu setzen. Es muss ::Detect() gerufen werden,
187 	// um das File zu identifizieren;
188 	// wenn das File keinen eindeutigen Header besitzt ( Mtf's ) wird das
189 	// Format anhand der Extension bestimmt
190 	GraphicDescriptor( const INetURLObject& rPath );
191 
192 	// Ctor, um einen Stream zu setzen. Es muss ::Detect() gerufen werden,
193 	// um das File zu identifizieren;
194 	// da einige Formate ( Mtf's ) keinen eindeutigen Header besitzen,
195 	// ist es sinnvoll den Filenamen (inkl. Ext. ) mitanzugeben,
196 	// da so das Format ueber die Extension ermittelt werden kann
197 	GraphicDescriptor( SvStream& rInStream, const String* pPath = NULL );
198 
199 	// Dtor
200 	virtual ~GraphicDescriptor();
201 
202 	// Startet die Detektion;
203 	// bei bExtendedInfo == sal_True werden soweit wie moeglich
204 	// Daten aus dem jeweiligen FileHeader ermittelt
205 	// ( Groesse, Farbtiefe usw. )
206 	virtual sal_Bool	Detect( sal_Bool bExtendedInfo = sal_False );
207 
208 	// liefert das Fileformat nach erfolgreicher  Detektion zurueck;
209 	// wenn kein Format erkannt wurde, ist das Formart GFF_NOT
GetFileFormat() const210 	sal_uInt16			GetFileFormat() const { return nFormat; }
211 
212 	// liefert die Pixel-Bildgroesse oder 0-Size zurueck
GetSizePixel() const213 	const Size&		GetSizePixel() const { return (Size&) aPixSize; }
214 
215 	// liefert die logische Bildgroesse in 1/100mm oder 0-Size zurueck
GetSize_100TH_MM() const216 	const Size&		GetSize_100TH_MM() const { return (Size&) aLogSize; }
217 
218 	// liefert die Bits/Pixel oder 0 zurueck
GetBitsPerPixel() const219 	sal_uInt16			GetBitsPerPixel() const { return nBitsPerPixel; }
220 
221 	// liefert die Anzahl der Planes oder 0 zurueck
GetPlanes() const222 	sal_uInt16			GetPlanes() const { return nPlanes; }
223 
224 	// zeigt an, ob das Bild evtl. komprimiert (wie auch immer) ist
IsCompressed() const225 	sal_Bool			IsCompressed() const { return bCompressed; }
226 
227 	// gibt die Filternummer des Filters zurueck,
228 	// der im GraphicFilter zum Lesen dieses Formats
229 	// benoetigt wird
230 	static String GetImportFormatShortName( sal_uInt16 nFormat );
231 };
232 
233 // -----------------
234 // - GraphicFilter -
235 // -----------------
236 
237 struct FilterErrorEx
238 {
239 	sal_uLong	nFilterError;
240 	sal_uLong	nStreamError;
241 	long	nDummy1;
242 	long	nDummy2;
243 	long	nDummy3;
244 	long	nDummy4;
245 
FilterErrorExFilterErrorEx246 			FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
247 };
248 
249 // -----------------------------------------------------------------------------
250 
251 struct ConvertData;
252 class FilterConfigCache;
253 class SVT_DLLPUBLIC GraphicFilter
254 {
255     friend class SvFilterOptionsDialog;
256 
257 private:
258 
259 	void			ImplInit();
260 	sal_uLong			ImplSetError( sal_uLong nError, const SvStream* pStm = NULL );
261 	sal_uInt16		ImpTestOrFindFormat( const String& rPath, SvStream& rStream, sal_uInt16& rFormat );
262 
263 					DECL_LINK( FilterCallback, ConvertData* pData );
264 
265 protected:
266 
267 	String				aFilterPath;
268 	FilterConfigCache*	pConfig;
269 	FilterErrorEx*		pErrorEx;
270 	sal_Bool			bAbort;
271 	sal_Bool			bUseConfig;
272 	sal_Bool			bDummy1;
273 	sal_Bool			bDummy2;
274 	sal_Bool			bDummy3;
275 	sal_Bool			bDummy4;
276 	long				nExpGraphHint;
277 	long				nDummy2;
278 	void*				pDummy1;
279 	void*				pDummy2;
280 
281 public:
282 
283 					GraphicFilter( sal_Bool bUseConfig = sal_True );
284 					~GraphicFilter();
285 
SetFilterPath(const String & rFilterPath)286 	void			SetFilterPath( const String& rFilterPath ) { aFilterPath = rFilterPath; };
287 
288 	sal_uInt16          GetImportFormatCount();
289 	sal_uInt16          GetImportFormatNumber( const String& rFormatName );
290 	sal_uInt16			GetImportFormatNumberForMediaType( const String& rMediaType );
291 	sal_uInt16          GetImportFormatNumberForShortName( const String& rShortName );
292 	sal_uInt16		GetImportFormatNumberForTypeName( const String& rType );
293 	String          GetImportFormatName( sal_uInt16 nFormat );
294 	String          GetImportFormatTypeName( sal_uInt16 nFormat );
295 	String          GetImportFormatMediaType( sal_uInt16 nFormat );
296 	String          GetImportFormatShortName( sal_uInt16 nFormat );
297 	String			GetImportOSFileType( sal_uInt16 nFormat );
298 	String			GetImportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry = 0 );
299 	sal_Bool			IsImportPixelFormat( sal_uInt16 nFormat );
300 
301 	sal_uInt16          GetExportFormatCount();
302 	sal_uInt16          GetExportFormatNumber( const String& rFormatName );
303 	sal_uInt16          GetExportFormatNumberForMediaType( const String& rShortName );
304 	sal_uInt16          GetExportFormatNumberForShortName( const String& rShortName );
305 	sal_uInt16		GetExportFormatNumberForTypeName( const String& rType );
306 	String          GetExportFormatName( sal_uInt16 nFormat );
307 	String          GetExportFormatTypeName( sal_uInt16 nFormat );
308 	String          GetExportFormatMediaType( sal_uInt16 nFormat );
309 	String          GetExportFormatShortName( sal_uInt16 nFormat );
310 	String			GetExportOSFileType( sal_uInt16 nFormat );
311 	String			GetExportWildcard( sal_uInt16 nFormat, sal_Int32 nEntry = 0 );
312 	sal_Bool			IsExportPixelFormat( sal_uInt16 nFormat );
313 
314 	sal_Bool			HasImportDialog( sal_uInt16 nFormat );
315 	sal_Bool			DoImportDialog( Window* pWindow, sal_uInt16 nFormat );
316 
317 	sal_Bool			HasExportDialog( sal_uInt16 nFormat );
318 	sal_Bool			DoExportDialog( Window* pWindow, sal_uInt16 nFormat );
319 	sal_Bool			DoExportDialog( Window* pWindow, sal_uInt16 nFormat, FieldUnit eFieldUnit );
320 
321 	sal_uInt16			ExportGraphic( const Graphic& rGraphic, const INetURLObject& rPath,
322 									sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
323 										const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL );
324 	sal_uInt16			ExportGraphic( const Graphic& rGraphic, const String& rPath,
325 									SvStream& rOStm, sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
326 										const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL );
GetExportGraphicHint() const327 	long            GetExportGraphicHint() const { return nExpGraphHint; }
328 
329 	sal_uInt16          CanImportGraphic( const INetURLObject& rPath,
330 									  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
331 									  sal_uInt16 * pDeterminedFormat = NULL);
332 
333 	sal_uInt16          ImportGraphic( Graphic& rGraphic, const INetURLObject& rPath,
334 								   sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
335 								   sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 );
336 
337 	sal_uInt16          CanImportGraphic( const String& rPath, SvStream& rStream,
338 									  sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
339 									  sal_uInt16 * pDeterminedFormat = NULL);
340 
341 	sal_uInt16          ImportGraphic( Graphic& rGraphic, const String& rPath,
342 								   SvStream& rStream,
343 								   sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW,
344 								   sal_uInt16 * pDeterminedFormat = NULL, sal_uInt32 nImportFlags = 0 );
345 
346 	sal_uInt16          ImportGraphic( Graphic& rGraphic, const String& rPath,
347 								   SvStream& rStream,
348 								   sal_uInt16 nFormat,
349 								   sal_uInt16 * pDeterminedFormat, sal_uInt32 nImportFlags,
350 								   com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData );
351 
352 	sal_Bool            Setup( sal_uInt16 nFormat );
353 
Abort()354 	void            Abort() { bAbort = sal_True; }
355 
356 	const FilterErrorEx&	GetLastError() const;
357 	void					ResetLastError();
358 
359     const Link      GetFilterCallback() const;
360 	static 			GraphicFilter* GetGraphicFilter();
361 	static int 		LoadGraphic( const String& rPath, const String& rFilter,
362 					 Graphic& rGraphic,
363 					 GraphicFilter* pFilter = NULL,
364 					 sal_uInt16* pDeterminedFormat = NULL );
365 };
366 
367 // ------------------------------------
368 // - Windows Metafile Lesen/Schreiben -
369 // ------------------------------------
370 
371 SVT_DLLPUBLIC sal_Bool ReadWindowMetafile( SvStream& rStream, GDIMetaFile& rMTF, FilterConfigItem* pConfigItem );
372 SVT_DLLPUBLIC sal_Bool WriteWindowMetafile( SvStream& rStream, const GDIMetaFile& rMTF );
373 SVT_DLLPUBLIC sal_Bool WriteWindowMetafileBits( SvStream& rStream, const GDIMetaFile& rMTF );
374 
375 #endif  //_FILTER_HXX
376