• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ie_impGraphic.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */
00002 
00003 /* AbiWord
00004  * Copyright (C) 1998 AbiSource, Inc.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 
00023 #ifndef IE_IMPGRAPHIC_H
00024 #define IE_IMPGRAPHIC_H
00025 
00026 #include "ut_types.h"
00027 #include "ie_types.h"
00028 #include "ie_imp.h"
00029 #include <string>
00030 #include <vector>
00031 
00032 class FG_Graphic;
00033 class UT_ByteBuf;
00034 class IE_ImpGraphic;
00035 
00039 class ABI_EXPORT IE_ImpGraphicSniffer
00040 {
00041     friend class IE_ImpGraphic;
00042 
00043 public:
00044     virtual ~IE_ImpGraphicSniffer() {}
00045 
00046     // these you get for free
00047     inline bool supportsType (IEGraphicFileType type) {return m_type == type;}
00048     inline IEGraphicFileType getType() const {return m_type;}
00049 
00050     // these you must override these
00051     virtual const IE_SuffixConfidence * getSuffixConfidence () = 0;
00052     virtual const IE_MimeConfidence * getMimeConfidence () = 0;
00053     virtual UT_Confidence_t recognizeContents (const char * szBuf,
00054                                                UT_uint32 iNumbytes);
00055     virtual UT_Confidence_t recognizeContents (GsfInput * input);
00056     virtual bool getDlgLabels (const char ** szDesc,
00057                    const char ** szSuffixList,
00058                    IEGraphicFileType * ft) = 0;
00059     virtual UT_Error constructImporter (IE_ImpGraphic ** ppieg) = 0;
00060 
00061  protected:
00062     IE_ImpGraphicSniffer()
00063         :m_type(IEGFT_Unknown) {}
00064 
00065  private:
00066     // only IE_ImpGraphic ever calls this
00067     IEGraphicFileType m_type;
00068     inline void setType (IEGraphicFileType type) {m_type = type;}
00069 };
00070 
00071 //
00072 // IE_ImpGraphic defines the abstract base class for graphic file importers.
00073 //
00074 // Subclasses which load raster files should generally convert to a
00075 // PNG format image and construct a FG_GraphicRaster.  Subclasses
00076 // which load vector files should generally convert to a SVG format
00077 // and construct a FG_GraphicVector.
00078 //
00079 // That way, the only formats that the layout and display code need to know
00080 // about are PNG and SVG.  The code to handle other formats should be isolated
00081 // in the impexp package.
00082 //
00083 class ABI_EXPORT IE_ImpGraphic
00084 {
00085 public:
00086 
00087   // constructs an importer of the right type based upon
00088   // either the filename or sniffing the file.  caller is
00089   // responsible for destroying the importer when finished
00090   // with it.
00091 
00092   static IEGraphicFileType  fileTypeForSuffix(const char * szSuffix);
00093   static IEGraphicFileType  fileTypeForMimetype(const char * szMimetype);
00094   static IEGraphicFileType  fileTypeForContents(const char * szBuf, UT_uint32 iNumbytes);
00095 
00096   static bool       enumerateDlgLabels(UT_uint32 ndx,
00097                        const char ** pszDesc,
00098                        const char ** pszSuffixList,
00099                        IEGraphicFileType * ft);
00100   static UT_uint32  getImporterCount(void);
00101   static void registerImporter (IE_ImpGraphicSniffer * sniffer);
00102   static void unregisterImporter (IE_ImpGraphicSniffer * sniffer);
00103   static void unregisterAllImporters ();
00104   static std::vector<std::string> & getSupportedMimeTypes ();
00105   static std::vector<std::string> & getSupportedMimeClasses ();
00106   static std::vector<std::string> & getSupportedSuffixes ();
00107   static const char * getMimeTypeForSuffix (const char * suffix);
00108 
00109   static UT_Error               constructImporterWithDescription(const char * szDesc, IE_ImpGraphic ** ppieg);
00110 
00111   static UT_Error               constructImporter(const UT_ByteBuf & bytes,
00112                           IEGraphicFileType ft,
00113                           IE_ImpGraphic **ppieg);
00114   static UT_Error       constructImporter(const char * szFilename,
00115                           IEGraphicFileType ft,
00116                           IE_ImpGraphic **ppieg);
00117   static UT_Error       constructImporter(GsfInput * input,
00118                           IEGraphicFileType ft,
00119                           IE_ImpGraphic **ppieg);
00120 
00121   virtual ~IE_ImpGraphic() {}
00122 
00123   static UT_Error loadGraphic(const char * szFilename,
00124                               IEGraphicFileType iegft,
00125                               FG_Graphic ** ppfg);
00126   static UT_Error loadGraphic(GsfInput * input,
00127                               IEGraphicFileType iegft,
00128                               FG_Graphic ** ppfg);
00129   static UT_Error loadGraphic(const UT_ByteBuf &pBB,
00130                               IEGraphicFileType iegft,
00131                               FG_Graphic ** ppfg);
00132 
00133   //  Note subclassers:  ownership of pBB is passed here, so
00134   //  free pBB if you don't need it.
00135 
00136   // you must override at least one of the importGraphic calls
00137   virtual UT_Error  importGraphic(UT_ByteBuf* pBB,
00138                                   FG_Graphic ** ppfg);
00139   virtual UT_Error  importGraphic(GsfInput * input,
00140                                   FG_Graphic ** ppfg);
00141 
00142   UT_Error  importGraphic(const char * szFilename,
00143                           FG_Graphic ** ppfg);
00144 
00145 
00146 
00147 private:
00148 
00149 };
00150 
00151 #endif /* IE_IMP_H */

Generated on Wed May 22 2013 for AbiWord by  doxygen 1.7.1