WPXListener.h

Go to the documentation of this file.
00001 /* libwpd
00002  * Copyright (C) 2002 William Lachance (william.lachance@sympatico.ca)
00003  * Copyright (C) 2002 Marc Maurer (j.m.maurer@student.utwente.nl)
00004  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00019  *
00020  * For further information visit http://libwpd.sourceforge.net
00021  */
00022 
00023 /* "This product is not manufactured, approved, or supported by
00024  * Corel Corporation or Corel Corporation Limited."
00025  */
00026 
00027 #ifndef WPXLISTENER_H
00028 #define WPXLISTENER_H
00029 
00030 #include "WPXHLListenerImpl.h"
00031 #include "WPXTable.h"
00032 #include "WPXPropertyListVector.h"
00033 #include "libwpd_internal.h"
00034 #include "WPXSubDocument.h"
00035 #include <vector>
00036 #include <set>
00037 
00038 class WPXPageSpan;
00039 
00040 typedef struct _WPXDocumentMetaData WPXDocumentMetaData;
00041 struct _WPXDocumentMetaData
00042 {
00043         WPXString m_author;
00044         WPXString m_subject;
00045         WPXString m_publisher;
00046         WPXString m_category;
00047         WPXString m_keywords;
00048         WPXString m_language;
00049         WPXString m_abstract;
00050         WPXString m_descriptiveName;
00051         WPXString m_descriptiveType;
00052 };
00053 
00054 typedef struct _WPXTableDefinition WPXTableDefinition;
00055 struct _WPXTableDefinition
00056 {
00057         uint8_t m_positionBits;
00058         float m_leftOffset;
00059         std::vector < WPXColumnDefinition > columns;
00060         std::vector < WPXColumnProperties > columnsProperties;
00061 };
00062 
00063 typedef struct _WPXParsingState WPXParsingState;
00064 struct _WPXParsingState
00065 {
00066         _WPXParsingState();
00067         ~_WPXParsingState();
00068 
00069         uint32_t m_textAttributeBits;
00070         float m_fontSize;
00071         WPXString *m_fontName;
00072         RGBSColor *m_fontColor;
00073         RGBSColor *m_highlightColor;
00074 
00075         bool m_isParagraphColumnBreak;
00076         bool m_isParagraphPageBreak;
00077         uint8_t m_paragraphJustification;
00078         uint8_t m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented
00079         float m_paragraphLineSpacing;
00080 
00081         bool m_isDocumentStarted;
00082         bool m_isPageSpanOpened;
00083         bool m_isSectionOpened;
00084         bool m_isPageSpanBreakDeferred;
00085 
00086         bool m_isSpanOpened;
00087         bool m_isParagraphOpened;
00088         bool m_isListElementOpened;
00089 
00090         std::vector<unsigned int> m_numRowsToSkip;
00091         WPXTableDefinition m_tableDefinition;
00092         int m_currentTableCol;
00093         int m_currentTableRow;
00094         int m_currentTableCellNumberInRow;
00095         bool m_isTableOpened;
00096         bool m_isTableRowOpened;
00097         bool m_isTableColumnOpened;
00098         bool m_isTableCellOpened;
00099         bool m_wasHeaderRow;
00100         bool m_isCellWithoutParagraph;
00101         uint32_t m_cellAttributeBits;
00102         uint8_t m_paragraphJustificationBeforeTable;
00103         
00104         int m_nextPageSpanIndice;
00105         int m_numPagesRemainingInSpan;
00106 
00107         bool m_sectionAttributesChanged;
00108         int m_numColumns;
00109         std::vector < WPXColumnDefinition > m_textColumns;
00110         bool m_isTextColumnWithoutParagraph;
00111 
00112         float m_pageFormLength;
00113         float m_pageFormWidth;
00114         WPXFormOrientation m_pageFormOrientation;
00115 
00116         float m_pageMarginLeft;
00117         float m_pageMarginRight;
00118         float m_paragraphMarginLeft;  // resulting paragraph margin that is one of the paragraph
00119         float m_paragraphMarginRight; // properties
00120         float m_paragraphMarginTop;
00121         float m_paragraphMarginBottom;
00122         float m_leftMarginByPageMarginChange;  // part of the margin due to the PAGE margin change
00123         float m_rightMarginByPageMarginChange; // inside a page that already has content.
00124         float m_leftMarginByParagraphMarginChange;  // part of the margin due to the PARAGRAPH
00125         float m_rightMarginByParagraphMarginChange; // margin change (in WP6)
00126         float m_leftMarginByTabs;  // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
00127         float m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
00128 
00129         float m_listReferencePosition; // position from the left page margin of the list number/bullet
00130         float m_listBeginPosition; // position from the left page margin of the beginning of the list
00131 
00132         float m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
00133         float m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
00134         float m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
00135 
00136         uint8_t m_currentListLevel;
00137         
00138         uint16_t m_alignmentCharacter;
00139         std::vector<WPXTabStop> m_tabStops;
00140         bool m_isTabPositionRelative;
00141 
00142         std::set <const WPXSubDocument *> m_subDocuments;
00143 
00144         bool m_inSubDocument;
00145         bool m_isNote;
00146 };
00147 
00148 class WPXListener
00149 {
00150 public:
00151         WPXListener(std::vector<WPXPageSpan *> *pageList, WPXHLListenerImpl *listenerImpl);
00152         virtual ~WPXListener();
00153 
00154         virtual void startDocument();
00155         void handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice);
00156         virtual void insertBreak(const uint8_t breakType);
00157         virtual void lineSpacingChange(const float lineSpacing);
00158         virtual void justificationChange(const uint8_t justification);
00159         virtual void setAlignmentCharacter(const uint16_t character) = 0;
00160         virtual void setLeaderCharacter(const uint16_t character, const uint8_t numberOfSpaces) = 0;
00161         virtual void defineTabStops(const bool isRelative, const std::vector<WPXTabStop> &tabStops, 
00162                                     const std::vector<bool> &usePreWP9LeaderMethods) = 0;
00163         virtual void insertCharacter(const uint16_t character) = 0;
00164         virtual void insertTab(const uint8_t tabType, const float tabPosition) = 0;
00165         virtual void handleLineBreak() = 0;
00166         virtual void insertEOL() = 0;
00167         virtual void attributeChange(const bool isOn, const uint8_t attribute) = 0;
00168         virtual void spacingAfterParagraphChange(const float spacingRelative, const float spacingAbsolute) = 0;
00169         virtual void pageMarginChange(const uint8_t side, const uint16_t margin) = 0;
00170         virtual void pageFormChange(const uint16_t length, const uint16_t width, const WPXFormOrientation orientation,
00171                                         const bool isPersistent) = 0;
00172         virtual void marginChange(const uint8_t side, const uint16_t margin) = 0;
00173         virtual void paragraphMarginChange(const uint8_t side, const int16_t margin) = 0;
00174         virtual void indentFirstLineChange(const int16_t offset) = 0;
00175         virtual void columnChange(const WPXTextColumnType columnType, const uint8_t numColumns, const std::vector<float> &columnWidth,
00176                                         const std::vector<bool> &isFixedWidth) = 0;
00177         virtual void endDocument() = 0;
00178 
00179         virtual void defineTable(const uint8_t position, const uint16_t leftOffset) = 0;
00180         virtual void addTableColumnDefinition(const uint32_t width, const uint32_t leftGutter, const uint32_t rightGutter,
00181                                         const uint32_t attributes, const uint8_t alignment) = 0;
00182         virtual void startTable() = 0;
00183         virtual void endTable() = 0;
00184 
00185         WPXParsingState *m_ps; // parse state
00186         WPXHLListenerImpl * m_listenerImpl;
00187         WPXPropertyList m_metaData;
00188         std::vector <WPXPageSpan *> *m_pageList;
00189 
00190 protected:
00191         virtual void _handleSubDocument(const WPXSubDocument *subDocument, const bool isHeaderFooter, WPXTableList tableList, int nextTableIndice) = 0;
00192         virtual void _flushText() = 0;
00193         virtual void _changeList() = 0;
00194 
00195         void _openSection();
00196         void _closeSection();
00197 
00198         void _openPageSpan();
00199         void _closePageSpan();
00200 
00201         virtual void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00202         virtual void _getTabStops(WPXPropertyListVector &tabStops);
00203         virtual void _appendJustification(WPXPropertyList &propList, int justification);
00204         virtual void _resetParagraphState(const bool isListElement=false);
00205         virtual void _openParagraph();
00206         void _closeParagraph();
00207 
00208         void _openListElement();
00209         void _closeListElement();
00210 
00211         void _openSpan();
00212         void _closeSpan();
00213 
00214         void _openTable();
00215         void _closeTable();
00216         void _openTableRow(const float height, const bool isMinimumHeight, const bool isHeaderRow);
00217         void _closeTableRow();
00218         void _openTableCell(const uint8_t colSpan, const uint8_t rowSpan, const uint8_t borderBits, 
00219                                 const RGBSColor * cellFgColor, const RGBSColor * cellBgColor,
00220                                 const RGBSColor * cellBorderColor,
00221                                 const WPXVerticalAlignment cellVerticalAlignment);
00222         void _closeTableCell();
00223 
00224         bool isUndoOn() { return m_isUndoOn; }
00225         bool m_isUndoOn;
00226         
00227 private:
00228         WPXString _colorToString(const RGBSColor * color);
00229         WPXString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
00230 };
00231 
00232 #endif /* WPXLISTENER_H */

Generated on Thu Aug 10 23:42:15 2006 for libwpd by doxygen 1.4.7