00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WPXCONTENTLISTENER_H
00026 #define WPXCONTENTLISTENER_H
00027
00028 #include "WPXTable.h"
00029 #include "WPXPropertyListVector.h"
00030 #include "WPXPropertyList.h"
00031 #include "libwpd_internal.h"
00032 #include "WPXSubDocument.h"
00033 #include "WPXPageSpan.h"
00034 #include "WPXDocumentInterface.h"
00035 #include "WPXListener.h"
00036 #include <vector>
00037 #include <list>
00038 #include <set>
00039
00040 typedef struct _WPXTableDefinition WPXTableDefinition;
00041 struct _WPXTableDefinition
00042 {
00043 _WPXTableDefinition() : m_positionBits(0), m_leftOffset(0.0f), m_columns(), m_columnsProperties() {};
00044 uint8_t m_positionBits;
00045 float m_leftOffset;
00046 std::vector < WPXColumnDefinition > m_columns;
00047 std::vector < WPXColumnProperties > m_columnsProperties;
00048 };
00049
00050 typedef struct _WPXContentParsingState WPXContentParsingState;
00051 struct _WPXContentParsingState
00052 {
00053 _WPXContentParsingState();
00054 ~_WPXContentParsingState();
00055
00056 uint32_t m_textAttributeBits;
00057 float m_fontSize;
00058 WPXString *m_fontName;
00059 RGBSColor *m_fontColor;
00060 RGBSColor *m_highlightColor;
00061
00062 bool m_isParagraphColumnBreak;
00063 bool m_isParagraphPageBreak;
00064 uint8_t m_paragraphJustification;
00065 uint8_t m_tempParagraphJustification;
00066 float m_paragraphLineSpacing;
00067
00068 bool m_isDocumentStarted;
00069 bool m_isPageSpanOpened;
00070 bool m_isSectionOpened;
00071 bool m_isPageSpanBreakDeferred;
00072 bool m_isHeaderFooterWithoutParagraph;
00073
00074 bool m_isSpanOpened;
00075 bool m_isParagraphOpened;
00076 bool m_isListElementOpened;
00077
00078 std::vector<unsigned int> m_numRowsToSkip;
00079 WPXTableDefinition m_tableDefinition;
00080 int m_currentTableCol;
00081 int m_currentTableRow;
00082 int m_currentTableCellNumberInRow;
00083 bool m_isTableOpened;
00084 bool m_isTableRowOpened;
00085 bool m_isTableColumnOpened;
00086 bool m_isTableCellOpened;
00087 bool m_wasHeaderRow;
00088 bool m_isCellWithoutParagraph;
00089 bool m_isRowWithoutCell;
00090 uint32_t m_cellAttributeBits;
00091 uint8_t m_paragraphJustificationBeforeTable;
00092
00093 unsigned m_currentPage;
00094 int m_numPagesRemainingInSpan;
00095 int m_currentPageNumber;
00096
00097 bool m_sectionAttributesChanged;
00098 int m_numColumns;
00099 std::vector < WPXColumnDefinition > m_textColumns;
00100 bool m_isTextColumnWithoutParagraph;
00101
00102 float m_pageFormLength;
00103 float m_pageFormWidth;
00104 WPXFormOrientation m_pageFormOrientation;
00105
00106 float m_pageMarginLeft;
00107 float m_pageMarginRight;
00108 float m_pageMarginTop;
00109 float m_pageMarginBottom;
00110 float m_paragraphMarginLeft;
00111 float m_paragraphMarginRight;
00112 float m_paragraphMarginTop;
00113 float m_paragraphMarginBottom;
00114 float m_leftMarginByPageMarginChange;
00115 float m_rightMarginByPageMarginChange;
00116 float m_sectionMarginLeft;
00117 float m_sectionMarginRight;
00118 float m_leftMarginByParagraphMarginChange;
00119 float m_rightMarginByParagraphMarginChange;
00120 float m_leftMarginByTabs;
00121 float m_rightMarginByTabs;
00122
00123 float m_listReferencePosition;
00124 float m_listBeginPosition;
00125
00126 float m_paragraphTextIndent;
00127 float m_textIndentByParagraphIndentChange;
00128 float m_textIndentByTabs;
00129
00130 uint8_t m_currentListLevel;
00131
00132 uint16_t m_alignmentCharacter;
00133 std::vector<WPXTabStop> m_tabStops;
00134 bool m_isTabPositionRelative;
00135
00136 std::set <const WPXSubDocument *> m_subDocuments;
00137
00138 bool m_inSubDocument;
00139 bool m_isNote;
00140 WPXSubDocumentType m_subDocumentType;
00141
00142 private:
00143 _WPXContentParsingState(const _WPXContentParsingState&);
00144 _WPXContentParsingState& operator=(const _WPXContentParsingState&);
00145 };
00146
00147 class WPXContentListener : public WPXListener
00148 {
00149 protected:
00150 WPXContentListener(std::list<WPXPageSpan> &pageList, WPXDocumentInterface *documentInterface);
00151 virtual ~WPXContentListener();
00152
00153 void startDocument();
00154 void startSubDocument();
00155 void endDocument();
00156 void endSubDocument();
00157 void handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, int nextTableIndice);
00158 void insertBreak(const uint8_t breakType);
00159 void lineSpacingChange(const float lineSpacing);
00160 void justificationChange(const uint8_t justification);
00161
00162 WPXContentParsingState *m_ps;
00163 WPXDocumentInterface * m_documentInterface;
00164 WPXPropertyList m_metaData;
00165
00166 virtual void _handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, int nextTableIndice) = 0;
00167 virtual void _flushText() = 0;
00168 virtual void _changeList() = 0;
00169
00170 void _openSection();
00171 void _closeSection();
00172
00173 void _openPageSpan();
00174 void _closePageSpan();
00175
00176 void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00177 void _getTabStops(WPXPropertyListVector &tabStops);
00178 void _appendJustification(WPXPropertyList &propList, int justification);
00179 void _resetParagraphState(const bool isListElement=false);
00180 virtual void _openParagraph();
00181 void _closeParagraph();
00182
00183 void _openListElement();
00184 void _closeListElement();
00185
00186 void _openSpan();
00187 void _closeSpan();
00188
00189 void _openTable();
00190 void _closeTable();
00191 void _openTableRow(const float height, const bool isMinimumHeight, const bool isHeaderRow);
00192 void _closeTableRow();
00193 void _openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
00194 const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
00195 const RGBSColor * cellBorderColor,
00196 const WPXVerticalAlignment cellVerticalAlignment);
00197 void _closeTableCell();
00198
00199 float _movePositionToFirstColumn(float position);
00200
00201 float _getNextTabStop() const;
00202 float _getPreviousTabStop() const;
00203
00204 void _insertBreakIfNecessary(WPXPropertyList &propList);
00205
00206 private:
00207 WPXContentListener(const WPXContentListener&);
00208 WPXContentListener& operator=(const WPXContentListener&);
00209 WPXString _colorToString(const RGBSColor * color);
00210 WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
00211 };
00212
00213 #endif