WPXContentListener.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwpd
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00011  *
00012  * For minor contributions see the git repository.
00013  *
00014  * Alternatively, the contents of this file may be used under the terms
00015  * of the GNU Lesser General Public License Version 2.1 or later
00016  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00017  * applicable instead of those above.
00018  *
00019  * For further information visit http://libwpd.sourceforge.net
00020  */
00021 
00022 /* "This product is not manufactured, approved, or supported by
00023  * Corel Corporation or Corel Corporation Limited."
00024  */
00025 
00026 #ifndef WPXCONTENTLISTENER_H
00027 #define WPXCONTENTLISTENER_H
00028 
00029 #include "WPXTable.h"
00030 #include "libwpd_internal.h"
00031 #include "WPXSubDocument.h"
00032 #include "WPXPageSpan.h"
00033 #include "WPXListener.h"
00034 #include <vector>
00035 #include <list>
00036 #include <set>
00037 
00038 typedef struct _WPXTableDefinition WPXTableDefinition;
00039 struct _WPXTableDefinition
00040 {
00041         _WPXTableDefinition() : m_positionBits(0), m_leftOffset(0.0), m_columns(), m_columnsProperties() {}
00042         unsigned char m_positionBits;
00043         double m_leftOffset;
00044         std::vector < WPXColumnDefinition > m_columns;
00045         std::vector < WPXColumnProperties > m_columnsProperties;
00046 };
00047 
00048 typedef struct _WPXContentParsingState WPXContentParsingState;
00049 struct _WPXContentParsingState
00050 {
00051         _WPXContentParsingState();
00052         ~_WPXContentParsingState();
00053 
00054         unsigned m_textAttributeBits;
00055         double m_fontSize;
00056         librevenge::RVNGString *m_fontName;
00057         RGBSColor *m_fontColor;
00058         RGBSColor *m_highlightColor;
00059 
00060         bool m_isParagraphColumnBreak;
00061         bool m_isParagraphPageBreak;
00062         unsigned char m_paragraphJustification;
00063         unsigned char m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented
00064         double 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         bool m_firstParagraphInPageSpan;
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         unsigned m_cellAttributeBits;
00091         unsigned char m_paragraphJustificationBeforeTable;
00092 
00093         unsigned m_currentPage;
00094         unsigned m_numPagesRemainingInSpan;
00095         unsigned m_currentPageNumber;
00096 
00097         bool m_sectionAttributesChanged;
00098         unsigned m_numColumns;
00099         std::vector < WPXColumnDefinition > m_textColumns;
00100         bool m_isTextColumnWithoutParagraph;
00101 
00102         double m_pageFormLength;
00103         double m_pageFormWidth;
00104         WPXFormOrientation m_pageFormOrientation;
00105 
00106         double m_pageMarginLeft;
00107         double m_pageMarginRight;
00108         double m_pageMarginTop;
00109         double m_pageMarginBottom;
00110         double m_paragraphMarginLeft;  // resulting paragraph margin that is one of the paragraph
00111         double m_paragraphMarginRight; // properties
00112         double m_paragraphMarginTop;
00113         double m_paragraphMarginBottom;
00114         double m_leftMarginByPageMarginChange;  // part of the margin due to the PAGE margin change
00115         double m_rightMarginByPageMarginChange; // inside a page that already has content.
00116         double m_sectionMarginLeft;  // In multicolumn sections, the above two will be rather interpreted
00117         double m_sectionMarginRight; // as section margin change
00118         double m_leftMarginByParagraphMarginChange;  // part of the margin due to the PARAGRAPH
00119         double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
00120         double m_leftMarginByTabs;  // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
00121         double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
00122 
00123         double m_listReferencePosition; // position from the left page margin of the list number/bullet
00124         double m_listBeginPosition; // position from the left page margin of the beginning of the list
00125 
00126         double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
00127         double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
00128         double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
00129 
00130         unsigned char m_currentListLevel;
00131 
00132         unsigned 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, librevenge::RVNGTextInterface *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, unsigned nextTableIndice);
00158         void insertBreak(const unsigned char breakType);
00159         void lineSpacingChange(const double lineSpacing);
00160         void justificationChange(const unsigned char justification);
00161 
00162         WPXContentParsingState *m_ps; // parse state
00163         librevenge::RVNGTextInterface *m_documentInterface;
00164         librevenge::RVNGPropertyList m_metaData;
00165 
00166         virtual void _handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, unsigned 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(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
00177         void _getTabStops(librevenge::RVNGPropertyListVector &tabStops);
00178         void _appendJustification(librevenge::RVNGPropertyList &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 double height, const bool isMinimumHeight, const bool isHeaderRow);
00192         void _closeTableRow();
00193         void _openTableCell(const unsigned char colSpan, const unsigned char rowSpan, const unsigned char borderBits,
00194                             const RGBSColor *cellFgColor, const RGBSColor *cellBgColor,
00195                             const RGBSColor *cellBorderColor,
00196                             const WPXVerticalAlignment cellVerticalAlignment);
00197         void _closeTableCell();
00198 
00199         double _movePositionToFirstColumn(double position);
00200 
00201         double _getNextTabStop() const;
00202         double _getPreviousTabStop() const;
00203 
00204         void _insertText(const librevenge::RVNGString &textBuffer);
00205 
00206         void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
00207 
00208         void _insertPageNumberParagraph(WPXPageNumberPosition position, WPXNumberingType type, librevenge::RVNGString fontName, double fontSize);
00209 
00210         unsigned _mapNonUnicodeCharacter(unsigned character);
00211 
00212 private:
00213         WPXContentListener(const WPXContentListener &);
00214         WPXContentListener &operator=(const WPXContentListener &);
00215         librevenge::RVNGString _colorToString(const RGBSColor *color);
00216         librevenge::RVNGString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
00217         unsigned _mapSymbolFontCharacter(unsigned character);
00218         unsigned _mapDingbatsFontCharacter(unsigned character);
00219 };
00220 
00221 #endif /* WPXCONTENTLISTENER_H */
00222 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */