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