• 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., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, 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 #include "ut_PropVector.h"
00044 
00045 #include <gsf/gsf-output.h>
00046 
00047 class IE_Exp_OpenWriter : public IE_Exp
00048 {
00049 public:
00050   IE_Exp_OpenWriter(PD_Document * pDocument);
00051   virtual ~IE_Exp_OpenWriter();
00052 
00053 protected:
00054   virtual UT_Error  _writeDocument(void);
00055 
00056 private:
00057   GsfOutfile * m_oo;
00058 };
00059 
00060 /*****************************************************************************/
00061 /*****************************************************************************/
00062 
00063 class OO_ListenerImpl
00064 {
00065 public:
00066    OO_ListenerImpl() {}
00067    virtual ~OO_ListenerImpl() {}
00068    virtual void insertText(const UT_UCSChar * data, UT_uint32 length) = 0;
00069    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00070                           const std::string & font, bool bIsHeading = false) = 0;
00071    virtual void closeBlock() = 0;
00072    virtual void openSpan(const std::string & props, const std::string & font) = 0;
00073    virtual void closeSpan() = 0;
00074    virtual void openHyperlink(const PP_AttrProp* pAP) = 0;
00075    virtual void closeHyperlink() = 0;
00076 };
00077 
00078 class OO_Listener : public PL_Listener
00079 {
00080 public:
00081    OO_Listener(PD_Document * pDocument, IE_Exp_OpenWriter * pie, OO_ListenerImpl *pListenerImpl);
00082 
00083    virtual bool populate(fl_ContainerLayout* sfh, const PX_ChangeRecord * pcr);
00084    virtual bool populateStrux(pf_Frag_Strux* sdh, const PX_ChangeRecord * pcr, fl_ContainerLayout* * psfh);
00085    virtual bool change(fl_ContainerLayout* sfh, const PX_ChangeRecord * pcr);
00086    virtual bool insertStrux(fl_ContainerLayout* sfh,
00087                 const PX_ChangeRecord * pcr,
00088                 pf_Frag_Strux* sdh,
00089                 PL_ListenerId lid,
00090                 void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
00091                             PL_ListenerId lid,
00092                             fl_ContainerLayout* sfhNew));
00093    virtual bool signal(UT_uint32 iSignal);
00094 
00095    void endDocument();
00096 
00097 private:
00098    void _openSpan(PT_AttrPropIndex api);
00099    void _closeSpan();
00100    void _openBlock(PT_AttrPropIndex apiSpan);
00101    void _closeBlock();
00102    void _openHyperlink(const PP_AttrProp* pAP);
00103    void _closeHyperlink();
00104 
00105    PD_Document * m_pDocument;
00106    IE_Exp_OpenWriter * m_pie;
00107    OO_ListenerImpl * m_pListenerImpl;
00108 
00109    bool m_bInBlock;
00110    bool m_bInSpan;
00111    bool m_bInHyperlink;
00112 };
00113 
00114 class OO_StylesContainer
00115 {
00116 public:
00117    OO_StylesContainer() {}
00118    ~OO_StylesContainer() {
00119        m_spanStylesHash.purgeData();
00120        m_blockAttsHash.purgeData();
00121        m_fontsHash.purgeData();
00122    }
00123    void addSpanStyle(const std::string &key);
00124    void addBlockStyle(const std::string & styleAtts, const std::string & styleProps);
00125    void addFont(const std::string & font);
00126    int getSpanStyleNum(const std::string &key) const;
00127    int getBlockStyleNum(const std::string & styleAtts, const std::string & styleProps) const;
00128    UT_GenericVector<int*> * enumerateSpanStyles() const;
00129    UT_String * pickBlockAtts(const UT_String *key);
00130    UT_GenericVector<const UT_String*> * getSpanStylesKeys() const;
00131    UT_GenericVector<const UT_String*> * getBlockStylesKeys() const;
00132    UT_GenericVector<const UT_String*> * getFontsKeys() const;
00133 private:
00134    UT_GenericStringMap<int*> m_spanStylesHash;
00135    UT_GenericStringMap<UT_String*> m_blockAttsHash;
00136    UT_GenericStringMap<int*> m_fontsHash;
00137 };
00138 
00144 class OO_AccumulatorImpl : public OO_ListenerImpl
00145 {
00146 public:
00147    OO_AccumulatorImpl(OO_StylesContainer *pStylesContainer) : OO_ListenerImpl() { m_pStylesContainer = pStylesContainer; }
00148    virtual void insertText(const UT_UCSChar * /*data*/, UT_uint32 /*length*/) {}
00149    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00150                           const std::string & font, bool bIsHeading = false);
00151    virtual void closeBlock() {};
00152    virtual void openSpan(const std::string & props, const std::string & font);
00153    virtual void closeSpan() {}
00154    virtual void openHyperlink(const PP_AttrProp* /*pAP*/) {}
00155    virtual void closeHyperlink() {}
00156 
00157 private:
00158    OO_StylesContainer *m_pStylesContainer;
00159 };
00160 
00165 class OO_WriterImpl : public OO_ListenerImpl
00166 {
00167 public:
00168    OO_WriterImpl(GsfOutfile *pOutfile, OO_StylesContainer *pStylesContainer);
00169    ~OO_WriterImpl();
00170    virtual void insertText(const UT_UCSChar * data, UT_uint32 length);
00171    virtual void openBlock(const std::string & styleAtts, const std::string & styleProps,
00172                           const std::string & font, bool bIsHeading = false);
00173    virtual void closeBlock();
00174    virtual void openSpan(const std::string & props, const std::string & font);
00175    virtual void closeSpan();
00176    virtual void openHyperlink(const PP_AttrProp* pAP);
00177    virtual void closeHyperlink();
00178 
00179 private:
00180    GsfOutput * m_pContentStream;
00181    OO_StylesContainer *m_pStylesContainer;
00182    UT_UTF8String m_blockEnd;
00183 };
00184 
00190 class OO_StylesWriter
00191 {
00192 public:
00196    static bool writeStyles(PD_Document * pDoc, GsfOutfile * oo, OO_StylesContainer & stylesContainer);
00197    /*
00198     * Add <office:font-decls> section to the buffer
00199     */
00200    static void addFontDecls(UT_UTF8String & buffer, OO_StylesContainer & stylesContainer);
00204    static void map(const PP_AttrProp * pAP, UT_UTF8String & styleAtts, UT_UTF8String & propAtts, UT_UTF8String & font);
00205 private:
00206   OO_StylesWriter ();
00207 };

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1