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