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