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

ie_exp_OpenWriter.h

Go to the documentation of this file.
00001 /* AbiSource
00002  * Copyright (C) 2002 Dom Lachowicz <cinamod@hotmail.com>
00003  * Copyright (C) 2009 Hubert Figuiere
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 #include <string>
00022 
00023 // abiword stuff
00024 #include "fd_Field.h"
00025 #include "fl_AutoNum.h"
00026 #include "fp_PageSize.h"
00027 
00028 #include "px_ChangeRecord.h"
00029 #include "px_CR_Object.h"
00030 #include "px_CR_Span.h"
00031 #include "px_CR_Strux.h"
00032 #include "pd_Document.h"
00033 #include "pp_AttrProp.h"
00034 
00035 #include "ut_misc.h"
00036 #include "ut_string.h"
00037 #include "ut_string_class.h"
00038 #include "ut_bytebuf.h"
00039 #include "ut_hash.h"
00040 #include "ut_vector.h"
00041 #include "ut_stack.h"
00042 #include "ut_assert.h"
00043 
00044 #include <gsf/gsf-output.h>
00045 
00046 class IE_Exp_OpenWriter : public IE_Exp
00047 {
00048 public:
00049   IE_Exp_OpenWriter(PD_Document * pDocument);
00050   virtual ~IE_Exp_OpenWriter();
00051 
00052 protected:
00053   virtual UT_Error  _writeDocument(void);
00054 
00055 private:
00056   GsfOutfile * m_oo;
00057 };
00058 
00059 /*****************************************************************************/
00060 /*****************************************************************************/
00061 
00062 class OO_ListenerImpl
00063 {
00064 public:
00065    OO_ListenerImpl() {}
00066    virtual ~OO_ListenerImpl() {}
00067    virtual void insertText(const UT_UCSChar * data, UT_uint32 length) = 0;
00068    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00069                           const std::string & font, bool bIsHeading = false) = 0;
00070    virtual void closeBlock() = 0;
00071    virtual void openSpan(const std::string & props, const std::string & font) = 0;
00072    virtual void closeSpan() = 0;
00073    virtual void openHyperlink(const PP_AttrProp* pAP) = 0;
00074    virtual void closeHyperlink() = 0;
00075 };
00076 
00077 class OO_Listener : public PL_Listener
00078 {
00079 public:
00080    OO_Listener(PD_Document * pDocument, OO_ListenerImpl *pListenerImpl);
00081 
00082    virtual bool populate(fl_ContainerLayout* sfh, const PX_ChangeRecord * pcr);
00083    virtual bool populateStrux(pf_Frag_Strux* sdh, const PX_ChangeRecord * pcr, fl_ContainerLayout* * psfh);
00084    virtual bool change(fl_ContainerLayout* sfh, const PX_ChangeRecord * pcr);
00085    virtual bool insertStrux(fl_ContainerLayout* sfh,
00086                 const PX_ChangeRecord * pcr,
00087                 pf_Frag_Strux* sdh,
00088                 PL_ListenerId lid,
00089                 void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
00090                             PL_ListenerId lid,
00091                             fl_ContainerLayout* sfhNew));
00092    virtual bool signal(UT_uint32 iSignal);
00093 
00094    void endDocument();
00095 
00096 private:
00097    void _openSpan(PT_AttrPropIndex api);
00098    void _closeSpan();
00099    void _openBlock(PT_AttrPropIndex apiSpan);
00100    void _closeBlock();
00101    void _openHyperlink(const PP_AttrProp* pAP);
00102    void _closeHyperlink();
00103 
00104    PD_Document * m_pDocument;
00105    OO_ListenerImpl * m_pListenerImpl;
00106 
00107    bool m_bInBlock;
00108    bool m_bInSpan;
00109    bool m_bInHyperlink;
00110 };
00111 
00112 class OO_StylesContainer
00113 {
00114 public:
00115    OO_StylesContainer() {}
00116    ~OO_StylesContainer() {
00117        m_spanStylesHash.purgeData();
00118        m_blockAttsHash.purgeData();
00119        m_fontsHash.purgeData();
00120    }
00121    void addSpanStyle(const std::string &key);
00122    void addBlockStyle(const std::string & styleAtts, const std::string & styleProps);
00123    void addFont(const std::string & font);
00124    int getSpanStyleNum(const std::string &key) const;
00125    int getBlockStyleNum(const std::string & styleAtts, const std::string & styleProps) const;
00126    UT_GenericVector<int*> * enumerateSpanStyles() const;
00127    UT_String * pickBlockAtts(const UT_String *key);
00128    UT_GenericVector<const UT_String*> * getSpanStylesKeys() const;
00129    UT_GenericVector<const UT_String*> * getBlockStylesKeys() const;
00130    UT_GenericVector<const UT_String*> * getFontsKeys() const;
00131 private:
00132    UT_GenericStringMap<int*> m_spanStylesHash;
00133    UT_GenericStringMap<UT_String*> m_blockAttsHash;
00134    UT_GenericStringMap<int*> m_fontsHash;
00135 };
00136 
00142 class OO_AccumulatorImpl : public OO_ListenerImpl
00143 {
00144 public:
00145    OO_AccumulatorImpl(OO_StylesContainer *pStylesContainer) : OO_ListenerImpl() { m_pStylesContainer = pStylesContainer; }
00146    virtual void insertText(const UT_UCSChar * /*data*/, UT_uint32 /*length*/) {}
00147    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00148                           const std::string & font, bool bIsHeading = false);
00149    virtual void closeBlock() {};
00150    virtual void openSpan(const std::string & props, const std::string & font);
00151    virtual void closeSpan() {}
00152    virtual void openHyperlink(const PP_AttrProp* /*pAP*/) {}
00153    virtual void closeHyperlink() {}
00154 
00155 private:
00156    OO_StylesContainer *m_pStylesContainer;
00157 };
00158 
00163 class OO_WriterImpl : public OO_ListenerImpl
00164 {
00165 public:
00166    OO_WriterImpl(GsfOutfile *pOutfile, OO_StylesContainer *pStylesContainer);
00167    ~OO_WriterImpl();
00168    virtual void insertText(const UT_UCSChar * data, UT_uint32 length);
00169    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00170                           const std::string & font, bool bIsHeading = false);
00171    virtual void closeBlock();
00172    virtual void openSpan(const std::string & props, const std::string & font);
00173    virtual void closeSpan();
00174    virtual void openHyperlink(const PP_AttrProp* pAP);
00175    virtual void closeHyperlink();
00176 
00177 private:
00178    GsfOutput * m_pContentStream;
00179    OO_StylesContainer *m_pStylesContainer;
00180    UT_UTF8String m_blockEnd;
00181 };
00182 
00188 class OO_StylesWriter
00189 {
00190 public:
00194    static bool writeStyles(PD_Document * pDoc, GsfOutfile * oo, OO_StylesContainer & stylesContainer);
00195    /*
00196     * Add <office:font-decls> section to the buffer
00197     */
00198    static void addFontDecls(UT_UTF8String & buffer, OO_StylesContainer & stylesContainer);
00202    static void map(const PP_AttrProp * pAP, UT_UTF8String & styleAtts, UT_UTF8String & propAtts, UT_UTF8String & font);
00203 private:
00204   OO_StylesWriter ();
00205 };

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1