libmswrite.h
1/* This file is part of the LibMSWrite Library
2 Copyright (C) 2001-2003 Clarence Dang <clarencedang@users.sourceforge.net>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License Version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License Version 2 for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 Version 2 along with this library; see the file COPYING.LIB. If not,
15 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17
18 LibMSWrite Project Website:
19 http://sourceforge.net/projects/libmswrite/
20*/
21
22#ifndef __LIBMSWRITE_H__
23#define __LIBMSWRITE_H__
24
25#include "structures.h"
26#include "structures_private.h"
27
28namespace MSWrite
29{
30#if 0
31 class DocumentInfo
32 {
33 private:
34 Word m_numObjects;
35 bool m_hasHeader;
36 bool m_hasFooter;
37 bool m_hasHeaderOnFirstPage;
38 bool m_hasFooterOnFirstPage;
39
40 public:
41 DocumentInfo ()
42 {
43 m_numObjects = 0;
44 m_hasHeader = m_hasFooter = false;
45 m_hasHeaderOnFirstPage = m_hasFooterOnFirstPage = false;
46 }
47
48 Word getNumObjects (void) const { return m_numObjects; }
49 void setNumObjects (const Word numObjects) { m_numObjects = numObjects; }
50
51 bool getHasHeader (void) const { return m_hasHeader; }
52 void setHasHeader (const bool hasHeader) { m_hasHeader = hasHeader; }
53
54 bool getHasFooter (void) const { return m_hasFooter; }
55 void setHasFooter (const bool hasFooter) { m_hasFooter = hasFooter; }
56
57 bool getHasHeaderOnFirstPage (void) const { return m_hasHeaderOnFirstPage; }
58 void setHasHeaderOnFirstPage (const bool hasHeaderOnFirstPage) { m_hasHeader = hasHeaderOnFirstPage; }
59
60 bool getHasFooterOnFirstPage (void) const { return m_hasFooterOnFirstPage; }
61 void setHasFooterOnFirstPage (const bool hasFooterOnFirstPage) { m_hasFooterOnFirstPage = hasFooterOnFirstPage; }
62 };
63#endif
64
65
66 // [PRIVATE] don't use
67 class FormatInfo : public NeedsDevice, public NeedsHeader
68 {
69 private:
70 List <FormatInfoPage> m_formatInfoPageList;
71 List <FormatInfoPage>::Iterator m_formatInfoPageIterator;
72 DWord m_nextChar;
73
74 enum FormatInfoPageTypes m_type;
75
76 friend class InternalParser;
77 friend class InternalGenerator;
78 Word m_leftMargin, m_rightMargin; // for ParaType only
79 FontTable *m_fontTable; // for CharType only
80 void setMargins (const Word leftMargin, const Word rightMargin)
81 {
82 m_leftMargin = leftMargin, m_rightMargin = rightMargin;
83 }
84 void setFontTable (FontTable *fontTable) { m_fontTable = fontTable; }
85
86 FormatInfo &operator= (const FormatInfo &rhs); // TODO
87 public:
88 FormatInfo ();
89 virtual ~FormatInfo ();
90
91 void setType (const enum FormatInfoPageTypes t) { m_type = t; }
92
93 bool readFromDevice (void);
94 bool writeToDevice (const void *defaultProperty);
95
96 void *begin (void);
97 void *next (void);
98 bool end (void) /*const*/;
99
100 bool add (const void *property, const bool force = false);
101 };
102
103
104 class Generator;
105 class Parser
106 {
107 protected:
108 Generator *m_generator;
109
110 public:
111 Parser (Generator *generator = NULL)
112 {
113 setGenerator (generator);
114 }
115
116 virtual ~Parser ()
117 {
118 }
119
120 void setGenerator (Generator *generator)
121 {
122 m_generator = generator;
123 }
124
125 virtual bool parse (void) = 0;
126 };
127
128
129 class Generator
130 {
131 public:
132 Generator ();
133 virtual ~Generator ();
134
140 virtual bool writeDocumentBegin (const Word format, const PageLayout *pageLayout) = 0;
141 virtual bool writeDocumentEnd (const Word format, const PageLayout *pageLayout) = 0;
142
148 virtual bool writeFooterBegin (void) { return true; }
149 virtual bool writeFooterEnd(void) { return true; }
150
151 virtual bool writeHeaderBegin (void) { return true; }
152 virtual bool writeHeaderEnd (void) { return true; }
153
154 virtual bool writeBodyBegin (void) = 0;
155 virtual bool writeBodyEnd (void) = 0;
156
162 virtual bool writeParaInfoBegin (const FormatParaProperty * /*paraProperty*/,
163 const OLE * /*ole*/ = NULL,
164 const Image * /*image*/ = NULL) { return true; }
165 virtual bool writeParaInfoEnd (const FormatParaProperty * /*paraProperty*/,
166 const OLE * /*ole*/ = NULL,
167 const Image * /*image*/ = NULL) { return true; }
168
174 virtual bool writeCharInfoBegin (const FormatCharProperty * /*charProperty*/) { return true; }
175 virtual bool writeCharInfoEnd (const FormatCharProperty * /*charProperty*/,
176 const bool /*endOfParagraph*/ = false) { return true; }
177
178
184 virtual bool writeBinary (const Byte * /*buffer*/, const DWord /*length*/) { return true; }
185
186
187 /*
188 *
189 * Text output
190 *
191 */
192
198 bool processText (const Byte *string, bool willReachEndOfParagraph);
199 virtual bool writeText (const Byte *string) = 0;
200
201
207 virtual bool writePageNew (const int /*pageNumberClaimed*/ = 0)
208 {
209 return true;
210 };
211 virtual bool writePageBreak (void)
212 {
213 return writeText ((const Byte *) "\xc"); // i.e. (char)12
214 }
215 virtual bool writePageNumber (void)
216 {
217 return writeText ((const Byte *) "\x1"); // i.e. (char)1
218 }
219 virtual bool writeCarriageReturn (void)
220 {
221 return writeText ((const Byte *) "\xd"); // i.e. (char)13
222 }
223 virtual bool writeNewLine (const bool /*endOfParagraph*/ = true)
224 {
225 return writeText ((const Byte *) "\n"); // i.e. (char)10
226 }
227 virtual bool writeOptionalHyphen (void)
228 {
229 return writeText ((const Byte *) "-");
230 }
231
238 virtual void sigProgress (const int /*value*/) {}
239 };
240
241
242 class InternalParser : public Parser, public NeedsDevice
243 {
244 private:
245 Header *m_header;
246 SectionTable *m_sectionTable;
247 PageLayout *m_pageLayout;
248 PageTable *m_pageTable;
249 FontTable *m_fontTable;
250 FormatInfo *m_paragraphInfo, *m_characterInfo;
251
252 Image *m_image;
253 OLE *m_ole;
254
255 public:
256 InternalParser ();
257 virtual ~InternalParser ();
258
259 bool parse (void);
260 };
261
262
263 class InternalGenerator : public Generator, public NeedsDevice
264 {
265 private:
266 Header *m_header;
267 SectionTable *m_sectionTable;
268 PageLayout *m_pageLayout;
269 PageTable *m_pageTable;
270 FontTable *m_fontTable;
271 FormatInfo *m_paragraphInfo, *m_characterInfo;
272
273 Image *m_image;
274 OLE *m_ole;
275
276 bool seekNextPage (void);
277
278 public:
279 InternalGenerator ();
280 virtual ~InternalGenerator ();
281
282 bool writeDocumentBegin (const Word format, const PageLayout *pageLayout);
283 bool writeDocumentEnd (const Word format, const PageLayout *pageLayout);
284
285 bool writeFooterBegin (void)
286 {
287 // don't care
288 return true;
289 }
290 bool writeFooterEnd(void)
291 {
292 // don't care
293 return true;
294 }
295
296 bool writeHeaderBegin (void)
297 {
298 // don't care
299 return true;
300 }
301 bool writeHeaderEnd (void)
302 {
303 // don't care
304 return true;
305 }
306
307 bool writeBodyBegin (void)
308 {
309 // don't care
310 return true;
311 }
312
313 bool writeBodyEnd (void)
314 {
315 // don't care
316 return true;
317 }
318
319
325 bool writeParaInfoBegin (const FormatParaProperty *paraProperty,
326 const OLE *oleHeader = NULL,
327 const Image *imageHeader = NULL);
328 bool writeParaInfoEnd (const FormatParaProperty *paraProperty,
329 const OLE *oleHeader = NULL,
330 const Image *imageHeader = NULL);
331
332 bool writeCharInfoBegin (const FormatCharProperty *charProperty);
333 bool writeCharInfoEnd (const FormatCharProperty *charProperty,
334 const bool endOfParagraph = false);
335
336
337 bool writeBinary (const Byte *buffer, const DWord length);
338
339
340 bool writeText (const Byte *string);
341
342
343 bool writePageNew (const int pageNumberClaimed = 0);
344
345 bool writePageBreak (void)
346 {
347 return writeText ((const Byte *) "\xC"); // i.e. (char)12
348 }
349 bool writePageNumber (void)
350 {
351 return writeText ((const Byte *) "\x1"); // i.e. (char)1
352 }
353 bool writeCarriageReturn (void)
354 {
355 // it's DOS/Windows(r) which has \r\n newlines
356 return writeText ((const Byte *) "\xD"); // i.e. (char)13
357 }
358 bool writeNewLine (const bool)
359 {
360 return writeText ((const Byte *) "\n"); // i.e. (char)10
361 }
362 bool writeOptionalHyphen (void)
363 {
364 return writeText ((const Byte *) "\x1F"); // i.e. (char)31
365 }
366
367 void sigProgress (const int)
368 {
369 // don't care
370 return;
371 }
372
373 };
374} // namespace MSWrite {
375
376#endif // __LIBMSWRITE_H__
377
378// end of libmswrite.h