WordPerfectCollector.h
1/* WordPerfectCollector: Collects sections and runs of text from a
2 * wordperfect 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., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 *
24 * For further information visit http://libwpd.sourceforge.net
25 *
26 */
27
28/* "This product is not manufactured, approved, or supported by
29 * Corel Corporation or Corel Corporation Limited."
30 */
31
32#ifndef _WORDPERFECTCOLLECTOR_H
33#define _WORDPERFECTCOLLECTOR_H
34
35#include "SectionStyle.h"
36
37#include <config.h>
38#include <libwpd/libwpd.h>
39#include "shared_headers.h"
40#include <vector>
41#include <map>
42#include <stack>
43
44class DocumentElement;
45class DocumentHandler;
46class TagOpenElement;
47class FontStyle;
48class ListStyle;
49
50class ParagraphStyle;
51class SpanStyle;
52class TableStyle;
53class PageSpan;
54
55// the state we use for writing the final document
56typedef struct _WriterDocumentState WriterDocumentState;
57struct _WriterDocumentState
58{
59 _WriterDocumentState();
60
61 bool mbFirstElement;
62 bool mbInFakeSection;
63 bool mbListElementOpenedAtCurrentLevel;
64 bool mbTableCellOpened;
65 bool mbHeaderRow;
66 bool mbInNote;
67};
68
69enum WriterListType { unordered, ordered };
70
71struct ltstr
72{
73 bool operator()(const _SH_String & s1, const _SH_String & s2) const
74 {
75 return strcmp(s1.cstr(), s2.cstr()) < 0;
76 }
77};
78
79class WordPerfectCollector : public _SH_DocumentInterface
80{
81public:
82 WordPerfectCollector(_SH_InputStream *pInput, DocumentHandler *pHandler);
83 virtual ~WordPerfectCollector();
84 bool filter();
85
86 virtual void setDocumentMetaData(const _SH_PropertyList &propList) {};
87 virtual void startDocument();
88 virtual void endDocument();
89
90 virtual void openPageSpan(const _SH_PropertyList &propList);
91 virtual void closePageSpan();
92 virtual void openHeader(const _SH_PropertyList &propList);
93 virtual void closeHeader();
94 virtual void openFooter(const _SH_PropertyList &propList);
95 virtual void closeFooter();
96 virtual void openParagraph(const _SH_PropertyList &propList, const _SH_PropertyListVector &tabStops);
97 virtual void closeParagraph();
98 virtual void openSpan(const _SH_PropertyList &propList);
99 virtual void closeSpan();
100 virtual void openSection(const _SH_PropertyList &propList, const _SH_PropertyListVector &columns);
101 virtual void closeSection();
102 virtual void insertTab();
103 virtual void insertText(const _SH_String &text);
104 virtual void insertLineBreak();
105 virtual void defineOrderedListLevel(const _SH_PropertyList &propList);
106 virtual void defineUnorderedListLevel(const _SH_PropertyList &propList);
107 virtual void openOrderedListLevel(const _SH_PropertyList &propList);
108 virtual void openUnorderedListLevel(const _SH_PropertyList &propList);
109 virtual void closeOrderedListLevel();
110 virtual void closeUnorderedListLevel();
111 virtual void openListElement(const _SH_PropertyList &propList, const _SH_PropertyListVector &tabStops);
112 virtual void closeListElement();
113 virtual void openFootnote(const _SH_PropertyList &propList);
114 virtual void closeFootnote();
115 virtual void openEndnote(const _SH_PropertyList &propList);
116 virtual void closeEndnote();
117 virtual void openTable(const _SH_PropertyList &propList, const _SH_PropertyListVector &columns);
118 virtual void openTableRow(const _SH_PropertyList &propList);
119 virtual void closeTableRow();
120 virtual void openTableCell(const _SH_PropertyList &propList);
121 virtual void closeTableCell();
122 virtual void insertCoveredTableCell(const _SH_PropertyList &propList);
123 virtual void closeTable();
124
125#if defined(HAVE_LIBWPD_090) || defined(HAVE_LIBWPD_0100)
126 virtual void definePageStyle(const _SH_PropertyList &propList) {}
127 virtual void defineParagraphStyle(const _SH_PropertyList &propList, const _SH_PropertyListVector &tabStops) {}
128 virtual void defineCharacterStyle(const _SH_PropertyList &propList) {}
129 virtual void defineSectionStyle(const _SH_PropertyList &propList, const _SH_PropertyListVector &columns) {}
130 virtual void insertSpace() {}
131 virtual void insertField(const _SH_String &type, const _SH_PropertyList &propList) {}
132 virtual void openComment(const _SH_PropertyList &propList) {}
133 virtual void closeComment() {}
134 virtual void openTextBox(const _SH_PropertyList &propList) {}
135 virtual void closeTextBox() {}
136 virtual void openFrame(const _SH_PropertyList &propList) {}
137 virtual void closeFrame() {}
138 virtual void insertBinaryObject(const _SH_PropertyList &propList, const _SH_BinaryData &data) {}
139 virtual void insertEquation(const _SH_PropertyList &propList, const _SH_String &data) {}
140#endif
141
142#if defined(HAVE_LIBWPD_0100)
143 virtual void startDocument(const _SH_PropertyList &propList) {}
144 virtual void defineEmbeddedFont(const _SH_PropertyList &propList) {}
145 virtual void defineParagraphStyle(const _SH_PropertyList &propList) {}
146 virtual void openParagraph(const _SH_PropertyList &propList) {}
147 virtual void openLink(const _SH_PropertyList &propList) {}
148 virtual void closeLink() {}
149 virtual void defineSectionStyle(const _SH_PropertyList &propList) {}
150 virtual void openSection(const _SH_PropertyList &propList) {}
151 virtual void insertField(const _SH_PropertyList &propList) {}
152 virtual void openListElement(const _SH_PropertyList &propList) {}
153 virtual void openTable(const _SH_PropertyList &propList) {}
154 virtual void insertBinaryObject(const _SH_PropertyList &propList) {}
155 virtual void insertEquation(const _SH_PropertyList &propList) {}
156 virtual void openGroup(const _SH_PropertyList &propList) {}
157 virtual void closeGroup() {}
158 virtual void defineGraphicStyle(const _SH_PropertyList &propList) {}
159 virtual void drawRectangle(const _SH_PropertyList &propList) {}
160 virtual void drawEllipse(const _SH_PropertyList &propList) {}
161 virtual void drawPolygon(const _SH_PropertyList &propList) {}
162 virtual void drawPolyline(const _SH_PropertyList &propList) {}
163 virtual void drawPath(const _SH_PropertyList &propList) {}
164 virtual void drawConnector(const _SH_PropertyList &propList) {}
165#endif
166
167protected:
168 void _resetDocumentState();
169 bool _parseSourceDocument(_SH_InputStream &input);
170 bool _writeTargetDocument(DocumentHandler &xHandler);
171 void _writeBegin();
172 void _writeDefaultStyles(DocumentHandler &xHandler);
173 void _writeMasterPages(DocumentHandler &xHandler);
174 void _writePageMasters(DocumentHandler &xHandler);
175 void _allocateFontName(const _SH_String &);
176
177private:
178 void _openListLevel(TagOpenElement *pListLevelOpenElement);
179 void _closeListLevel(const char *szListType);
180
181 _SH_InputStream *mpInput;
182 DocumentHandler *mpHandler;
183 bool mbUsed; // whether or not it has been before (you can only use me once!)
184
185 WriterDocumentState mWriterDocumentState;
186
187 // paragraph styles
188 std::map<_SH_String, ParagraphStyle *, ltstr> mTextStyleHash;
189
190 // span styles
191 std::map<_SH_String, SpanStyle *, ltstr> mSpanStyleHash;
192
193 // font styles
194 std::map<_SH_String, FontStyle *, ltstr> mFontHash;
195
196 // section styles
197 std::vector<SectionStyle *> mSectionStyles;
198 float mfSectionSpaceAfter;
199
200 // table styles
201 std::vector<TableStyle *> mTableStyles;
202
203 // list styles
204 unsigned int miNumListStyles;
205
206 // style elements
207 std::vector<DocumentElement *> mStylesElements;
208 // content elements
209 std::vector<DocumentElement *> mBodyElements;
210 // the current set of elements that we're writing to
211 std::vector<DocumentElement *> * mpCurrentContentElements;
212
213 // page state
214 std::vector<PageSpan *> mPageSpans;
215 PageSpan *mpCurrentPageSpan;
216 int miNumPageStyles;
217
218 // list styles / state
219 ListStyle *mpCurrentListStyle;
220 unsigned int miCurrentListLevel;
221 unsigned int miLastListLevel;
222 unsigned int miLastListNumber;
223 std::vector<ListStyle *> mListStyles;
224 bool mbListContinueNumbering;
225 bool mbListElementOpened;
226 bool mbListElementParagraphOpened;
227
228 // table state
229 TableStyle *mpCurrentTableStyle;
230};
231#endif