1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 //Added by Craig Bradney in July 2007
9 //To be used for basic format detection and checking
10 //One central place for storing all our extensions we support, etc
11 
12 #ifndef _UTIL_FORMATs_H
13 #define _UTIL_FORMATs_H
14 
15 #include <QByteArray>
16 #include <QFile>
17 #include <QFileInfo>
18 #include <QList>
19 #include <QMap>
20 #include <QString>
21 #include <QStringList>
22 #include "scribusapi.h"
23 #include "scconfig.h"
24 
25 bool SCRIBUS_API extensionIndicatesEPS(const QString &ext);
26 bool SCRIBUS_API extensionIndicatesEPSorPS(const QString &ext);
27 bool SCRIBUS_API extensionIndicatesJPEG(const QString &ext);
28 bool SCRIBUS_API extensionIndicatesPDF(const QString &ext);
29 bool SCRIBUS_API extensionIndicatesPNG(const QString &ext);
30 bool SCRIBUS_API extensionIndicatesPSD(const QString &ext);
31 bool SCRIBUS_API extensionIndicatesPattern(const QString &ext);
32 bool SCRIBUS_API extensionIndicatesTIFF(const QString &ext);
33 QString SCRIBUS_API getImageType(const QString& filename);
34 
35 class SCRIBUS_API FormatsManager
36 {
37 	public:
38 
39 		enum ScImageFormatType
40 		{
41             ALLIMAGES 		= 1|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|524288|1048576|2097152|4194304|8388608,
42 #ifdef GMAGICK_FOUND
43             IMAGESIMGFRAME	= 1|2|4|16|32|64|128|256|512|65536|1048576|2097152|4194304|8388608,  // all Types suitable for Image Frames
44 #else
45             IMAGESIMGFRAME	= 1|2|4|16|32|64|128|256|512|262144|524288|1048576|2097152|4194304|8388608,  // all Types suitable for Image Frames
46 #endif
47 			VECTORIMAGES	= 1|64|1024|2048|16384|32768|131072|262144|4194304,  // All pure vector image types
48             RASTORIMAGES	= 2|4|8|32|128|256|512|65536|524288|1048576|2097152|8388608,  // All pure rastor image types
49 			EPS				= 1,      // Encapsulated PostScript
50 			GIF				= 2,      // GIF files
51 			JPEG			= 4,      // JPEG
52 			PAT				= 8,      // Pattern files
53 			PDF				= 16,     // PDF Format
54 			PNG				= 32,     // PNG files
55 			PS				= 64,     // PostScript
56 			PSD				= 128,    // Photoshop Format
57 			TIFF			= 256,    // TIFF
58 			XPM				= 512,    // XPM files
59 			WMF				= 1024,   // WMF files
60 			SVG				= 2048,   // SVG files
61 			AI				= 4096,   // Adobe Illustrator files
62 			XFIG			= 8192,   // Xfig files
63 			CVG				= 16384,  // Calamus Cvg files
64 			WPG				= 32768,  // Word Perfect WPG files
65 #ifdef GMAGICK_FOUND
66 			GMAGICK			= 65536,  // GraphicsMagick
67 #endif
68 			UNICONV			= 131072, // UniConvertor
69 			PCT				= 262144,  // Mac Pict
70 			BMP				= 524288,  // BMP
71 			PGF				= 1048576, // PGF
72 			ORA				= 2097152, // ORA
73             QT				= 4194304, // Qt
74             KRA             = 8388608  // Krita
75 		};
76 
77 /*
78 		enum ScDocumentFormatType
79 		{
80 			ALLDOCUMENTS	= 1|2,
81 			TEXT			= 2|4,
82 			SPREADSHEETS	= 2|4,
83 			DTP				= 0,
84 			WEB				= 0,
85 			PRESENTATION	= 0,
86 			FORMULAS		= 0,
87 			SCRIBUSDOCS		= 1,
88 			TEXT			= 2,
89 			CSV				= 4,
90 			HTML			= 8,
91 			XML				= 16,
92 			CSV				= 32,
93 			CSV				= 64,
94 			CSV				= 128,
95 			CSV				= 256,
96 			CSV				= 512,
97 							= 1024,
98 			OORG_WRITER		= 2048,
99 			MS_WORD			= 4096,
100 			ADOBE_INDESIGN	= 8192,
101 			ADOBE_PAGEMAKER	= 16384,
102 			QUARK_XPRESS	= 32768,
103 		};
104 */
105 		FormatsManager();
106 		~FormatsManager();
107 
108 	/**
109 		 * @brief Returns a pointer to the FormatsManager instance
110 		 * @return A pointer to the FormatsManager instance
111 	 */
112 		static FormatsManager* instance();
113 	/**
114 		 * @brief Deletes the FormatsManager Instance
115 		 * Must be called when FormatsManager is no longer needed.
116 	 */
117 		static void deleteInstance();
118 		void imageFormatSupported(const QString&);
119 		//! Returns the name of a format, eg "Encapsulated PostScript"
120 		QString nameOfFormat(int type);
121 
122 		//! Returns the mimetypes of a format, eg "application/postscript"
123 		QStringList mimetypeOfFormat(int type);
124 
125 		//! Returns in the form of "EPS (*.eps *.EPS *.epsf *.EPSF *.epsi *.EPSI)"
126 		QString extensionsForFormat(int type);
127 
128 		//! Returns in the form of "*.eps *.epsf *.epsi" or "eps|epsf|epsi"
129  		QString extensionListForFormat(int type, int listType);
130 
131 		//! Returns in the form of "All Supported Formats (*.eps *.EPS *.epsf *.EPSF *.epsi *.EPSI);;EPS (*.eps *.EPS);;EPSI (*.epsf *.EPSF);;EPSI (*.epsi *.EPSI);;All Files (*)"
132 		QString fileDialogFormatList(int type);
133 
134 	protected:
135 		QMap<int, QString> m_fmtNames;
136 		QMap<int, QStringList> m_fmtMimeTypes;
137 		QMap<int, QStringList> m_fmts;
138 		QStringList m_fmtList;
139 
140 		QList<QByteArray> m_qtSupportedImageFormats;
141 		QList<QByteArray> m_supportedImageFormats;
142 		void updateSupportedImageFormats(QList<QByteArray>& supportedImageFormats);
143 		void fileTypeStrings(int type, QString& formatList, QString& formatText, QString& formatAll, bool lowerCaseOnly=false);
144 
145 	private:
146 	/**
147 	 * @brief The only instance of FormatsManager available.
148 	 *
149 	 * FormatsManager is singleton and the instance can be queried with the method
150 	 * instance().
151 	 */
152 	static FormatsManager* m_instance;
153 };
154 
155 #endif
156