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

ie_exp_HTML_util.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
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 #ifndef IE_EXP_HTML_UTIL_H
00023 #define IE_EXP_HTML_UTIL_H
00024 
00025 // External includes
00026 #include <vector>
00027 #include <string>
00028 #include <map>
00029 #include <algorithm>
00030 #include <gsf/gsf-output.h>
00031 
00032 // Abiword includes
00033 #include <ie_TOC.h>
00034 #include <ie_Table.h>
00035 #include <pd_Document.h>
00036 #include <ut_go_file.h>
00037 #include <ut_string_class.h>
00038 #include <ut_types.h>
00039 #include <ut_debugmsg.h>
00040 #include <ut_base64.h>
00041 
00042 #define MYEOL "\n"
00043 #define FILES_DIR_NAME "_files"
00044 #define MULTIPART_BOUNDARY "AbiWord_multipart_boundary____________"
00045 #define MULTIPART_FIELD(key, value) UT_UTF8String_sprintf("%s : %s\n", key, value)
00046 
00047 extern const char * s_prop_list[];
00048 extern const UT_uint32 s_PropListLen;
00049 extern const char s_DTD_XHTML_AWML[];
00050 extern const char s_DTD_XHTML[];
00051 extern const char s_DTD_HTML4[];
00052 extern const char s_Delimiter[];
00053 extern const char s_HeaderCompact[];
00054 extern bool m_bSecondPass;
00055 extern bool m_bInAFENote;
00056 extern bool m_bInAnnotation;
00057 extern UT_UTF8String sMathSVGScript;
00058 extern UT_UTF8String sStyleSheet;
00059 
00060 extern const char * s_Header[2];
00061 
00062 UT_UTF8String s_string_to_url (const UT_String & str);
00063 UT_UTF8String s_string_to_url (const UT_UTF8String & str);
00064 bool is_CSS (const char * prop_name, const char ** prop_default = 0);
00065 void s_removeWhiteSpace (const char * text, std::string& utf8str,
00066                            bool bLowerCase = true);
00067 // Returns alpha-numeric contents of string
00068 UT_UTF8String ConvertToClean(const UT_UTF8String &str);
00069 
00070 // Returns css representation for size params
00071 UT_UTF8String getStyleSizeString(const gchar * szWidth, double widthPercentage,
00072     UT_Dimension widthDim, const gchar * szHeight,
00073     UT_Dimension heightDim, bool bUseScale);
00074 
00075 bool getPropertySize(const PP_AttrProp * pAP, const gchar* szWidthProp,
00076     const gchar* szHeightProp, const gchar** szWidth, double& widthPercentage,
00077     const gchar** szHeight, double dPageWidthInches, double dSecLeftMarginInches,
00078     double dSecRightMarginInches, double dCellWidthInches,
00079     ie_Table &tableHelper);
00080 
00081 class IE_Exp_HTML_OutputWriter;
00082 /*
00083  * This class allows to control creation of files (like CSS, JS and images)
00084  * while exporting to {X,P}HTML
00085  */
00086 class ABI_EXPORT IE_Exp_HTML_DataExporter{
00087 public:
00088     IE_Exp_HTML_DataExporter(PD_Document* pDocument,
00089             const UT_UTF8String &filename);
00090     virtual ~IE_Exp_HTML_DataExporter(){}
00091     /*
00092      * Saves object with specified dataid to disk and returns relative to index
00093      * document path it
00094      */
00095     virtual UT_UTF8String saveData(
00096         const gchar *szDataId, const gchar* extension) = 0;
00097     virtual UT_UTF8String saveData(const UT_UTF8String &name,
00098     const UT_UTF8String &data) = 0;
00099 
00100     /*
00101      * Encodes data with specified dataid using Base64 and places string
00102      * containing result in buffer
00103      */
00104     void encodeDataBase64(const gchar *szDataId, UT_UTF8String &result,
00105         bool bAddInfo = true);
00106 
00107 protected:
00108     PD_Document *m_pDocument;
00109     UT_UTF8String m_fileDirectory;
00110     UT_UTF8String m_baseDirectory;
00111 };
00112 
00113 class IE_Exp_HTML_FileExporter : public IE_Exp_HTML_DataExporter
00114 {
00115 public:
00116     IE_Exp_HTML_FileExporter(PD_Document* pDocument,
00117             const UT_UTF8String &baseName);
00118 
00119     UT_UTF8String saveData(const gchar *szDataId, const gchar* extension);
00120     UT_UTF8String saveData(const UT_UTF8String &name,
00121     const UT_UTF8String &data);
00122 private:
00123     void _init();
00124     bool m_bInitialized;
00125     std::map<UT_UTF8String, UT_UTF8String> m_saved;
00126 };
00127 
00128 
00129 
00130 class ABI_EXPORT IE_Exp_HTML_MultipartExporter : public IE_Exp_HTML_DataExporter
00131 {
00132 public:
00133     IE_Exp_HTML_MultipartExporter(PD_Document* pDocument,
00134             const UT_UTF8String &baseName,
00135             UT_UTF8String &buffer,
00136             const UT_UTF8String &title);
00137 
00138     UT_UTF8String saveData(const gchar *szDataId, const gchar* extension);
00139     UT_UTF8String saveData(const UT_UTF8String &name,
00140         const UT_UTF8String &data);
00141 
00142     UT_UTF8String generateHeader(const UT_UTF8String &index,
00143         const UT_UTF8String &mimetype);
00144 private:
00145     UT_UTF8String &m_buffer;
00146     UT_UTF8String m_title;
00147 };
00148 
00152 class ABI_EXPORT IE_Exp_HTML_OutputWriter
00153 {
00154 public:
00155     virtual ~IE_Exp_HTML_OutputWriter() {}
00156     virtual void write(const UT_UTF8String &str) = 0;
00157  };
00158 
00159 class ABI_EXPORT IE_Exp_HTML_FileWriter : public IE_Exp_HTML_OutputWriter
00160 {
00161 public:
00162     IE_Exp_HTML_FileWriter(GsfOutput *output);
00163     void write(const UT_UTF8String &str);
00164 private:
00165     GsfOutput *m_output;
00166 };
00167 
00168 class ABI_EXPORT IE_Exp_HTML_StringWriter: public IE_Exp_HTML_OutputWriter
00169 {
00170 public:
00171     IE_Exp_HTML_StringWriter();
00172     void write(const UT_UTF8String &str);
00173     UT_UTF8String getString() const { return m_buffer; }
00174 private:
00175     UT_UTF8String m_buffer;
00176 };
00177 
00181 class ABI_EXPORT IE_Exp_HTML_TagWriter
00182 {
00183 public:
00184     IE_Exp_HTML_TagWriter(IE_Exp_HTML_OutputWriter *pOutputWriter);
00185     void openTag(const std::string &tagName, bool isInline = false, bool isSingle = false);
00186     void addAttribute(const std::string &name, const std::string &value);
00187     void writeData(const std::string &data);
00188     void closeTag();
00189     void flush();
00190 
00191     void openComment();
00192     void closeComment();
00193 
00194     void enableXmlMode(bool enable = true);
00195 private:
00196 
00197     inline void _closeAttributes();
00198     std::vector<std::string> m_tagStack;
00199     std::vector<bool> m_inlineFlagStack;
00200     IE_Exp_HTML_OutputWriter *m_pOutputWriter;
00201     bool m_bXmlModeEnabled;
00202     bool m_bCurrentTagIsSingle;
00203     bool m_bAttributesWritten;
00204     bool m_bDataWritten;
00205     bool m_bInComment;
00206     std::string m_buffer;
00207 };
00208 
00209 
00210 
00211 #endif

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1