WPSContentListener.h
Go to the documentation of this file.
00001 /* libwps
00002  * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library 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 GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00017  *
00018  * For further information visit http://libwps.sourceforge.net
00019  */
00020 
00021 /*
00022  * This file is in sync with CVS
00023  * /libwpd2/src/lib/WPXContentListener.h 1.9
00024  */
00025 
00026 
00027 #ifndef WPSCONTENTLISTENER_H
00028 #define WPSCONTENTLISTENER_H
00029 
00030 #include "libwps_internal.h"
00031 #include "WPSPageSpan.h"
00032 #include <libwpd/WPXPropertyListVector.h>
00033 #include <libwpd/WPXDocumentInterface.h>
00034 #include <list>
00035 
00036 typedef struct _WPSContentParsingState WPSContentParsingState;
00037 struct _WPSContentParsingState
00038 {
00039         _WPSContentParsingState();
00040         ~_WPSContentParsingState();
00041 
00042         uint32_t m_textAttributeBits;
00043         uint16_t m_spec;
00044         float m_fontSize;
00045         WPXString m_fontName;
00046         uint32_t m_lcid;
00047         uint32_t m_textcolor;
00048 
00049         uint16_t m_fieldcode;
00050 
00051         int m_codepage;
00052 
00053         bool m_isParagraphColumnBreak;
00054         bool m_isParagraphPageBreak;
00055         uint8_t m_paragraphJustification;
00056         float m_paragraphLineSpacing;
00057         uint32_t m_paraLayoutFlags;
00058 
00059         uint16_t m_footnoteId;
00060         uint16_t m_endnoteId;
00061 
00062         uint8_t m_numbering;
00063         uint16_t m_numstyle;
00064         uint16_t m_numsep;
00065 
00066         int m_curListType;
00067         bool m_isOrdered;
00068 
00069         bool m_isDocumentStarted;
00070         bool m_isPageSpanOpened;
00071         bool m_isSectionOpened;
00072         bool m_isPageSpanBreakDeferred;
00073 
00074         bool m_isSpanOpened;
00075         bool m_isParagraphOpened;
00076 
00077         bool m_isFootEndNote;
00078 
00079         bool m_isParaListItem;
00080 
00081         std::list<WPSPageSpan>::iterator m_nextPageSpanIter;
00082         int m_numPagesRemainingInSpan;
00083 
00084         bool m_sectionAttributesChanged;
00085 
00086         float m_pageFormLength;
00087         float m_pageFormWidth;
00088         WPSFormOrientation m_pageFormOrientation;
00089 
00090         float m_pageMarginLeft;
00091         float m_pageMarginRight;
00092         float m_paragraphMarginLeft;
00093         float m_paragraphMarginRight;
00094         float m_paragraphMarginTop;
00095         float m_paragraphMarginBottom;
00096 
00097         float m_paragraphIndentFirst;
00098 
00099         WPXString m_textBuffer;
00100 
00101 private:
00102         _WPSContentParsingState(const _WPSContentParsingState&);
00103         _WPSContentParsingState& operator=(const _WPSContentParsingState&);
00104 };
00105 
00106 struct ListSignature
00107 {
00108         uint16_t a,b,c;
00109 
00110         bool operator == (ListSignature &y)
00111         {
00112                 return (a == y.a) && (b == y.b) && (c == y.c);
00113         }
00114 };
00115 
00116 struct TabPos
00117 {
00118         float pos;
00119         char  align;
00120         char  leader;
00121 };
00122 
00123 class WPSContentListener
00124 {
00125 public:
00126         void startDocument();
00127         void endDocument();
00128         void insertBreak(const uint8_t breakType);
00129         void insertCharacter(const uint16_t character);
00130         void insertField();
00131 
00132         void openFootnote();
00133         void closeFootnote();
00134         void openEndnote();
00135         void closeEndnote();
00136 
00137         void setSpec(const uint16_t specCode);
00138         void setTextFont(const WPXString fontName);
00139         void setFontSize(const uint16_t fontSize);
00140         void setLCID(const uint32_t lcid);
00141         void setCodepage(const int codepage);
00142         void setColor(const unsigned int rgb);
00143         void setFieldType(uint16_t code);
00144         void setFieldFormat(uint16_t code);
00145 
00146         void setAlign(const uint8_t align);
00147         void setParaFlags(const uint32_t flags);
00148         void setMargins(const float first=0.0, const float left=0.0, const float right=0.0,
00149                         const float before=0.0, const float after=0.0);
00150         void setTabs(std::vector<TabPos> &tabs);
00151 
00152         void setNumberingType(const uint8_t style);
00153         void setNumberingProp(const uint16_t type, const uint16_t sep);
00154 
00155         void insertEOL();
00156 
00157         uint16_t getSpec() const;
00158 protected:
00159         WPSContentListener(std::list<WPSPageSpan> &pageList, WPXDocumentInterface *documentInterface);
00160         virtual ~WPSContentListener();
00161 
00162         WPSContentParsingState *m_ps; // parse state
00163         WPXDocumentInterface * m_documentInterface;
00164         WPXPropertyList m_metaData;
00165 
00166         void _flushText();
00167 
00168         void _openSection();
00169         void _closeSection();
00170 
00171         void _openPageSpan();
00172         void _closePageSpan();
00173 
00174         void _openParagraph();
00175         void _closeParagraph();
00176 
00177         void _openSpan();
00178         void _closeSpan();
00179 
00180         void _insertText(const WPXString &textBuffer);
00181 
00182         int  _getListId();
00183 private:
00184         WPSContentListener(const WPSContentListener&);
00185         WPSContentListener& operator=(const WPSContentListener&);
00186 
00187         std::vector<TabPos> m_tabs;
00188         std::list<WPSPageSpan> &m_pageList;
00189         std::vector<ListSignature> m_listFormats;
00190 };
00191 
00192 #endif /* WPSCONTENTLISTENER_H */