WPXContentListener.h

Go to the documentation of this file.
00001 /* libwpd
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://libwpd.sourceforge.net
00019  */
00020 
00021 /* "This product is not manufactured, approved, or supported by
00022  * Corel Corporation or Corel Corporation Limited."
00023  */
00024 
00025 #ifndef WPXCONTENTLISTENER_H
00026 #define WPXCONTENTLISTENER_H
00027 
00028 #include "WPXHLListenerImpl.h"
00029 #include "WPXTable.h"
00030 #include "WPXPropertyListVector.h"
00031 #include "libwpd_internal.h"
00032 #include "WPXSubDocument.h"
00033 #include "WPXPageSpan.h"
00034 #include "WPXListener.h"
00035 #include <vector>
00036 #include <list>
00037 #include <set>
00038 
00039 typedef struct _WPXTableDefinition WPXTableDefinition;
00040 struct _WPXTableDefinition
00041 {
00042         uint8_t m_positionBits;
00043         float m_leftOffset;
00044         std::vector < WPXColumnDefinition > columns;
00045         std::vector < WPXColumnProperties > columnsProperties;
00046 };
00047 
00048 typedef struct _WPXContentParsingState WPXContentParsingState;
00049 struct _WPXContentParsingState
00050 {
00051         _WPXContentParsingState();
00052         ~_WPXContentParsingState();
00053 
00054         uint32_t m_textAttributeBits;
00055         float m_fontSize;
00056         WPXString *m_fontName;
00057         RGBSColor *m_fontColor;
00058         RGBSColor *m_highlightColor;
00059 
00060         bool m_isParagraphColumnBreak;
00061         bool m_isParagraphPageBreak;
00062         uint8_t m_paragraphJustification;
00063         uint8_t m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented
00064         float m_paragraphLineSpacing;
00065 
00066         bool m_isDocumentStarted;
00067         bool m_isPageSpanOpened;
00068         bool m_isSectionOpened;
00069         bool m_isPageSpanBreakDeferred;
00070         bool m_isHeaderFooterWithoutParagraph;
00071 
00072         bool m_isSpanOpened;
00073         bool m_isParagraphOpened;
00074         bool m_isListElementOpened;
00075 
00076         std::vector<unsigned int> m_numRowsToSkip;
00077         WPXTableDefinition m_tableDefinition;
00078         int m_currentTableCol;
00079         int m_currentTableRow;
00080         int m_currentTableCellNumberInRow;
00081         bool m_isTableOpened;
00082         bool m_isTableRowOpened;
00083         bool m_isTableColumnOpened;
00084         bool m_isTableCellOpened;
00085         bool m_wasHeaderRow;
00086         bool m_isCellWithoutParagraph;
00087         uint32_t m_cellAttributeBits;
00088         uint8_t m_paragraphJustificationBeforeTable;
00089         uint8_t m_paragraphJustificationBeforeColumns;
00090         
00091         std::list<WPXPageSpan>::iterator m_nextPageSpanIter;
00092         int m_numPagesRemainingInSpan;
00093 
00094         bool m_sectionAttributesChanged;
00095         int m_numColumns;
00096         std::vector < WPXColumnDefinition > m_textColumns;
00097         bool m_isTextColumnWithoutParagraph;
00098 
00099         float m_pageFormLength;
00100         float m_pageFormWidth;
00101         WPXFormOrientation m_pageFormOrientation;
00102 
00103         float m_pageMarginLeft;
00104         float m_pageMarginRight;
00105         float m_paragraphMarginLeft;  // resulting paragraph margin that is one of the paragraph
00106         float m_paragraphMarginRight; // properties
00107         float m_paragraphMarginTop;
00108         float m_paragraphMarginBottom;
00109         float m_leftMarginByPageMarginChange;  // part of the margin due to the PAGE margin change
00110         float m_rightMarginByPageMarginChange; // inside a page that already has content.
00111         float m_sectionMarginLeft;  // In multicolumn sections, the above two will be rather interpreted
00112         float m_sectionMarginRight; // as section margin change 
00113         float m_leftMarginByParagraphMarginChange;  // part of the margin due to the PARAGRAPH
00114         float m_rightMarginByParagraphMarginChange; // margin change (in WP6)
00115         float m_leftMarginByTabs;  // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
00116         float m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
00117 
00118         float m_listReferencePosition; // position from the left page margin of the list number/bullet
00119         float m_listBeginPosition; // position from the left page margin of the beginning of the list
00120 
00121         float m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
00122         float m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
00123         float m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
00124 
00125         uint8_t m_currentListLevel;
00126         
00127         uint16_t m_alignmentCharacter;
00128         std::vector<WPXTabStop> m_tabStops;
00129         bool m_isTabPositionRelative;
00130 
00131         std::set <const WPXSubDocument *> m_subDocuments;
00132 
00133         bool m_inSubDocument;
00134         bool m_isNote;
00135 };
00136 
00137 class WPXContentListener : public WPXListener
00138 {
00139 protected:
00140         WPXContentListener(std::list<WPXPageSpan> &pageList, WPXHLListenerImpl *listenerImpl);
00141         virtual ~WPXContentListener();
00142 
00143         void startDocument();
00144         void endDocument();
00145         void handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice);
00146         void insertBreak(const uint8_t breakType);
00147         void lineSpacingChange(const float lineSpacing);
00148         void justificationChange(const uint8_t justification);
00149 
00150         WPXContentParsingState *m_ps; // parse state
00151         WPXHLListenerImpl * m_listenerImpl;
00152         WPXPropertyList m_metaData;
00153 
00154         virtual void _handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice) = 0;
00155         virtual void _flushText() = 0;
00156         virtual void _changeList() = 0;
00157 
00158         void _openSection();
00159         void _closeSection();
00160 
00161         void _openPageSpan();
00162         void _closePageSpan();
00163 
00164         void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00165         void _getTabStops(WPXPropertyListVector &tabStops);
00166         void _appendJustification(WPXPropertyList &propList, int justification);
00167         void _resetParagraphState(const bool isListElement=false);
00168         virtual void _openParagraph();
00169         void _closeParagraph();
00170 
00171         void _openListElement();
00172         void _closeListElement();
00173 
00174         void _openSpan();
00175         void _closeSpan();
00176 
00177         void _openTable();
00178         void _closeTable();
00179         void _openTableRow(const float height, const bool isMinimumHeight, const bool isHeaderRow);
00180         void _closeTableRow();
00181         void _openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits, 
00182                                 const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
00183                                 const RGBSColor * cellBorderColor,
00184                                 const WPXVerticalAlignment cellVerticalAlignment);
00185         void _closeTableCell();
00186 
00187         float _movePositionToFirstColumn(float position);
00188 
00189 private:
00190         WPXString _colorToString(const RGBSColor * color);
00191         WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
00192 };
00193 
00194 #endif /* WPXCONTENTLISTENER_H */

Generated on Tue Sep 5 03:10:21 2006 for libwpd by doxygen 1.4.7