27#include "libmswrite.h"
31 FormatInfo::FormatInfo () : m_nextChar (0),
32 m_leftMargin (0xFFFF), m_rightMargin (0xFFFF),
38 FormatInfo::~FormatInfo ()
42 bool FormatInfo::readFromDevice (
void)
46 #ifdef DEBUG_FORMATINFO
47 if (m_type == ParaType)
48 m_device->debug (
"\n<<<< libmswrite.cpp::FormatInfo::readFromDevice (ParaType) >>>>\n");
50 m_device->debug (
"\n<<<< libmswrite.cpp::FormatInfo::readFromDevice (CharType) >>>>\n");
53 int formatInfoPageNum;
54 if (m_type == ParaType)
55 formatInfoPageNum = m_header->getNumPageParaInfo ();
57 formatInfoPageNum = m_header->getNumPageCharInfo ();
60 #ifdef DEBUG_FORMATINFO
61 m_device->debug (
"numpages format info=", formatInfoPageNum);
65 if (m_header->getNumCharBytes () && formatInfoPageNum == 0)
67 if (m_type == ParaType)
69 ErrorAndQuit (Error::InvalidFormat,
"no paragraph formatting information page\n");
73 ErrorAndQuit (Error::InvalidFormat,
"no character formatting information page\n");
78 if (!m_device->seek (((m_type == ParaType) ?
79 m_header->getPageParaInfo () : m_header->getPageCharInfo ()) * 128, SEEK_SET))
102 for (
int i = 0; i < formatInfoPageNum; i++)
104 if (!m_formatInfoPageList.addToBack ())
105 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for an information page\n");
107 FormatInfoPage &fip = *m_formatInfoPageList.begin (
false);
108 if (m_device->bad ())
return false;
110 fip.setHeader (m_header);
111 fip.setDevice (m_device);
112 fip.setType (m_type);
114 if (m_type == ParaType)
115 fip.setMargins (m_leftMargin, m_rightMargin);
117 fip.setFontTable (m_fontTable);
119 if (!fip.readFromDevice ())
126 bool FormatInfo::writeToDevice (
const void *defaultProperty)
130 #ifdef DEBUG_FORMATINFO
131 if (m_type == ParaType)
132 m_device->debug (
"\n<<<< libmswrite.cpp::FormatInfo::writeToDevice (ParaType) >>>>\n");
134 m_device->debug (
"\n<<<< libmswrite.cpp::FormatInfo::writeToDevice (CharType) >>>>\n");
138 if (m_type == ParaType)
139 m_header->setPageParaInfo (m_device->tellInternal () / 128);
154 if (!m_formatInfoPageList.getNumElements ())
156 #ifdef DEBUG_FORMATINFO
157 m_device->debug (
"\tno formatting information pages, creating one\n");
162 if (m_header->getNumCharBytes ())
164 if (m_type == ParaType)
165 m_device->error (Error::Warn,
"data but no paragraph formatting info\n");
167 m_device->error (Error::Warn,
"data but no character formatting info\n");
170 long currentOffset = m_device->tellInternal ();
171 if (!m_device->seekInternal (128 + m_header->getNumCharBytes (), SEEK_SET))
return false;
172 if (!add (defaultProperty,
true))
return false;
173 if (!m_device->seekInternal (currentOffset, SEEK_SET))
return false;
176 List <FormatInfoPage>::Iterator it;
177 for (it = m_formatInfoPageList.begin (); it != m_formatInfoPageList.end (); ++it)
179 FormatInfoPage &fip = *it;
182 fip.setHeader (m_header);
183 fip.setDevice (m_device);
184 fip.setType (m_type);
186 if (m_type == ParaType)
187 fip.setMargins (m_leftMargin, m_rightMargin);
189 fip.setFontTable (m_fontTable);
191 if (!fip.writeToDevice ())
198 void *FormatInfo::begin (
void)
202 m_formatInfoPageIterator = m_formatInfoPageList.begin ();
204 if (m_formatInfoPageIterator == m_formatInfoPageList.end ())
207 void *ret = (*m_formatInfoPageIterator).begin ();
211 if (m_type == ParaType)
212 m_nextChar = ((FormatParaProperty *) ret)->getAfterEndCharByte ();
214 m_nextChar = ((FormatCharProperty *) ret)->getAfterEndCharByte ();
220 void *FormatInfo::next (
void)
222 #ifdef CHECK_INTERNAL
231 if ((*m_formatInfoPageIterator).end ())
233 m_formatInfoPageIterator++;
236 if (m_formatInfoPageIterator == m_formatInfoPageList.end ())
239 if ((*m_formatInfoPageIterator).getFirstCharByte () != m_nextChar)
240 m_device->error (Error::Warn,
"FormatInfoPage::firstCharByte does not flow on from nextChar\n");
242 ret = (*m_formatInfoPageIterator).begin ();
246 ret = (*m_formatInfoPageIterator).next ();
250 if (m_type == ParaType)
251 m_nextChar = ((FormatParaProperty *) ret)->getAfterEndCharByte ();
253 m_nextChar = ((FormatCharProperty *) ret)->getAfterEndCharByte ();
259 bool FormatInfo::end (
void)
261 return m_formatInfoPageIterator == m_formatInfoPageList.end ();
264 bool FormatInfo::add (
const void *property,
const bool force)
268 #ifdef DEBUG_FORMATINFO
269 m_device->debug (
">>>> FormatInfo::add <<<<\n");
272 DWord currentChar = m_device->tellInternal () - 128;
275 if (m_nextChar == currentChar && !force)
277 #ifdef DEBUG_FORMATINFO
278 m_device->debug (
"\tEmpty FormatProperty, ignoring\n");
283 bool needToAllocate =
false;
285 if (m_formatInfoPageList.getNumElements ())
287 FormatInfoPage &fip = *m_formatInfoPageList.begin (
false);
288 if (!fip.add (property))
291 if (m_device->bad ())
294 needToAllocate =
true;
298 needToAllocate =
true;
302 #ifdef DEBUG_FORMATINFO
303 m_device->debug (
"\tneedToAllocate=yes, FormatInfoPage::firstCharByte=", m_nextChar);
306 if (!m_formatInfoPageList.addToBack ())
307 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for new formatInfoPage\n");
309 FormatInfoPage &fip = *m_formatInfoPageList.begin (
false);
310 fip.setDevice (m_device);
311 fip.setFirstCharByte (m_nextChar);
312 fip.setType (m_type);
314 if (m_type == ParaType)
315 fip.setMargins (m_leftMargin, m_rightMargin);
318 assert (m_fontTable);
319 fip.setFontTable (m_fontTable);
322 if (!fip.add (property))
326 m_nextChar = currentChar;
331 Generator::Generator ()
335 Generator::~Generator ()
339 bool Generator::processText (
const Byte *
string,
bool willReachEndOfParagraph)
352 const int outBufferMaxLen = 1024;
353 Byte outBuffer [outBufferMaxLen];
354 DWord outBufferLen = 0;
356 for (; *string;
string++)
359 if (outBufferLen >= outBufferMaxLen - 1)
362 outBuffer [outBufferMaxLen - 1] =
'\0';
363 if (!writeText (outBuffer))
return false;
378 outBuffer [outBufferLen] = 0;
379 if (!writeText (outBuffer))
return false;
386 case 1:
if (!writePageNumber ())
return false;
break;
387 case 12:
if (!writePageBreak ())
return false;
break;
388 case 10:
if (!writeNewLine (willReachEndOfParagraph &&
string [1] == 0))
return false;
break;
389 case 13:
if (!writeCarriageReturn ())
return false;
break;
390 case 31:
if (!writeOptionalHyphen ())
return false;
break;
397 outBuffer [outBufferLen++] = *string;
405 outBuffer [outBufferLen] = 0;
406 if (!writeText (outBuffer))
return false;
413 InternalParser::InternalParser () : m_header (NULL),
414 m_sectionTable (NULL),
418 m_paragraphInfo (NULL),
419 m_characterInfo (NULL),
425 InternalParser::~InternalParser ()
430 delete m_characterInfo;
431 delete m_paragraphInfo;
435 delete m_sectionTable;
440 bool InternalParser::parse (
void)
444 fprintf (stderr,
"INTERNAL ERROR: InternalParser::parse() called without a device\n");
449 ErrorAndQuit (Error::InternalError,
"generator not passed to parser\n");
455 m_header =
new Header;
457 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for header\n");
459 m_sectionTable =
new SectionTable;
461 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for sectionTable\n");
463 m_pageLayout =
new PageLayout;
465 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for pageLayout\n");
467 m_pageTable =
new PageTable;
469 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for pageTable\n");
471 m_fontTable =
new FontTable;
473 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for fontTable\n");
475 m_paragraphInfo =
new FormatInfo;
476 if (!m_paragraphInfo)
477 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for paragraphInfo\n");
479 m_characterInfo =
new FormatInfo;
480 if (!m_characterInfo)
481 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for charInfo\n");
487 m_header->setDevice (m_device);
488 if (!m_header->readFromDevice ())
return false;
489 DWord numCharBytes = m_header->getNumCharBytes ();
491 m_sectionTable->setHeader (m_header);
492 m_sectionTable->setDevice (m_device);
493 if (!m_sectionTable->readFromDevice ())
496 m_pageLayout->setHeader (m_header);
497 m_pageLayout->setDevice (m_device);
498 if (!m_pageLayout->readFromDevice ())
501 m_pageTable->setPageNumberStart (m_pageLayout->getPageNumberStart ());
502 m_pageTable->setHeader (m_header);
503 m_pageTable->setDevice (m_device);
504 if (!m_pageTable->readFromDevice ())
507 m_fontTable->setHeader (m_header);
508 m_fontTable->setDevice (m_device);
509 if (!m_fontTable->readFromDevice ())
512 m_paragraphInfo->setHeader (m_header);
513 m_paragraphInfo->setDevice (m_device);
514 m_paragraphInfo->setType (ParaType);
515 m_paragraphInfo->setMargins (m_pageLayout->getLeftMargin (), m_pageLayout->getRightMargin ());
516 if (!m_paragraphInfo->readFromDevice ())
519 m_characterInfo->setHeader (m_header);
520 m_characterInfo->setDevice (m_device);
521 m_characterInfo->setType (CharType);
522 m_characterInfo->setFontTable (m_fontTable);
523 if (!m_characterInfo->readFromDevice ())
527 DocumentInfo documentInfo;
528 FormatParaProperty *paraProperty = (FormatParaProperty *) m_paragraphInfo->begin ();
532 if (paraProperty->getIsObject ())
534 if (paraProperty->getIsHeader ())
536 documentInfo.setHasHeader (
true);
537 if (paraProperty->getIsOnFirstPage ())
538 documentInfo.setHasHeaderOnFirstPage (
true);
540 if (paraProperty->getIsFooter ())
542 documentInfo.setHasFooter (
true);
543 if (paraProperty->getIsOnFirstPage ())
544 documentInfo.setHasFooterOnFirstPage (
true);
546 paraProperty = (FormatParaProperty *) m_paragraphInfo->next ();
548 documentInfo.setNumObjects (numObjects);
554 enum Section { InNothing, InBody, InHeader, InFooter } inWhat = InNothing;
557 bool wroteBody =
false;
559 PagePointer *pp = m_pageTable->begin ();
560 if (m_device->bad ())
return false;
565 #ifdef DEBUG_INTERNALPARSER
566 m_device->debug (
"@@@ InternalParser: start of document write\n");
569 if (!m_generator->writeDocumentBegin (m_header->getMagic (), m_pageLayout))
return false;
570 m_generator->sigProgress (0);
573 if (!m_device->seekInternal (1 * 128, SEEK_SET))
576 FormatParaProperty *paraProp = (FormatParaProperty *) m_paragraphInfo->begin ();
577 if (m_device->bad ())
return false;
578 FormatCharProperty *charProp = (FormatCharProperty *) m_characterInfo->begin ();
579 if (m_device->bad ())
return false;
580 DWord paraStartByte = 0;
582 if (numCharBytes)
while (paraProp)
584 #ifdef DEBUG_INTERNALPARSER
585 m_device->debug (
"@@@ InternalParser: Start of loop - section write\n");
591 enum Section inWhatNext = InNothing;
592 if (paraProp->getIsFooter ())
593 inWhatNext = InFooter;
594 else if (paraProp->getIsHeader ())
595 inWhatNext = InHeader;
600 if (inWhatNext != inWhat)
605 case InFooter:
if (!m_generator->writeFooterEnd ())
return false;
else break;
606 case InHeader:
if (!m_generator->writeHeaderEnd ())
return false;
else break;
607 case InBody:
if (!m_generator->writeBodyEnd ())
return false;
else break;
612 switch (inWhat = inWhatNext)
614 case InFooter:
if (!m_generator->writeFooterBegin ())
return false;
else break;
615 case InHeader:
if (!m_generator->writeHeaderBegin ())
return false;
else break;
616 case InBody:
if (!m_generator->writeBodyBegin ())
return false;
619 if (!m_generator->writePageNew ())
632 bool paraIsText = paraProp->getIsText ();
633 int objectType = ObjectType::NotObject;
635 DWord paraEndByte, paraAfterEndByte;
636 paraAfterEndByte = paraProp->getAfterEndCharByte ();
637 paraEndByte = paraAfterEndByte - 1;
641 #ifdef DEBUG_INTERNALPARSER
642 m_device->debug (
"@@@ InternalParser: Start of paragraph write\n");
646 if (!m_generator->writeParaInfoBegin (paraProp, NULL, NULL))
return false;
659 if (!m_device->readInternal (data, 2))
return false;
660 ReadWord (mappingMode, data);
661 if (!m_device->seekInternal (-2, SEEK_CUR))
return false;
666 objectType = ObjectType::OLE;
670 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for OLE object\n");
672 m_ole->setDevice (m_device);
673 if (!m_ole->readFromDevice ())
676 if (!m_generator->writeParaInfoBegin (paraProp, m_ole, NULL))
return false;
679 objectType = ObjectType::BMP;
683 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for BMP image object\n");
685 m_image->setDevice (m_device);
686 if (!m_image->readFromDevice ())
689 if (!m_generator->writeParaInfoBegin (paraProp, NULL, m_image))
return false;
692 objectType = ObjectType::WMF;
696 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for WMF image object\n");
698 m_image->setDevice (m_device);
699 if (!m_image->readFromDevice ())
702 if (!m_generator->writeParaInfoBegin (paraProp, NULL, m_image))
return false;
707 if (objectType != ObjectType::OLE)
709 if (m_image->getNumHeaderBytes () + m_image->getNumDataBytes ()
710 != paraAfterEndByte - paraStartByte)
712 m_device->error (Error::Warn,
"imageHeader: numHeaderBytes + numDataBytes != paragraph length\n");
715 if (!m_device->seekInternal (paraAfterEndByte + 128, SEEK_SET))
return false;
720 #ifdef DEBUG_INTERNALPARSER
721 m_device->debug (
"@@@ InternalParser: Start of text write\n");
724 DWord uptoByte = paraStartByte;
727 while (uptoByte < paraAfterEndByte)
731 if (uptoByte >= charProp->getAfterEndCharByte ())
733 charProp = (FormatCharProperty *) m_characterInfo->next ();
734 if (m_device->bad ())
return false;
737 #ifdef DEBUG_INTERNALPARSER
738 m_device->debug (
"@@@ InternalParser: character write\n");
741 if (!m_generator->writeCharInfoBegin (charProp))
return false;
745 DWord aimUltimateByte = charProp->getEndCharByte () > paraEndByte ? paraEndByte : charProp->getEndCharByte ();
747 while (uptoByte <= aimUltimateByte)
750 bool pageTableAck =
false;
753 DWord aimByte = aimUltimateByte;
759 if (pp->getFirstCharByte () <= aimByte)
762 if (pp->getFirstCharByte ())
764 aimByte = pp->getFirstCharByte () - 1;
766 aimByte = 0xFFFFFFFF;
768 #ifdef DEBUG_INTERNALPARSER
769 m_device->debug (
"@@@ InternalParser: writePageNew pending\n");
775 while (uptoByte <= aimByte && aimByte != 0xFFFFFFFF)
777 const DWord amountToRead = aimByte - uptoByte + 1 > 1023
778 ? 1023 : aimByte - uptoByte + 1;
784 if (!m_device->readInternal (buffer, amountToRead))
return false;
786 buffer [amountToRead] =
'\0';
787 if (!m_generator->processText (buffer, uptoByte + amountToRead - 1 == paraEndByte))
return false;
790 uptoByte += amountToRead;
796 #ifdef DEBUG_INTERNALPARSER
797 m_device->debug (
"@@@ InternalParser: writePageNew\n");
800 if (!m_generator->writePageNew (pp->getPageNumber ()))
return false;
802 pp = m_pageTable->next ();
803 if (m_device->bad ())
return false;
808 #ifdef DEBUG_INTERNALPARSER
809 m_device->debug (
"@@@ InternalParser: character end write\n");
814 if (!m_generator->writeCharInfoEnd (charProp, uptoByte == paraAfterEndByte))
826 if (objectType == ObjectType::OLE)
828 if (!m_generator->writeBinary (m_ole->getExternalObject (), m_ole->getExternalObjectSize ()))
833 if (!m_generator->writeBinary (m_image->getExternalImage (), m_image->getExternalImageSize ()))
845 if (!m_generator->writeParaInfoEnd (paraProp, NULL))
return false;
851 case ObjectType::OLE:
852 if (!m_generator->writeParaInfoEnd (paraProp, m_ole, NULL))
return false;
856 case ObjectType::BMP:
857 if (!m_generator->writeParaInfoEnd (paraProp, NULL, m_image))
return false;
861 case ObjectType::WMF:
862 if (!m_generator->writeParaInfoEnd (paraProp, NULL, m_image))
return false;
869 paraStartByte = paraAfterEndByte;
872 m_generator->sigProgress (paraStartByte * 100 / numCharBytes);
875 paraProp = (FormatParaProperty *) m_paragraphInfo->next ();
876 if (m_device->bad ())
return false;
882 case InFooter:
if (!m_generator->writeFooterEnd ())
return false;
else break;
883 case InHeader:
if (!m_generator->writeHeaderEnd ())
return false;
else break;
884 case InBody:
if (!m_generator->writeBodyEnd ())
return false;
else break;
891 #ifdef DEBUG_INTERNALPARSER
892 m_device->debug (
"@@@ InternalParser: did not write body, writing one now\n");
895 if (!m_generator->writeBodyBegin ())
return false;
896 if (!m_generator->writeBodyEnd ())
return false;
899 m_generator->sigProgress (100);
900 if (!m_generator->writeDocumentEnd (m_header->getMagic (), m_pageLayout))
return false;
906 InternalGenerator::InternalGenerator () : m_header (NULL),
907 m_sectionTable (NULL),
911 m_paragraphInfo (NULL),
912 m_characterInfo (NULL),
918 InternalGenerator::~InternalGenerator ()
923 delete m_characterInfo;
924 delete m_paragraphInfo;
928 delete m_sectionTable;
932 bool InternalGenerator::seekNextPage (
void)
934 return m_device->seekInternal ((m_device->tellInternal () + 127) / 128 * 128, SEEK_SET);
937 bool InternalGenerator::writeDocumentBegin (
const Word,
const PageLayout *pageLayout)
941 fprintf (stderr,
"INTERNAL ERROR: InternalGenerator::writeDocumentBegin() called without a device\n");
945 m_header =
new Header;
947 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for header\n");
948 m_header->setDevice (m_device);
950 m_pageLayout =
new PageLayout;
952 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for pageLayout\n");
953 m_pageLayout->setDevice (m_device);
955 m_sectionTable =
new SectionTable;
957 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for sectionTable\n");
958 m_sectionTable->setDevice (m_device);
960 m_pageTable =
new PageTable;
962 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for pageTable\n");
963 m_pageTable->setDevice (m_device);
965 m_fontTable =
new FontTable;
967 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for fontTable\n");
968 m_fontTable->setDevice (m_device);
970 m_paragraphInfo =
new FormatInfo;
971 if (!m_paragraphInfo)
972 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for paragraphInfo\n");
973 m_paragraphInfo->setType (ParaType);
974 m_paragraphInfo->setDevice (m_device);
976 m_characterInfo =
new FormatInfo;
977 if (!m_characterInfo)
978 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for characterInfo\n");
979 m_characterInfo->setType (CharType);
980 m_characterInfo->setDevice (m_device);
982 *m_pageLayout = *pageLayout;
985 if (!m_device->seekInternal (1 * 128, SEEK_SET))
return false;
990 bool InternalGenerator::writeDocumentEnd (
const Word format,
const PageLayout *)
992 #ifdef DEBUG_INTERNALGENERATOR
993 m_device->debug (
"!!!! InternalGenerator: writeDocumentEnd\n");
996 m_header->setNumCharBytes (m_device->tellInternal () - 128);
998 #ifdef DEBUG_INTERNALGENERATOR
999 m_device->debug (
"before charinfo seek next page: ", m_device->tellInternal ());
1001 if (!seekNextPage ())
return false;
1002 #ifdef DEBUG_INTERNALGENERATOR
1003 m_device->debug (
"!!!! InternalGenerator: Write characterInfo; page=", m_device->tellInternal () / 128);
1005 FormatCharProperty defaultCharProperty;
1006 defaultCharProperty.setFontTable (m_fontTable);
1007 Font defaultFont ((
const Byte *)
"Arial");
1008 defaultCharProperty.setFont (&defaultFont);
1011 m_characterInfo->setDevice (m_device);
1012 m_characterInfo->setHeader (m_header);
1013 m_characterInfo->setFontTable (m_fontTable);
1014 if (!m_characterInfo->writeToDevice (&defaultCharProperty))
return false;
1016 #ifdef DEBUG_INTERNALGENERATOR
1017 m_device->debug (
"before parainfo seek next page: ", m_device->tellInternal ());
1019 if (!seekNextPage ())
return false;
1020 #ifdef DEBUG_INTERNALGENERATOR
1021 m_device->debug (
"!!!! InternalGenerator: Write paragraphInfo; page=", m_device->tellInternal () / 128);
1023 FormatParaProperty defaultParaProperty;
1024 defaultParaProperty.setMargins (m_pageLayout->getLeftMargin (), m_pageLayout->getRightMargin ());
1027 m_paragraphInfo->setDevice (m_device);
1028 m_paragraphInfo->setHeader (m_header);
1029 m_paragraphInfo->setMargins (m_pageLayout->getLeftMargin (), m_pageLayout->getRightMargin ());
1030 if (!m_paragraphInfo->writeToDevice (&defaultParaProperty))
return false;
1032 #ifdef DEBUG_INTERNALGENERATOR
1033 m_device->debug (
"!!!! InternalGenerator: Write footnoteTable\n");
1037 m_header->setPageFootnoteTable ((m_device->tellInternal () + 127) / 128);
1039 if (!seekNextPage ())
return false;
1040 #ifdef DEBUG_INTERNALGENERATOR
1041 m_device->debug (
"!!!! InternalGenerator: Write pageLayout; page=", m_device->tellInternal () / 128);
1043 m_pageLayout->setDevice (m_device);
1044 m_pageLayout->setHeader (m_header);
1045 if (!m_pageLayout->writeToDevice ())
return false;
1047 #ifdef DEBUG_INTERNALGENERATOR
1048 m_device->debug (
"!!!! InternalGenerator: Write sectionTable\n");
1050 if (!seekNextPage ())
return false;
1051 m_sectionTable->setDevice (m_device);
1052 m_sectionTable->setHeader (m_header);
1053 if (!m_sectionTable->writeToDevice (m_pageLayout->getIsModified ()))
return false;
1055 #ifdef DEBUG_INTERNALGENERATOR
1056 m_device->debug (
"!!!! InternalGenerator: Write pageTable\n");
1058 if (!seekNextPage ())
return false;
1059 m_pageTable->setDevice (m_device);
1060 m_pageTable->setHeader (m_header);
1061 m_pageTable->setPageNumberStart (m_pageLayout->getPageNumberStart ());
1062 if (!m_pageTable->writeToDevice ())
return false;
1064 #ifdef DEBUG_INTERNALGENERATOR
1065 m_device->debug (
"!!!! InternalGenerator: Write fontTable\n");
1067 if (!seekNextPage ())
return false;
1068 m_fontTable->setDevice (m_device);
1069 m_fontTable->setHeader (m_header);
1070 if (!m_fontTable->writeToDevice ())
return false;
1072 #ifdef DEBUG_INTERNALGENERATOR
1073 m_device->debug (
"!!!! InternalGenerator: Write header\n");
1076 m_header->setFormat (format);
1077 m_header->setNumPages ((m_device->tellInternal () + 127) / 128);
1078 m_header->setDevice (m_device);
1079 if (!m_device->seekInternal (0 * 128, SEEK_SET))
return false;
1080 if (!m_header->writeToDevice ())
return false;
1088 if (!m_device->seekInternal (m_header->getNumPages () * 128, SEEK_SET))
return false;
1093 bool InternalGenerator::writeParaInfoBegin (
const FormatParaProperty * ,
1097 #ifdef DEBUG_INTERNALGENERATOR
1098 m_device->debug (
"!!!! InternalGenerator: writeParaInfoBegin\n");
1105 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for OLE\n");
1108 m_ole->setDevice (m_device);
1109 m_ole->setExternalObjectSize (ole->getExternalObjectSize ());
1114 m_image =
new Image;
1116 ErrorAndQuit (Error::OutOfMemory,
"could not allocate memory for image\n");
1119 m_image->setDevice (m_device);
1120 m_image->setExternalImageSize (image->getExternalImageSize ());
1126 bool InternalGenerator::writeParaInfoEnd (
const FormatParaProperty *paraProperty,
1130 #ifdef DEBUG_INTERNALGENERATOR
1131 m_device->debug (
"!!!! InternalGenerator: writeParaInfoEnd\n");
1136 if (!m_ole->writeToDevice ())
1144 if (!m_image->writeToDevice ())
1151 m_paragraphInfo->setMargins (m_pageLayout->getLeftMargin (), m_pageLayout->getRightMargin ());
1152 return m_paragraphInfo->add (paraProperty,
false);
1155 bool InternalGenerator::writeCharInfoBegin (
const FormatCharProperty * )
1157 #ifdef DEBUG_INTERNALGENERATOR
1158 m_device->debug (
"!!!! InternalGenerator: writeCharInfoBegin\n");
1164 bool InternalGenerator::writeCharInfoEnd (
const FormatCharProperty *charProperty,
1167 #ifdef DEBUG_INTERNALGENERATOR
1168 m_device->debug (
"!!!! InternalGenerator: writeCharInfoEnd\n");
1171 m_characterInfo->setFontTable (m_fontTable);
1172 return m_characterInfo->add (charProperty,
false);
1175 bool InternalGenerator::writeBinary (
const Byte *buffer,
const DWord length)
1179 if (!m_ole->setExternalObject (buffer, length))
1184 if (!m_image->setExternalImage (buffer, length))
1188 ErrorAndQuit (Error::InternalError,
"attempt to write unknown type of binary data\n");
1193 bool InternalGenerator::writeText (
const Byte *
string)
1195 #ifdef DEBUG_INTERNALGENERATOR
1199 DWord length = DWord (strlen ((
const char *)
string));
1201 if (!m_device->writeInternal (
string, length))
return false;
1206 bool InternalGenerator::writePageNew (
const int pageNumberClaimed)
1208 #ifdef DEBUG_INTERNALGENERATOR
1209 m_device->debug (
"!!!! InternalGenerator: writePageNew() with pageNo ",
1214 if (pageNumberClaimed == 0)
1218 pp.setPageNumber (pageNumberClaimed);
1219 pp.setFirstCharByte (m_device->tellInternal () - 128);
1221 return m_pageTable->add (&pp);