1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filter.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
35 #include <bf_svtools/fltcall.hxx>
38 #ifndef INCLUDED_SVTDLLAPI_H
39 #include "bf_svtools/svtdllapi.h"
42 #ifndef _STREAM_HXX //autogen
43 #include <tools/stream.hxx>
45 #ifndef _SV_GRAPH_HXX //autogen
46 #include <vcl/graph.hxx>
48 #ifndef _GEN_HXX //autogen
49 #include <tools/gen.hxx>
52 #include <tools/urlobj.hxx>
56 #include <vcl/field.hxx>
59 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_
60 #include <com/sun/star/uno/Sequence.h>
62 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
63 #include <com/sun/star/beans/PropertyValue.hpp>
72 // -----------------------
73 // - GraphicFilter-Types -
74 // -----------------------
76 struct ImplDirEntryHelper
78 static BOOL
Exists( const INetURLObject
& rObj
);
79 static void Kill( const String
& rStr
);
84 #define OPT_FILTERSECTION "Graphic"
87 #define GRFILTER_OPENERROR 1
88 #define GRFILTER_IOERROR 2
89 #define GRFILTER_FORMATERROR 3
90 #define GRFILTER_VERSIONERROR 4
91 #define GRFILTER_FILTERERROR 5
92 #define GRFILTER_ABORT 6
93 #define GRFILTER_TOOBIG 7
95 #define GRFILTER_FORMAT_NOTFOUND ((USHORT)0xFFFF)
96 #define GRFILTER_FORMAT_DONTKNOW ((USHORT)0xFFFF)
98 #define GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG 00000001
99 #define GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG 00000002
100 #define GRFILTER_I_FLAGS_FOR_PREVIEW 00000004
101 #define GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD 00000010
103 #define IMP_BMP "SVBMP"
104 #define IMP_SVMETAFILE "SVMETAFILE"
105 #define IMP_WMF "SVWMF"
106 #define IMP_EMF "SVEMF"
107 #define IMP_SVSGF "SVSGF"
108 #define IMP_SVSGV "SVSGV"
109 #define IMP_GIF "SVIGIF"
110 #define IMP_PNG "SVIPNG"
111 #define IMP_JPEG "SVIJPEG"
112 #define IMP_XBM "SVIXBM"
113 #define IMP_XPM "SVIXPM"
114 #define EXP_BMP "SVBMP"
115 #define EXP_SVMETAFILE "SVMETAFILE"
116 #define EXP_WMF "SVWMF"
117 #define EXP_EMF "SVEMF"
118 #define EXP_JPEG "SVEJPEG"
119 #define EXP_SVG "SVESVG"
120 #define EXP_PNG "SVEPNG"
122 #define BMP_SHORTNAME "BMP"
123 #define GIF_SHORTNAME "GIF"
124 #define JPG_SHORTNAME "JPG"
125 #define MET_SHORTNAME "MET"
126 #define PCT_SHORTNAME "PCT"
127 #define PNG_SHORTNAME "PNG"
128 #define SVM_SHORTNAME "SVM"
129 #define TIF_SHORTNAME "TIF"
130 #define WMF_SHORTNAME "WMF"
131 #define EMF_SHORTNAME "EMF"
133 // ------------------------------------
134 // - Info-Klasse fuer alle von uns
135 // unterstuetzten Grafik-Fileformate
136 // ------------------------------------
138 #define GFF_NOT ( (USHORT)0x0000 )
139 #define GFF_BMP ( (USHORT)0x0001 )
140 #define GFF_GIF ( (USHORT)0x0002 )
141 #define GFF_JPG ( (USHORT)0x0003 )
142 #define GFF_PCD ( (USHORT)0x0004 )
143 #define GFF_PCX ( (USHORT)0x0005 )
144 #define GFF_PNG ( (USHORT)0x0006 )
145 #define GFF_TIF ( (USHORT)0x0007 )
146 #define GFF_XBM ( (USHORT)0x0008 )
147 #define GFF_XPM ( (USHORT)0x0009 )
148 #define GFF_PBM ( (USHORT)0x000a )
149 #define GFF_PGM ( (USHORT)0x000b )
150 #define GFF_PPM ( (USHORT)0x000c )
151 #define GFF_RAS ( (USHORT)0x000d )
152 #define GFF_TGA ( (USHORT)0x000e )
153 #define GFF_PSD ( (USHORT)0x000f )
154 #define GFF_EPS ( (USHORT)0x0010 )
155 #define GFF_DXF ( (USHORT)0x00f1 )
156 #define GFF_MET ( (USHORT)0x00f2 )
157 #define GFF_PCT ( (USHORT)0x00f3 )
158 #define GFF_SGF ( (USHORT)0x00f4 )
159 #define GFF_SVM ( (USHORT)0x00f5 )
160 #define GFF_WMF ( (USHORT)0x00f6 )
161 #define GFF_SGV ( (USHORT)0x00f7 )
162 #define GFF_EMF ( (USHORT)0x00f8 )
163 #define GFF_XXX ( (USHORT)0xffff )
172 ULONG nRealBufferSize
;
175 // ---------------------
176 // - GraphicDescriptor -
177 // ---------------------
179 class GraphicDescriptor
189 USHORT nBitsPerPixel
;
203 //#if 0 // _SOLAR__PRIVATE
205 BOOL
ImpDetectBMP( SvStream
& rStm
, BOOL bExtendedInfo
);
206 BOOL
ImpDetectGIF( SvStream
& rStm
, BOOL bExtendedInfo
);
207 BOOL
ImpDetectJPG( SvStream
& rStm
, BOOL bExtendedInfo
);
208 BOOL
ImpDetectPCD( SvStream
& rStm
, BOOL bExtendedInfo
);
209 BOOL
ImpDetectPCX( SvStream
& rStm
, BOOL bExtendedInfo
);
210 BOOL
ImpDetectPNG( SvStream
& rStm
, BOOL bExtendedInfo
);
211 BOOL
ImpDetectTIF( SvStream
& rStm
, BOOL bExtendedInfo
);
212 BOOL
ImpDetectXBM( SvStream
& rStm
, BOOL bExtendedInfo
);
213 BOOL
ImpDetectXPM( SvStream
& rStm
, BOOL bExtendedInfo
);
214 BOOL
ImpDetectPBM( SvStream
& rStm
, BOOL bExtendedInfo
);
215 BOOL
ImpDetectPGM( SvStream
& rStm
, BOOL bExtendedInfo
);
216 BOOL
ImpDetectPPM( SvStream
& rStm
, BOOL bExtendedInfo
);
217 BOOL
ImpDetectRAS( SvStream
& rStm
, BOOL bExtendedInfo
);
218 BOOL
ImpDetectTGA( SvStream
& rStm
, BOOL bExtendedInfo
);
219 BOOL
ImpDetectPSD( SvStream
& rStm
, BOOL bExtendedInfo
);
220 BOOL
ImpDetectEPS( SvStream
& rStm
, BOOL bExtendedInfo
);
221 BOOL
ImpDetectDXF( SvStream
& rStm
, BOOL bExtendedInfo
);
222 BOOL
ImpDetectMET( SvStream
& rStm
, BOOL bExtendedInfo
);
223 BOOL
ImpDetectPCT( SvStream
& rStm
, BOOL bExtendedInfo
);
224 BOOL
ImpDetectSGF( SvStream
& rStm
, BOOL bExtendedInfo
);
225 BOOL
ImpDetectSVM( SvStream
& rStm
, BOOL bExtendedInfo
);
226 BOOL
ImpDetectWMF( SvStream
& rStm
, BOOL bExtendedInfo
);
227 BOOL
ImpDetectSGV( SvStream
& rStm
, BOOL bExtendedInfo
);
228 BOOL
ImpDetectEMF( SvStream
& rStm
, BOOL bExtendedInfo
);
232 GraphicDescriptor( const GraphicDescriptor
& );
233 GraphicDescriptor
& operator=( const GraphicDescriptor
& );
237 SvStream
& GetSearchStream() const;
238 const String
& GetPathExtension() const;
241 // Ctor, um einen Stream zu setzen. Es muss ::Detect() gerufen werden,
242 // um das File zu identifizieren;
243 // da einige Formate ( Mtf's ) keinen eindeutigen Header besitzen,
244 // ist es sinnvoll den Filenamen (inkl. Ext. ) mitanzugeben,
245 // da so das Format ueber die Extension ermittelt werden kann
246 GraphicDescriptor( SvStream
& rInStream
, const String
* pPath
= NULL
);
249 virtual ~GraphicDescriptor();
251 // Startet die Detektion;
252 // bei bExtendedInfo == TRUE werden soweit wie moeglich
253 // Daten aus dem jeweiligen FileHeader ermittelt
254 // ( Groesse, Farbtiefe usw. )
255 virtual BOOL
Detect( BOOL bExtendedInfo
= FALSE
);
257 // liefert das Fileformat nach erfolgreicher Detektion zurueck;
258 // wenn kein Format erkannt wurde, ist das Formart GFF_NOT
259 USHORT
GetFileFormat() const { return nFormat
; }
261 // liefert die Pixel-Bildgroesse oder 0-Size zurueck
262 const Size
& GetSizePixel() const { return (Size
&) aPixSize
; }
264 // liefert die logische Bildgroesse in 1/100mm oder 0-Size zurueck
265 const Size
& GetSize_100TH_MM() const { return (Size
&) aLogSize
; }
267 // liefert die Bits/Pixel oder 0 zurueck
268 USHORT
GetBitsPerPixel() const { return nBitsPerPixel
; }
270 // liefert die Anzahl der Planes oder 0 zurueck
271 USHORT
GetPlanes() const { return nPlanes
; }
273 // zeigt an, ob das Bild evtl. komprimiert (wie auch immer) ist
274 BOOL
IsCompressed() const { return bCompressed
; }
276 // gibt den LinkHdl zum Setzen der Bytes zurueck
277 const Link
& GetRequestHdl() const { return aReqLink
; }
279 // gibt die Filternummer des Filters zurueck,
280 // der im GraphicFilter zum Lesen dieses Formats
282 static String
GetImportFormatShortName( sal_uInt16 nFormat
);
298 FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
301 // -----------------------------------------------------------------------------
303 class FilterConfigCache
;
306 friend class SvFilterOptionsDialog
;
311 ULONG
ImplSetError( ULONG nError
, const SvStream
* pStm
= NULL
);
312 sal_uInt16
ImpTestOrFindFormat( const String
& rPath
, SvStream
& rStream
, sal_uInt16
& rFormat
);
314 DECL_LINK( FilterCallback
, ConvertData
* pData
);
319 FilterConfigCache
* pConfig
;
320 FilterErrorEx
* pErrorEx
;
334 GraphicFilter( sal_Bool bUseConfig
= sal_True
);
337 void SetFilterPath( const String
& rFilterPath
) { aFilterPath
= rFilterPath
; };
339 USHORT
GetImportFormatCount();
340 USHORT
GetImportFormatNumber( const String
& rFormatName
);
341 USHORT
GetImportFormatNumberForMediaType( const String
& rMediaType
);
342 USHORT
GetImportFormatNumberForShortName( const String
& rShortName
);
343 sal_uInt16
GetImportFormatNumberForTypeName( const String
& rType
);
344 String
GetImportFormatName( USHORT nFormat
);
345 String
GetImportFormatTypeName( USHORT nFormat
);
346 String
GetImportFormatMediaType( USHORT nFormat
);
347 String
GetImportFormatShortName( USHORT nFormat
);
348 String
GetImportWildcard( USHORT nFormat
, sal_Int32 nEntry
= 0 );
349 BOOL
IsImportPixelFormat( USHORT nFormat
);
351 USHORT
GetExportFormatCount();
352 USHORT
GetExportFormatNumber( const String
& rFormatName
);
353 USHORT
GetExportFormatNumberForMediaType( const String
& rShortName
);
354 USHORT
GetExportFormatNumberForShortName( const String
& rShortName
);
355 sal_uInt16
GetExportFormatNumberForTypeName( const String
& rType
);
356 String
GetExportFormatName( USHORT nFormat
);
357 String
GetExportFormatTypeName( USHORT nFormat
);
358 String
GetExportFormatMediaType( USHORT nFormat
);
359 String
GetExportFormatShortName( USHORT nFormat
);
360 String
GetExportWildcard( USHORT nFormat
, sal_Int32 nEntry
= 0 );
361 USHORT
ExportGraphic( const Graphic
& rGraphic
, const INetURLObject
& rPath
,
362 USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
363 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
= NULL
);
364 USHORT
ExportGraphic( const Graphic
& rGraphic
, const String
& rPath
,
365 SvStream
& rOStm
, USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
366 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
= NULL
);
368 USHORT
CanImportGraphic( const INetURLObject
& rPath
,
369 USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
370 USHORT
* pDeterminedFormat
= NULL
);
372 USHORT
ImportGraphic( Graphic
& rGraphic
, const INetURLObject
& rPath
,
373 USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
374 USHORT
* pDeterminedFormat
= NULL
, sal_uInt32 nImportFlags
= 0 );
376 USHORT
CanImportGraphic( const String
& rPath
, SvStream
& rStream
,
377 USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
378 USHORT
* pDeterminedFormat
= NULL
);
380 USHORT
ImportGraphic( Graphic
& rGraphic
, const String
& rPath
,
382 USHORT nFormat
= GRFILTER_FORMAT_DONTKNOW
,
383 USHORT
* pDeterminedFormat
= NULL
, sal_uInt32 nImportFlags
= 0 );
385 USHORT
ImportGraphic( Graphic
& rGraphic
, const String
& rPath
,
388 USHORT
* pDeterminedFormat
, sal_uInt32 nImportFlags
,
389 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
);
391 void Abort() { bAbort
= TRUE
; }
393 void ResetLastError();
395 static GraphicFilter
* GetGraphicFilter();
398 // ------------------------------------
399 // - Windows Metafile Lesen/Schreiben -
400 // ------------------------------------
402 BOOL
ReadWindowMetafile( SvStream
& rStream
, GDIMetaFile
& rMTF
, FilterConfigItem
* pConfigItem
);
403 BOOL
WriteWindowMetafileBits( SvStream
& rStream
, const GDIMetaFile
& rMTF
);