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

ie_exp_XSL-FO.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 2001 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 #ifndef IE_EXP_XSL_FO_H
00021 #define IE_EXP_XSL_FO_H
00022 
00023 #include "ie_exp.h"
00024 #include "ie_Table.h"
00025 #include "pl_Listener.h"
00026 #include "fl_AutoNum.h"
00027 
00028 class PD_Document;
00029 class s_XSL_FO_Listener;
00030 
00031 // The exporter/writer for the XML/XSL FO spec
00032 
00033 class IE_Exp_XSL_FO_Sniffer : public IE_ExpSniffer
00034 {
00035     friend class IE_Exp;
00036 
00037 public:
00038     IE_Exp_XSL_FO_Sniffer (const char * name);
00039     virtual ~IE_Exp_XSL_FO_Sniffer () {}
00040 
00041     virtual bool recognizeSuffix (const char * szSuffix);
00042     virtual bool getDlgLabels (const char ** szDesc,
00043                                const char ** szSuffixList,
00044                                IEFileType * ft);
00045     virtual UT_Error constructExporter (PD_Document * pDocument,
00046                                         IE_Exp ** ppie);
00047 };
00048 
00049 class IE_Exp_XSL_FO : public IE_Exp
00050 {
00051 public:
00052     IE_Exp_XSL_FO(PD_Document * pDocument);
00053     virtual ~IE_Exp_XSL_FO();
00054 
00055 protected:
00056     virtual UT_Error    _writeDocument();
00057 
00058 private:
00059     s_XSL_FO_Listener * m_pListener;
00060     UT_uint32 m_error;
00061 };
00062 
00063 
00064 // A little class to help export lists
00065 class ListHelper
00066 {
00067 public:
00068     explicit ListHelper()
00069         : m_pan(NULL),
00070           m_iInc(-1),
00071           m_iCount(0),
00072           m_iStart(0)
00073     {
00074     }
00075 
00076     void addList(const fl_AutoNumConstPtr & pAutoNum)
00077     {
00078         UT_return_if_fail(pAutoNum);
00079 
00080         m_pan = pAutoNum;
00081         m_iStart = m_pan->getStartValue32();
00082 
00083         if(m_pan->getType() < BULLETED_LIST)
00084             m_iInc = 1;
00085 
00086         populateText(m_pan->getDelim());
00087     }
00088 
00089     UT_uint32 retrieveID()
00090     {
00091         return m_pan->getID();
00092     }
00093 
00094     UT_UTF8String getNextLabel()
00095     {
00096         UT_return_val_if_fail(m_pan,"");
00097 
00098         if(m_iInc > -1)
00099         {
00100             UT_uint32 val = m_iStart + (m_iInc * m_iCount);
00101             m_iCount++;
00102             return UT_UTF8String_sprintf("%s%d%s", m_sPreText.utf8_str(), val, m_sPostText.utf8_str());
00103         }
00104         else
00105         {
00106             UT_UTF8String bullet;
00107             UT_UCS4Char symbol[2] = {'\0', '\0'};
00108 
00109             //TODO: support all lists
00110             //FIXME: most lists don't seem to work; looks like Bug 3601
00111 
00112             switch(m_pan->getType())
00113             {
00114                 //taken from fl_AutoNum.cpp
00115 
00116                 case BULLETED_LIST:
00117                 {
00118                     symbol[0] = (UT_UCSChar) (unsigned char) 0xb7;
00119                     bullet.appendUCS4(symbol);
00120                     break;
00121                 }
00122 
00123                 case DASHED_LIST:
00124                 {
00125                     bullet = "-";
00126                     break;
00127                 }
00128 
00129                 case SQUARE_LIST:
00130                 {
00131                     symbol[0] = (UT_UCSChar) (unsigned char) 0x6E;
00132                     bullet.appendUCS4(symbol);
00133                     break;
00134                 }
00135 
00136                 case TRIANGLE_LIST:
00137                 {
00138                     symbol[0] = (UT_UCSChar) (unsigned char) 0x73;
00139                     bullet.appendUCS4(symbol);
00140                     break;
00141                 }
00142 
00143                 case DIAMOND_LIST:
00144                 {
00145                     symbol[0] = (UT_UCSChar) (unsigned char) 0xA9;
00146                     bullet.appendUCS4(symbol);
00147                     break;
00148                 }
00149 
00150                 case STAR_LIST:
00151                 {
00152                     symbol[0] = (UT_UCSChar) (unsigned char) 0x53;
00153                     bullet.appendUCS4(symbol);
00154                     break;
00155                 }
00156 
00157                 case IMPLIES_LIST:
00158                 {
00159                     symbol[0] = (UT_UCSChar) (unsigned char) 0xDE;
00160                     bullet.appendUCS4(symbol);
00161                     break;
00162                 }
00163 
00164                 case TICK_LIST:
00165                 {
00166                     symbol[0] = (UT_UCSChar) (unsigned char) 0x33;
00167                     bullet.appendUCS4(symbol);
00168                     break;
00169                 }
00170 
00171                 case BOX_LIST:
00172                 {
00173                     symbol[0] = (UT_UCSChar) (unsigned char) 0x72;
00174                     bullet.appendUCS4(symbol);
00175                     break;
00176                 }
00177 
00178                 case HAND_LIST:
00179                 {
00180                     symbol[0] = (UT_UCSChar) (unsigned char) 0x2B;
00181                     bullet.appendUCS4(symbol);
00182                     break;
00183                 }
00184 
00185                 case HEART_LIST:
00186                 {
00187                     symbol[0] = (UT_UCSChar) (unsigned char) 0xAA;
00188                     bullet.appendUCS4(symbol);
00189                     break;
00190                 }
00191 
00192                 default:
00193                 {
00194                     UT_DEBUGMSG(("Unhandled list type in XSL-FO exporter: %d\n", m_pan->getType()));
00195                     break;
00196                 }
00197             }
00198 
00199             return bullet;
00200         }
00201     }
00202 
00203 protected:
00204 
00205     void populateText(const gchar *lDelim)
00206     {
00207         UT_UCS4String text = lDelim;
00208         bool bPre = true;
00209 
00210         for(UT_uint32 i = 0; i < text.length(); i++)
00211         {
00212             if(bPre && (text[i] == '%') && ((i + 1) < text.length()) && (text[i+1] == 'L'))
00213             {
00214                 bPre = false;
00215                 i++;
00216             }
00217             else if(bPre)
00218             {
00219                 m_sPreText += text[i];
00220             }
00221             else
00222             {
00223                 m_sPostText += text[i];
00224             }
00225         }
00226 
00227         m_sPreText.escapeXML();
00228         m_sPostText.escapeXML();
00229     }
00230 
00231 private:
00232 
00233     fl_AutoNumConstPtr m_pan;
00234     UT_UTF8String m_sPostText; //text after "%L"
00235     UT_UTF8String m_sPreText; //text before "%L"
00236     UT_sint32 m_iInc;
00237     UT_uint32 m_iCount;
00238     UT_uint32 m_iStart;
00239 };
00240 
00241 /************************************************************/
00242 /************************************************************/
00243 
00244 class s_XSL_FO_Listener : public PL_Listener
00245 {
00246 public:
00247 
00248     s_XSL_FO_Listener(PD_Document * pDocument,
00249                       IE_Exp_XSL_FO * pie);
00250     virtual ~s_XSL_FO_Listener();
00251 
00252     virtual bool        populate(fl_ContainerLayout* sfh,
00253                                  const PX_ChangeRecord * pcr);
00254 
00255     virtual bool        populateStrux(pf_Frag_Strux* sdh,
00256                                       const PX_ChangeRecord * pcr,
00257                                       fl_ContainerLayout* * psfh);
00258 
00259     virtual bool        change(fl_ContainerLayout* sfh,
00260                                const PX_ChangeRecord * pcr);
00261 
00262     virtual bool        insertStrux(fl_ContainerLayout* sfh,
00263                                     const PX_ChangeRecord * pcr,
00264                                     pf_Frag_Strux* sdh,
00265                                     PL_ListenerId lid,
00266                                     void (* pfnBindHandles)(pf_Frag_Strux* sdhNew,
00267                                                             PL_ListenerId lid,
00268                                                             fl_ContainerLayout* sfhNew));
00269 
00270     virtual bool        signal(UT_uint32 iSignal);
00271 
00272 protected:
00273 
00274     void                _handlePageSize(PT_AttrPropIndex api);
00275     void                _handleDataItems(void);
00276     void                _handleLists(void);
00277     void                _handleBookmark(PT_AttrPropIndex api);
00278     void                _handleEmbedded(PT_AttrPropIndex api);
00279     void                _handleField(const PX_ChangeRecord_Object * pcro, PT_AttrPropIndex api);
00280     void                _handleFrame(PT_AttrPropIndex api);
00281     void                _handleHyperlink(PT_AttrPropIndex api);
00282     void                _handleImage(PT_AttrPropIndex api);
00283     void                _handleMath(PT_AttrPropIndex api);
00284     void                _handlePositionedImage(PT_AttrPropIndex api);
00285     void                _outputData(const UT_UCSChar * data, UT_uint32 length);
00286 
00287     void                _closeSection(void);
00288     void                _closeBlock(void);
00289     void                _closeSpan(void);
00290     void                _closeLink(void);
00291     void                _openBlock(PT_AttrPropIndex api);
00292     void                _openSection(PT_AttrPropIndex api);
00293     void                _openSpan(PT_AttrPropIndex api);
00294     void                _openListItem(void);
00295     void                _popListToDepth(UT_sint32 depth);
00296 
00297     void                _openTable(PT_AttrPropIndex api);
00298     void                _openRow(void);
00299     void                _openCell(PT_AttrPropIndex api);
00300     void                _closeTable(void);
00301     void                _closeRow(void);
00302     void                _closeCell(void);
00303     void                _handleTableColumns(void);
00304 
00305     UT_UTF8String       _getCellColors(void);
00306     UT_UTF8String       _getCellThicknesses(void);
00307     UT_UTF8String       _getTableColors(void);
00308     UT_UTF8String       _getTableThicknesses(void);
00309 
00310     void                _tagClose(UT_uint32 tagID, const UT_UTF8String & content, bool newline = true);
00311     void                _tagOpen(UT_uint32 tagID, const UT_UTF8String & content, bool newline = true);
00312     void                _tagOpenClose(const UT_UTF8String & content, bool suppress = true, bool newline = true);
00313     UT_uint32           _tagTop(void);
00314 
00315 private:
00316 
00317     PD_Document *       m_pDocument;
00318     IE_Exp_XSL_FO *     m_pie;
00319 
00320     bool                m_bFirstWrite;
00321     bool                m_bInLink;
00322     bool                m_bInNote;
00323     bool                m_bInSection;
00324     bool                m_bInSpan;
00325     bool                m_bWroteListField;
00326 
00327     UT_sint32           m_iBlockDepth;
00328     UT_uint32           m_iLastClosed;
00329     UT_sint32           m_iListBlockDepth;
00330     UT_uint32           m_iListID;
00331 
00332     ie_Table            mTableHelper;
00333     UT_Vector           m_utvDataIDs;
00334     UT_NumberStack      m_utnsTagStack;
00335     UT_GenericVector<ListHelper *> m_Lists;
00336 };
00337 
00338 #endif /* IE_EXP_XSL_FO_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1