summaryrefslogtreecommitdiffstats
path: root/filters/kword/mswrite/libmswrite.h
blob: c4d063d4c9038080d28974ed446ca970da6ab0ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* This file is part of the LibMSWrite Library
   Copyright (C) 2001-2003 Clarence Dang <clarencedang@users.sourceforge.net>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License Version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License Version 2 for more details.

   You should have received a copy of the GNU Library General Public License
   Version 2 along with this library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.

   LibMSWrite Project Website:
   http://sourceforge.net/projects/libmswrite/
*/

#ifndef __LIBMSWRITE_H__
#define __LIBMSWRITE_H__

#include "structures.h"
#include "structures_private.h"

namespace MSWrite
{
#if 0
	class DocumentInfo
	{
	private:
		Word m_numObjects;
		bool m_hasHeader;
		bool m_hasFooter;
		bool m_hasHeaderOnFirstPage;
		bool m_hasFooterOnFirstPage;

	public:
		DocumentInfo ()
		{
			m_numObjects = 0;
			m_hasHeader = m_hasFooter = false;
			m_hasHeaderOnFirstPage = m_hasFooterOnFirstPage = false;
		}

		Word getNumObjects (void) const	{	return m_numObjects;	}
		void setNumObjects (const Word numObjects)	{	m_numObjects = numObjects;	}

		bool getHasHeader (void) const	{	return m_hasHeader;	}
		void setHasHeader (const bool hasHeader)	{	m_hasHeader = hasHeader;	}

		bool getHasFooter (void) const	{	return m_hasFooter;	}
		void setHasFooter (const bool hasFooter)	{	m_hasFooter = hasFooter;	}

		bool getHasHeaderOnFirstPage (void) const	{	return m_hasHeaderOnFirstPage;	}
		void setHasHeaderOnFirstPage (const bool hasHeaderOnFirstPage)	{	m_hasHeader = hasHeaderOnFirstPage;	}

		bool getHasFooterOnFirstPage (void) const	{	return m_hasFooterOnFirstPage;	}
		void setHasFooterOnFirstPage (const bool hasFooterOnFirstPage)	{	m_hasFooterOnFirstPage = hasFooterOnFirstPage;	}
	};
#endif


	// [PRIVATE] don't use
	class FormatInfo : public NeedsDevice, public NeedsHeader
	{
	private:
		List <FormatInfoPage> m_formatInfoPageList;
		List <FormatInfoPage>::Iterator m_formatInfoPageIterator;
		DWord m_nextChar;

		enum FormatInfoPageTypes m_type;

		friend class InternalParser;
		friend class InternalGenerator;
			Word m_leftMargin, m_rightMargin;	// for ParaType only
			FontTable *m_fontTable;	// for CharType only
			void setMargins (const Word leftMargin, const Word rightMargin)
			{
				m_leftMargin = leftMargin, m_rightMargin = rightMargin;
			}
			void setFontTable (FontTable *fontTable)	{	m_fontTable = fontTable;	}

		FormatInfo &operator= (const FormatInfo &rhs);	// TODO
	public:
		FormatInfo ();
		virtual ~FormatInfo ();

		void setType (const enum FormatInfoPageTypes t)	{	m_type = t;	}

		bool readFromDevice (void);
		bool writeToDevice (const void *defaultProperty);

		void *begin (void);
		void *next (void);
		bool end (void) /*const*/;

		bool add (const void *property, const bool force = false);
	};


	class Generator;
	class Parser
	{
	protected:
		Generator *m_generator;

	public:
		Parser (Generator *generator = NULL)
		{
			setGenerator (generator);
		}
		
		virtual ~Parser ()
		{
		}

		void setGenerator (Generator *generator)
		{
			m_generator = generator;
		}

		virtual bool parse (void) = 0;
	};


	class Generator
	{
	public:
		Generator ();
		virtual ~Generator ();

		/**
		 *
		 * Document block (you must implement these signals)
		 *
		 */
		virtual bool writeDocumentBegin (const Word format, const PageLayout *pageLayout) = 0;
		virtual bool writeDocumentEnd (const Word format, const PageLayout *pageLayout) = 0;

		/**
		 *
		 * Various sections in the document
		 *
		 */
		virtual bool writeFooterBegin (void)	{	return true;	}
		virtual bool writeFooterEnd(void)	{	return true;	}

		virtual bool writeHeaderBegin (void)	{	return true;	}
		virtual bool writeHeaderEnd (void)	{	return true;	}

		virtual bool writeBodyBegin (void) = 0;
		virtual bool writeBodyEnd (void)	= 0;

		/**
		 *
		 * Paragraph block
		 *
		 */
		virtual bool writeParaInfoBegin (const FormatParaProperty * /*paraProperty*/,
													const OLE * /*ole*/ = NULL,
													const Image * /*image*/ = NULL)	{	return true;	}
		virtual bool writeParaInfoEnd (const FormatParaProperty * /*paraProperty*/,
													const OLE * /*ole*/ = NULL,
													const Image * /*image*/ = NULL)	{	return true;	}

		/**
		 *
		 * Character block
		 *
		 */
		virtual bool writeCharInfoBegin (const FormatCharProperty * /*charProperty*/)	{	return true;	}
		virtual bool writeCharInfoEnd (const FormatCharProperty * /*charProperty*/,
													const bool /*endOfParagraph*/ = false)	{	return true;	}


		/**
		 *
		 * Binary output
		 *
		 */
		virtual bool writeBinary (const Byte * /*buffer*/, const DWord /*length*/)	{	return true;	}


		/*
		 *
		 * Text output
		 *
		 */

		/**
		 *
		 * processText
		 * this calls writeText, newLineWrite etc...
		 */
		bool processText (const Byte *string, bool willReachEndOfParagraph);
		virtual bool writeText (const Byte *string) = 0;


		/**
		 *
		 * Miscellaneous special signals called by processText
		 *
		 */
		virtual bool writePageNew (const int /*pageNumberClaimed*/ = 0)
		{
			return true;
		};
		virtual bool writePageBreak (void)
		{
			return writeText ((const Byte *) "\xc");	// i.e. (char)12
		}
		virtual bool writePageNumber (void)
		{
			return writeText ((const Byte *) "\x1");	// i.e. (char)1
		}
		virtual bool writeCarriageReturn (void)
		{
			return writeText ((const Byte *) "\xd");	// i.e. (char)13
		}
		virtual bool writeNewLine (const bool /*endOfParagraph*/ = true)
		{
			return writeText ((const Byte *) "\n");	// i.e. (char)10
		}
		virtual bool writeOptionalHyphen (void)
		{
			return writeText ((const Byte *) "-");
		}

		/**
		 *
		 * implement this signal to show the progress of the conversion
		 * (0 <= value <= 100)
		 *
		 */
		virtual void sigProgress (const int /*value*/)	{}
	};


	class InternalParser : public Parser, public NeedsDevice
	{
	private:
		Header *m_header;
		SectionTable *m_sectionTable;
		PageLayout *m_pageLayout;
		PageTable *m_pageTable;
		FontTable *m_fontTable;
		FormatInfo *m_paragraphInfo, *m_characterInfo;

		Image *m_image;
		OLE *m_ole;

	public:
		InternalParser ();
		virtual ~InternalParser ();

		bool parse (void);
	};


	class InternalGenerator : public Generator, public NeedsDevice
	{
	private:
		Header *m_header;
		SectionTable *m_sectionTable;
		PageLayout *m_pageLayout;
		PageTable *m_pageTable;
		FontTable *m_fontTable;
		FormatInfo *m_paragraphInfo, *m_characterInfo;

		Image *m_image;
		OLE *m_ole;
		
		bool seekNextPage (void);
		
	public:
		InternalGenerator ();
		virtual ~InternalGenerator ();

		bool writeDocumentBegin (const Word format, const PageLayout *pageLayout);
		bool writeDocumentEnd (const Word format, const PageLayout *pageLayout);

		bool writeFooterBegin (void)
		{
			// don't care
			return true;
		}
		bool writeFooterEnd(void)
		{
			// don't care
			return true;
		}

		bool writeHeaderBegin (void)
		{
			// don't care
			return true;
		}
		bool writeHeaderEnd (void)
		{
			// don't care
			return true;
		}

		bool writeBodyBegin (void)
		{
			// don't care
			return true;
		}

		bool writeBodyEnd (void)
		{
			// don't care
			return true;
		}


		/**
		 *
		 * Paragraph block
		 *
		 */
		bool writeParaInfoBegin (const FormatParaProperty *paraProperty,
											const OLE *oleHeader = NULL,
											const Image *imageHeader = NULL);
		bool writeParaInfoEnd (const FormatParaProperty *paraProperty,
										const OLE *oleHeader = NULL,
										const Image *imageHeader = NULL);

		bool writeCharInfoBegin (const FormatCharProperty *charProperty);
		bool writeCharInfoEnd (const FormatCharProperty *charProperty,
										const bool endOfParagraph = false);


		bool writeBinary (const Byte *buffer, const DWord length);


		bool writeText (const Byte *string);


		bool writePageNew (const int pageNumberClaimed = 0);

		bool writePageBreak (void)
		{
			return writeText ((const Byte *) "\xC");	// i.e. (char)12
		}
		bool writePageNumber (void)
		{
			return writeText ((const Byte *) "\x1");	// i.e. (char)1
		}
		bool writeCarriageReturn (void)
		{
			// it's DOS/Windows(r) which has \r\n newlines
			return writeText ((const Byte *) "\xD");	// i.e. (char)13
		}
		bool writeNewLine (const bool)
		{
			return writeText ((const Byte *) "\n");	// i.e. (char)10
		}
		bool writeOptionalHyphen (void)
		{
			return writeText ((const Byte *) "\x1F");	// i.e. (char)31
		}

		void sigProgress (const int)
		{
			// don't care
			return;
		}

	};
}	// namespace MSWrite	{

#endif	// __LIBMSWRITE_H__

// end of libmswrite.h