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 "WPSListener.h" 00033 #include <libwpd/WPXPropertyListVector.h> 00034 #include <libwpd/WPXHLListenerImpl.h> 00035 #include <vector> 00036 #include <list> 00037 #include <set> 00038 00039 typedef struct _WPSContentParsingState WPSContentParsingState; 00040 struct _WPSContentParsingState 00041 { 00042 _WPSContentParsingState(); 00043 ~_WPSContentParsingState(); 00044 00045 uint32_t m_textAttributeBits; 00046 float m_fontSize; 00047 WPXString *m_fontName; 00048 RGBSColor *m_fontColor; 00049 RGBSColor *m_highlightColor; 00050 00051 bool m_isParagraphColumnBreak; 00052 bool m_isParagraphPageBreak; 00053 uint8_t m_paragraphJustification; 00054 uint8_t m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented 00055 float m_paragraphLineSpacing; 00056 00057 bool m_isDocumentStarted; 00058 bool m_isPageSpanOpened; 00059 bool m_isSectionOpened; 00060 bool m_isPageSpanBreakDeferred; 00061 bool m_isHeaderFooterWithoutParagraph; 00062 00063 bool m_isSpanOpened; 00064 bool m_isParagraphOpened; 00065 bool m_isListElementOpened; 00066 00067 std::vector<unsigned int> m_numRowsToSkip; 00068 bool m_wasHeaderRow; 00069 bool m_isCellWithoutParagraph; 00070 uint32_t m_cellAttributeBits; 00071 uint8_t m_paragraphJustificationBeforeColumns; 00072 00073 std::list<WPSPageSpan>::iterator m_nextPageSpanIter; 00074 int m_numPagesRemainingInSpan; 00075 00076 bool m_sectionAttributesChanged; 00077 int m_numColumns; 00078 std::vector < WPSColumnDefinition > m_textColumns; 00079 bool m_isTextColumnWithoutParagraph; 00080 00081 float m_pageFormLength; 00082 float m_pageFormWidth; 00083 WPSFormOrientation m_pageFormOrientation; 00084 00085 float m_pageMarginLeft; 00086 float m_pageMarginRight; 00087 float m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph 00088 float m_paragraphMarginRight; // properties 00089 float m_paragraphMarginTop; 00090 float m_paragraphMarginBottom; 00091 float m_leftMarginByPageMarginChange; // part of the margin due to the PAGE margin change 00092 float m_rightMarginByPageMarginChange; // inside a page that already has content. 00093 float m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted 00094 float m_sectionMarginRight; // as section margin change 00095 float m_leftMarginByParagraphMarginChange; // part of the margin due to the PARAGRAPH 00096 float m_rightMarginByParagraphMarginChange; // margin change (in WP6) 00097 float m_leftMarginByTabs; // part of the margin due to the LEFT or LEFT/RIGHT Indent; the 00098 float m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph 00099 00100 float m_listReferencePosition; // position from the left page margin of the list number/bullet 00101 float m_listBeginPosition; // position from the left page margin of the beginning of the list 00102 00103 float m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties 00104 float m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???) 00105 float m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab" 00106 00107 uint8_t m_currentListLevel; 00108 00109 uint16_t m_alignmentCharacter; 00110 std::vector<WPSTabStop> m_tabStops; 00111 bool m_isTabPositionRelative; 00112 00113 bool m_isNote; 00114 private: 00115 _WPSContentParsingState(const _WPSContentParsingState&); 00116 _WPSContentParsingState& operator=(const _WPSContentParsingState&); 00117 }; 00118 00119 class WPSContentListener : public WPSListener 00120 { 00121 protected: 00122 WPSContentListener(std::list<WPSPageSpan> &pageList, WPXHLListenerImpl *listenerImpl); 00123 virtual ~WPSContentListener(); 00124 00125 void startDocument(); 00126 void endDocument(); 00127 void insertBreak(const uint8_t breakType); 00128 void lineSpacingChange(const float lineSpacing); 00129 void justificationChange(const uint8_t justification); 00130 00131 WPSContentParsingState *m_ps; // parse state 00132 WPXHLListenerImpl * m_listenerImpl; 00133 WPXPropertyList m_metaData; 00134 00135 virtual void _flushText() = 0; 00136 virtual void _changeList() = 0; 00137 00138 void _openSection(); 00139 void _closeSection(); 00140 00141 void _openPageSpan(); 00142 void _closePageSpan(); 00143 00144 void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false); 00145 void _getTabStops(WPXPropertyListVector &tabStops); 00146 void _appendJustification(WPXPropertyList &propList, int justification); 00147 void _resetParagraphState(const bool isListElement=false); 00148 virtual void _openParagraph(); 00149 void _closeParagraph(); 00150 00151 void _openListElement(); 00152 void _closeListElement(); 00153 00154 void _openSpan(); 00155 void _closeSpan(); 00156 00157 float _movePositionToFirstColumn(float position); 00158 00159 private: 00160 WPSContentListener(const WPSContentListener&); 00161 WPSContentListener& operator=(const WPSContentListener&); 00162 WPXString _colorToString(const RGBSColor * color); 00163 WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor); 00164 }; 00165 00166 #endif /* WPSCONTENTLISTENER_H */