31#include "structures_private.h"
32#include "structures.h"
44 Header &Header::operator= (
const Header &rhs)
49 HeaderGenerated::operator= (rhs);
51 m_numCharBytes = rhs.m_numCharBytes;
52 m_pageCharInfo = rhs.m_pageCharInfo;
57 bool Header::readFromDevice (
void)
62 m_device->debug (
"\n<<<< Header::readFromDevice >>>>\n");
65 if (!m_device->seekInternal (0, SEEK_SET))
return false;
66 if (!HeaderGenerated::readFromDevice ())
return false;
71 case 0xBE31: m_device->debug (
"normal write file\n");
break;
72 case 0xBE32: m_device->debug (
"write file with OLE\n");
break;
73 default: ErrorAndQuit (Error::InternalError,
"magic test passed but failed later?");
77 m_numCharBytes = m_numCharBytesPlus128 - 128;
80 m_device->debug (
"num bytes of data (text+images+OLE): ", m_numCharBytes);
81 m_device->debug (
"page # start of parainfo: ", m_pageParaInfo);
82 m_device->debug (
"page # footnote table: ", m_pageFootnoteTable);
83 m_device->debug (
"page # pageLayout: ", m_pageSectionProperty);
84 m_device->debug (
"page # sectionTable: ", m_pageSectionTable);
85 m_device->debug (
"page # pageTable: ", m_pagePageTable);
86 m_device->debug (
"page # fontTable: ", m_pageFontTable);
87 m_device->debug (
"num pages in file: ", m_numPages);
95 if (m_pageFootnoteTable != m_pageSectionProperty)
96 ErrorAndQuit (Error::InvalidFormat,
"document should not have a footnoteTable\n");
102 if (m_pageSectionProperty == m_pagePageTable)
105 if (m_pageSectionTable != m_pagePageTable)
106 ErrorAndQuit (Error::InvalidFormat,
"sectionTable without sectionProperty\n");
111 if (m_pageSectionTable != m_pageSectionProperty + 1)
112 ErrorAndQuit (Error::InvalidFormat,
"sectionTable not immediately after sectionProperty\n");
114 if (m_pageSectionTable == m_pagePageTable)
115 ErrorAndQuit (Error::InvalidFormat,
"sectionProperty without sectionTable\n");
119 m_pageCharInfo = (m_numCharBytesPlus128 + 127) / 128;
122 m_device->debug (
"page # start of charinfo: ", m_pageCharInfo);
126 if (m_pageCharInfo > m_pageParaInfo)
127 ErrorAndQuit (Error::InvalidFormat,
"charInfo page after paraInfo page\n");
132 bool Header::writeToDevice (
void)
137 m_device->debug (
"\n<<<< Header::writeToDevice >>>>\n");
140 m_numCharBytesPlus128 = m_numCharBytes + 128;
142 if (!m_device->seekInternal (0, SEEK_SET))
return false;
143 if (!HeaderGenerated::writeToDevice ())
return false;
149 SectionDescriptor::SectionDescriptor ()
153 SectionDescriptor::~SectionDescriptor ()
157 SectionDescriptor &SectionDescriptor::operator= (
const SectionDescriptor &rhs)
162 SectionDescriptorGenerated::operator= (rhs);
168 SectionTable::SectionTable ()
172 SectionTable::~SectionTable ()
176 SectionTable &SectionTable::operator= (
const SectionTable &rhs)
181 SectionTableGenerated::operator= (rhs);
182 NeedsHeader::operator= (rhs);
190 bool SectionTable::readFromDevice (
void)
194 #ifdef DEBUG_PAGELAYOUT
195 m_device->debug (
"\n<<<< SectionTable::readFromDevice >>>>\n");
198 int numSectionTablePages = m_header->getNumPageSectionTable ();
200 #ifdef DEBUG_PAGELAYOUT
201 m_device->debug (
"num sectionTablePages=", numSectionTablePages);
205 if (numSectionTablePages == 0)
207 else if (numSectionTablePages > 1)
208 ErrorAndQuit (Error::InvalidFormat,
"invalid #sectionTablePages\n");
211 if (!m_device->seekInternal (m_header->getPageSectionTable () * 128, SEEK_SET))
214 if (!SectionTableGenerated::readFromDevice ())
return false;
216 #ifdef DEBUG_PAGELAYOUT
217 m_device->debug (
"num sectionDescriptors=", m_numSectionDescriptors);
218 for (
int i = 0; i < 2; i++)
220 m_device->debug (
"Dumping SED #", i);
221 m_device->debug (
"\tbyte after section=", m_sed [i]->getAfterEndCharByte ());
222 m_device->debug (
"\tsectionProperty location=", m_sed [i]->getSectionPropertyLocation ());
226 if (m_numSectionDescriptors != 2)
227 m_device->error (Error::Warn,
"#sectionDescriptors != 2, ignoring");
230 if (m_sed [0]->getAfterEndCharByte () != m_header->getNumCharBytes ())
231 m_device->error (Error::Warn,
"sectionDescriptor #1 does not cover entire document\n");
234 if (m_sed [0]->getSectionPropertyLocation () != m_header->getPageSectionProperty () * DWord (128))
235 m_device->error (Error::Warn,
"sectionDescriptor #1 does not refer to correct sectionProperty, ignoring\n");
238 if (m_sed [1]->getAfterEndCharByte () != m_header->getNumCharBytes () + 1)
239 m_device->error (Error::Warn,
"sectionDescriptor #2 does not cover post-document\n");
242 if (m_sed [1]->getSectionPropertyLocation () != (DWord) 0xFFFFFFFF)
243 m_device->error (Error::Warn,
"sectionDescriptor #2 is not a dummy\n");
248 bool SectionTable::writeToDevice (
const bool needed)
252 #ifdef DEBUG_PAGELAYOUT
253 m_device->debug (
"\n>>>> SectionTable::writeToDevice <<<<\n");
256 m_header->setPageSectionTable (m_device->tellInternal () / 128);
264 m_sed [0]->setAfterEndCharByte (m_header->getNumCharBytes ());
267 m_sed [0]->setSectionPropertyLocation (m_header->getPageSectionProperty () * 128);
270 m_sed [1]->setAfterEndCharByte (m_header->getNumCharBytes () + 1);
273 m_sed [1]->setSectionPropertyLocation ((DWord) 0xFFFFFFFF);
275 if (!SectionTableGenerated::writeToDevice ())
282 FontTable::FontTable ()
286 FontTable::~FontTable ()
290 FontTable &FontTable::operator= (
const FontTable &rhs)
295 FontTableGenerated::operator= (rhs);
296 NeedsHeader::operator= (rhs);
298 m_fontList = rhs.m_fontList;
303 bool FontTable::readFromDevice (
void)
308 m_device->debug (
"\n<<<< FontTable::readFromDevice >>>>\n");
311 int numFontTablePages = m_header->getNumPageFontTable ();
314 if (numFontTablePages == 0)
318 if (!m_device->seekInternal (m_header->getPageFontTable () * 128, SEEK_SET))
321 if (!FontTableGenerated::readFromDevice ())
return false;
324 m_device->debug (
"num Fonts: ", m_numFonts);
327 bool dontAddToBack =
false;
328 for (
int i = 0; i < FontTableGenerated::m_numFonts; i++)
331 m_device->debug (
"Font: ", i);
336 if (!m_fontList.addToBack ())
337 ErrorAndQuit (Error::OutOfMemory,
"could not add Font to fontList\n");
340 dontAddToBack =
false;
342 List <Font>::Iterator it = m_fontList.begin (
false);
346 font.setDevice (m_device);
347 if (!font.readFromDevice ())
350 if (m_device->bad ())
358 if (font.getNumDataBytes () == 0xFFFF)
361 m_device->debug (
"\tcurrent offset=", m_device->tellInternal ());
362 m_device->debug (
"\tnext page offset=", (m_device->tellInternal () + 127) / 128 * 128);
366 if (!m_device->seekInternal ((m_device->tellInternal () + 127) / 128 * 128, SEEK_SET))
369 dontAddToBack =
true;
374 if (font.getNumDataBytes () == 0)
376 if (i != m_numFonts - 1)
377 m_device->error (Error::Warn,
"font marked as last but is not\n");
380 m_fontList.erase (it);
391 bool FontTable::writeToDevice (
void)
396 m_device->debug (
"\n>>>> FontTable::writeToDevice <<<<\n");
400 m_header->setPageFontTable (m_device->tellInternal () / 128);
402 FontTableGenerated::m_numFonts = m_fontList.getNumElements ();
405 if (FontTableGenerated::m_numFonts == 0)
407 m_device->error (Error::Warn,
"not writing fontTable\n");
412 if (!FontTableGenerated::writeToDevice ())
return false;
415 for (List <Font>::Iterator it = m_fontList.begin ();
416 it != m_fontList.end ();
420 m_device->debug (
"\twriting font #", i);
426 font.setDevice (m_device);
427 if (!font.writeToDevice ())
430 if (m_device->bad ())
439 m_device->debug (
"\tcurrent offset=", m_device->tellInternal ());
440 m_device->debug (
"\tnext page offset=", (m_device->tellInternal () + 127) / 128 * 128);
444 if (!m_device->seekInternal ((m_device->tellInternal () + 127) / 128 * 128, SEEK_SET))
459 Font *FontTable::getFont (
const DWord fontCode)
const
462 List <Font>::Iterator it = m_fontList.begin ();
463 for (
int i = 0; i < int (fontCode) && it != m_fontList.end (); i++, ++it)
465 if (it == m_fontList.end ())
return NULL;
469 DWord FontTable::findFont (
const Font *want)
const
473 List <Font>::Iterator it;
474 for (it = m_fontList.begin (); it != m_fontList.end (); ++it)
486 DWord FontTable::addFont (
const Font *input)
491 m_device->debug (
"\t\t\tTrying to add Font ", input->getName ());
494 DWord e = findFont (input);
500 m_device->debug (
"\t\t\t\tAlready in list, fontCode=", e);
510 m_device->debug (
"\t\t\t\tNew font, adding to list\n");
513 if (!m_fontList.addToBack (*input))
514 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for next font element\n");
515 return m_fontList.getNumElements () - 1;
520 PagePointer::PagePointer ()
524 PagePointer::~PagePointer ()
528 PagePointer &PagePointer::operator= (
const PagePointer &rhs)
533 PagePointerGenerated::operator= (rhs);
538 bool PagePointer::readFromDevice (
void)
542 if (!PagePointerGenerated::readFromDevice ())
545 #ifdef DEBUG_PAGETABLE
546 m_device->debug (
"\t\tpage number: ", m_pageNumber);
547 m_device->debug (
"\t\tfirst char: ", m_firstCharByte);
553 bool PagePointer::writeToDevice (
void)
557 if (!PagePointerGenerated::writeToDevice ())
564 PageTable::PageTable () : m_pageNumberStart (0xFFFF)
568 PageTable::~PageTable ()
572 PageTable &PageTable::operator= (
const PageTable &rhs)
577 PageTableGenerated::operator= (rhs);
578 NeedsHeader::operator= (rhs);
580 m_pagePointerList = rhs.m_pagePointerList;
581 m_pageNumberStart = rhs.m_pageNumberStart;
583 m_pageTableIterator = rhs.m_pageTableIterator;
588 bool PageTable::readFromDevice (
void)
592 #ifdef DEBUG_PAGETABLE
593 m_device->debug (
"\n<<<< PageTable::readFromDevice >>>>\n");
596 #ifdef CHECK_INTERNAL
597 if (m_pageNumberStart == (Word) 0xFFFF || NeedsHeader::m_header == NULL)
598 ErrorAndQuit (Error::InternalError,
"PageTable call not setup\n");
602 if (m_header->getNumPagePageTable () == 0)
606 if (!m_device->seekInternal (m_header->getPagePageTable () * 128, SEEK_SET))
609 if (!PageTableGenerated::readFromDevice ())
612 #ifdef DEBUG_PAGETABLE
613 Dump (numPagePointers);
617 DWord lastCharByte = (DWord) 0xFFFFFFFF;
618 Word lastPage = (Word) 0xFFFF;
619 for (
int i = 0; i < m_numPagePointers; i++)
621 if (!m_pagePointerList.addToBack ())
622 ErrorAndQuit (Error::OutOfMemory,
"could not add pagePointer to list\n");
624 PagePointer &pp = *m_pagePointerList.begin (
false);
626 #ifdef DEBUG_PAGETABLE
627 m_device->debug (
"\tPagePointer: ", i);
631 pp.setDevice (m_device);
632 if (!pp.readFromDevice ())
return false;
637 if (pp.getPageNumber () != m_pageNumberStart)
638 ErrorAndQuit (Error::InvalidFormat,
"pageTable & sectionProperty disagree on pageNumberStart\n");
648 if (pp.getPageNumber () != lastPage + 1)
649 m_device->error (Error::Warn,
"pages don't follow each other\n");
651 if (pp.getFirstCharByte () <= lastCharByte)
652 ErrorAndQuit (Error::InvalidFormat,
"pageTable is not going forward?\n");
656 lastPage = pp.getPageNumber ();
657 lastCharByte = pp.getFirstCharByte ();
663 bool PageTable::writeToDevice (
void)
667 #ifdef DEBUG_PAGETABLE
668 m_device->debug (
"\n>>>> PageTable::writeToDevice <<<<\n");
671 m_header->setPagePageTable (m_device->tellInternal () / 128);
674 PageTableGenerated::m_numPagePointers = m_pagePointerList.getNumElements ();
677 if (m_numPagePointers == 0)
681 if (!PageTableGenerated::writeToDevice ())
685 List <PagePointer>::Iterator it;
686 for (it = m_pagePointerList.begin (); it != m_pagePointerList.end (); ++it, i++)
688 PagePointer &pp = (*it);
690 #ifdef DEBUG_PAGETABLE
691 m_device->debug (
"\tPagePointer: ", i);
695 pp.setDevice (m_device);
696 if (!pp.writeToDevice ())
704 FormatPointer::FormatPointer () : m_afterEndCharByte (0)
708 FormatPointer::~FormatPointer ()
712 FormatPointer &FormatPointer::operator= (
const FormatPointer &rhs)
717 FormatPointerGenerated::operator= (rhs);
719 m_afterEndCharByte = rhs.m_afterEndCharByte;
720 m_formatProperty = rhs.m_formatProperty;
725 bool FormatPointer::readFromDevice (
void)
729 if (!FormatPointerGenerated::readFromDevice ())
732 m_afterEndCharByte = m_afterEndCharBytePlus128 - 128;
734 #ifdef DEBUG_FORMATINFO
735 m_device->debug (
"\t\tafterEndCharByte: ", m_afterEndCharByte);
736 m_device->debug (
"\t\tformatPropertyOffset: ", m_formatPropertyOffset);
742 bool FormatPointer::writeToDevice (
void)
746 #ifdef DEBUG_FORMATINFO
747 m_device->debug (
"\t\t\t\tafterEndCharByte: ", m_afterEndCharByte);
748 m_device->debug (
"\t\t\t\tformatPropertyOffset: ", m_formatPropertyOffset);
751 m_afterEndCharBytePlus128 = m_afterEndCharByte + 128;
753 if (!FormatPointerGenerated::writeToDevice ())
760 FormatInfoPage::FormatInfoPage () : m_firstCharByte (0),
761 m_formatPointer (NULL),
762 m_formatCharProperty (NULL),
764 m_formatParaProperty (NULL),
765 m_leftMargin (0xFFFF), m_rightMargin (0xFFFF),
766 m_formatPointerUpto (0),
768 m_formatPointerPos (0), m_formatPropertyPos (123)
775 FormatInfoPage::~FormatInfoPage ()
777 delete [] m_formatParaProperty;
778 delete [] m_formatCharProperty;
779 delete [] m_formatPointer;
783 bool FormatInfoPage::readFromDevice (
void)
787 #ifdef DEBUG_FORMATINFO
788 if (m_type == ParaType)
789 m_device->debug (
"FormatInfoPage::readFromDevice (ParaType)\n");
791 m_device->debug (
"FormatInfoPage::readFromDevice (CharType)\n");
794 if (!FormatInfoPageGenerated::readFromDevice ())
797 m_firstCharByte = FormatInfoPageGenerated::m_firstCharBytePlus128 - 128;
799 #ifdef DEBUG_FORMATINFO
800 m_device->debug (
"number of FormatPointers on this page: ", FormatInfoPageGenerated::m_numFormatPointers);
801 m_device->debug (
"byte number of first character covered by this page: ", m_firstCharByte);
807 bool FormatInfoPage::writeToDevice (
void)
811 #ifdef DEBUG_FORMATINFO
812 if (m_type == ParaType)
813 m_device->debug (
"FormatInfoPage::writeToDevice (ParaType)\n");
815 m_device->debug (
"FormatInfoPage::writeToDevice (CharType)\n");
818 FormatInfoPageGenerated::m_firstCharBytePlus128 = m_firstCharByte + 128;
820 #ifdef DEBUG_FORMATINFO
821 m_device->debug (
"\tnumber of FormatPointers on this page: ", FormatInfoPageGenerated::m_numFormatPointers);
822 m_device->debug (
"\tbyte number of first character covered by this page: ", m_firstCharByte);
828 return FormatInfoPageGenerated::writeToDevice ();
831 bool FormatInfoPage::writeToArray (
void)
835 #ifdef DEBUG_FORMATINFO
836 if (m_type == ParaType)
837 m_device->debug (
"\tFormatInfoPage::writeToArray (ParaType)\n");
839 m_device->debug (
"\tFormatInfoPage::writeToArray (CharType)\n");
844 m_formatPointerPos = 0;
845 m_formatPropertyPos = 123;
847 #ifdef DEBUG_FORMATINFO
848 m_device->debug (
"\t\tWriting FormatPointer[], num=", m_numFormatPointers);
850 for (
int i = 0; i < m_numFormatPointers; i++)
852 #ifdef DEBUG_FORMATINFO
853 m_device->debug (
"\t\t\tOffset=", m_formatPointerPos);
856 memdev.setCache (m_packedStructs + m_formatPointerPos);
857 m_formatPointer [i].setDevice (&memdev);
858 if (!m_formatPointer [i].writeToDevice ())
return false;
859 memdev.setCache (NULL);
860 m_formatPointerPos += FormatPointer::s_size;
863 #ifdef DEBUG_FORMATINFO
864 m_device->debug (
"\t\tWriting FormatProperty[], num=", m_numProperty);
866 for (
int i = 0; i < m_numProperty; i++)
869 if (m_type == ParaType)
871 FormatParaProperty *prop = &m_formatParaProperty [i];
873 m_formatPropertyPos -= (
sizeof (Byte) + prop->getNumDataBytes ());
874 memdev.setCache (m_packedStructs + m_formatPropertyPos);
875 prop->setDevice (&memdev);
876 if (!prop->writeToDevice ())
return false;
877 memdev.setCache (NULL);
881 FormatCharProperty *prop = &m_formatCharProperty [i];
883 m_formatPropertyPos -= (
sizeof (Byte) + prop->getNumDataBytes ());
884 memdev.setCache (m_packedStructs + m_formatPropertyPos);
885 prop->setDevice (&memdev);
886 if (!prop->writeToDevice ())
return false;
887 memdev.setCache (NULL);
889 #ifdef DEBUG_FORMATINFO
890 m_device->debug (
"\t\t\tWrote at Offset=", m_formatPropertyPos);
894 if (!FormatInfoPageGenerated::writeToArray ())
900 void *FormatInfoPage::begin (
void)
904 #ifdef DEBUG_FORMATINFO
905 if (m_type == ParaType)
906 m_device->debug (
"\nFormatInfoPage::begin (ParaType)\n");
908 m_device->debug (
"\nFormatInfoPage::begin (CharType)\n");
911 m_formatPointerUpto = 0;
914 m_lastPropertyOffset = -1;
916 if (!m_formatPointer)
918 m_formatPointer =
new FormatPointer [1];
920 if (!m_formatPointer)
922 m_device->error (Error::OutOfMemory,
"could not allocate memory for FormatPointer\n");
926 m_formatPointer->setDevice (m_device);
929 return this->next ();
932 void *FormatInfoPage::next (
void)
936 #ifdef DEBUG_FORMATINFO
937 if (m_type == ParaType)
938 m_device->debug (
"\tPara FormatPointer #", m_formatPointerUpto);
940 m_device->debug (
"\tChar FormatPointer #", m_formatPointerUpto);
949 if (!m_formatPointer)
951 m_device->error (Error::InternalError,
"formatPointer not initialised - call FormatInfoPage::begin() before next()\n");
956 m_device->setCache (m_packedStructs + m_formatPointerUpto * FormatPointer::s_size);
957 if (!m_formatPointer->readFromDevice ())
return NULL;
958 m_device->setCache (NULL);
959 DWord formatPointerAfterEndCharByte = m_formatPointer->getAfterEndCharByte ();
962 if (formatPointerAfterEndCharByte <= m_nextCharByte)
963 m_device->error (Error::Warn,
"FormatPointer afterEndCharByte does not go forward\n");
964 m_nextCharByte = formatPointerAfterEndCharByte;
967 if (formatPointerAfterEndCharByte >= m_header->getNumCharBytes ())
969 #ifdef DEBUG_FORMATINFO
970 m_device->debug (
"\t\tThis is the last FormatPointer!\n");
974 if (formatPointerAfterEndCharByte > m_header->getNumCharBytes ())
976 m_device->error (Error::Warn,
"FormatPointer ends after EOF, forcing it to end at EOF\n");
977 m_formatPointer->setAfterEndCharByte (m_header->getNumCharBytes ());
978 m_nextCharByte = m_header->getNumCharBytes ();
982 if (m_formatPointerUpto != m_numFormatPointers - 1)
984 m_device->error (Error::Warn,
"FormatPointer ends at EOF but is not the last, forcing it to be the last\n");
985 m_formatPointerUpto = m_numFormatPointers - 1;
993 int currentPropertyOffset = m_formatPointer->getFormatPropertyOffset ();
995 bool up2date = (currentPropertyOffset == m_lastPropertyOffset);
996 if (!up2date) m_device->setCache (m_packedStructs + currentPropertyOffset);
998 if (m_type == CharType)
1003 delete [] m_formatCharProperty;
1004 m_formatCharProperty =
new FormatCharProperty [1];
1006 if (!m_formatCharProperty)
1008 m_device->error (Error::OutOfMemory,
"could not allocate memory for FormatCharProperty\n");
1009 m_device->setCache (NULL);
1013 m_formatCharProperty->setDevice (m_device);
1014 m_formatCharProperty->setFontTable (m_fontTable);
1015 if (!m_formatCharProperty->updateFont ())
1017 m_device->setCache (NULL);
1022 if (currentPropertyOffset != 0xFFFF)
1024 if (!m_formatCharProperty->readFromDevice ())
1026 m_device->setCache (NULL);
1032 assert (m_formatCharProperty);
1033 m_formatCharProperty->setAfterEndCharByte (m_formatPointer->getAfterEndCharByte ());
1034 ret = m_formatCharProperty;
1041 delete [] m_formatParaProperty;
1042 m_formatParaProperty =
new FormatParaProperty [1];
1044 if (!m_formatParaProperty)
1046 m_device->error (Error::OutOfMemory,
"could not allocate memory for FormatParaProperty\n");
1047 m_device->setCache (NULL);
1051 m_formatParaProperty->setDevice (m_device);
1052 m_formatParaProperty->setMargins (m_leftMargin, m_rightMargin);
1055 if (currentPropertyOffset != 0xFFFF)
1057 if (!m_formatParaProperty->readFromDevice ())
1059 m_device->setCache (NULL);
1065 assert (m_formatParaProperty);
1066 m_formatParaProperty->setAfterEndCharByte (m_formatPointer->getAfterEndCharByte ());
1067 ret = m_formatParaProperty;
1070 if (!up2date) m_device->setCache (NULL);
1071 m_lastPropertyOffset = currentPropertyOffset;
1073 m_formatPointerUpto++;
1074 assert (m_formatPointer);
1078 bool FormatInfoPage::end (
void)
const
1080 assert (m_formatPointerUpto <= FormatInfoPageGenerated::m_numFormatPointers);
1081 return m_formatPointerUpto >= FormatInfoPageGenerated::m_numFormatPointers;
1084 bool FormatInfoPage::add (
const void *property)
1091 const int MaxElements = 123 / FormatPointer::s_size;
1093 #ifdef DEBUG_FORMATINFO
1094 if (m_type == ParaType)
1095 m_device->debug (
">>>> FormatInfoPage::add (ParaType) <<<<\n");
1097 m_device->debug (
">>>> FormatInfoPage::add (CharType) <<<<\n");
1099 Dump (formatPointerPos);
1100 Dump (formatPropertyPos);
1108 if (!m_formatPointer)
1110 #ifdef DEBUG_FORMATINFO
1111 m_device->debug (
"\tFIRST CALL! Allocating memory for FormatPointer[] and FormatProperty[]\n");
1115 m_formatPointer =
new FormatPointer [MaxElements + 1];
1116 if (!m_formatPointer)
1117 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for formatPointer[]\n");
1119 FormatInfoPageGenerated::m_numFormatPointers = 0;
1122 if (m_type == ParaType)
1124 assert (!m_formatParaProperty);
1125 m_formatParaProperty =
new FormatParaProperty [MaxElements + 1];
1126 m_formatParaProperty [MaxElements].setDevice (m_device);
1127 if (!m_formatParaProperty)
1128 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for formatParaProperty[]\n");
1132 assert (!m_formatCharProperty);
1133 m_formatCharProperty =
new FormatCharProperty [MaxElements + 1];
1134 m_formatCharProperty [MaxElements].setDevice (m_device);
1135 if (!m_formatCharProperty)
1136 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for formatCharProperty[]\n");
1147 FormatParaProperty inpp;
1148 FormatCharProperty incp;
1150 if (m_type == ParaType)
1152 #ifdef DEBUG_FORMATINFO
1153 m_device->debug (
"\tTrying to add ParaProperty, #numDataBytes=", ((FormatParaProperty *) property)->getNumDataBytes ());
1156 inpp = *((FormatParaProperty *) property);
1157 inpp.setDevice (m_device);
1158 inpp.setAfterEndCharByte (m_device->tellInternal () - 128);
1159 inpp.setMargins (m_leftMargin, m_rightMargin);
1160 if (!inpp.updateIndents ())
return false;
1164 #ifdef DEBUG_FORMATINFO
1165 m_device->debug (
"\tTrying to add CharProperty, #numDataBytes=", ((FormatCharProperty *) property)->getNumDataBytes ());
1168 incp = *((FormatCharProperty *) property);
1169 incp.setDevice (m_device);
1170 incp.setAfterEndCharByte (m_device->tellInternal () - 128);
1171 incp.setFontTable (m_fontTable);
1172 if (!incp.updateFontCode ())
return false;
1191 bool checkedLastFormatPointer =
false;
1192 if (m_type == CharType && m_numProperty > 0 )
1194 #ifdef DEBUG_FORMATINFO
1195 m_device->debug (
"\tIs it the same property as last? ");
1199 FormatCharProperty *lastProp = (FormatCharProperty *) m_formatPointer [m_numFormatPointers - 1].getFormatProperty ();
1200 if (incp == *lastProp)
1202 #ifdef DEBUG_FORMATINFO
1203 m_device->debug (
"Yes, extending FormatPointer #", m_numFormatPointers - 1);
1204 m_device->debug (
"\t\tFrom ", m_formatPointer [m_numFormatPointers - 1].getAfterEndCharByte ());
1207 m_formatPointer [m_numFormatPointers - 1].setAfterEndCharByte (incp.getAfterEndCharByte ());
1209 #ifdef DEBUG_FORMATINFO
1210 m_device->debug (
"\t\tTo: ", incp.getAfterEndCharByte ());
1215 checkedLastFormatPointer =
true;
1216 #ifdef DEBUG_FORMATINFO
1217 m_device->debug (
"No\n");
1220 #ifdef DEBUG_FORMATINFO
1221 m_device->debug (
"\tSame as earlier FormatPointer? ");
1225 for (
int i = 0; i < m_numFormatPointers - (checkedLastFormatPointer ? 1 : 0); i++)
1227 #ifdef DEBUG_FORMATINFO
1228 m_device->debug (i);
1229 m_device->debug (
"? ");
1231 if (m_type == ParaType)
1233 FormatParaProperty *prop = (FormatParaProperty *) m_formatPointer [i].getFormatProperty ();
1237 if (m_formatPointerPos + FormatPointer::s_size > m_formatPropertyPos)
1239 #ifdef DEBUG_FORMATINFO
1240 m_device->debug (
"Yes, but out of room on this page\n");
1245 #ifdef DEBUG_FORMATINFO
1246 m_device->debug (
"Yes, same property as ", i);
1248 m_formatPointer [m_numFormatPointers].setAfterEndCharByte (inpp.getAfterEndCharByte ());
1249 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (m_formatPointer [i].getFormatPropertyOffset ());
1250 m_formatPointer [m_numFormatPointers].setFormatProperty (prop);
1252 m_formatPointerPos += FormatPointer::s_size;
1253 m_numFormatPointers++;
1259 FormatCharProperty *prop = (FormatCharProperty *) m_formatPointer [i].getFormatProperty ();
1263 if (m_formatPointerPos + FormatPointer::s_size > m_formatPropertyPos)
1265 #ifdef DEBUG_FORMATINFO
1266 m_device->debug (
"Yes, but out of room on this page\n");
1271 #ifdef DEBUG_FORMATINFO
1272 m_device->debug (
"Yes, same property as ", i);
1274 m_formatPointer [m_numFormatPointers].setAfterEndCharByte (incp.getAfterEndCharByte ());
1275 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (m_formatPointer [i].getFormatPropertyOffset ());
1276 m_formatPointer [m_numFormatPointers].setFormatProperty (prop);
1278 m_formatPointerPos += FormatPointer::s_size;
1279 m_numFormatPointers++;
1284 #ifdef DEBUG_FORMATINFO
1285 m_device->debug (
"No, outputting full FormatPointer & Property\n");
1289 if (m_type == ParaType)
1291 int nextPropertyPos = m_formatPropertyPos;
1292 if (inpp.getNumDataBytes ())
1293 nextPropertyPos -= (
sizeof (Byte) + inpp.getNumDataBytes ());
1295 if (m_formatPointerPos + FormatPointer::s_size > nextPropertyPos)
1297 #ifdef DEBUG_FORMATINFO
1298 m_device->debug (
"\tOut of room on this page!\n");
1303 m_formatPropertyPos = nextPropertyPos;
1304 if (inpp.getNumDataBytes ())
1305 m_formatParaProperty [m_numProperty] = inpp;
1307 m_formatPointer [m_numFormatPointers].setAfterEndCharByte (inpp.getAfterEndCharByte ());
1308 if (inpp.getNumDataBytes ())
1310 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (m_formatPropertyPos);
1311 m_formatPointer [m_numFormatPointers].setFormatProperty (&m_formatParaProperty [m_numProperty]);
1315 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (0xFFFF);
1316 m_formatPointer [m_numFormatPointers].setFormatProperty (&m_formatParaProperty [MaxElements]);
1318 m_formatPointerPos += FormatPointer::s_size;
1320 if (inpp.getNumDataBytes ()) m_numProperty++;
1321 m_numFormatPointers++;
1326 int nextPropertyPos = m_formatPropertyPos;
1327 if (incp.getNumDataBytes ())
1328 nextPropertyPos -= (
sizeof (Byte) + incp.getNumDataBytes ());
1330 if (m_formatPointerPos + FormatPointer::s_size > nextPropertyPos)
1332 #ifdef DEBUG_FORMATINFO
1333 m_device->debug (
"\tOut of room on this page!\n");
1338 m_formatPropertyPos = nextPropertyPos;
1339 if (incp.getNumDataBytes ())
1340 m_formatCharProperty [m_numProperty] = incp;
1342 m_formatPointer [m_numFormatPointers].setAfterEndCharByte (incp.getAfterEndCharByte ());
1343 if (incp.getNumDataBytes ())
1345 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (m_formatPropertyPos);
1346 m_formatPointer [m_numFormatPointers].setFormatProperty (&m_formatCharProperty [m_numProperty]);
1350 m_formatPointer [m_numFormatPointers].setFormatPropertyOffset (0xFFFF);
1351 m_formatPointer [m_numFormatPointers].setFormatProperty (&m_formatCharProperty [MaxElements]);
1353 m_formatPointerPos += FormatPointer::s_size;
1355 if (incp.getNumDataBytes ()) m_numProperty++;
1356 m_numFormatPointers++;
1362 BMP_BitmapFileHeader::BMP_BitmapFileHeader ()
1366 BMP_BitmapFileHeader::~BMP_BitmapFileHeader ()
1370 BMP_BitmapFileHeader &BMP_BitmapFileHeader::operator= (
const BMP_BitmapFileHeader &rhs)
1375 BMP_BitmapFileHeaderGenerated::operator= (rhs);
1380 bool BMP_BitmapFileHeader::readFromDevice (
void)
1385 m_device->debug (
"\n<<<< BMP_BitmapFileHeader::readFromDevice >>>>\n");
1388 if (!BMP_BitmapFileHeaderGenerated::readFromDevice ())
1396 Dump (actualImageOffset);
1402 bool BMP_BitmapFileHeader::writeToDevice (
void)
1407 m_device->debug (
"\n<<<< BMP_BitmapFileHeader::writeToDevice >>>>\n");
1410 if (!BMP_BitmapFileHeaderGenerated::writeToDevice ())
1418 BMP_BitmapInfoHeader::BMP_BitmapInfoHeader ()
1422 BMP_BitmapInfoHeader::~BMP_BitmapInfoHeader ()
1426 BMP_BitmapInfoHeader &BMP_BitmapInfoHeader::operator= (
const BMP_BitmapInfoHeader &rhs)
1431 BMP_BitmapInfoHeaderGenerated::operator= (rhs);
1436 bool BMP_BitmapInfoHeader::readFromDevice (
void)
1441 m_device->debug (
"\n<<<< BMP_BitmapInfoHeader::readFromDevice >>>>\n");
1444 if (!BMP_BitmapInfoHeaderGenerated::readFromDevice ())
1448 Dump (numHeaderBytes);
1452 Dump (bitsPerPixel);
1455 Dump (xPixelsPerMeter);
1456 Dump (yPixelsPerMeter);
1458 Dump (coloursImportant);
1464 bool BMP_BitmapInfoHeader::writeToDevice (
void)
1469 m_device->debug (
"\n<<<< BMP_BitmapInfoHeader::writeToDevice >>>>\n");
1472 if (!BMP_BitmapInfoHeaderGenerated::writeToDevice ())
1479 BMP_BitmapColourIndex::BMP_BitmapColourIndex ()
1483 BMP_BitmapColourIndex::~BMP_BitmapColourIndex ()
1487 BMP_BitmapColourIndex &BMP_BitmapColourIndex::operator= (
const BMP_BitmapColourIndex &rhs)
1492 BMP_BitmapColourIndexGenerated::operator= (rhs);
1498 BitmapHeader::BitmapHeader ()
1502 BitmapHeader::~BitmapHeader ()
1506 BitmapHeader &BitmapHeader::operator= (
const BitmapHeader &rhs)
1511 BitmapHeaderGenerated::operator= (rhs);
1516 bool BitmapHeader::readFromDevice (
void)
1521 m_device->debug (
"\n<<<< BitmapHeader::readFromDevice >>>>\n");
1524 if (!BitmapHeaderGenerated::readFromDevice ())
1533 Dump (bitsPerPixel);
1540 bool BitmapHeader::writeToDevice (
void)
1545 m_device->debug (
"\n>>>> BitmapHeader::writeToDevice <<<<\n");
1548 if (!BitmapHeaderGenerated::writeToDevice ())
1555 WMFHeader::WMFHeader ()
1559 WMFHeader::~WMFHeader ()
1563 WMFHeader &WMFHeader::operator= (
const WMFHeader &rhs)
1568 WMFHeaderGenerated::operator= (rhs);
1573 bool WMFHeader::readFromDevice (
void)
1578 m_device->debug (
"\n<<<< WMFHeader::readFromDevice >>>>\n");
1581 if (!WMFHeaderGenerated::readFromDevice ())
1590 Dump (maxRecordSize);
1597 bool WMFHeader::writeToDevice (
void)
1602 m_device->debug (
"\n>>>> WMFHeader::writeToDevice <<<<\n");
1611 Dump (maxRecordSize);
1615 if (!WMFHeaderGenerated::writeToDevice ())