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  * 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://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 "WPXPropertyListVector.h"
00031 #include "WPXPropertyList.h"
00032 #include "libwpd_internal.h"
00033 #include "WPXSubDocument.h"
00034 #include "WPXPageSpan.h"
00035 #include "WPXDocumentInterface.h"
00036 #include "WPXListener.h"
00037 #include <vector>
00038 #include <list>
00039 #include <set>
00040 
00041 typedef struct _WPXTableDefinition WPXTableDefinition;
00042 struct _WPXTableDefinition
00043 {
00044         _WPXTableDefinition() : m_positionBits(0), m_leftOffset(0.0), m_columns(), m_columnsProperties() {};
00045         uint8_t m_positionBits;
00046         double m_leftOffset;
00047         std::vector < WPXColumnDefinition > m_columns;
00048         std::vector < WPXColumnProperties > m_columnsProperties;
00049 };
00050 
00051 typedef struct _WPXContentParsingState WPXContentParsingState;
00052 struct _WPXContentParsingState
00053 {
00054         _WPXContentParsingState();
00055         ~_WPXContentParsingState();
00056 
00057         uint32_t m_textAttributeBits;
00058         double m_fontSize;
00059         WPXString *m_fontName;
00060         RGBSColor *m_fontColor;
00061         RGBSColor *m_highlightColor;
00062 
00063         bool m_isParagraphColumnBreak;
00064         bool m_isParagraphPageBreak;
00065         uint8_t m_paragraphJustification;
00066         uint8_t m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented
00067         double m_paragraphLineSpacing;
00068 
00069         bool m_isDocumentStarted;
00070         bool m_isPageSpanOpened;
00071         bool m_isSectionOpened;
00072         bool m_isPageSpanBreakDeferred;
00073         bool m_isHeaderFooterWithoutParagraph;
00074 
00075         bool m_isSpanOpened;
00076         bool m_isParagraphOpened;
00077         bool m_isListElementOpened;
00078 
00079         bool m_firstParagraphInPageSpan;
00080 
00081         std::vector<unsigned int> m_numRowsToSkip;
00082         WPXTableDefinition m_tableDefinition;
00083         int m_currentTableCol;
00084         int m_currentTableRow;
00085         int m_currentTableCellNumberInRow;
00086         bool m_isTableOpened;
00087         bool m_isTableRowOpened;
00088         bool m_isTableColumnOpened;
00089         bool m_isTableCellOpened;
00090         bool m_wasHeaderRow;
00091         bool m_isCellWithoutParagraph;
00092         bool m_isRowWithoutCell;
00093         uint32_t m_cellAttributeBits;
00094         uint8_t m_paragraphJustificationBeforeTable;
00095 
00096         unsigned m_currentPage;
00097         int m_numPagesRemainingInSpan;
00098         int m_currentPageNumber;
00099 
00100         bool m_sectionAttributesChanged;
00101         int m_numColumns;
00102         std::vector < WPXColumnDefinition > m_textColumns;
00103         bool m_isTextColumnWithoutParagraph;
00104 
00105         double m_pageFormLength;
00106         double m_pageFormWidth;
00107         WPXFormOrientation m_pageFormOrientation;
00108 
00109         double m_pageMarginLeft;
00110         double m_pageMarginRight;
00111         double m_pageMarginTop;
00112         double m_pageMarginBottom;
00113         double m_paragraphMarginLeft;  // resulting paragraph margin that is one of the paragraph
00114         double m_paragraphMarginRight; // properties
00115         double m_paragraphMarginTop;
00116         double m_paragraphMarginBottom;
00117         double m_leftMarginByPageMarginChange;  // part of the margin due to the PAGE margin change
00118         double m_rightMarginByPageMarginChange; // inside a page that already has content.
00119         double m_sectionMarginLeft;  // In multicolumn sections, the above two will be rather interpreted
00120         double m_sectionMarginRight; // as section margin change
00121         double m_leftMarginByParagraphMarginChange;  // part of the margin due to the PARAGRAPH
00122         double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
00123         double m_leftMarginByTabs;  // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
00124         double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
00125 
00126         double m_listReferencePosition; // position from the left page margin of the list number/bullet
00127         double m_listBeginPosition; // position from the left page margin of the beginning of the list
00128 
00129         double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
00130         double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
00131         double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
00132 
00133         uint8_t m_currentListLevel;
00134 
00135         uint16_t m_alignmentCharacter;
00136         std::vector<WPXTabStop> m_tabStops;
00137         bool m_isTabPositionRelative;
00138 
00139         std::set <const WPXSubDocument *> m_subDocuments;
00140 
00141         bool m_inSubDocument;
00142         bool m_isNote;
00143         WPXSubDocumentType m_subDocumentType;
00144 
00145 private:
00146         _WPXContentParsingState(const _WPXContentParsingState &);
00147         _WPXContentParsingState &operator=(const _WPXContentParsingState &);
00148 };
00149 
00150 class WPXContentListener : public WPXListener
00151 {
00152 protected:
00153         WPXContentListener(std::list<WPXPageSpan> &pageList, WPXDocumentInterface *documentInterface);
00154         virtual ~WPXContentListener();
00155 
00156         void startDocument();
00157         void startSubDocument();
00158         void endDocument();
00159         void endSubDocument();
00160         void handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, int nextTableIndice);
00161         void insertBreak(const uint8_t breakType);
00162         void lineSpacingChange(const double lineSpacing);
00163         void justificationChange(const uint8_t justification);
00164 
00165         WPXContentParsingState *m_ps; // parse state
00166         WPXDocumentInterface *m_documentInterface;
00167         WPXPropertyList m_metaData;
00168 
00169         virtual void _handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, int nextTableIndice) = 0;
00170         virtual void _flushText() = 0;
00171         virtual void _changeList() = 0;
00172 
00173         void _openSection();
00174         void _closeSection();
00175 
00176         void _openPageSpan();
00177         void _closePageSpan();
00178 
00179         void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00180         void _getTabStops(WPXPropertyListVector &tabStops);
00181         void _appendJustification(WPXPropertyList &propList, int justification);
00182         void _resetParagraphState(const bool isListElement=false);
00183         virtual void _openParagraph();
00184         void _closeParagraph();
00185 
00186         void _openListElement();
00187         void _closeListElement();
00188 
00189         void _openSpan();
00190         void _closeSpan();
00191 
00192         void _openTable();
00193         void _closeTable();
00194         void _openTableRow(const double height, const bool isMinimumHeight, const bool isHeaderRow);
00195         void _closeTableRow();
00196         void _openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits,
00197                             const RGBSColor *cellFgColor, const RGBSColor *cellBgColor,
00198                             const RGBSColor *cellBorderColor,
00199                             const WPXVerticalAlignment cellVerticalAlignment);
00200         void _closeTableCell();
00201 
00202         double _movePositionToFirstColumn(double position);
00203 
00204         double _getNextTabStop() const;
00205         double _getPreviousTabStop() const;
00206 
00207         void _insertText(const WPXString &textBuffer);
00208 
00209         void _insertBreakIfNecessary(WPXPropertyList &propList);
00210 
00211         void _insertPageNumberParagraph(WPXPageNumberPosition position, WPXNumberingType type, WPXString fontName, double fontSize);
00212 
00213         uint32_t _mapNonUnicodeCharacter(uint32_t character);
00214 
00215 private:
00216         WPXContentListener(const WPXContentListener &);
00217         WPXContentListener &operator=(const WPXContentListener &);
00218         WPXString _colorToString(const RGBSColor *color);
00219         WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
00220         uint32_t _mapSymbolFontCharacter(uint32_t character);
00221         uint32_t _mapDingbatsFontCharacter(uint32_t character);
00222 };
00223 
00224 #endif /* WPXCONTENTLISTENER_H */
00225 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */