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

ie_exp_RTF.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 
00021 #ifndef IE_EXP_RTF_H
00022 #define IE_EXP_RTF_H
00023 
00024 #include "ie_exp.h"
00025 #include "ut_vector.h"
00026 #include "ut_hash.h"
00027 #include "ut_misc.h"
00028 #include "ut_iconv.h"
00029 #include "pl_Listener.h"
00030 #include "fl_AutoLists.h"
00031 #include "fl_AutoNum.h"
00032 
00033 class PD_Document;
00034 class PD_Style;
00035 class PP_AttrProp;
00036 class s_RTF_ListenerWriteDoc;
00037 class s_RTF_ListenerGetProps;
00038 class s_RTF_AttrPropAdapter;
00039 class s_RTF_AttrPropAdapter_Style;
00040 class ie_exp_RTF_MsWord97List;
00041 class ie_exp_RTF_MsWord97ListSimple;
00042 class ie_exp_RTF_MsWord97ListMulti;
00043 class ie_exp_RTF_ListOveride;
00044 class _rtf_font_info;
00045 
00046 // The exporter/writer for RTF file format (based upon spec version 1.5).
00047 
00048 class ABI_EXPORT IE_Exp_RTF_Sniffer : public IE_ExpSniffer
00049 {
00050     friend class IE_Exp;
00051 
00052 public:
00053     IE_Exp_RTF_Sniffer ();
00054     virtual ~IE_Exp_RTF_Sniffer () {}
00055 
00056     UT_Confidence_t supportsMIME (const char * szMIME);
00057 
00058     virtual bool recognizeSuffix (const char * szSuffix);
00059     virtual bool getDlgLabels (const char ** szDesc,
00060                                const char ** szSuffixList,
00061                                IEFileType * ft);
00062     virtual UT_Error constructExporter (PD_Document * pDocument,
00063                                         IE_Exp ** ppie);
00064 };
00065 
00066 /*
00067  * this is for exporting to RTF understood by attic software
00068  * like WordPad and probably Word6.0.
00069  */
00070 class ABI_EXPORT IE_Exp_RTF_attic_Sniffer : public IE_ExpSniffer
00071 {
00072     friend class IE_Exp;
00073 
00074 public:
00075     IE_Exp_RTF_attic_Sniffer ();
00076     virtual ~IE_Exp_RTF_attic_Sniffer () {}
00077 
00078     virtual bool recognizeSuffix (const char * szSuffix);
00079     virtual bool getDlgLabels (const char ** szDesc,
00080                                const char ** szSuffixList,
00081                                IEFileType * ft);
00082     virtual UT_Error constructExporter (PD_Document * pDocument,
00083                                         IE_Exp ** ppie);
00084 };
00085 
00086 // hack for "msword" export
00087 
00088 class ABI_EXPORT IE_Exp_MsWord_Hack_Sniffer : public IE_ExpSniffer
00089 {
00090     friend class IE_Exp;
00091 
00092 public:
00093     IE_Exp_MsWord_Hack_Sniffer ();
00094     virtual ~IE_Exp_MsWord_Hack_Sniffer () {}
00095 
00096     virtual bool recognizeSuffix (const char * szSuffix);
00097     virtual bool getDlgLabels (const char ** szDesc,
00098                    const char ** szSuffixList,
00099                    IEFileType * ft);
00100     virtual UT_Error constructExporter (PD_Document * pDocument,
00101                         IE_Exp ** ppie);
00102 };
00103 
00104 struct NumberedStyle;
00105 
00106 class ABI_EXPORT IE_Exp_RTF : public IE_Exp
00107 {
00108     friend class s_RTF_ListenerWriteDoc;
00109     friend class s_RTF_ListenerGetProps;
00110 
00111 public:
00112     IE_Exp_RTF(PD_Document * pDocument);
00113     IE_Exp_RTF(PD_Document * pDocument,bool atticFormat);
00114     virtual ~IE_Exp_RTF();
00115     ie_exp_RTF_MsWord97ListMulti * getNthMultiLevel(UT_uint32 i) const;
00116     ie_exp_RTF_MsWord97ListSimple * getNthSimple(UT_uint32 i) const;
00117     ie_exp_RTF_ListOveride * getNthOveride(UT_uint32 i) const;
00118     UT_uint32 getMultiLevelCount(void) const;
00119     UT_uint32 getSimpleListCount(void) const;
00120     UT_uint32 getOverideCount(void)  const;
00121     UT_uint32 getMatchingOverideNum(UT_uint32 ID);
00122     void exportHdrFtr(const char * pszHdrFtr , const char * pszHdrFtrID,const char * pszKeyword);
00123     UT_BidiCharType isCharRTL() {return m_CharRTL;}
00124     void setCharRTL(UT_BidiCharType t) {m_CharRTL = t;}
00125     void     setByteBuf(UT_ByteBuf * pBuf)
00126     { _setByteBuf(pBuf);}
00127     UT_ByteBuf * getByteBuf(void)
00128     { return _getByteBuf();}
00129 protected:
00130     virtual UT_Error    _writeDocument(void);
00131     UT_Error            _writeDocumentLocal(bool bSkipHeader);
00132     UT_sint32           _findColor(const char * szColor) const;
00133     UT_sint32           _findOrAddColor (const char * szColor);
00134     void                _addColor(const char * szColor);
00135     void                _rtf_open_brace(void);
00136     void                _rtf_close_brace(void);
00137     bool                _rtf_reopen_brace(void);
00138     void                _rtf_keyword(const char * szKey);
00139     void                _rtf_keyword(const char * szKey, UT_sint32 d);
00140     void                _rtf_keyword_space(const char * szKey, UT_sint32 d);
00141     void                _rtf_keyword(const char * szKey, const char * szValue);
00142     void                _rtf_nonascii_hex2(UT_sint32 d);
00143     void                _rtf_nonascii_hex2(UT_sint32 d, UT_String & pStr);
00144     void                _rtf_keyword_hex2(const char * szKey, UT_sint32 d);
00145     void                _rtf_keyword_ifnotdefault(const char * szKey, const char * szValue, UT_sint32 defaultValue);
00146     void                _rtf_keyword_ifnotdefault_twips(const char * szKey, const char * szValue, UT_sint32 defaultValue);
00147     void                _rtf_semi(void);
00148     void                _rtf_fontname(const char * szFontName);
00149     void                _rtf_chardata(const char * pbuf, UT_uint32 buflen);
00150     void                _rtf_chardata(const std::string& buf);
00151     void                _rtf_pcdata(UT_UTF8String &sPCData, bool bSupplyUC=false, UT_uint32 iAltChars=1);
00152     void                _rtf_pcdata(const std::string & szPCData, bool bSupplyUC=false, UT_uint32 iAltChars=1);
00153     void                _rtf_pcdata(const char * szPCData, bool bSupplyUC=false, UT_uint32 iAltChars=1);
00154     void                _rtf_nl(void);
00155     const gchar *    _getStyleProp(s_RTF_AttrPropAdapter_Style * pADStyle,
00156                                       const s_RTF_AttrPropAdapter * apa,
00157                                       const char * szProp);
00158 
00159     bool                _write_rtf_header(void);
00160     bool                _write_rtf_trailer(void);
00161 
00162     void                            _clearStyles();
00163     void                            _selectStyles();
00164     UT_uint32                       _getStyleNumber(const PD_Style * pStyle);
00165     UT_uint32                       _getStyleNumber(const gchar * szStyleName);
00166 
00167     void                            _write_prop_ifnotdefault(const PD_Style * pStyle, const gchar * szPropName, const char * szRTFName);
00168     void                            _write_prop_ifyes(const PD_Style * pStyle, const gchar * szPropName, const char * szRTFName);
00169     void                            _write_tabdef(const char * szTabStops);
00170     void                            _write_charfmt(const s_RTF_AttrPropAdapter &);
00171 
00172     void                            _write_parafmt(const PP_AttrProp * pSpanAP,
00173                                                    const PP_AttrProp * pBlockAP,
00174                                                    const PP_AttrProp * pSectionAP,
00175                                                    bool & bStartedList, pf_Frag_Strux* sdh, UT_uint32 &iCurrID,
00176                                                    bool &bIsListBlock, UT_sint32 iNestLevel);
00177 
00178     void                            _write_style_fmt(const PD_Style *);
00179     void                            _write_stylesheets(void);
00180     void                            _write_listtable(void);
00181     void                            _output_MultiLevelRTF(ie_exp_RTF_MsWord97ListMulti * pMulti);
00182     void                            _output_SimpleListRTF(ie_exp_RTF_MsWord97ListSimple * pSimple);
00183     void                            _output_OveridesRTF(ie_exp_RTF_ListOveride * pOver, UT_uint32 i);
00184     void                            _output_ListRTF(const fl_AutoNumConstPtr & pAuto, UT_uint32 iLevel);
00185     void                            _output_LevelText(const fl_AutoNumConstPtr & pAuto, UT_uint32 iLevel,UT_UCSChar bulletsym);
00186     void                            _get_LeftRight_Side(UT_String & LeftSide, UT_String & RightSide);
00187     void                            _generate_level_Text(const fl_AutoNumConstPtr & pAuto,UT_String & LevelText,UT_String &LevelNumbers, UT_uint32 & lenText, UT_uint32 & ifoundLevel);
00188 
00189     void                            _output_revision(const s_RTF_AttrPropAdapter & apa, bool bPara,pf_Frag_Strux* sdh,
00190                                                      UT_sint32 iNestLevel, bool & bStartedList,  bool &bIsListBlock,
00191                                                      UT_uint32 &iCurrID);
00192 
00193     UT_sint32           _findFont(const s_RTF_AttrPropAdapter * apa) const;
00194     UT_sint32           _findFont(const _rtf_font_info * pfi) const;
00195     void                _addFont(const _rtf_font_info * pfi);
00196 
00197  private:
00198     static bool s_escapeString(UT_UTF8String &sOutStr, UT_UCS4String &sInStr,
00199                                UT_uint32 iAltChars);
00200     static bool s_escapeString(UT_UTF8String &sOutStr, const char * szInStr,
00201                                UT_uint32 iSize, UT_uint32 iAltChars);
00202     static bool s_escapeString( std::string& outStr, const std::string& inStr,
00203                                UT_uint32 iAltChars = 1 );
00204     static std::string s_escapeString( const std::string& inStr, UT_uint32 iAltChars = 1 );
00205     static std::string s_escapeXMLString( const std::string& inStr );
00206 
00207     s_RTF_ListenerWriteDoc *    m_pListenerWriteDoc;
00208     UT_Vector                   m_vecColors;            /* vector of "const char * szColor" */
00209     UT_Vector                   m_vecFonts;             /* vector of struct _font */
00210     bool                        m_bNeedUnicodeText;     /* doc has unicode chars */
00211     UT_sint32                   m_braceLevel;           /* nesting depth of {} braces */
00212     bool                        m_bLastWasKeyword;      /* just wrote a keyword, so need space before text data */
00213     bool                        m_atticFormat;      /* whether to use unicode for all characters >0xff or convert to native windows encoding*/
00214     UT_GenericStringMap<NumberedStyle*> m_hashStyles;
00215     /* Hash containing styles to be exported. The key is the
00216        AbiWord style name. The value is a NumberedStyle object
00217        (see the cpp file). */
00218     UT_Vector                   m_vecMultiLevel;
00219     UT_Vector                   m_vecSimpleList;
00220     UT_Vector                   m_vecOverides;
00221 
00222     UT_BidiCharType             m_CharRTL;
00223     UT_iconv_t                  m_conv;
00224 };
00225 
00226 /*****************************************************************/
00227 /*****************************************************************/
00228 
00229 /* This struct contains the RTF font info as needed for the
00230    font table. */
00231 class ABI_EXPORT _rtf_font_info
00232 {
00233 public:
00234     _rtf_font_info();
00235     bool init(const s_RTF_AttrPropAdapter & apa, bool bDoFieldFont = false);
00236     bool init(const char * szfontName);
00237     virtual ~_rtf_font_info(void);
00238     bool _is_same(const _rtf_font_info & fi) const;
00239     const char * getFontFamily(void) const { return szFamily;}
00240     const char * getFontName(void) const { return m_szName.c_str();}
00241     int getFontCharset(void) const { return nCharset;}
00242     int getFontPitch(void) const { return nPitch;}
00243     bool isTrueType(void) const { return fTrueType;}
00244 private:
00245     const gchar * szFamily;
00246     int nCharset;
00247     int nPitch;
00248     UT_String m_szName;
00249     bool fTrueType;
00250 };
00251 
00252 class ABI_EXPORT ie_exp_RTF_MsWord97List
00253 {
00254  public:
00255     ie_exp_RTF_MsWord97List(const fl_AutoNumConstPtr & pAuto);
00256     virtual ~ie_exp_RTF_MsWord97List(void);
00257     const fl_AutoNumConstPtr & getAuto(void) const { return m_pAutoNum;}
00258     UT_uint32 getID(void) const {return m_Id;}
00259  private:
00260     fl_AutoNumConstPtr m_pAutoNum;
00261     UT_uint32 m_Id;
00262 };
00263 
00264 class ABI_EXPORT ie_exp_RTF_MsWord97ListSimple : public ie_exp_RTF_MsWord97List
00265 {
00266  public:
00267     ie_exp_RTF_MsWord97ListSimple(const fl_AutoNumConstPtr & pAuto);
00268     ~ie_exp_RTF_MsWord97ListSimple(void);
00269     bool isSimple(void) const { return true;}
00270     bool isMulti(void) const { return false;}
00271  private:
00272 };
00273 
00274 class ABI_EXPORT ie_exp_RTF_MsWord97ListMulti : public ie_exp_RTF_MsWord97List
00275 {
00276  public:
00277     ie_exp_RTF_MsWord97ListMulti(const fl_AutoNumConstPtr & pAuto);
00278     ~ie_exp_RTF_MsWord97ListMulti(void);
00279     bool isSimple(void) const { return false;}
00280     bool isMulti(void) const { return true;}
00281     void addLevel(UT_uint32 iLevel, ie_exp_RTF_MsWord97List * pMsWord97List);
00282     ie_exp_RTF_MsWord97List * getListAtLevel(UT_uint32 iLevel, UT_uint32 nthList);
00283     UT_uint32 getMatchingID(UT_uint32 listID);
00284  private:
00285     UT_Vector * m_vLevels[9];
00286 };
00287 
00288 class ABI_EXPORT ie_exp_RTF_ListOveride
00289 {
00290 public:
00291     ie_exp_RTF_ListOveride(const fl_AutoNumConstPtr & pAuto);
00292     ~ie_exp_RTF_ListOveride(void);
00293     void setOverideID(UT_uint32 ID) {m_OverideID = ID;}
00294     UT_uint32 getOverideID(void) const { return m_OverideID;}
00295     const fl_AutoNumConstPtr & getAutoNum(void) const { return m_pAutoNum;}
00296     bool doesOverideMatch(UT_uint32 ID) const { return (ID == m_AbiListID);}
00297     UT_uint32 getAbiListID(void) const { return m_AbiListID;}
00298 private:
00299     UT_uint32 m_AbiListID;
00300     UT_uint32 m_OverideID;
00301     fl_AutoNumConstPtr m_pAutoNum;
00302 };
00303 #endif /* IE_EXP_RTF_H */
00304 
00305 
00306 
00307 
00308 
00309 
00310 

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1