filters

structures_generated.cpp
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/*
23 * structures_generated - Internal MS Write file structures
24 * This file was generated by make_structures_generated 0.51pre 2003/07/09.
25 * ALL CHANGES MADE TO THIS FILE "WILL BE LOST IN TIME LIKE TEARS IN RAIN"!
26 */
27
28#include <assert.h>
29#include <stdio.h>
30#include <string.h>
31
32#include "structures_generated.h"
33#include "structures_private.h" // for forward references to embedded structures
34#include "structures.h" // for forward references to embedded structures
35
36namespace MSWrite
37{
38 // -------------------- BEGIN HeaderGenerated --------------------
39
40 HeaderGenerated::HeaderGenerated ()
41 {
42 // --- set defaults for variables --
43 m_magic = (Word) (0xBE31/*Write 3.0*/);
44 m_zero = (Word) (0);
45 m_magic2 = (Word) (0xAB00);
46 memset (m_zero2, (Word) (0), 4 * sizeof (Word));
47 // no default for m_numCharBytesPlus128
48 // no default for m_pageParaInfo
49 // no default for m_pageFootnoteTable
50 // no default for m_pageSectionProperty
51 // no default for m_pageSectionTable
52 // no default for m_pagePageTable
53 // no default for m_pageFontTable
54 memset (m_zero3, (Word) (0), 33 * sizeof (Word));
55 // no default for m_numPages
56 }
57
58 HeaderGenerated::~HeaderGenerated ()
59 {
60 }
61
62 HeaderGenerated &HeaderGenerated::operator= (const HeaderGenerated &rhs)
63 {
64 if (this == &rhs)
65 return *this;
66
67 NeedsDevice::operator= (rhs);
68 memcpy (m_data, rhs.m_data, s_size);
69
70 m_magic = rhs.m_magic;
71 m_zero = rhs.m_zero;
72 m_magic2 = rhs.m_magic2;
73 memcpy (m_zero2, rhs.m_zero2, 4 * sizeof (Word));
74 m_numCharBytesPlus128 = rhs.m_numCharBytesPlus128;
75 m_pageParaInfo = rhs.m_pageParaInfo;
76 m_pageFootnoteTable = rhs.m_pageFootnoteTable;
77 m_pageSectionProperty = rhs.m_pageSectionProperty;
78 m_pageSectionTable = rhs.m_pageSectionTable;
79 m_pagePageTable = rhs.m_pagePageTable;
80 m_pageFontTable = rhs.m_pageFontTable;
81 memcpy (m_zero3, rhs.m_zero3, 33 * sizeof (Word));
82 m_numPages = rhs.m_numPages;
83
84 return *this;
85 }
86
87 bool HeaderGenerated::verifyVariables (void)
88 {
89 CHECK_DEVICE;
90
91 if (!Verify (Error::InvalidFormat, m_magic == 0xBE31 || m_magic == 0xBE32, DWord (m_magic))) return false;
92 if (!Verify (Error::InvalidFormat, m_zero == 0, DWord (m_zero))) return false;
93 if (!Verify (Error::InvalidFormat, m_magic2 == 0xAB00, DWord (m_magic2))) return false;
94 for (int i = 0; i < 4; i++)
95 {
96 if (!Verify (Error::InvalidFormat, m_zero2 [i] == 0, long (m_zero2))) return false;
97 }
98 if (!Verify (Error::InvalidFormat, m_numCharBytesPlus128 >= 128, DWord (m_numCharBytesPlus128))) return false;
99 // m_pageParaInfo will not be checked
100 // m_pageFootnoteTable will not be checked
101 // m_pageSectionProperty will not be checked
102 // m_pageSectionTable will not be checked
103 // m_pagePageTable will not be checked
104 // m_pageFontTable will not be checked
105 for (int i = 0; i < 33; i++)
106 {
107 if (!Verify (Error::Warn, m_zero3 [i] == 0, long (m_zero3))) return false;
108 }
109 if (!Verify (Error::InvalidFormat, m_numPages > 0, DWord (m_numPages))) return false;
110 return true;
111 }
112
113 bool HeaderGenerated::readFromDevice (void)
114 {
115 CHECK_DEVICE;
116
117 // read the data straight from the file
118 if (!m_device->readInternal (m_data, s_size))
119 ErrorAndQuit (Error::FileError, "could not read HeaderGenerated data");
120
121 ReadWord (m_magic, m_data + 0);
122 ReadWord (m_zero, m_data + 2);
123 ReadWord (m_magic2, m_data + 4);
124 for (int i = 0; i < 4; i++)
125 {
126 ReadWord (m_zero2 [i], m_data + 6 + i * sizeof (Word));
127 }
128
129 ReadDWord (m_numCharBytesPlus128, m_data + 14);
130 ReadWord (m_pageParaInfo, m_data + 18);
131 ReadWord (m_pageFootnoteTable, m_data + 20);
132 ReadWord (m_pageSectionProperty, m_data + 22);
133 ReadWord (m_pageSectionTable, m_data + 24);
134 ReadWord (m_pagePageTable, m_data + 26);
135 ReadWord (m_pageFontTable, m_data + 28);
136 for (int i = 0; i < 33; i++)
137 {
138 ReadWord (m_zero3 [i], m_data + 30 + i * sizeof (Word));
139 }
140
141 ReadWord (m_numPages, m_data + 96);
142 return verifyVariables ();
143 }
144
145 bool HeaderGenerated::writeToArray (void)
146 {
147 CHECK_DEVICE;
148
149 WriteWord (m_magic, m_data + 0);
150 WriteWord (m_zero, m_data + 2);
151 WriteWord (m_magic2, m_data + 4);
152 for (int i = 0; i < 4; i++)
153 {
154 WriteWord (m_zero2 [i], m_data + 6 + i * sizeof (Word));
155 }
156
157 WriteDWord (m_numCharBytesPlus128, m_data + 14);
158 WriteWord (m_pageParaInfo, m_data + 18);
159 WriteWord (m_pageFootnoteTable, m_data + 20);
160 WriteWord (m_pageSectionProperty, m_data + 22);
161 WriteWord (m_pageSectionTable, m_data + 24);
162 WriteWord (m_pagePageTable, m_data + 26);
163 WriteWord (m_pageFontTable, m_data + 28);
164 for (int i = 0; i < 33; i++)
165 {
166 WriteWord (m_zero3 [i], m_data + 30 + i * sizeof (Word));
167 }
168
169 WriteWord (m_numPages, m_data + 96);
170 return true;
171 }
172
173 bool HeaderGenerated::writeToDevice (void)
174 {
175 CHECK_DEVICE;
176
177 // ensure that the variables are in range
178 if (!verifyVariables ()) return false;
179
180 // write the variables to the array
181 if (!writeToArray ()) return false;
182
183 // write the data straight to the file
184 if (!m_device->writeInternal (m_data, s_size))
185 ErrorAndQuit (Error::FileError, "could not write HeaderGenerated data");
186
187 return true;
188 }
189
190
191 // -------------------- BEGIN PageLayoutGenerated --------------------
192
193 PageLayoutGenerated::PageLayoutGenerated ()
194 {
195 // --- set defaults for variables --
196 m_magic102 = (Byte) (102);
197 m_magic512 = (Word) (512);
198 m_pageHeight = (Word) (Inch2Twip (11));
199 m_pageWidth = (Word) (Inch2Twip (8.5));
200 m_pageNumberStart = (Word) (1);
201 m_topMargin = (Word) (Inch2Twip (1));
202 m_textHeight = (Word) (Inch2Twip (9));
203 m_leftMargin = (Word) (Inch2Twip (1.25));
204 m_textWidth = (Word) (Inch2Twip (6));
205 m_magic256 = (Word) (256);
206 m_headerFromTop = (Word) (Inch2Twip (0.75));
207 m_footerFromTop = (Word) (Inch2Twip (11.0/*m_pageHeight*/ - 0.75));
208 m_magic720 = (Word) (720);
209 m_zero = (Word) (0);
210 m_magic1080 = (Word) (1080);
211 m_unknown = (Word) (0);
212 m_zero2 = (Word) (0);
213 }
214
215 PageLayoutGenerated::~PageLayoutGenerated ()
216 {
217 }
218
219 PageLayoutGenerated &PageLayoutGenerated::operator= (const PageLayoutGenerated &rhs)
220 {
221 if (this == &rhs)
222 return *this;
223
224 NeedsDevice::operator= (rhs);
225 memcpy (m_data, rhs.m_data, s_size);
226
227 m_magic102 = rhs.m_magic102;
228 m_magic512 = rhs.m_magic512;
229 m_pageHeight = rhs.m_pageHeight;
230 m_pageWidth = rhs.m_pageWidth;
231 m_pageNumberStart = rhs.m_pageNumberStart;
232 m_topMargin = rhs.m_topMargin;
233 m_textHeight = rhs.m_textHeight;
234 m_leftMargin = rhs.m_leftMargin;
235 m_textWidth = rhs.m_textWidth;
236 m_magic256 = rhs.m_magic256;
237 m_headerFromTop = rhs.m_headerFromTop;
238 m_footerFromTop = rhs.m_footerFromTop;
239 m_magic720 = rhs.m_magic720;
240 m_zero = rhs.m_zero;
241 m_magic1080 = rhs.m_magic1080;
242 m_unknown = rhs.m_unknown;
243 m_zero2 = rhs.m_zero2;
244
245 return *this;
246 }
247
248 bool PageLayoutGenerated::verifyVariables (void)
249 {
250 CHECK_DEVICE;
251
252 if (!Verify (Error::Warn, m_magic102 == 102, DWord (m_magic102))) return false;
253 if (!Verify (Error::Warn, m_magic512 == 512, DWord (m_magic512))) return false;
254 // m_pageHeight will not be checked
255 // m_pageWidth will not be checked
256 // m_pageNumberStart will not be checked
257 // m_topMargin will not be checked
258 // m_textHeight will not be checked
259 // m_leftMargin will not be checked
260 // m_textWidth will not be checked
261 if (!Verify (Error::Warn, m_magic256 == 256, DWord (m_magic256))) return false;
262 // m_headerFromTop will not be checked
263 // m_footerFromTop will not be checked
264 if (!Verify (Error::Warn, m_magic720 == 720, DWord (m_magic720))) return false;
265 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
266 if (!Verify (Error::Warn, m_magic1080 == 1080, DWord (m_magic1080))) return false;
267 // m_unknown will not be checked
268 if (!Verify (Error::Warn, m_zero2 == 0, DWord (m_zero2))) return false;
269 return true;
270 }
271
272 bool PageLayoutGenerated::readFromDevice (void)
273 {
274 CHECK_DEVICE;
275
276 // read the data straight from the file
277 if (!m_device->readInternal (m_data, s_size))
278 ErrorAndQuit (Error::FileError, "could not read PageLayoutGenerated data");
279
280 ReadByte (m_magic102, m_data + 0);
281 ReadWord (m_magic512, m_data + 1);
282 ReadWord (m_pageHeight, m_data + 3);
283 ReadWord (m_pageWidth, m_data + 5);
284 ReadWord (m_pageNumberStart, m_data + 7);
285 ReadWord (m_topMargin, m_data + 9);
286 ReadWord (m_textHeight, m_data + 11);
287 ReadWord (m_leftMargin, m_data + 13);
288 ReadWord (m_textWidth, m_data + 15);
289 ReadWord (m_magic256, m_data + 17);
290 ReadWord (m_headerFromTop, m_data + 19);
291 ReadWord (m_footerFromTop, m_data + 21);
292 ReadWord (m_magic720, m_data + 23);
293 ReadWord (m_zero, m_data + 25);
294 ReadWord (m_magic1080, m_data + 27);
295 ReadWord (m_unknown, m_data + 29);
296 ReadWord (m_zero2, m_data + 31);
297 return verifyVariables ();
298 }
299
300 bool PageLayoutGenerated::writeToArray (void)
301 {
302 CHECK_DEVICE;
303
304 WriteByte (m_magic102, m_data + 0);
305 WriteWord (m_magic512, m_data + 1);
306 WriteWord (m_pageHeight, m_data + 3);
307 WriteWord (m_pageWidth, m_data + 5);
308 WriteWord (m_pageNumberStart, m_data + 7);
309 WriteWord (m_topMargin, m_data + 9);
310 WriteWord (m_textHeight, m_data + 11);
311 WriteWord (m_leftMargin, m_data + 13);
312 WriteWord (m_textWidth, m_data + 15);
313 WriteWord (m_magic256, m_data + 17);
314 WriteWord (m_headerFromTop, m_data + 19);
315 WriteWord (m_footerFromTop, m_data + 21);
316 WriteWord (m_magic720, m_data + 23);
317 WriteWord (m_zero, m_data + 25);
318 WriteWord (m_magic1080, m_data + 27);
319 WriteWord (m_unknown, m_data + 29);
320 WriteWord (m_zero2, m_data + 31);
321 return true;
322 }
323
324 bool PageLayoutGenerated::writeToDevice (void)
325 {
326 CHECK_DEVICE;
327
328 // ensure that the variables are in range
329 if (!verifyVariables ()) return false;
330
331 // write the variables to the array
332 if (!writeToArray ()) return false;
333
334 // write the data straight to the file
335 if (!m_device->writeInternal (m_data, s_size))
336 ErrorAndQuit (Error::FileError, "could not write PageLayoutGenerated data");
337
338 return true;
339 }
340
341
342 // -------------------- BEGIN SectionDescriptorGenerated --------------------
343
344 SectionDescriptorGenerated::SectionDescriptorGenerated ()
345 {
346 // --- set defaults for variables --
347 // no default for m_afterEndCharByte
348 m_undefined = (Word) (0);
349 // no default for m_sectionPropertyLocation
350 }
351
352 SectionDescriptorGenerated::~SectionDescriptorGenerated ()
353 {
354 }
355
356 SectionDescriptorGenerated &SectionDescriptorGenerated::operator= (const SectionDescriptorGenerated &rhs)
357 {
358 if (this == &rhs)
359 return *this;
360
361 NeedsDevice::operator= (rhs);
362 memcpy (m_data, rhs.m_data, s_size);
363
364 m_afterEndCharByte = rhs.m_afterEndCharByte;
365 m_undefined = rhs.m_undefined;
366 m_sectionPropertyLocation = rhs.m_sectionPropertyLocation;
367
368 return *this;
369 }
370
371 bool SectionDescriptorGenerated::verifyVariables (void)
372 {
373 CHECK_DEVICE;
374
375 // m_afterEndCharByte will not be checked
376 // m_undefined will not be checked
377 // m_sectionPropertyLocation will not be checked
378 return true;
379 }
380
381 bool SectionDescriptorGenerated::readFromDevice (void)
382 {
383 CHECK_DEVICE;
384
385 // read the data straight from the file
386 if (!m_device->readInternal (m_data, s_size))
387 ErrorAndQuit (Error::FileError, "could not read SectionDescriptorGenerated data");
388
389 ReadDWord (m_afterEndCharByte, m_data + 0);
390 ReadWord (m_undefined, m_data + 4);
391 ReadDWord (m_sectionPropertyLocation, m_data + 6);
392 return verifyVariables ();
393 }
394
395 bool SectionDescriptorGenerated::writeToArray (void)
396 {
397 CHECK_DEVICE;
398
399 WriteDWord (m_afterEndCharByte, m_data + 0);
400 WriteWord (m_undefined, m_data + 4);
401 WriteDWord (m_sectionPropertyLocation, m_data + 6);
402 return true;
403 }
404
405 bool SectionDescriptorGenerated::writeToDevice (void)
406 {
407 CHECK_DEVICE;
408
409 // ensure that the variables are in range
410 if (!verifyVariables ()) return false;
411
412 // write the variables to the array
413 if (!writeToArray ()) return false;
414
415 // write the data straight to the file
416 if (!m_device->writeInternal (m_data, s_size))
417 ErrorAndQuit (Error::FileError, "could not write SectionDescriptorGenerated data");
418
419 return true;
420 }
421
422
423 // -------------------- BEGIN SectionTableGenerated --------------------
424
425 SectionTableGenerated::SectionTableGenerated ()
426 {
427 // --- set pointer(s) to NULL (prevent segfault with premature exit) ---
428 for (int i = 0; i < 2; i++)
429 m_sed [i] = NULL;
430
431 // --- allocate memory for embedded structures ---
432 for (int i = 0; i < 2; i++)
433 {
434 m_sed [i] = new SectionDescriptor; // forward ref to structures*.cpp
435 if (!m_sed [i]) return;
436 }
437
438 // --- set defaults for variables --
439 m_numSectionDescriptors = (Word) (2);
440 m_undefined = (Word) (0);
441 // leaving constructor of m_sed to set its own defaults
442 }
443
444 SectionTableGenerated::~SectionTableGenerated ()
445 {
446 for (int i = 0; i < 2; i++)
447 delete m_sed [i];
448 }
449
450 SectionTableGenerated &SectionTableGenerated::operator= (const SectionTableGenerated &rhs)
451 {
452 if (this == &rhs)
453 return *this;
454
455 NeedsDevice::operator= (rhs);
456 memcpy (m_data, rhs.m_data, s_size);
457
458 m_numSectionDescriptors = rhs.m_numSectionDescriptors;
459 m_undefined = rhs.m_undefined;
460 for (int i = 0; i < 2; i++)
461 *m_sed [i] = *(rhs.m_sed [i]);
462
463 return *this;
464 }
465
466 bool SectionTableGenerated::verifyVariables (void)
467 {
468 CHECK_DEVICE;
469
470 // m_numSectionDescriptors will not be checked
471 // m_undefined will not be checked
472 for (int i = 0; i < 2; i++)
473 {
474 if (!m_sed [i]) { ErrorAndQuit (Error::OutOfMemory, "could not allocate memory for sed in constructor"); }
475 }
476 return true;
477 }
478
479 bool SectionTableGenerated::readFromDevice (void)
480 {
481 CHECK_DEVICE;
482
483 // read the data straight from the file
484 if (!m_device->readInternal (m_data, s_size))
485 ErrorAndQuit (Error::FileError, "could not read SectionTableGenerated data");
486
487 ReadWord (m_numSectionDescriptors, m_data + 0);
488 ReadWord (m_undefined, m_data + 2);
489 for (int i = 0; i < 2; i++)
490 {
491 m_device->setCache (m_data + 4 + i * SectionDescriptorGenerated::s_size);
492 m_sed [i]->setDevice (m_device);
493 if (!m_sed [i]->readFromDevice ()) return false;
494 m_device->setCache (NULL);
495 }
496
497 return verifyVariables ();
498 }
499
500 bool SectionTableGenerated::writeToArray (void)
501 {
502 CHECK_DEVICE;
503
504 WriteWord (m_numSectionDescriptors, m_data + 0);
505 WriteWord (m_undefined, m_data + 2);
506 for (int i = 0; i < 2; i++)
507 {
508 m_device->setCache (m_data + 4 + i * SectionDescriptorGenerated::s_size);
509 m_sed [i]->setDevice (m_device);
510 if (!m_sed [i]->writeToDevice ()) return false;
511 m_device->setCache (NULL);
512 }
513
514 return true;
515 }
516
517 bool SectionTableGenerated::writeToDevice (void)
518 {
519 CHECK_DEVICE;
520
521 // ensure that the variables are in range
522 if (!verifyVariables ()) return false;
523
524 // write the variables to the array
525 if (!writeToArray ()) return false;
526
527 // write the data straight to the file
528 if (!m_device->writeInternal (m_data, s_size))
529 ErrorAndQuit (Error::FileError, "could not write SectionTableGenerated data");
530
531 return true;
532 }
533
534
535 // -------------------- BEGIN FontGenerated --------------------
536
537 FontGenerated::FontGenerated ()
538 {
539 // --- set defaults for variables --
540 m_numDataBytes = (Word) (0);
541 m_family = (Byte) (0);
542 }
543
544 FontGenerated::~FontGenerated ()
545 {
546 }
547
548 FontGenerated &FontGenerated::operator= (const FontGenerated &rhs)
549 {
550 if (this == &rhs)
551 return *this;
552
553 NeedsDevice::operator= (rhs);
554 memcpy (m_data, rhs.m_data, s_size);
555
556 m_numDataBytes = rhs.m_numDataBytes;
557 m_family = rhs.m_family;
558
559 return *this;
560 }
561
562 bool FontGenerated::verifyVariables (void)
563 {
564 CHECK_DEVICE;
565
566 // m_numDataBytes will not be checked
567 // m_family will not be checked
568 return true;
569 }
570
571 bool FontGenerated::readFromDevice (void)
572 {
573 CHECK_DEVICE;
574
575 // read the data straight from the file
576 if (!m_device->readInternal (m_data, s_size))
577 ErrorAndQuit (Error::FileError, "could not read FontGenerated data");
578
579 ReadWord (m_numDataBytes, m_data + 0);
580 ReadByte (m_family, m_data + 2);
581 return verifyVariables ();
582 }
583
584 bool FontGenerated::writeToArray (void)
585 {
586 CHECK_DEVICE;
587
588 WriteWord (m_numDataBytes, m_data + 0);
589 WriteByte (m_family, m_data + 2);
590 return true;
591 }
592
593 bool FontGenerated::writeToDevice (void)
594 {
595 CHECK_DEVICE;
596
597 // ensure that the variables are in range
598 if (!verifyVariables ()) return false;
599
600 // write the variables to the array
601 if (!writeToArray ()) return false;
602
603 // write the data straight to the file
604 if (!m_device->writeInternal (m_data, s_size))
605 ErrorAndQuit (Error::FileError, "could not write FontGenerated data");
606
607 return true;
608 }
609
610
611 // -------------------- BEGIN FontTableGenerated --------------------
612
613 FontTableGenerated::FontTableGenerated ()
614 {
615 // --- set defaults for variables --
616 m_numFonts = (Word) (0);
617 }
618
619 FontTableGenerated::~FontTableGenerated ()
620 {
621 }
622
623 FontTableGenerated &FontTableGenerated::operator= (const FontTableGenerated &rhs)
624 {
625 if (this == &rhs)
626 return *this;
627
628 NeedsDevice::operator= (rhs);
629 memcpy (m_data, rhs.m_data, s_size);
630
631 m_numFonts = rhs.m_numFonts;
632
633 return *this;
634 }
635
636 bool FontTableGenerated::verifyVariables (void)
637 {
638 CHECK_DEVICE;
639
640 // m_numFonts will not be checked
641 return true;
642 }
643
644 bool FontTableGenerated::readFromDevice (void)
645 {
646 CHECK_DEVICE;
647
648 // read the data straight from the file
649 if (!m_device->readInternal (m_data, s_size))
650 ErrorAndQuit (Error::FileError, "could not read FontTableGenerated data");
651
652 ReadWord (m_numFonts, m_data + 0);
653 return verifyVariables ();
654 }
655
656 bool FontTableGenerated::writeToArray (void)
657 {
658 CHECK_DEVICE;
659
660 WriteWord (m_numFonts, m_data + 0);
661 return true;
662 }
663
664 bool FontTableGenerated::writeToDevice (void)
665 {
666 CHECK_DEVICE;
667
668 // ensure that the variables are in range
669 if (!verifyVariables ()) return false;
670
671 // write the variables to the array
672 if (!writeToArray ()) return false;
673
674 // write the data straight to the file
675 if (!m_device->writeInternal (m_data, s_size))
676 ErrorAndQuit (Error::FileError, "could not write FontTableGenerated data");
677
678 return true;
679 }
680
681
682 // -------------------- BEGIN PagePointerGenerated --------------------
683
684 PagePointerGenerated::PagePointerGenerated ()
685 {
686 // --- set defaults for variables --
687 // no default for m_pageNumber
688 // no default for m_firstCharByte
689 }
690
691 PagePointerGenerated::~PagePointerGenerated ()
692 {
693 }
694
695 PagePointerGenerated &PagePointerGenerated::operator= (const PagePointerGenerated &rhs)
696 {
697 if (this == &rhs)
698 return *this;
699
700 NeedsDevice::operator= (rhs);
701 memcpy (m_data, rhs.m_data, s_size);
702
703 m_pageNumber = rhs.m_pageNumber;
704 m_firstCharByte = rhs.m_firstCharByte;
705
706 return *this;
707 }
708
709 bool PagePointerGenerated::verifyVariables (void)
710 {
711 CHECK_DEVICE;
712
713 if (!Verify (Error::InvalidFormat, m_pageNumber > 0, DWord (m_pageNumber))) return false;
714 // m_firstCharByte will not be checked
715 return true;
716 }
717
718 bool PagePointerGenerated::readFromDevice (void)
719 {
720 CHECK_DEVICE;
721
722 // read the data straight from the file
723 if (!m_device->readInternal (m_data, s_size))
724 ErrorAndQuit (Error::FileError, "could not read PagePointerGenerated data");
725
726 ReadWord (m_pageNumber, m_data + 0);
727 ReadDWord (m_firstCharByte, m_data + 2);
728 return verifyVariables ();
729 }
730
731 bool PagePointerGenerated::writeToArray (void)
732 {
733 CHECK_DEVICE;
734
735 WriteWord (m_pageNumber, m_data + 0);
736 WriteDWord (m_firstCharByte, m_data + 2);
737 return true;
738 }
739
740 bool PagePointerGenerated::writeToDevice (void)
741 {
742 CHECK_DEVICE;
743
744 // ensure that the variables are in range
745 if (!verifyVariables ()) return false;
746
747 // write the variables to the array
748 if (!writeToArray ()) return false;
749
750 // write the data straight to the file
751 if (!m_device->writeInternal (m_data, s_size))
752 ErrorAndQuit (Error::FileError, "could not write PagePointerGenerated data");
753
754 return true;
755 }
756
757
758 // -------------------- BEGIN PageTableGenerated --------------------
759
760 PageTableGenerated::PageTableGenerated ()
761 {
762 // --- set defaults for variables --
763 m_numPagePointers = (Word) (0);
764 m_zero = (Word) (0);
765 }
766
767 PageTableGenerated::~PageTableGenerated ()
768 {
769 }
770
771 PageTableGenerated &PageTableGenerated::operator= (const PageTableGenerated &rhs)
772 {
773 if (this == &rhs)
774 return *this;
775
776 NeedsDevice::operator= (rhs);
777 memcpy (m_data, rhs.m_data, s_size);
778
779 m_numPagePointers = rhs.m_numPagePointers;
780 m_zero = rhs.m_zero;
781
782 return *this;
783 }
784
785 bool PageTableGenerated::verifyVariables (void)
786 {
787 CHECK_DEVICE;
788
789 // m_numPagePointers will not be checked
790 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
791 return true;
792 }
793
794 bool PageTableGenerated::readFromDevice (void)
795 {
796 CHECK_DEVICE;
797
798 // read the data straight from the file
799 if (!m_device->readInternal (m_data, s_size))
800 ErrorAndQuit (Error::FileError, "could not read PageTableGenerated data");
801
802 ReadWord (m_numPagePointers, m_data + 0);
803 ReadWord (m_zero, m_data + 2);
804 return verifyVariables ();
805 }
806
807 bool PageTableGenerated::writeToArray (void)
808 {
809 CHECK_DEVICE;
810
811 WriteWord (m_numPagePointers, m_data + 0);
812 WriteWord (m_zero, m_data + 2);
813 return true;
814 }
815
816 bool PageTableGenerated::writeToDevice (void)
817 {
818 CHECK_DEVICE;
819
820 // ensure that the variables are in range
821 if (!verifyVariables ()) return false;
822
823 // write the variables to the array
824 if (!writeToArray ()) return false;
825
826 // write the data straight to the file
827 if (!m_device->writeInternal (m_data, s_size))
828 ErrorAndQuit (Error::FileError, "could not write PageTableGenerated data");
829
830 return true;
831 }
832
833
834 // -------------------- BEGIN FormatPointerGenerated --------------------
835
836 FormatPointerGenerated::FormatPointerGenerated ()
837 {
838 // --- set defaults for variables --
839 // no default for m_afterEndCharBytePlus128
840 // no default for m_formatPropertyOffset
841 }
842
843 FormatPointerGenerated::~FormatPointerGenerated ()
844 {
845 }
846
847 FormatPointerGenerated &FormatPointerGenerated::operator= (const FormatPointerGenerated &rhs)
848 {
849 if (this == &rhs)
850 return *this;
851
852 NeedsDevice::operator= (rhs);
853 memcpy (m_data, rhs.m_data, s_size);
854
855 m_afterEndCharBytePlus128 = rhs.m_afterEndCharBytePlus128;
856 m_formatPropertyOffset = rhs.m_formatPropertyOffset;
857
858 return *this;
859 }
860
861 bool FormatPointerGenerated::verifyVariables (void)
862 {
863 CHECK_DEVICE;
864
865 if (!Verify (Error::InvalidFormat, m_afterEndCharBytePlus128 >= 128, DWord (m_afterEndCharBytePlus128))) return false;
866 if (!Verify (Error::InvalidFormat, m_formatPropertyOffset == 0xFFFF || m_formatPropertyOffset < 123 - 1/*numDataBytes of either FormatProperty, can't have 0 byte FormatProperty*/, DWord (m_formatPropertyOffset))) return false;
867 return true;
868 }
869
870 bool FormatPointerGenerated::readFromDevice (void)
871 {
872 CHECK_DEVICE;
873
874 // read the data straight from the file
875 if (!m_device->readInternal (m_data, s_size))
876 ErrorAndQuit (Error::FileError, "could not read FormatPointerGenerated data");
877
878 ReadDWord (m_afterEndCharBytePlus128, m_data + 0);
879 ReadWord (m_formatPropertyOffset, m_data + 4);
880 return verifyVariables ();
881 }
882
883 bool FormatPointerGenerated::writeToArray (void)
884 {
885 CHECK_DEVICE;
886
887 WriteDWord (m_afterEndCharBytePlus128, m_data + 0);
888 WriteWord (m_formatPropertyOffset, m_data + 4);
889 return true;
890 }
891
892 bool FormatPointerGenerated::writeToDevice (void)
893 {
894 CHECK_DEVICE;
895
896 // ensure that the variables are in range
897 if (!verifyVariables ()) return false;
898
899 // write the variables to the array
900 if (!writeToArray ()) return false;
901
902 // write the data straight to the file
903 if (!m_device->writeInternal (m_data, s_size))
904 ErrorAndQuit (Error::FileError, "could not write FormatPointerGenerated data");
905
906 return true;
907 }
908
909
910 // -------------------- BEGIN FormatCharPropertyGenerated --------------------
911
912 FormatCharPropertyGenerated::FormatCharPropertyGenerated ()
913 {
914 // --- set defaults in raw array (needed because it's a useThisMuch structure) ---
915 WriteByte ((Byte) (1), m_data + 1);// unknown
916 m_data [2] = 0; // isBold, isItalic, fontCodeLow
917 WriteByte ((Byte) (24), m_data + 3);// fontSize
918 m_data [4] = 0; // isUnderlined, zero, isPageNumber, zero2, fontCodeHigh, zero3, position
919 m_data [5] = 0;
920 m_data [6] = 0;
921
922 // --- set defaults for variables --
923 m_numDataBytes = (Byte) (0);
924 m_unknown = (Byte) (1);
925 m_isBold = (unsigned) (0);
926 m_isItalic = (unsigned) (0);
927 m_fontCodeLow = (unsigned) (0);
928 m_fontSize = (Byte) (24);
929 m_isUnderlined = (unsigned) (0);
930 m_zero = (unsigned) (0);
931 m_isPageNumber = (unsigned) (0);
932 m_zero2 = (unsigned) (0);
933 m_fontCodeHigh = (unsigned) (0);
934 m_zero3 = (unsigned) (0);
935 m_position = (Byte) (0);
936 }
937
938 FormatCharPropertyGenerated::~FormatCharPropertyGenerated ()
939 {
940 }
941
942 FormatCharPropertyGenerated &FormatCharPropertyGenerated::operator= (const FormatCharPropertyGenerated &rhs)
943 {
944 if (this == &rhs)
945 return *this;
946
947 NeedsDevice::operator= (rhs);
948 UseThisMuch::operator= (rhs);
949 memcpy (m_data, rhs.m_data, s_size);
950
951 m_numDataBytes = rhs.m_numDataBytes;
952 m_unknown = rhs.m_unknown;
953 m_isBold = rhs.m_isBold;
954 m_isItalic = rhs.m_isItalic;
955 m_fontCodeLow = rhs.m_fontCodeLow;
956 m_fontSize = rhs.m_fontSize;
957 m_isUnderlined = rhs.m_isUnderlined;
958 m_zero = rhs.m_zero;
959 m_isPageNumber = rhs.m_isPageNumber;
960 m_zero2 = rhs.m_zero2;
961 m_fontCodeHigh = rhs.m_fontCodeHigh;
962 m_zero3 = rhs.m_zero3;
963 m_position = rhs.m_position;
964
965 return *this;
966 }
967
968 bool FormatCharPropertyGenerated::verifyVariables (void)
969 {
970 CHECK_DEVICE;
971
972 if (!Verify (Error::InvalidFormat, m_numDataBytes >= 1 && m_numDataBytes <= s_size - sizeof (Byte), DWord (m_numDataBytes))) return false;
973 if (!Verify (Error::Warn, m_unknown <= 1, DWord (m_unknown))) return false;
974 // m_isBold will not be checked
975 // m_isItalic will not be checked
976 // m_fontCodeLow will not be checked
977 // m_fontSize will not be checked
978 // m_isUnderlined will not be checked
979 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
980 // m_isPageNumber will not be checked
981 if (!Verify (Error::Warn, m_zero2 == 0, DWord (m_zero2))) return false;
982 // m_fontCodeHigh will not be checked
983 if (!Verify (Error::Warn, m_zero3 == 0, DWord (m_zero3))) return false;
984 // m_position will not be checked
985 return true;
986 }
987
988 bool FormatCharPropertyGenerated::readFromDevice (void)
989 {
990 CHECK_DEVICE;
991
992 // find out how many bytes to read
993 if (!m_device->readInternal (m_data, 1))
994 ErrorAndQuit (Error::FileError, "could not read FormatCharPropertyGenerated numDataBytes");
995 ReadByte (m_numDataBytes, m_data);
996 if (!Verify (Error::InvalidFormat, m_numDataBytes >= 1 && m_numDataBytes <= s_size - sizeof (Byte), DWord (m_numDataBytes))) return false;
997 if (!m_device->readInternal (m_data + 1, m_numDataBytes))
998 ErrorAndQuit (Error::FileError, "could not read FormatCharPropertyGenerated data");
999
1000 ReadByte (m_unknown, m_data + 1);
1001 signalHaveSetData (m_unknown == Byte (1), 0/*offset*/ + 8/*size*/);
1002 ReadBitsFromByte (m_isBold, m_data [2], 0, 1);
1003 signalHaveSetData (m_isBold == bool (0), 8/*offset*/ + 1/*size*/);
1004 ReadBitsFromByte (m_isItalic, m_data [2], 1, 1);
1005 signalHaveSetData (m_isItalic == bool (0), 9/*offset*/ + 1/*size*/);
1006 ReadBitsFromByte (m_fontCodeLow, m_data [2], 2, 6);
1007 signalHaveSetData (m_fontCodeLow == unsigned (0), 10/*offset*/ + 6/*size*/);
1008 ReadByte (m_fontSize, m_data + 3);
1009 signalHaveSetData (m_fontSize == Byte (24), 16/*offset*/ + 8/*size*/);
1010 ReadBitsFromByte (m_isUnderlined, m_data [4], 0, 1);
1011 signalHaveSetData (m_isUnderlined == bool (0), 24/*offset*/ + 1/*size*/);
1012 ReadBitsFromByte (m_zero, m_data [4], 1, 5);
1013 signalHaveSetData (m_zero == unsigned (0), 25/*offset*/ + 5/*size*/);
1014 ReadBitsFromByte (m_isPageNumber, m_data [4], 6, 1);
1015 signalHaveSetData (m_isPageNumber == bool (0), 30/*offset*/ + 1/*size*/);
1016 ReadBitsFromByte (m_zero2, m_data [4], 7, 1);
1017 signalHaveSetData (m_zero2 == bool (0), 31/*offset*/ + 1/*size*/);
1018 ReadBitsFromByte (m_fontCodeHigh, m_data [5], 0, 3);
1019 signalHaveSetData (m_fontCodeHigh == unsigned (0), 32/*offset*/ + 3/*size*/);
1020 ReadBitsFromByte (m_zero3, m_data [5], 3, 5);
1021 signalHaveSetData (m_zero3 == unsigned (0), 35/*offset*/ + 5/*size*/);
1022 ReadByte (m_position, m_data + 6);
1023 signalHaveSetData (m_position == Byte (0), 40/*offset*/ + 8/*size*/);
1024 return verifyVariables ();
1025 }
1026
1027 bool FormatCharPropertyGenerated::writeToArray (void)
1028 {
1029 CHECK_DEVICE;
1030
1031 // set m_data to 0 to avoid problems with bit ops
1032 memset (m_data, 0, s_size);
1033
1034 WriteByte (m_numDataBytes, m_data + 0);
1035 WriteByte (m_unknown, m_data + 1);
1036 WriteBitsToByte (m_isBold, m_data [2], 0, 1);
1037 WriteBitsToByte (m_isItalic, m_data [2], 1, 1);
1038 WriteBitsToByte (m_fontCodeLow, m_data [2], 2, 6);
1039 WriteByte (m_fontSize, m_data + 3);
1040 WriteBitsToByte (m_isUnderlined, m_data [4], 0, 1);
1041 WriteBitsToByte (m_zero, m_data [4], 1, 5);
1042 WriteBitsToByte (m_isPageNumber, m_data [4], 6, 1);
1043 WriteBitsToByte (m_zero2, m_data [4], 7, 1);
1044 WriteBitsToByte (m_fontCodeHigh, m_data [5], 0, 3);
1045 WriteBitsToByte (m_zero3, m_data [5], 3, 5);
1046 WriteByte (m_position, m_data + 6);
1047 return true;
1048 }
1049
1050 bool FormatCharPropertyGenerated::writeToDevice (void)
1051 {
1052 CHECK_DEVICE;
1053
1054 // sync m_numDataBytes with reality
1055 updateNumDataBytes ();
1056
1057 // ensure that the variables are in range
1058 if (!verifyVariables ()) return false;
1059
1060 // write the variables to the array
1061 if (!writeToArray ()) return false;
1062
1063 // write the data straight to the file
1064 if (!m_device->writeInternal (m_data, 1 /*sizeof (m_numDataBytes)*/ + (m_numDataBytes ? m_numDataBytes : getNeedNumDataBytes ())))
1065 ErrorAndQuit (Error::FileError, "could not write FormatCharPropertyGenerated data");
1066
1067 return true;
1068 }
1069
1070
1071 // -------------------- BEGIN FormatParaPropertyTabulatorGenerated --------------------
1072
1073 FormatParaPropertyTabulatorGenerated::FormatParaPropertyTabulatorGenerated ()
1074 {
1075 // --- set defaults for variables --
1076 m_indent = (Word) (0);
1077 m_type = (Byte) (0);
1078 m_zero = (Byte) (0);
1079 }
1080
1081 FormatParaPropertyTabulatorGenerated::~FormatParaPropertyTabulatorGenerated ()
1082 {
1083 }
1084
1085 FormatParaPropertyTabulatorGenerated &FormatParaPropertyTabulatorGenerated::operator= (const FormatParaPropertyTabulatorGenerated &rhs)
1086 {
1087 if (this == &rhs)
1088 return *this;
1089
1090 NeedsDevice::operator= (rhs);
1091 memcpy (m_data, rhs.m_data, s_size);
1092
1093 m_indent = rhs.m_indent;
1094 m_type = rhs.m_type;
1095 m_zero = rhs.m_zero;
1096
1097 return *this;
1098 }
1099
1100 bool FormatParaPropertyTabulatorGenerated::verifyVariables (void)
1101 {
1102 CHECK_DEVICE;
1103
1104 // m_indent will not be checked
1105 if (!Verify (Error::InvalidFormat, m_type == 0 || m_type == 3, DWord (m_type))) return false;
1106 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
1107 return true;
1108 }
1109
1110 bool FormatParaPropertyTabulatorGenerated::readFromDevice (void)
1111 {
1112 CHECK_DEVICE;
1113
1114 // read the data straight from the file
1115 if (!m_device->readInternal (m_data, s_size))
1116 ErrorAndQuit (Error::FileError, "could not read FormatParaPropertyTabulatorGenerated data");
1117
1118 ReadWord (m_indent, m_data + 0);
1119 ReadByte (m_type, m_data + 2);
1120 ReadByte (m_zero, m_data + 3);
1121 return verifyVariables ();
1122 }
1123
1124 bool FormatParaPropertyTabulatorGenerated::writeToArray (void)
1125 {
1126 CHECK_DEVICE;
1127
1128 WriteWord (m_indent, m_data + 0);
1129 WriteByte (m_type, m_data + 2);
1130 WriteByte (m_zero, m_data + 3);
1131 return true;
1132 }
1133
1134 bool FormatParaPropertyTabulatorGenerated::writeToDevice (void)
1135 {
1136 CHECK_DEVICE;
1137
1138 // ensure that the variables are in range
1139 if (!verifyVariables ()) return false;
1140
1141 // write the variables to the array
1142 if (!writeToArray ()) return false;
1143
1144 // write the data straight to the file
1145 if (!m_device->writeInternal (m_data, s_size))
1146 ErrorAndQuit (Error::FileError, "could not write FormatParaPropertyTabulatorGenerated data");
1147
1148 return true;
1149 }
1150
1151
1152 // -------------------- BEGIN FormatParaPropertyGenerated --------------------
1153
1154 FormatParaPropertyGenerated::FormatParaPropertyGenerated ()
1155 {
1156 // --- set pointer(s) to NULL (prevent segfault with premature exit) ---
1157 for (int i = 0; i < 14; i++)
1158 m_tab [i] = NULL;
1159
1160 // --- allocate memory for embedded structures ---
1161 for (int i = 0; i < 14; i++)
1162 {
1163 m_tab [i] = new FormatParaPropertyTabulator; // forward ref to structures*.cpp
1164 if (!m_tab [i]) return;
1165 }
1166
1167 // --- set defaults in raw array (needed because it's a useThisMuch structure) ---
1168 WriteByte ((Byte) (60), m_data + 1);// magic0_60_or_61
1169 m_data [2] = 0; // alignment
1170 WriteWord ((Word) (30), m_data + 3);// magic30
1171 memset (m_data + 5, 0, 6); // rightIndent, leftIndent, leftIndentFirstLine
1172 WriteWord ((Word) (240), m_data + 11);// lineSpacing
1173 memset (m_data + 13, 0, 10); // zero, headerOrFooter, isNotNormalParagraph, isOnFirstPage, isObject, zero2, zero3
1174 memset (m_data + 23, 0, 56); // HACK: default embedded structures is 0
1175
1176 // --- set defaults for variables --
1177 m_numDataBytes = (Byte) (0);
1178 m_magic0_60_or_61 = (Byte) (60);
1179 m_alignment = (Byte) (0);
1180 m_magic30 = (Word) (30);
1181 m_rightIndent = (Word) (0);
1182 m_leftIndent = (Word) (0);
1183 m_leftIndentFirstLine = (Short) (0);
1184 m_lineSpacing = (Word) (240);
1185 for (int i = 0; i < 2; i++)
1186 m_zero [i] = (Word) (0);
1187 m_headerOrFooter = (unsigned) (0);
1188 m_isNotNormalParagraph = (unsigned) (0);
1189 m_isOnFirstPage = (unsigned) (0);
1190 m_isObject = (unsigned) (0);
1191 m_zero2 = (unsigned) (0);
1192 memset (m_zero3, (Byte) (0), 5 * sizeof (Byte));
1193 // leaving constructor of m_tab to set its own defaults
1194 }
1195
1196 FormatParaPropertyGenerated::~FormatParaPropertyGenerated ()
1197 {
1198 for (int i = 0; i < 14; i++)
1199 delete m_tab [i];
1200 }
1201
1202 FormatParaPropertyGenerated &FormatParaPropertyGenerated::operator= (const FormatParaPropertyGenerated &rhs)
1203 {
1204 if (this == &rhs)
1205 return *this;
1206
1207 NeedsDevice::operator= (rhs);
1208 UseThisMuch::operator= (rhs);
1209 memcpy (m_data, rhs.m_data, s_size);
1210
1211 m_numDataBytes = rhs.m_numDataBytes;
1212 m_magic0_60_or_61 = rhs.m_magic0_60_or_61;
1213 m_alignment = rhs.m_alignment;
1214 m_magic30 = rhs.m_magic30;
1215 m_rightIndent = rhs.m_rightIndent;
1216 m_leftIndent = rhs.m_leftIndent;
1217 m_leftIndentFirstLine = rhs.m_leftIndentFirstLine;
1218 m_lineSpacing = rhs.m_lineSpacing;
1219 memcpy (m_zero, rhs.m_zero, 2 * sizeof (Word));
1220 m_headerOrFooter = rhs.m_headerOrFooter;
1221 m_isNotNormalParagraph = rhs.m_isNotNormalParagraph;
1222 m_isOnFirstPage = rhs.m_isOnFirstPage;
1223 m_isObject = rhs.m_isObject;
1224 m_zero2 = rhs.m_zero2;
1225 memcpy (m_zero3, rhs.m_zero3, 5 * sizeof (Byte));
1226 for (int i = 0; i < 14; i++)
1227 *m_tab [i] = *(rhs.m_tab [i]);
1228
1229 return *this;
1230 }
1231
1232 bool FormatParaPropertyGenerated::verifyVariables (void)
1233 {
1234 CHECK_DEVICE;
1235
1236 if (!Verify (Error::InvalidFormat, m_numDataBytes >= 1 && m_numDataBytes <= s_size - sizeof (Byte), DWord (m_numDataBytes))) return false;
1237 if (!Verify (Error::Warn, m_magic0_60_or_61 == 0 || m_magic0_60_or_61 == 60 || m_magic0_60_or_61 == 61, DWord (m_magic0_60_or_61))) return false;
1238 // m_alignment will not be checked
1239 if (!Verify (Error::Warn, m_magic30 == 30, DWord (m_magic30))) return false;
1240 // m_rightIndent will not be checked
1241 // m_leftIndent will not be checked
1242 // m_leftIndentFirstLine will not be checked
1243 // m_lineSpacing will not be checked
1244 for (int i = 0; i < 2; i++)
1245 {
1246 if (!Verify (Error::Warn, m_zero [i] == 0, long (m_zero))) return false;
1247 }
1248 // m_headerOrFooter will not be checked
1249 // m_isNotNormalParagraph will not be checked
1250 // m_isOnFirstPage will not be checked
1251 // m_isObject will not be checked
1252 if (!Verify (Error::Warn, m_zero2 == 0, DWord (m_zero2))) return false;
1253 for (int i = 0; i < 5; i++)
1254 {
1255 if (!Verify (Error::Warn, m_zero3 [i] == 0, long (m_zero3))) return false;
1256 }
1257 for (int i = 0; i < 14; i++)
1258 {
1259 if (!m_tab [i]) { ErrorAndQuit (Error::OutOfMemory, "could not allocate memory for tab in constructor"); }
1260 }
1261 return true;
1262 }
1263
1264 bool FormatParaPropertyGenerated::readFromDevice (void)
1265 {
1266 CHECK_DEVICE;
1267
1268 // find out how many bytes to read
1269 if (!m_device->readInternal (m_data, 1))
1270 ErrorAndQuit (Error::FileError, "could not read FormatParaPropertyGenerated numDataBytes");
1271 ReadByte (m_numDataBytes, m_data);
1272 if (!Verify (Error::InvalidFormat, m_numDataBytes >= 1 && m_numDataBytes <= s_size - sizeof (Byte), DWord (m_numDataBytes))) return false;
1273 if (!m_device->readInternal (m_data + 1, m_numDataBytes))
1274 ErrorAndQuit (Error::FileError, "could not read FormatParaPropertyGenerated data");
1275
1276 ReadByte (m_magic0_60_or_61, m_data + 1);
1277 signalHaveSetData (m_magic0_60_or_61 == Byte (60), 0/*offset*/ + 8/*size*/);
1278 ReadByte (m_alignment, m_data + 2);
1279 signalHaveSetData (m_alignment == Byte (0), 8/*offset*/ + 8/*size*/);
1280 ReadWord (m_magic30, m_data + 3);
1281 signalHaveSetData (m_magic30 == Word (30), 16/*offset*/ + 16/*size*/);
1282 ReadWord (m_rightIndent, m_data + 5);
1283 signalHaveSetData (m_rightIndent == Word (0), 32/*offset*/ + 16/*size*/);
1284 ReadWord (m_leftIndent, m_data + 7);
1285 signalHaveSetData (m_leftIndent == Word (0), 48/*offset*/ + 16/*size*/);
1286 ReadShort (m_leftIndentFirstLine, m_data + 9);
1287 signalHaveSetData (m_leftIndentFirstLine == Short (0), 64/*offset*/ + 16/*size*/);
1288 ReadWord (m_lineSpacing, m_data + 11);
1289 signalHaveSetData (m_lineSpacing == Word (240), 80/*offset*/ + 16/*size*/);
1290 for (int i = 0; i < 2; i++)
1291 {
1292 ReadWord (m_zero [i], m_data + 13 + i * sizeof (Word));
1293 }
1294
1295 ReadBitsFromByte (m_headerOrFooter, m_data [17], 0, 1);
1296 signalHaveSetData (m_headerOrFooter == bool (0), 128/*offset*/ + 1/*size*/);
1297 ReadBitsFromByte (m_isNotNormalParagraph, m_data [17], 1, 2);
1298 signalHaveSetData (m_isNotNormalParagraph == unsigned (0), 129/*offset*/ + 2/*size*/);
1299 ReadBitsFromByte (m_isOnFirstPage, m_data [17], 3, 1);
1300 signalHaveSetData (m_isOnFirstPage == bool (0), 131/*offset*/ + 1/*size*/);
1301 ReadBitsFromByte (m_isObject, m_data [17], 4, 1);
1302 signalHaveSetData (m_isObject == bool (0), 132/*offset*/ + 1/*size*/);
1303 ReadBitsFromByte (m_zero2, m_data [17], 5, 3);
1304 signalHaveSetData (m_zero2 == unsigned (0), 133/*offset*/ + 3/*size*/);
1305 memcpy (m_zero3, m_data + 18, 5 * sizeof (Byte));
1306 for (int i = 0; i < 14; i++)
1307 {
1308 m_device->setCache (m_data + 23 + i * FormatParaPropertyTabulatorGenerated::s_size);
1309 m_tab [i]->setDevice (m_device);
1310 if (!m_tab [i]->readFromDevice ()) return false;
1311 m_device->setCache (NULL);
1312 }
1313
1314 return verifyVariables ();
1315 }
1316
1317 bool FormatParaPropertyGenerated::writeToArray (void)
1318 {
1319 CHECK_DEVICE;
1320
1321 // set m_data to 0 to avoid problems with bit ops
1322 memset (m_data, 0, s_size);
1323
1324 WriteByte (m_numDataBytes, m_data + 0);
1325 WriteByte (m_magic0_60_or_61, m_data + 1);
1326 WriteByte (m_alignment, m_data + 2);
1327 WriteWord (m_magic30, m_data + 3);
1328 WriteWord (m_rightIndent, m_data + 5);
1329 WriteWord (m_leftIndent, m_data + 7);
1330 WriteShort (m_leftIndentFirstLine, m_data + 9);
1331 WriteWord (m_lineSpacing, m_data + 11);
1332 for (int i = 0; i < 2; i++)
1333 {
1334 WriteWord (m_zero [i], m_data + 13 + i * sizeof (Word));
1335 }
1336
1337 WriteBitsToByte (m_headerOrFooter, m_data [17], 0, 1);
1338 WriteBitsToByte (m_isNotNormalParagraph, m_data [17], 1, 2);
1339 WriteBitsToByte (m_isOnFirstPage, m_data [17], 3, 1);
1340 WriteBitsToByte (m_isObject, m_data [17], 4, 1);
1341 WriteBitsToByte (m_zero2, m_data [17], 5, 3);
1342 memcpy (m_data + 18, m_zero3, 5 * sizeof (Byte));
1343 for (int i = 0; i < 14; i++)
1344 {
1345 m_device->setCache (m_data + 23 + i * FormatParaPropertyTabulatorGenerated::s_size);
1346 m_tab [i]->setDevice (m_device);
1347 if (!m_tab [i]->writeToDevice ()) return false;
1348 m_device->setCache (NULL);
1349 }
1350
1351 return true;
1352 }
1353
1354 bool FormatParaPropertyGenerated::writeToDevice (void)
1355 {
1356 CHECK_DEVICE;
1357
1358 // sync m_numDataBytes with reality
1359 updateNumDataBytes ();
1360
1361 // ensure that the variables are in range
1362 if (!verifyVariables ()) return false;
1363
1364 // write the variables to the array
1365 if (!writeToArray ()) return false;
1366
1367 // write the data straight to the file
1368 if (!m_device->writeInternal (m_data, 1 /*sizeof (m_numDataBytes)*/ + (m_numDataBytes ? m_numDataBytes : getNeedNumDataBytes ())))
1369 ErrorAndQuit (Error::FileError, "could not write FormatParaPropertyGenerated data");
1370
1371 return true;
1372 }
1373
1374
1375 // -------------------- BEGIN FormatInfoPageGenerated --------------------
1376
1377 FormatInfoPageGenerated::FormatInfoPageGenerated ()
1378 {
1379 // --- set defaults for variables --
1380 // no default for m_firstCharBytePlus128
1381 memset (m_packedStructs, (Byte) (0), 123 * sizeof (Byte));
1382 m_numFormatPointers = (Byte) (0);
1383 }
1384
1385 FormatInfoPageGenerated::~FormatInfoPageGenerated ()
1386 {
1387 }
1388
1389 FormatInfoPageGenerated &FormatInfoPageGenerated::operator= (const FormatInfoPageGenerated &rhs)
1390 {
1391 if (this == &rhs)
1392 return *this;
1393
1394 NeedsDevice::operator= (rhs);
1395 memcpy (m_data, rhs.m_data, s_size);
1396
1397 m_firstCharBytePlus128 = rhs.m_firstCharBytePlus128;
1398 memcpy (m_packedStructs, rhs.m_packedStructs, 123 * sizeof (Byte));
1399 m_numFormatPointers = rhs.m_numFormatPointers;
1400
1401 return *this;
1402 }
1403
1404 bool FormatInfoPageGenerated::verifyVariables (void)
1405 {
1406 CHECK_DEVICE;
1407
1408 if (!Verify (Error::InvalidFormat, m_firstCharBytePlus128 >= 128, DWord (m_firstCharBytePlus128))) return false;
1409 // m_packedStructs will not be checked
1410 // m_numFormatPointers will not be checked
1411 return true;
1412 }
1413
1414 bool FormatInfoPageGenerated::readFromDevice (void)
1415 {
1416 CHECK_DEVICE;
1417
1418 // read the data straight from the file
1419 if (!m_device->readInternal (m_data, s_size))
1420 ErrorAndQuit (Error::FileError, "could not read FormatInfoPageGenerated data");
1421
1422 ReadDWord (m_firstCharBytePlus128, m_data + 0);
1423 memcpy (m_packedStructs, m_data + 4, 123 * sizeof (Byte));
1424 ReadByte (m_numFormatPointers, m_data + 127);
1425 return verifyVariables ();
1426 }
1427
1428 bool FormatInfoPageGenerated::writeToArray (void)
1429 {
1430 CHECK_DEVICE;
1431
1432 WriteDWord (m_firstCharBytePlus128, m_data + 0);
1433 memcpy (m_data + 4, m_packedStructs, 123 * sizeof (Byte));
1434 WriteByte (m_numFormatPointers, m_data + 127);
1435 return true;
1436 }
1437
1438 bool FormatInfoPageGenerated::writeToDevice (void)
1439 {
1440 CHECK_DEVICE;
1441
1442 // ensure that the variables are in range
1443 if (!verifyVariables ()) return false;
1444
1445 // write the variables to the array
1446 if (!writeToArray ()) return false;
1447
1448 // write the data straight to the file
1449 if (!m_device->writeInternal (m_data, s_size))
1450 ErrorAndQuit (Error::FileError, "could not write FormatInfoPageGenerated data");
1451
1452 return true;
1453 }
1454
1455
1456 // -------------------- BEGIN BMP_BitmapFileHeaderGenerated --------------------
1457
1458 BMP_BitmapFileHeaderGenerated::BMP_BitmapFileHeaderGenerated ()
1459 {
1460 // --- set defaults for variables --
1461 m_magic = (Word) (Word ('B') + (Word ('M') << 8));
1462 // no default for m_totalBytes
1463 for (int i = 0; i < 2; i++)
1464 m_zero [i] = (Word) (0);
1465 // no default for m_actualImageOffset
1466 }
1467
1468 BMP_BitmapFileHeaderGenerated::~BMP_BitmapFileHeaderGenerated ()
1469 {
1470 }
1471
1472 BMP_BitmapFileHeaderGenerated &BMP_BitmapFileHeaderGenerated::operator= (const BMP_BitmapFileHeaderGenerated &rhs)
1473 {
1474 if (this == &rhs)
1475 return *this;
1476
1477 NeedsDevice::operator= (rhs);
1478 memcpy (m_data, rhs.m_data, s_size);
1479
1480 m_magic = rhs.m_magic;
1481 m_totalBytes = rhs.m_totalBytes;
1482 memcpy (m_zero, rhs.m_zero, 2 * sizeof (Word));
1483 m_actualImageOffset = rhs.m_actualImageOffset;
1484
1485 return *this;
1486 }
1487
1488 bool BMP_BitmapFileHeaderGenerated::verifyVariables (void)
1489 {
1490 CHECK_DEVICE;
1491
1492 if (!Verify (Error::InvalidFormat, m_magic == Word ('B') + (Word ('M') << 8), DWord (m_magic))) return false;
1493 // m_totalBytes will not be checked
1494 for (int i = 0; i < 2; i++)
1495 {
1496 if (!Verify (Error::Warn, m_zero [i] == 0, long (m_zero))) return false;
1497 }
1498 // m_actualImageOffset will not be checked
1499 return true;
1500 }
1501
1502 bool BMP_BitmapFileHeaderGenerated::readFromDevice (void)
1503 {
1504 CHECK_DEVICE;
1505
1506 // read the data straight from the file
1507 if (!m_device->readInternal (m_data, s_size))
1508 ErrorAndQuit (Error::FileError, "could not read BMP_BitmapFileHeaderGenerated data");
1509
1510 ReadWord (m_magic, m_data + 0);
1511 ReadDWord (m_totalBytes, m_data + 2);
1512 for (int i = 0; i < 2; i++)
1513 {
1514 ReadWord (m_zero [i], m_data + 6 + i * sizeof (Word));
1515 }
1516
1517 ReadDWord (m_actualImageOffset, m_data + 10);
1518 return verifyVariables ();
1519 }
1520
1521 bool BMP_BitmapFileHeaderGenerated::writeToArray (void)
1522 {
1523 CHECK_DEVICE;
1524
1525 WriteWord (m_magic, m_data + 0);
1526 WriteDWord (m_totalBytes, m_data + 2);
1527 for (int i = 0; i < 2; i++)
1528 {
1529 WriteWord (m_zero [i], m_data + 6 + i * sizeof (Word));
1530 }
1531
1532 WriteDWord (m_actualImageOffset, m_data + 10);
1533 return true;
1534 }
1535
1536 bool BMP_BitmapFileHeaderGenerated::writeToDevice (void)
1537 {
1538 CHECK_DEVICE;
1539
1540 // ensure that the variables are in range
1541 if (!verifyVariables ()) return false;
1542
1543 // write the variables to the array
1544 if (!writeToArray ()) return false;
1545
1546 // write the data straight to the file
1547 if (!m_device->writeInternal (m_data, s_size))
1548 ErrorAndQuit (Error::FileError, "could not write BMP_BitmapFileHeaderGenerated data");
1549
1550 return true;
1551 }
1552
1553
1554 // -------------------- BEGIN BMP_BitmapInfoHeaderGenerated --------------------
1555
1556 BMP_BitmapInfoHeaderGenerated::BMP_BitmapInfoHeaderGenerated ()
1557 {
1558 // --- set defaults for variables --
1559 m_numHeaderBytes = (DWord) (s_size);
1560 // no default for m_width
1561 // no default for m_height
1562 m_numPlanes = (Word) (1);
1563 // no default for m_bitsPerPixel
1564 m_compression = (DWord) (0);
1565 m_sizeImage = (DWord) (0);
1566 m_xPixelsPerMeter = (Long) (0);
1567 m_yPixelsPerMeter = (Long) (0);
1568 m_coloursUsed = (DWord) (0);
1569 // no default for m_coloursImportant
1570 }
1571
1572 BMP_BitmapInfoHeaderGenerated::~BMP_BitmapInfoHeaderGenerated ()
1573 {
1574 }
1575
1576 BMP_BitmapInfoHeaderGenerated &BMP_BitmapInfoHeaderGenerated::operator= (const BMP_BitmapInfoHeaderGenerated &rhs)
1577 {
1578 if (this == &rhs)
1579 return *this;
1580
1581 NeedsDevice::operator= (rhs);
1582 memcpy (m_data, rhs.m_data, s_size);
1583
1584 m_numHeaderBytes = rhs.m_numHeaderBytes;
1585 m_width = rhs.m_width;
1586 m_height = rhs.m_height;
1587 m_numPlanes = rhs.m_numPlanes;
1588 m_bitsPerPixel = rhs.m_bitsPerPixel;
1589 m_compression = rhs.m_compression;
1590 m_sizeImage = rhs.m_sizeImage;
1591 m_xPixelsPerMeter = rhs.m_xPixelsPerMeter;
1592 m_yPixelsPerMeter = rhs.m_yPixelsPerMeter;
1593 m_coloursUsed = rhs.m_coloursUsed;
1594 m_coloursImportant = rhs.m_coloursImportant;
1595
1596 return *this;
1597 }
1598
1599 bool BMP_BitmapInfoHeaderGenerated::verifyVariables (void)
1600 {
1601 CHECK_DEVICE;
1602
1603 if (!Verify (Error::InvalidFormat, m_numHeaderBytes == DWord (s_size), DWord (m_numHeaderBytes))) return false;
1604 // m_width will not be checked
1605 // m_height will not be checked
1606 if (!Verify (Error::InvalidFormat, m_numPlanes == 1, DWord (m_numPlanes))) return false;
1607 if (!Verify (Error::Warn, m_bitsPerPixel == 1 || m_bitsPerPixel == 4 || m_bitsPerPixel == 8 || m_bitsPerPixel == 24, DWord (m_bitsPerPixel))) return false;
1608 // m_compression will not be checked
1609 // m_sizeImage will not be checked
1610 // m_xPixelsPerMeter will not be checked
1611 // m_yPixelsPerMeter will not be checked
1612 // m_coloursUsed will not be checked
1613 // m_coloursImportant will not be checked
1614 return true;
1615 }
1616
1617 bool BMP_BitmapInfoHeaderGenerated::readFromDevice (void)
1618 {
1619 CHECK_DEVICE;
1620
1621 // read the data straight from the file
1622 if (!m_device->readInternal (m_data, s_size))
1623 ErrorAndQuit (Error::FileError, "could not read BMP_BitmapInfoHeaderGenerated data");
1624
1625 ReadDWord (m_numHeaderBytes, m_data + 0);
1626 ReadLong (m_width, m_data + 4);
1627 ReadLong (m_height, m_data + 8);
1628 ReadWord (m_numPlanes, m_data + 12);
1629 ReadWord (m_bitsPerPixel, m_data + 14);
1630 ReadDWord (m_compression, m_data + 16);
1631 ReadDWord (m_sizeImage, m_data + 20);
1632 ReadLong (m_xPixelsPerMeter, m_data + 24);
1633 ReadLong (m_yPixelsPerMeter, m_data + 28);
1634 ReadDWord (m_coloursUsed, m_data + 32);
1635 ReadDWord (m_coloursImportant, m_data + 36);
1636 return verifyVariables ();
1637 }
1638
1639 bool BMP_BitmapInfoHeaderGenerated::writeToArray (void)
1640 {
1641 CHECK_DEVICE;
1642
1643 WriteDWord (m_numHeaderBytes, m_data + 0);
1644 WriteLong (m_width, m_data + 4);
1645 WriteLong (m_height, m_data + 8);
1646 WriteWord (m_numPlanes, m_data + 12);
1647 WriteWord (m_bitsPerPixel, m_data + 14);
1648 WriteDWord (m_compression, m_data + 16);
1649 WriteDWord (m_sizeImage, m_data + 20);
1650 WriteLong (m_xPixelsPerMeter, m_data + 24);
1651 WriteLong (m_yPixelsPerMeter, m_data + 28);
1652 WriteDWord (m_coloursUsed, m_data + 32);
1653 WriteDWord (m_coloursImportant, m_data + 36);
1654 return true;
1655 }
1656
1657 bool BMP_BitmapInfoHeaderGenerated::writeToDevice (void)
1658 {
1659 CHECK_DEVICE;
1660
1661 // ensure that the variables are in range
1662 if (!verifyVariables ()) return false;
1663
1664 // write the variables to the array
1665 if (!writeToArray ()) return false;
1666
1667 // write the data straight to the file
1668 if (!m_device->writeInternal (m_data, s_size))
1669 ErrorAndQuit (Error::FileError, "could not write BMP_BitmapInfoHeaderGenerated data");
1670
1671 return true;
1672 }
1673
1674
1675 // -------------------- BEGIN BMP_BitmapColourIndexGenerated --------------------
1676
1677 BMP_BitmapColourIndexGenerated::BMP_BitmapColourIndexGenerated ()
1678 {
1679 // --- set defaults for variables --
1680 // no default for m_blue
1681 // no default for m_green
1682 // no default for m_red
1683 m_reserved = (Byte) (0);
1684 }
1685
1686 BMP_BitmapColourIndexGenerated::~BMP_BitmapColourIndexGenerated ()
1687 {
1688 }
1689
1690 BMP_BitmapColourIndexGenerated &BMP_BitmapColourIndexGenerated::operator= (const BMP_BitmapColourIndexGenerated &rhs)
1691 {
1692 if (this == &rhs)
1693 return *this;
1694
1695 NeedsDevice::operator= (rhs);
1696 memcpy (m_data, rhs.m_data, s_size);
1697
1698 m_blue = rhs.m_blue;
1699 m_green = rhs.m_green;
1700 m_red = rhs.m_red;
1701 m_reserved = rhs.m_reserved;
1702
1703 return *this;
1704 }
1705
1706 bool BMP_BitmapColourIndexGenerated::verifyVariables (void)
1707 {
1708 CHECK_DEVICE;
1709
1710 // m_blue will not be checked
1711 // m_green will not be checked
1712 // m_red will not be checked
1713 // m_reserved will not be checked
1714 return true;
1715 }
1716
1717 bool BMP_BitmapColourIndexGenerated::readFromDevice (void)
1718 {
1719 CHECK_DEVICE;
1720
1721 // read the data straight from the file
1722 if (!m_device->readInternal (m_data, s_size))
1723 ErrorAndQuit (Error::FileError, "could not read BMP_BitmapColourIndexGenerated data");
1724
1725 ReadByte (m_blue, m_data + 0);
1726 ReadByte (m_green, m_data + 1);
1727 ReadByte (m_red, m_data + 2);
1728 ReadByte (m_reserved, m_data + 3);
1729 return verifyVariables ();
1730 }
1731
1732 bool BMP_BitmapColourIndexGenerated::writeToArray (void)
1733 {
1734 CHECK_DEVICE;
1735
1736 WriteByte (m_blue, m_data + 0);
1737 WriteByte (m_green, m_data + 1);
1738 WriteByte (m_red, m_data + 2);
1739 WriteByte (m_reserved, m_data + 3);
1740 return true;
1741 }
1742
1743 bool BMP_BitmapColourIndexGenerated::writeToDevice (void)
1744 {
1745 CHECK_DEVICE;
1746
1747 // ensure that the variables are in range
1748 if (!verifyVariables ()) return false;
1749
1750 // write the variables to the array
1751 if (!writeToArray ()) return false;
1752
1753 // write the data straight to the file
1754 if (!m_device->writeInternal (m_data, s_size))
1755 ErrorAndQuit (Error::FileError, "could not write BMP_BitmapColourIndexGenerated data");
1756
1757 return true;
1758 }
1759
1760
1761 // -------------------- BEGIN BitmapHeaderGenerated --------------------
1762
1763 BitmapHeaderGenerated::BitmapHeaderGenerated ()
1764 {
1765 // --- set defaults for variables --
1766 m_zero = (Word) (0);
1767 m_width = (Word) (0);
1768 m_height = (Word) (0);
1769 m_widthBytes = (Word) (0);
1770 m_numPlanes = (Byte) (0);
1771 m_bitsPerPixel = (Byte) (0);
1772 m_zero2 = (DWord) (0);
1773 }
1774
1775 BitmapHeaderGenerated::~BitmapHeaderGenerated ()
1776 {
1777 }
1778
1779 BitmapHeaderGenerated &BitmapHeaderGenerated::operator= (const BitmapHeaderGenerated &rhs)
1780 {
1781 if (this == &rhs)
1782 return *this;
1783
1784 NeedsDevice::operator= (rhs);
1785 memcpy (m_data, rhs.m_data, s_size);
1786
1787 m_zero = rhs.m_zero;
1788 m_width = rhs.m_width;
1789 m_height = rhs.m_height;
1790 m_widthBytes = rhs.m_widthBytes;
1791 m_numPlanes = rhs.m_numPlanes;
1792 m_bitsPerPixel = rhs.m_bitsPerPixel;
1793 m_zero2 = rhs.m_zero2;
1794
1795 return *this;
1796 }
1797
1798 bool BitmapHeaderGenerated::verifyVariables (void)
1799 {
1800 CHECK_DEVICE;
1801
1802 if (!Verify (Error::InvalidFormat, m_zero == 0, DWord (m_zero))) return false;
1803 // m_width will not be checked
1804 // m_height will not be checked
1805 // m_widthBytes will not be checked
1806 if (!Verify (Error::InvalidFormat, m_numPlanes == 0 || m_numPlanes == 1, DWord (m_numPlanes))) return false;
1807 // m_bitsPerPixel will not be checked
1808 if (!Verify (Error::InvalidFormat, m_zero2 == 0, DWord (m_zero2))) return false;
1809 return true;
1810 }
1811
1812 bool BitmapHeaderGenerated::readFromDevice (void)
1813 {
1814 CHECK_DEVICE;
1815
1816 // read the data straight from the file
1817 if (!m_device->readInternal (m_data, s_size))
1818 ErrorAndQuit (Error::FileError, "could not read BitmapHeaderGenerated data");
1819
1820 ReadWord (m_zero, m_data + 0);
1821 ReadWord (m_width, m_data + 2);
1822 ReadWord (m_height, m_data + 4);
1823 ReadWord (m_widthBytes, m_data + 6);
1824 ReadByte (m_numPlanes, m_data + 8);
1825 ReadByte (m_bitsPerPixel, m_data + 9);
1826 ReadDWord (m_zero2, m_data + 10);
1827 return verifyVariables ();
1828 }
1829
1830 bool BitmapHeaderGenerated::writeToArray (void)
1831 {
1832 CHECK_DEVICE;
1833
1834 WriteWord (m_zero, m_data + 0);
1835 WriteWord (m_width, m_data + 2);
1836 WriteWord (m_height, m_data + 4);
1837 WriteWord (m_widthBytes, m_data + 6);
1838 WriteByte (m_numPlanes, m_data + 8);
1839 WriteByte (m_bitsPerPixel, m_data + 9);
1840 WriteDWord (m_zero2, m_data + 10);
1841 return true;
1842 }
1843
1844 bool BitmapHeaderGenerated::writeToDevice (void)
1845 {
1846 CHECK_DEVICE;
1847
1848 // ensure that the variables are in range
1849 if (!verifyVariables ()) return false;
1850
1851 // write the variables to the array
1852 if (!writeToArray ()) return false;
1853
1854 // write the data straight to the file
1855 if (!m_device->writeInternal (m_data, s_size))
1856 ErrorAndQuit (Error::FileError, "could not write BitmapHeaderGenerated data");
1857
1858 return true;
1859 }
1860
1861
1862 // -------------------- BEGIN WMFHeaderGenerated --------------------
1863
1864 WMFHeaderGenerated::WMFHeaderGenerated ()
1865 {
1866 // --- set defaults for variables --
1867 m_fieldType = (Word) (1);
1868 m_headerSize = (Word) (9);
1869 m_winVersion = (Word) (0x0300);
1870 // no default for m_fileSize
1871 m_numObjects = (Word) (0);
1872 // no default for m_maxRecordSize
1873 m_zero = (Word) (0);
1874 }
1875
1876 WMFHeaderGenerated::~WMFHeaderGenerated ()
1877 {
1878 }
1879
1880 WMFHeaderGenerated &WMFHeaderGenerated::operator= (const WMFHeaderGenerated &rhs)
1881 {
1882 if (this == &rhs)
1883 return *this;
1884
1885 NeedsDevice::operator= (rhs);
1886 memcpy (m_data, rhs.m_data, s_size);
1887
1888 m_fieldType = rhs.m_fieldType;
1889 m_headerSize = rhs.m_headerSize;
1890 m_winVersion = rhs.m_winVersion;
1891 m_fileSize = rhs.m_fileSize;
1892 m_numObjects = rhs.m_numObjects;
1893 m_maxRecordSize = rhs.m_maxRecordSize;
1894 m_zero = rhs.m_zero;
1895
1896 return *this;
1897 }
1898
1899 bool WMFHeaderGenerated::verifyVariables (void)
1900 {
1901 CHECK_DEVICE;
1902
1903 if (!Verify (Error::InvalidFormat, m_fieldType == 1, DWord (m_fieldType))) return false;
1904 if (!Verify (Error::InvalidFormat, m_headerSize == 9, DWord (m_headerSize))) return false;
1905 if (!Verify (Error::Warn, m_winVersion <= 0x0300, DWord (m_winVersion))) return false;
1906 // m_fileSize will not be checked
1907 // m_numObjects will not be checked
1908 // m_maxRecordSize will not be checked
1909 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
1910 return true;
1911 }
1912
1913 bool WMFHeaderGenerated::readFromDevice (void)
1914 {
1915 CHECK_DEVICE;
1916
1917 // read the data straight from the file
1918 if (!m_device->readInternal (m_data, s_size))
1919 ErrorAndQuit (Error::FileError, "could not read WMFHeaderGenerated data");
1920
1921 ReadWord (m_fieldType, m_data + 0);
1922 ReadWord (m_headerSize, m_data + 2);
1923 ReadWord (m_winVersion, m_data + 4);
1924 ReadDWord (m_fileSize, m_data + 6);
1925 ReadWord (m_numObjects, m_data + 10);
1926 ReadDWord (m_maxRecordSize, m_data + 12);
1927 ReadWord (m_zero, m_data + 16);
1928 return verifyVariables ();
1929 }
1930
1931 bool WMFHeaderGenerated::writeToArray (void)
1932 {
1933 CHECK_DEVICE;
1934
1935 WriteWord (m_fieldType, m_data + 0);
1936 WriteWord (m_headerSize, m_data + 2);
1937 WriteWord (m_winVersion, m_data + 4);
1938 WriteDWord (m_fileSize, m_data + 6);
1939 WriteWord (m_numObjects, m_data + 10);
1940 WriteDWord (m_maxRecordSize, m_data + 12);
1941 WriteWord (m_zero, m_data + 16);
1942 return true;
1943 }
1944
1945 bool WMFHeaderGenerated::writeToDevice (void)
1946 {
1947 CHECK_DEVICE;
1948
1949 // ensure that the variables are in range
1950 if (!verifyVariables ()) return false;
1951
1952 // write the variables to the array
1953 if (!writeToArray ()) return false;
1954
1955 // write the data straight to the file
1956 if (!m_device->writeInternal (m_data, s_size))
1957 ErrorAndQuit (Error::FileError, "could not write WMFHeaderGenerated data");
1958
1959 return true;
1960 }
1961
1962
1963 // -------------------- BEGIN ImageGenerated --------------------
1964
1965 ImageGenerated::ImageGenerated ()
1966 {
1967 // --- set pointer(s) to NULL (prevent segfault with premature exit) ---
1968 m_bmh = NULL;
1969
1970 // --- allocate memory for embedded structures ---
1971 m_bmh = new BitmapHeader; // forward ref to structures*.cpp
1972 if (!m_bmh) return;
1973
1974 // --- set defaults for variables --
1975 // no default for m_mappingMode
1976 // no default for m_MFP_width
1977 // no default for m_MFP_height
1978 m_MFP_unknown = (Word) (0);
1979 m_indent = (Word) (0);
1980 // no default for m_width
1981 // no default for m_height
1982 m_zero = (Word) (0);
1983 // leaving constructor of m_bmh to set its own defaults
1984 m_numHeaderBytes = (Word) (s_size);
1985 // no default for m_numDataBytes
1986 m_horizontalScalingRel1000 = (Word) (1000);
1987 m_verticalScalingRel1000 = (Word) (1000);
1988 }
1989
1990 ImageGenerated::~ImageGenerated ()
1991 {
1992 delete m_bmh;
1993 }
1994
1995 ImageGenerated &ImageGenerated::operator= (const ImageGenerated &rhs)
1996 {
1997 if (this == &rhs)
1998 return *this;
1999
2000 NeedsDevice::operator= (rhs);
2001 memcpy (m_data, rhs.m_data, s_size);
2002
2003 m_mappingMode = rhs.m_mappingMode;
2004 m_MFP_width = rhs.m_MFP_width;
2005 m_MFP_height = rhs.m_MFP_height;
2006 m_MFP_unknown = rhs.m_MFP_unknown;
2007 m_indent = rhs.m_indent;
2008 m_width = rhs.m_width;
2009 m_height = rhs.m_height;
2010 m_zero = rhs.m_zero;
2011 *m_bmh = *(rhs.m_bmh);
2012 m_numHeaderBytes = rhs.m_numHeaderBytes;
2013 m_numDataBytes = rhs.m_numDataBytes;
2014 m_horizontalScalingRel1000 = rhs.m_horizontalScalingRel1000;
2015 m_verticalScalingRel1000 = rhs.m_verticalScalingRel1000;
2016
2017 return *this;
2018 }
2019
2020 bool ImageGenerated::verifyVariables (void)
2021 {
2022 CHECK_DEVICE;
2023
2024 if (!Verify (Error::InvalidFormat, m_mappingMode != 0xE4, DWord (m_mappingMode))) return false;
2025 // m_MFP_width will not be checked
2026 // m_MFP_height will not be checked
2027 if (!Verify (Error::Warn, m_MFP_unknown==0, DWord (m_MFP_unknown))) return false;
2028 // m_indent will not be checked
2029 // m_width will not be checked
2030 // m_height will not be checked
2031 // m_zero will not be checked
2032 if (!m_bmh) { ErrorAndQuit (Error::OutOfMemory, "could not allocate memory for bmh in constructor"); }
2033 if (!Verify (Error::InvalidFormat, m_numHeaderBytes == s_size, DWord (m_numHeaderBytes))) return false;
2034 // m_numDataBytes will not be checked
2035 // m_horizontalScalingRel1000 will not be checked
2036 // m_verticalScalingRel1000 will not be checked
2037 return true;
2038 }
2039
2040 bool ImageGenerated::readFromDevice (void)
2041 {
2042 CHECK_DEVICE;
2043
2044 // read the data straight from the file
2045 if (!m_device->readInternal (m_data, s_size))
2046 ErrorAndQuit (Error::FileError, "could not read ImageGenerated data");
2047
2048 ReadWord (m_mappingMode, m_data + 0);
2049 ReadWord (m_MFP_width, m_data + 2);
2050 ReadWord (m_MFP_height, m_data + 4);
2051 ReadWord (m_MFP_unknown, m_data + 6);
2052 ReadWord (m_indent, m_data + 8);
2053 ReadWord (m_width, m_data + 10);
2054 ReadWord (m_height, m_data + 12);
2055 ReadWord (m_zero, m_data + 14);
2056
2057 m_device->setCache (m_data + 16);
2058 m_bmh->setDevice (m_device);
2059 if (!m_bmh->readFromDevice ()) return false;
2060 m_device->setCache (NULL);
2061
2062 ReadWord (m_numHeaderBytes, m_data + 30);
2063 ReadDWord (m_numDataBytes, m_data + 32);
2064 ReadWord (m_horizontalScalingRel1000, m_data + 36);
2065 ReadWord (m_verticalScalingRel1000, m_data + 38);
2066 return verifyVariables ();
2067 }
2068
2069 bool ImageGenerated::writeToArray (void)
2070 {
2071 CHECK_DEVICE;
2072
2073 WriteWord (m_mappingMode, m_data + 0);
2074 WriteWord (m_MFP_width, m_data + 2);
2075 WriteWord (m_MFP_height, m_data + 4);
2076 WriteWord (m_MFP_unknown, m_data + 6);
2077 WriteWord (m_indent, m_data + 8);
2078 WriteWord (m_width, m_data + 10);
2079 WriteWord (m_height, m_data + 12);
2080 WriteWord (m_zero, m_data + 14);
2081
2082 m_device->setCache (m_data + 16);
2083 m_bmh->setDevice (m_device);
2084 if (!m_bmh->writeToDevice ()) return false;
2085 m_device->setCache (NULL);
2086
2087 WriteWord (m_numHeaderBytes, m_data + 30);
2088 WriteDWord (m_numDataBytes, m_data + 32);
2089 WriteWord (m_horizontalScalingRel1000, m_data + 36);
2090 WriteWord (m_verticalScalingRel1000, m_data + 38);
2091 return true;
2092 }
2093
2094 bool ImageGenerated::writeToDevice (void)
2095 {
2096 CHECK_DEVICE;
2097
2098 // ensure that the variables are in range
2099 if (!verifyVariables ()) return false;
2100
2101 // write the variables to the array
2102 if (!writeToArray ()) return false;
2103
2104 // write the data straight to the file
2105 if (!m_device->writeInternal (m_data, s_size))
2106 ErrorAndQuit (Error::FileError, "could not write ImageGenerated data");
2107
2108 return true;
2109 }
2110
2111
2112 // -------------------- BEGIN OLEGenerated --------------------
2113
2114 OLEGenerated::OLEGenerated ()
2115 {
2116 // --- set defaults for variables --
2117 // no default for m_mappingMode
2118 m_zero = (DWord) (0);
2119 // no default for m_objectType
2120 // no default for m_indent
2121 // no default for m_width
2122 // no default for m_height
2123 m_zero2 = (Word) (0);
2124 // no default for m_numDataBytes
2125 m_zero3 = (DWord) (0);
2126 // no default for m_objectName
2127 m_zero4 = (Word) (0);
2128 // no default for m_numHeaderBytes
2129 m_zero5 = (DWord) (0);
2130 // no default for m_widthScaledRel1000
2131 // no default for m_heightScaledRel1000
2132 }
2133
2134 OLEGenerated::~OLEGenerated ()
2135 {
2136 }
2137
2138 OLEGenerated &OLEGenerated::operator= (const OLEGenerated &rhs)
2139 {
2140 if (this == &rhs)
2141 return *this;
2142
2143 NeedsDevice::operator= (rhs);
2144 memcpy (m_data, rhs.m_data, s_size);
2145
2146 m_mappingMode = rhs.m_mappingMode;
2147 m_zero = rhs.m_zero;
2148 m_objectType = rhs.m_objectType;
2149 m_indent = rhs.m_indent;
2150 m_width = rhs.m_width;
2151 m_height = rhs.m_height;
2152 m_zero2 = rhs.m_zero2;
2153 m_numDataBytes = rhs.m_numDataBytes;
2154 m_zero3 = rhs.m_zero3;
2155 m_objectName = rhs.m_objectName;
2156 m_zero4 = rhs.m_zero4;
2157 m_numHeaderBytes = rhs.m_numHeaderBytes;
2158 m_zero5 = rhs.m_zero5;
2159 m_widthScaledRel1000 = rhs.m_widthScaledRel1000;
2160 m_heightScaledRel1000 = rhs.m_heightScaledRel1000;
2161
2162 return *this;
2163 }
2164
2165 bool OLEGenerated::verifyVariables (void)
2166 {
2167 CHECK_DEVICE;
2168
2169 if (!Verify (Error::InvalidFormat, m_mappingMode == 0xE4, DWord (m_mappingMode))) return false;
2170 if (!Verify (Error::Warn, m_zero == 0, DWord (m_zero))) return false;
2171 if (!Verify (Error::InvalidFormat, m_objectType >= 1 && m_objectType <= 3, DWord (m_objectType))) return false;
2172 // m_indent will not be checked
2173 // m_width will not be checked
2174 // m_height will not be checked
2175 if (!Verify (Error::Warn, m_zero2 == 0, DWord (m_zero2))) return false;
2176 // m_numDataBytes will not be checked
2177 if (!Verify (Error::Warn, m_zero3 == 0, DWord (m_zero3))) return false;
2178 // m_objectName will not be checked
2179 if (!Verify (Error::Warn, m_zero4 == 0, DWord (m_zero4))) return false;
2180 if (!Verify (Error::InvalidFormat, m_numHeaderBytes == s_size, DWord (m_numHeaderBytes))) return false;
2181 if (!Verify (Error::Warn, m_zero5 == 0, DWord (m_zero5))) return false;
2182 // m_widthScaledRel1000 will not be checked
2183 // m_heightScaledRel1000 will not be checked
2184 return true;
2185 }
2186
2187 bool OLEGenerated::readFromDevice (void)
2188 {
2189 CHECK_DEVICE;
2190
2191 // read the data straight from the file
2192 if (!m_device->readInternal (m_data, s_size))
2193 ErrorAndQuit (Error::FileError, "could not read OLEGenerated data");
2194
2195 ReadWord (m_mappingMode, m_data + 0);
2196 ReadDWord (m_zero, m_data + 2);
2197 ReadWord (m_objectType, m_data + 6);
2198 ReadWord (m_indent, m_data + 8);
2199 ReadWord (m_width, m_data + 10);
2200 ReadWord (m_height, m_data + 12);
2201 ReadWord (m_zero2, m_data + 14);
2202 ReadDWord (m_numDataBytes, m_data + 16);
2203 ReadDWord (m_zero3, m_data + 20);
2204 ReadDWord (m_objectName, m_data + 24);
2205 ReadWord (m_zero4, m_data + 28);
2206 ReadWord (m_numHeaderBytes, m_data + 30);
2207 ReadDWord (m_zero5, m_data + 32);
2208 ReadWord (m_widthScaledRel1000, m_data + 36);
2209 ReadWord (m_heightScaledRel1000, m_data + 38);
2210 return verifyVariables ();
2211 }
2212
2213 bool OLEGenerated::writeToArray (void)
2214 {
2215 CHECK_DEVICE;
2216
2217 WriteWord (m_mappingMode, m_data + 0);
2218 WriteDWord (m_zero, m_data + 2);
2219 WriteWord (m_objectType, m_data + 6);
2220 WriteWord (m_indent, m_data + 8);
2221 WriteWord (m_width, m_data + 10);
2222 WriteWord (m_height, m_data + 12);
2223 WriteWord (m_zero2, m_data + 14);
2224 WriteDWord (m_numDataBytes, m_data + 16);
2225 WriteDWord (m_zero3, m_data + 20);
2226 WriteDWord (m_objectName, m_data + 24);
2227 WriteWord (m_zero4, m_data + 28);
2228 WriteWord (m_numHeaderBytes, m_data + 30);
2229 WriteDWord (m_zero5, m_data + 32);
2230 WriteWord (m_widthScaledRel1000, m_data + 36);
2231 WriteWord (m_heightScaledRel1000, m_data + 38);
2232 return true;
2233 }
2234
2235 bool OLEGenerated::writeToDevice (void)
2236 {
2237 CHECK_DEVICE;
2238
2239 // ensure that the variables are in range
2240 if (!verifyVariables ()) return false;
2241
2242 // write the variables to the array
2243 if (!writeToArray ()) return false;
2244
2245 // write the data straight to the file
2246 if (!m_device->writeInternal (m_data, s_size))
2247 ErrorAndQuit (Error::FileError, "could not write OLEGenerated data");
2248
2249 return true;
2250 }
2251
2252
2253} // namespace MSWrite {
2254
2255// end of structures_generated.cpp