1 /* DocumentCollector: Collects sections and runs of text from a 2 * file (and styles to go along with them) and writes them 3 * to a target file 4 * 5 * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) 6 * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com) 7 * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Library General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * 23 * For further information visit http://libwpd.sourceforge.net 24 * 25 */ 26 27 /* "This product is not manufactured, approved, or supported by 28 * Corel Corporation or Corel Corporation Limited." 29 */ 30 31 #ifndef _DOCUMENTCOLLECTOR_HXX 32 #define _DOCUMENTCOLLECTOR_HXX 33 #include "SectionStyle.hxx" 34 35 #if defined _MSC_VER 36 #pragma warning( push, 1 ) 37 #endif 38 #include <libwpd/libwpd.h> 39 #if defined _MSC_VER 40 #pragma warning( pop ) 41 #endif 42 #include <vector> 43 #include <map> 44 #include <stack> 45 #include <string.h> 46 47 class DocumentElement; 48 class DocumentHandler; 49 class TagOpenElement; 50 class FontStyle; 51 class ListStyle; 52 53 class ParagraphStyle; 54 class SpanStyle; 55 class TableStyle; 56 class PageSpan; 57 58 // the state we use for writing the final document 59 typedef struct _WriterDocumentState WriterDocumentState; 60 struct _WriterDocumentState 61 { 62 _WriterDocumentState(); 63 64 bool mbFirstElement; 65 bool mbInFakeSection; 66 bool mbListElementOpenedAtCurrentLevel; 67 bool mbTableCellOpened; 68 bool mbHeaderRow; 69 bool mbInNote; 70 }; 71 72 enum WriterListType { unordered, ordered }; 73 74 struct ltstr 75 { operator ()ltstr76 bool operator()(const WPXString & s1, const WPXString & s2) const 77 { 78 return strcmp(s1.cstr(), s2.cstr()) < 0; 79 } 80 }; 81 82 class DocumentCollector : public WPXHLListenerImpl 83 { 84 public: 85 DocumentCollector(WPXInputStream *pInput, DocumentHandler *pHandler); 86 virtual ~DocumentCollector(); 87 bool filter(); 88 setDocumentMetaData(const WPXPropertyList &)89 virtual void setDocumentMetaData(const WPXPropertyList & /* propList */) {} startDocument()90 virtual void startDocument() {} endDocument()91 virtual void endDocument() {} 92 93 virtual void openPageSpan(const WPXPropertyList &propList); closePageSpan()94 virtual void closePageSpan() {} 95 96 virtual void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns); 97 virtual void closeSection(); 98 99 virtual void openHeader(const WPXPropertyList &propList); 100 virtual void closeHeader(); 101 virtual void openFooter(const WPXPropertyList &propList); 102 virtual void closeFooter(); 103 104 virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); 105 virtual void closeParagraph(); 106 107 virtual void openSpan(const WPXPropertyList &propList); 108 virtual void closeSpan(); 109 110 111 virtual void insertTab(); 112 virtual void insertText(const WPXString &text); 113 virtual void insertLineBreak(); 114 115 virtual void defineOrderedListLevel(const WPXPropertyList &propList); 116 virtual void defineUnorderedListLevel(const WPXPropertyList &propList); 117 virtual void openOrderedListLevel(const WPXPropertyList &propList); 118 virtual void openUnorderedListLevel(const WPXPropertyList &propList); 119 virtual void closeOrderedListLevel(); 120 virtual void closeUnorderedListLevel(); 121 virtual void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); 122 virtual void closeListElement(); 123 124 virtual void openFootnote(const WPXPropertyList &propList); 125 virtual void closeFootnote(); 126 virtual void openEndnote(const WPXPropertyList &propList); 127 virtual void closeEndnote(); 128 129 virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns); 130 virtual void openTableRow(const WPXPropertyList &propList); 131 virtual void closeTableRow(); 132 virtual void openTableCell(const WPXPropertyList &propList); 133 virtual void closeTableCell(); 134 virtual void insertCoveredTableCell(const WPXPropertyList &propList); 135 virtual void closeTable(); 136 virtual bool parseSourceDocument(WPXInputStream &input) = 0; 137 138 protected: 139 void _resetDocumentState(); 140 bool _writeTargetDocument(DocumentHandler *pHandler); 141 void _writeDefaultStyles(DocumentHandler *pHandler); 142 void _writeMasterPages(DocumentHandler *pHandler); 143 void _writePageMasters(DocumentHandler *pHandler); 144 void _allocateFontName(const WPXString &); 145 146 private: 147 void _openListLevel(TagOpenElement *pListLevelOpenElement); 148 void _closeListLevel(const char *szListType); 149 150 WPXInputStream *mpInput; 151 DocumentHandler *mpHandler; 152 bool mbUsed; // whether or not it has been before (you can only use me once!) 153 154 WriterDocumentState mWriterDocumentState; 155 156 // paragraph styles 157 std::map<WPXString, ParagraphStyle *, ltstr> mTextStyleHash; 158 159 // span styles 160 std::map<WPXString, SpanStyle *, ltstr> mSpanStyleHash; 161 162 // font styles 163 std::map<WPXString, FontStyle *, ltstr> mFontHash; 164 165 // section styles 166 std::vector<SectionStyle *> mSectionStyles; 167 float mfSectionSpaceAfter; 168 169 // table styles 170 std::vector<TableStyle *> mTableStyles; 171 172 // list styles 173 unsigned int miNumListStyles; 174 175 // style elements 176 std::vector<DocumentElement *> mStylesElements; 177 // content elements 178 std::vector<DocumentElement *> mBodyElements; 179 // the current set of elements that we're writing to 180 std::vector<DocumentElement *> * mpCurrentContentElements; 181 182 // page state 183 std::vector<PageSpan *> mPageSpans; 184 PageSpan *mpCurrentPageSpan; 185 int miNumPageStyles; 186 187 // list styles / state 188 ListStyle *mpCurrentListStyle; 189 unsigned int miCurrentListLevel; 190 unsigned int miLastListLevel; 191 unsigned int miLastListNumber; 192 std::vector<ListStyle *> mListStyles; 193 bool mbListContinueNumbering; 194 bool mbListElementOpened; 195 bool mbListElementParagraphOpened; 196 197 // table state 198 TableStyle *mpCurrentTableStyle; 199 }; 200 201 #endif 202