filters

structures_private.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 __STRUCTURES_PRIVATE_H__
23#define __STRUCTURES_PRIVATE_H__
24
25#include "structures_generated.h"
26#include "list.h"
27
28namespace MSWrite
29{
30 class Header : public HeaderGenerated
31 {
32 private:
33 DWord m_numCharBytes;
34 Word m_pageCharInfo;
35
36 bool readFromDevice (void); friend class InternalParser;
37 bool writeToDevice (void); friend class InternalGenerator;
38
39 public:
40 Header ();
41 virtual ~Header ();
42
43 Header &operator= (const Header &rhs);
44
45 Word getFormat (void) const { return getMagic (); }
46 void setFormat (const Word f) { setMagic (f); }
47
48 DWord getNumCharBytes (void) const { return m_numCharBytes; }
49 void setNumCharBytes (const DWord w) { m_numCharBytes = w; }
50
51 Word getNumPageCharInfo (void) const { return m_pageParaInfo - m_pageCharInfo; }
52 Word getNumPageParaInfo (void) const { return m_pageFootnoteTable - m_pageParaInfo; }
53 Word getNumPageFootnoteTable (void) const { return m_pageSectionProperty - m_pageFootnoteTable; }
54 Word getNumPageSectionProperty (void) const { return m_pageSectionTable - m_pageSectionProperty; }
55 Word getNumPageSectionTable (void) const { return m_pagePageTable - m_pageSectionTable; }
56 Word getNumPagePageTable (void) const { return m_pageFontTable - m_pagePageTable; }
57 Word getNumPageFontTable (void) const { return m_numPages - m_pageFontTable; }
58
59 Word getPageCharInfo (void) const { return m_pageCharInfo; }
60 };
61
62 class NeedsHeader
63 {
64 protected:
65 Header *m_header;
66
67 public:
68 NeedsHeader (Header *header = NULL)
69 {
70 setHeader (header);
71 }
72
73 virtual ~NeedsHeader ()
74 {
75 }
76
77 NeedsHeader &operator= (const NeedsHeader &rhs)
78 {
79 if (this == &rhs)
80 return *this;
81
82 m_header = rhs.m_header;
83
84 return *this;
85 }
86
87 void setHeader (Header *header) { m_header = header; }
88 };
89
90
91 class SectionDescriptor : public SectionDescriptorGenerated
92 {
93 public:
94 SectionDescriptor ();
95 virtual ~SectionDescriptor ();
96
97 SectionDescriptor &operator= (const SectionDescriptor &rhs);
98 };
99
100
101 class SectionTable : public SectionTableGenerated, public NeedsHeader
102 {
103 public:
104 SectionTable ();
105 virtual ~SectionTable ();
106
107 SectionTable &operator= (const SectionTable &rhs);
108
109 private:
110 bool readFromDevice (void); friend class InternalParser;
111 bool writeToDevice (const bool needed); friend class InternalGenerator;
112 };
113
114
115 class Font; // from structures.h
116 class FontTable : public FontTableGenerated, public NeedsHeader
117 {
118 private:
119 List <Font> m_fontList;
120
121 bool readFromDevice (void); friend class InternalParser;
122 bool writeToDevice (void); friend class InternalGenerator;
123
124 public:
125 FontTable ();
126 virtual ~FontTable ();
127
128 FontTable &operator= (const FontTable &rhs);
129
130 Font *getFont (const DWord fontCode) const;
131 DWord findFont (const Font *want) const;
132 DWord addFont (const Font *input);
133 };
134
135
136 class PagePointer : public PagePointerGenerated
137 {
138 private:
139 friend class PageTable;
140 bool readFromDevice (void);
141 bool writeToDevice (void);
142
143 public:
144 PagePointer ();
145 virtual ~PagePointer ();
146
147 PagePointer &operator= (const PagePointer &rhs);
148 };
149
150
151 class PageTable : public PageTableGenerated, public NeedsHeader
152 {
153 private:
154 List <PagePointer> m_pagePointerList;
155 Word m_pageNumberStart; // for consistency checking
156
157 friend class InternalParser;
158 friend class InternalGenerator;
159 bool readFromDevice (void);
160 bool writeToDevice (void);
161
162 // call before readFromDevice ()
163 void setPageNumberStart (const Word s) { m_pageNumberStart = s; }
164
165 List <PagePointer>::Iterator m_pageTableIterator;
166
167 public:
168 PageTable ();
169 virtual ~PageTable ();
170
171 PageTable &operator= (const PageTable &rhs);
172
173 PagePointer *begin (void)
174 {
175 m_pageTableIterator = m_pagePointerList.begin ();
176 return &(*m_pageTableIterator);
177 }
178
179 PagePointer *next (void)
180 {
181 m_pageTableIterator = m_pageTableIterator.next ();
182 return &(*m_pageTableIterator);
183 }
184
185 bool end (void) /*const*/
186 {
187 return m_pageTableIterator == m_pagePointerList.end ();
188 }
189
190 bool add (const PagePointer *newone)
191 {
192 return m_pagePointerList.addToBack (*newone);
193 }
194 };
195
196
197 class FormatPointer : public FormatPointerGenerated
198 {
199 private:
200 DWord m_afterEndCharByte;
201
202 friend class FormatInfoPage;
203 bool readFromDevice (void);
204 bool writeToDevice (void);
205
206 //
207 // for exporting
208 //
209 const void *m_formatProperty;
210
211 const void *getFormatProperty (void) const { return m_formatProperty; }
212 void setFormatProperty (const void *val) { m_formatProperty = val; }
213
214 public:
215 FormatPointer ();
216 virtual ~FormatPointer ();
217
218 FormatPointer &operator= (const FormatPointer &rhs);
219
220 DWord getAfterEndCharByte (void) const { return m_afterEndCharByte; }
221 void setAfterEndCharByte (const DWord val) { m_afterEndCharByte = val; }
222 };
223
224
225 enum FormatInfoPageTypes
226 {
227 CharType,
228 ParaType
229 };
230
231 class FormatCharProperty; // from structures.h
232 class FormatParaProperty; // from structures.h
233 class FormatInfoPage : public FormatInfoPageGenerated, public NeedsHeader
234 {
235 private:
236 DWord m_firstCharByte; // FormatInfoPageGenerated::m_firstCharBytePlus128 - 128
237 enum FormatInfoPageTypes m_type; // CharInfo or ParaInfo?
238
239
240 //
241 // uncompressed data
242 //
243
244 // list of FormatPointers (what byte it covers upto and which FormatProperty)
245 FormatPointer *m_formatPointer;
246
247 // FormatProperty (which one? It depends on m_type)
248 FormatCharProperty *m_formatCharProperty;
249 FontTable *m_fontTable; // for CharProperty
250 FormatParaProperty *m_formatParaProperty;
251 Word m_leftMargin, m_rightMargin; // for ParaProperty
252
253
254 //
255 // Iterator helpers
256 //
257 int m_formatPointerUpto; // [import] which formatPointer we are up to
258 DWord m_nextCharByte; // [import] for consistency checking
259 int m_lastPropertyOffset; // [import] lazy optimisation (don't reload Property if FormatPointer points to last Property)
260 int m_formatPointerPos, m_formatPropertyPos; // [export]
261 int m_numProperty; // [export]
262
263
264 friend class FormatInfo; // libmswrite.h
265 bool readFromDevice (void);
266 bool writeToDevice (void);
267 bool writeToArray (void);
268
269 // TODO operator=
270 FormatInfoPage &operator= (const FormatInfoPage &rhs);
271
272 public:
273 FormatInfoPage ();
274 virtual ~FormatInfoPage ();
275
276 void setMargins (const Word leftMargin, const Word rightMargin)
277 {
278 m_leftMargin = leftMargin, m_rightMargin = rightMargin;
279 }
280 void setFontTable (FontTable *fontTable)
281 {
282 m_fontTable = fontTable;
283 }
284
285 void setType (const enum FormatInfoPageTypes t) { m_type = t; }
286
287 DWord getFirstCharByte (void) const { return m_firstCharByte; }
288 void setFirstCharByte (const DWord val) { m_firstCharByte = val; }
289
290 DWord getNextCharByte (void) const { return m_nextCharByte; }
291
292 // my version of iterators is a lot simpler now, isn't it? :)
293 void *begin (void);
294 void *next (void);
295 bool end (void) const;
296
297 bool add (const void *property);
298 };
299
300
301 class BMP_BitmapFileHeader : public BMP_BitmapFileHeaderGenerated
302 {
303 public:
304 BMP_BitmapFileHeader ();
305 virtual ~BMP_BitmapFileHeader ();
306
307 BMP_BitmapFileHeader &operator= (const BMP_BitmapFileHeader &rhs);
308
309 bool readFromDevice (void);
310 bool writeToDevice (void);
311 };
312
313
314 class BMP_BitmapInfoHeader : public BMP_BitmapInfoHeaderGenerated
315 {
316 public:
317 BMP_BitmapInfoHeader ();
318 virtual ~BMP_BitmapInfoHeader ();
319
320 BMP_BitmapInfoHeader &operator= (const BMP_BitmapInfoHeader &rhs);
321
322 bool readFromDevice (void);
323 bool writeToDevice (void);
324 };
325
326
327 class BMP_BitmapColourIndex : public BMP_BitmapColourIndexGenerated
328 {
329 public:
330 BMP_BitmapColourIndex ();
331 virtual ~BMP_BitmapColourIndex ();
332
333 BMP_BitmapColourIndex &operator= (const BMP_BitmapColourIndex &rhs);
334 };
335
336
337 class BitmapHeader : public BitmapHeaderGenerated
338 {
339 //private:
340 // friend class ImageGenerated;
341 public:
342 BitmapHeader ();
343 virtual ~BitmapHeader ();
344
345 BitmapHeader &operator= (const BitmapHeader &rhs);
346
347 bool readFromDevice (void);
348 bool writeToDevice (void);
349 };
350
351
352 class WMFHeader : public WMFHeaderGenerated
353 {
354 //private:
355 // friend class Image;
356 public:
357 WMFHeader ();
358 virtual ~WMFHeader ();
359
360 WMFHeader &operator= (const WMFHeader &rhs);
361
362 bool readFromDevice (void);
363 bool writeToDevice (void);
364 };
365
366} // namespace MSWrite {
367
368#endif // __STRUCTURES_PRIVATE_H__
369
370// end of structures_private.h