• 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 <memory>
00027 #include <string>
00028 #include <vector>
00029 
00030 #include "ut_types.h"
00031 #include "fg_Graphic.h"
00032 #include "ie_types.h"
00033 #include "ie_imp.h"
00034 
00035 class UT_ByteBuf;
00036 class IE_ImpGraphic;
00037 
00041 class ABI_EXPORT IE_ImpGraphicSniffer
00042 {
00043     friend class IE_ImpGraphic;
00044 
00045 public:
00046     virtual ~IE_ImpGraphicSniffer() {}
00047 
00048     // these you get for free
00049     inline bool supportsType (IEGraphicFileType type) {return m_type == type;}
00050     inline IEGraphicFileType getType() const {return m_type;}
00051 
00052     // these you must override these
00053     virtual const IE_SuffixConfidence * getSuffixConfidence () = 0;
00054     virtual const IE_MimeConfidence * getMimeConfidence () = 0;
00055     virtual UT_Confidence_t recognizeContents (const char * szBuf,
00056                                                UT_uint32 iNumbytes);
00057     virtual UT_Confidence_t recognizeContents (GsfInput * input);
00058     virtual bool getDlgLabels (const char ** szDesc,
00059                    const char ** szSuffixList,
00060                    IEGraphicFileType * ft) = 0;
00061     virtual UT_Error constructImporter (IE_ImpGraphic ** ppieg) = 0;
00062 
00063  protected:
00064     IE_ImpGraphicSniffer()
00065         :m_type(IEGFT_Unknown) {}
00066 
00067  private:
00068     // only IE_ImpGraphic ever calls this
00069     IEGraphicFileType m_type;
00070     inline void setType (IEGraphicFileType type) {m_type = type;}
00071 };
00072 
00073 //
00074 // IE_ImpGraphic defines the abstract base class for graphic file importers.
00075 //
00076 // Subclasses which load raster files should generally convert to a
00077 // PNG format image and construct a FG_GraphicRaster.  Subclasses
00078 // which load vector files should generally convert to a SVG format
00079 // and construct a FG_GraphicVector.
00080 //
00081 // That way, the only formats that the layout and display code need to know
00082 // about are PNG and SVG.  The code to handle other formats should be isolated
00083 // in the impexp package.
00084 //
00085 class ABI_EXPORT IE_ImpGraphic
00086 {
00087 public:
00088 
00089   // constructs an importer of the right type based upon
00090   // either the filename or sniffing the file.  caller is
00091   // responsible for destroying the importer when finished
00092   // with it.
00093 
00094   static IEGraphicFileType  fileTypeForSuffix(const char * szSuffix);
00095   static IEGraphicFileType  fileTypeForMimetype(const char * szMimetype);
00096   static IEGraphicFileType  fileTypeForContents(const char * szBuf, UT_uint32 iNumbytes);
00097 
00098   static bool       enumerateDlgLabels(UT_uint32 ndx,
00099                        const char ** pszDesc,
00100                        const char ** pszSuffixList,
00101                        IEGraphicFileType * ft);
00102   static UT_uint32  getImporterCount(void);
00103   static void registerImporter (IE_ImpGraphicSniffer * sniffer);
00104   static void unregisterImporter (IE_ImpGraphicSniffer * sniffer);
00105   static void unregisterAllImporters ();
00106   static const std::vector<std::string> & getSupportedMimeTypes();
00107   static const std::vector<std::string> & getSupportedMimeClasses();
00108   static const std::vector<std::string> & getSupportedSuffixes();
00109   static const char * getMimeTypeForSuffix (const char * suffix);
00110 
00111   static UT_Error               constructImporterWithDescription(const char * szDesc, IE_ImpGraphic ** ppieg);
00112 
00113   static UT_Error       constructImporter(const UT_ConstByteBufPtr & bytes,
00114                           IEGraphicFileType ft,
00115                           IE_ImpGraphic **ppieg);
00116   static UT_Error       constructImporter(const char * szFilename,
00117                           IEGraphicFileType ft,
00118                           IE_ImpGraphic **ppieg);
00119   static UT_Error       constructImporter(GsfInput * input,
00120                           IEGraphicFileType ft,
00121                           IE_ImpGraphic **ppieg);
00122 
00123   virtual ~IE_ImpGraphic() {}
00124 
00125   static UT_Error loadGraphic(const char * szFilename,
00126                               IEGraphicFileType iegft,
00127                               FG_ConstGraphicPtr& pfg);
00128   static UT_Error loadGraphic(GsfInput * input,
00129                               IEGraphicFileType iegft,
00130                               FG_ConstGraphicPtr& pfg);
00131   static UT_Error loadGraphic(const UT_ConstByteBufPtr &pBB,
00132                               IEGraphicFileType iegft,
00133                               FG_ConstGraphicPtr& pfg);
00134 
00135   //  Note subclassers:  ownership of pBB is passed here, so
00136   //  free pBB if you don't need it.
00137 
00138   // you must override at least one of the importGraphic calls
00139   virtual UT_Error  importGraphic(const UT_ConstByteBufPtr & pBB,
00140                                   FG_ConstGraphicPtr& pfg);
00141   virtual UT_Error  importGraphic(GsfInput * input,
00142                                   FG_ConstGraphicPtr& pfg);
00143 
00144   UT_Error  importGraphic(const char * szFilename,
00145                           FG_ConstGraphicPtr& pfg);
00146 
00147 
00148 
00149 private:
00150 
00151 };
00152 
00153 #endif /* IE_IMP_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1