1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <tools/gen.hxx>
24 #include <tools/stream.hxx>
25 #include <tools/urlobj.hxx>
26 #include <vcl/dllapi.h>
27 #include <vcl/field.hxx>
28 #include <vcl/graph.hxx>
30 #include <com/sun/star/uno/Sequence.h>
31 #include <com/sun/star/beans/PropertyValue.hpp>
33 class FilterConfigCache
;
34 struct WMF_EXTERNALHEADER
;
38 #define GRFILTER_OPENERROR 1
39 #define GRFILTER_IOERROR 2
40 #define GRFILTER_FORMATERROR 3
41 #define GRFILTER_VERSIONERROR 4
42 #define GRFILTER_FILTERERROR 5
43 #define GRFILTER_ABORT 6
44 #define GRFILTER_TOOBIG 7
46 #define GRFILTER_OUTHINT_GREY 1
48 #define GRFILTER_FORMAT_NOTFOUND ((sal_uInt16)0xFFFF)
49 #define GRFILTER_FORMAT_DONTKNOW ((sal_uInt16)0xFFFF)
51 #define GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG 00000001
52 #define GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG 00000002
53 #define GRFILTER_I_FLAGS_FOR_PREVIEW 00000004
54 #define GRFILTER_I_FLAGS_ALLOW_PARTIAL_STREAMREAD 00000010
56 #define IMP_BMP "SVBMP"
57 #define IMP_SVMETAFILE "SVMETAFILE"
58 #define IMP_WMF "SVWMF"
59 #define IMP_EMF "SVEMF"
60 #define IMP_SVSGF "SVSGF"
61 #define IMP_SVSGV "SVSGV"
62 #define IMP_GIF "SVIGIF"
63 #define IMP_PNG "SVIPNG"
64 #define IMP_JPEG "SVIJPEG"
65 #define IMP_XBM "SVIXBM"
66 #define IMP_XPM "SVIXPM"
67 #define IMP_SVG "SVISVG"
68 #define EXP_BMP "SVBMP"
69 #define EXP_SVMETAFILE "SVMETAFILE"
70 #define EXP_WMF "SVWMF"
71 #define EXP_EMF "SVEMF"
72 #define EXP_JPEG "SVEJPEG"
73 #define EXP_SVG "SVESVG"
74 #define EXP_PNG "SVEPNG"
76 #define BMP_SHORTNAME "BMP"
77 #define GIF_SHORTNAME "GIF"
78 #define JPG_SHORTNAME "JPG"
79 #define MET_SHORTNAME "MET"
80 #define PCT_SHORTNAME "PCT"
81 #define PNG_SHORTNAME "PNG"
82 #define SVM_SHORTNAME "SVM"
83 #define TIF_SHORTNAME "TIF"
84 #define WMF_SHORTNAME "WMF"
85 #define EMF_SHORTNAME "EMF"
86 #define SVG_SHORTNAME "SVG"
88 // Info class for all supported file formats
90 #define GFF_NOT ( (sal_uInt16)0x0000 )
91 #define GFF_BMP ( (sal_uInt16)0x0001 )
92 #define GFF_GIF ( (sal_uInt16)0x0002 )
93 #define GFF_JPG ( (sal_uInt16)0x0003 )
94 #define GFF_PCD ( (sal_uInt16)0x0004 )
95 #define GFF_PCX ( (sal_uInt16)0x0005 )
96 #define GFF_PNG ( (sal_uInt16)0x0006 )
97 #define GFF_TIF ( (sal_uInt16)0x0007 )
98 #define GFF_XBM ( (sal_uInt16)0x0008 )
99 #define GFF_XPM ( (sal_uInt16)0x0009 )
100 #define GFF_PBM ( (sal_uInt16)0x000a )
101 #define GFF_PGM ( (sal_uInt16)0x000b )
102 #define GFF_PPM ( (sal_uInt16)0x000c )
103 #define GFF_RAS ( (sal_uInt16)0x000d )
104 #define GFF_TGA ( (sal_uInt16)0x000e )
105 #define GFF_PSD ( (sal_uInt16)0x000f )
106 #define GFF_EPS ( (sal_uInt16)0x0010 )
107 #define GFF_DXF ( (sal_uInt16)0x00f1 )
108 #define GFF_MET ( (sal_uInt16)0x00f2 )
109 #define GFF_PCT ( (sal_uInt16)0x00f3 )
110 #define GFF_SGF ( (sal_uInt16)0x00f4 )
111 #define GFF_SVM ( (sal_uInt16)0x00f5 )
112 #define GFF_WMF ( (sal_uInt16)0x00f6 )
113 #define GFF_SGV ( (sal_uInt16)0x00f7 )
114 #define GFF_EMF ( (sal_uInt16)0x00f8 )
115 #define GFF_SVG ( (sal_uInt16)0x00f9 )
116 #define GFF_XXX ( (sal_uInt16)0xffff )
118 // ---------------------
119 // - GraphicDescriptor -
120 // ---------------------
122 class VCL_DLLPUBLIC GraphicDescriptor
129 sal_uInt16 nBitsPerPixel
;
132 sal_Bool bCompressed
;
137 sal_Bool
ImpDetectBMP( SvStream
& rStm
, sal_Bool bExtendedInfo
);
138 sal_Bool
ImpDetectGIF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
139 sal_Bool
ImpDetectJPG( SvStream
& rStm
, sal_Bool bExtendedInfo
);
140 sal_Bool
ImpDetectPCD( SvStream
& rStm
, sal_Bool bExtendedInfo
);
141 sal_Bool
ImpDetectPCX( SvStream
& rStm
, sal_Bool bExtendedInfo
);
142 sal_Bool
ImpDetectPNG( SvStream
& rStm
, sal_Bool bExtendedInfo
);
143 sal_Bool
ImpDetectTIF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
144 sal_Bool
ImpDetectXBM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
145 sal_Bool
ImpDetectXPM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
146 sal_Bool
ImpDetectPBM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
147 sal_Bool
ImpDetectPGM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
148 sal_Bool
ImpDetectPPM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
149 sal_Bool
ImpDetectRAS( SvStream
& rStm
, sal_Bool bExtendedInfo
);
150 sal_Bool
ImpDetectTGA( SvStream
& rStm
, sal_Bool bExtendedInfo
);
151 sal_Bool
ImpDetectPSD( SvStream
& rStm
, sal_Bool bExtendedInfo
);
152 sal_Bool
ImpDetectEPS( SvStream
& rStm
, sal_Bool bExtendedInfo
);
153 sal_Bool
ImpDetectDXF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
154 sal_Bool
ImpDetectMET( SvStream
& rStm
, sal_Bool bExtendedInfo
);
155 sal_Bool
ImpDetectPCT( SvStream
& rStm
, sal_Bool bExtendedInfo
);
156 sal_Bool
ImpDetectSGF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
157 sal_Bool
ImpDetectSVM( SvStream
& rStm
, sal_Bool bExtendedInfo
);
158 sal_Bool
ImpDetectWMF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
159 sal_Bool
ImpDetectSGV( SvStream
& rStm
, sal_Bool bExtendedInfo
);
160 sal_Bool
ImpDetectEMF( SvStream
& rStm
, sal_Bool bExtendedInfo
);
161 sal_Bool
ImpDetectSVG( SvStream
& rStm
, sal_Bool bExtendedInfo
);
162 GraphicDescriptor( const GraphicDescriptor
& );
163 GraphicDescriptor
& operator=( const GraphicDescriptor
& );
167 /** Ctor to set a filename
169 ::Detect() must be called to identify the file
170 If the file has no unique header (Mtf's), the format
171 is determined from the extension */
172 GraphicDescriptor( const INetURLObject
& rPath
);
174 /** Ctor using a stream
176 ::Detect() must be called to identify the file
177 As some formats (Mtf's) do not have a unique header, it makes sense
178 to supply the file name (incl. ext.), so that the format can be
179 derived from the extension */
180 GraphicDescriptor( SvStream
& rInStream
, const String
* pPath
= NULL
);
182 virtual ~GraphicDescriptor();
184 /** starts the detection
186 if bExtendedInfo == sal_True the file header is used to derive
187 as many properties as possible (size, color, etc.) */
188 virtual sal_Bool
Detect( sal_Bool bExtendedInfo
= sal_False
);
190 /** @return the file format, GFF_NOT if no format was recognized */
191 sal_uInt16
GetFileFormat() const { return nFormat
; }
193 /** @return graphic size in pixels or 0 size */
194 const Size
& GetSizePixel() const { return (Size
&) aPixSize
; }
196 /** @return the logical graphic size in 1/100mm or 0 size */
197 const Size
& GetSize_100TH_MM() const { return (Size
&) aLogSize
; }
199 /** @return bits/pixel or 0 **/
200 sal_uInt16
GetBitsPerPixel() const { return nBitsPerPixel
; }
202 /** return number of planes or 0 */
203 sal_uInt16
GetPlanes() const { return nPlanes
; }
205 /** @return true if the graphic is compressed */
206 sal_Bool
IsCompressed() const { return bCompressed
; }
208 /** @return filter number that is needed by the GraphFilter to read this format */
209 static String
GetImportFormatShortName( sal_uInt16 nFormat
);
212 /** Information about errors during the GraphicFilter operation. */
215 sal_uLong nFilterError
;
216 sal_uLong nStreamError
;
218 FilterErrorEx() : nFilterError( 0UL ), nStreamError( 0UL ) {}
221 /** Class to import and export graphic formats. */
222 class VCL_DLLPUBLIC GraphicFilter
224 friend class SvFilterOptionsDialog
;
229 sal_uLong
ImplSetError( sal_uLong nError
, const SvStream
* pStm
= NULL
);
230 sal_uInt16
ImpTestOrFindFormat( const String
& rPath
, SvStream
& rStream
, sal_uInt16
& rFormat
);
232 DECL_LINK( FilterCallback
, ConvertData
* pData
);
236 OUString aFilterPath
;
237 FilterConfigCache
* pConfig
;
238 FilterErrorEx
* pErrorEx
;
245 GraphicFilter( sal_Bool bUseConfig
= sal_True
);
248 void SetFilterPath( const OUString
& rFilterPath
) { aFilterPath
= rFilterPath
; };
250 sal_uInt16
GetImportFormatCount();
251 sal_uInt16
GetImportFormatNumber( const String
& rFormatName
);
252 sal_uInt16
GetImportFormatNumberForMediaType( const String
& rMediaType
);
253 sal_uInt16
GetImportFormatNumberForShortName( const String
& rShortName
);
254 sal_uInt16
GetImportFormatNumberForTypeName( const String
& rType
);
255 String
GetImportFormatName( sal_uInt16 nFormat
);
256 String
GetImportFormatTypeName( sal_uInt16 nFormat
);
257 String
GetImportFormatMediaType( sal_uInt16 nFormat
);
258 String
GetImportFormatShortName( sal_uInt16 nFormat
);
259 String
GetImportOSFileType( sal_uInt16 nFormat
);
260 String
GetImportWildcard( sal_uInt16 nFormat
, sal_Int32 nEntry
= 0 );
261 sal_Bool
IsImportPixelFormat( sal_uInt16 nFormat
);
263 sal_uInt16
GetExportFormatCount();
264 sal_uInt16
GetExportFormatNumber( const String
& rFormatName
);
265 sal_uInt16
GetExportFormatNumberForMediaType( const String
& rShortName
);
266 sal_uInt16
GetExportFormatNumberForShortName( const String
& rShortName
);
267 String
GetExportInternalFilterName( sal_uInt16 nFormat
);
268 sal_uInt16
GetExportFormatNumberForTypeName( const String
& rType
);
269 String
GetExportFormatName( sal_uInt16 nFormat
);
270 String
GetExportFormatTypeName( sal_uInt16 nFormat
);
271 String
GetExportFormatMediaType( sal_uInt16 nFormat
);
272 String
GetExportFormatShortName( sal_uInt16 nFormat
);
273 String
GetExportOSFileType( sal_uInt16 nFormat
);
274 String
GetExportWildcard( sal_uInt16 nFormat
, sal_Int32 nEntry
= 0 );
275 sal_Bool
IsExportPixelFormat( sal_uInt16 nFormat
);
277 sal_uInt16
ExportGraphic( const Graphic
& rGraphic
, const INetURLObject
& rPath
,
278 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
279 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
= NULL
);
280 sal_uInt16
ExportGraphic( const Graphic
& rGraphic
, const String
& rPath
,
281 SvStream
& rOStm
, sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
282 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
= NULL
);
283 long GetExportGraphicHint() const { return nExpGraphHint
; }
285 sal_uInt16
CanImportGraphic( const INetURLObject
& rPath
,
286 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
287 sal_uInt16
* pDeterminedFormat
= NULL
);
289 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const INetURLObject
& rPath
,
290 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
291 sal_uInt16
* pDeterminedFormat
= NULL
, sal_uInt32 nImportFlags
= 0 );
293 sal_uInt16
CanImportGraphic( const String
& rPath
, SvStream
& rStream
,
294 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
295 sal_uInt16
* pDeterminedFormat
= NULL
);
297 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const String
& rPath
,
299 sal_uInt16 nFormat
= GRFILTER_FORMAT_DONTKNOW
,
300 sal_uInt16
* pDeterminedFormat
= NULL
, sal_uInt32 nImportFlags
= 0,
301 WMF_EXTERNALHEADER
*pExtHeader
= NULL
);
303 sal_uInt16
ImportGraphic( Graphic
& rGraphic
, const String
& rPath
,
306 sal_uInt16
* pDeterminedFormat
, sal_uInt32 nImportFlags
,
307 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
,
308 WMF_EXTERNALHEADER
*pExtHeader
= NULL
);
310 void Abort() { bAbort
= sal_True
; }
312 const FilterErrorEx
& GetLastError() const;
313 void ResetLastError();
315 const Link
GetFilterCallback() const;
316 static GraphicFilter
& GetGraphicFilter();
317 static int LoadGraphic( const String
& rPath
, const String
& rFilter
,
319 GraphicFilter
* pFilter
= NULL
,
320 sal_uInt16
* pDeterminedFormat
= NULL
);
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */