34#include <libwpd/libwpd.h>
37#include "WordPerfectCollector.h"
38#include "DocumentElement.h"
39#include "TextRunStyle.h"
43#include "SectionStyle.h"
44#include "TableStyle.h"
45#include "FilterInternal.h"
46#include "WriterProperties.h"
48_WriterDocumentState::_WriterDocumentState() :
50 mbInFakeSection(false),
51 mbListElementOpenedAtCurrentLevel(false),
52 mbTableCellOpened(false),
58WordPerfectCollector::WordPerfectCollector(_SH_InputStream *pInput, DocumentHandler *pHandler) :
62 mfSectionSpaceAfter(0.0f),
64 mpCurrentContentElements(&mBodyElements),
65 mpCurrentPageSpan(NULL),
67 mpCurrentListStyle(NULL),
68 miCurrentListLevel(0),
71 mbListContinueNumbering(false),
72 mbListElementOpened(false),
73 mbListElementParagraphOpened(false)
77WordPerfectCollector::~WordPerfectCollector()
81bool WordPerfectCollector::filter()
92 if (!_parseSourceDocument(*mpInput))
94 if (!_writeTargetDocument(*mpHandler))
98 WRITER_DEBUG_MSG((
"WriterWordPerfect: Cleaning up our mess..\n"));
100 WRITER_DEBUG_MSG((
"Destroying the body elements\n"));
101 for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); iterBody++) {
106 WRITER_DEBUG_MSG((
"Destroying the styles elements\n"));
107 for (std::vector<DocumentElement *>::iterator iterStyles = mStylesElements.begin(); iterStyles != mStylesElements.end(); iterStyles++) {
108 delete (*iterStyles);
109 (*iterStyles) = NULL;
113 WRITER_DEBUG_MSG((
"Destroying the rest of the styles elements\n"));
114 for (std::map<_SH_String, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin(); iterTextStyle != mTextStyleHash.end(); iterTextStyle++) {
115 delete(iterTextStyle->second);
117 for (std::map<_SH_String, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); iterFont++) {
118 delete(iterFont->second);
121 for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) {
122 delete((*iterListStyles));
124 for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) {
125 delete((*iterSectionStyles));
127 for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) {
128 delete((*iterTableStyles));
131 for (std::vector<PageSpan *>::iterator iterPageSpans = mPageSpans.begin(); iterPageSpans != mPageSpans.end(); iterPageSpans++) {
132 delete((*iterPageSpans));
138bool WordPerfectCollector::_parseSourceDocument(_SH_InputStream &input)
140#if defined(HAVE_LIBWPD_0100)
141 libwpd::WPDResult result = libwpd::WPDocument::parse(&input,
static_cast<_SH_DocumentInterface*
>(
this), NULL);
142#elif defined(HAVE_LIBWPD_090)
143 WPDResult result = WPDocument::parse(&input,
static_cast<_SH_DocumentInterface*
>(
this), NULL);
145 WPDResult result = WPDocument::parse(&input,
static_cast<_SH_DocumentInterface*
>(
this));
147#if defined(HAVE_LIBWPD_0100)
148 if (result != libwpd::WPD_OK)
150 if (result != WPD_OK)
157void WordPerfectCollector::_writeDefaultStyles(DocumentHandler &xHandler)
159 TagOpenElement stylesOpenElement(
"office:styles");
160 stylesOpenElement.write(xHandler);
162 TagOpenElement defaultParagraphStyleOpenElement(
"style:default-style");
163 defaultParagraphStyleOpenElement.addAttribute(
"style:family",
"paragraph");
164 defaultParagraphStyleOpenElement.write(xHandler);
166 TagOpenElement defaultParagraphStylePropertiesOpenElement(
"style:properties");
167 defaultParagraphStylePropertiesOpenElement.addAttribute(
"style:family",
"paragraph");
168 defaultParagraphStylePropertiesOpenElement.addAttribute(
"style:tab-stop-distance",
"0.5inch");
169 defaultParagraphStylePropertiesOpenElement.write(xHandler);
170 TagCloseElement defaultParagraphStylePropertiesCloseElement(
"style:properties");
171 defaultParagraphStylePropertiesCloseElement.write(xHandler);
173 TagCloseElement defaultParagraphStyleCloseElement(
"style:default-style");
174 defaultParagraphStyleCloseElement.write(xHandler);
176 TagOpenElement standardStyleOpenElement(
"style:style");
177 standardStyleOpenElement.addAttribute(
"style:name",
"Standard");
178 standardStyleOpenElement.addAttribute(
"style:family",
"paragraph");
179 standardStyleOpenElement.addAttribute(
"style:class",
"text");
180 standardStyleOpenElement.write(xHandler);
181 TagCloseElement standardStyleCloseElement(
"style:style");
182 standardStyleCloseElement.write(xHandler);
184 TagOpenElement textBodyStyleOpenElement(
"style:style");
185 textBodyStyleOpenElement.addAttribute(
"style:name",
"Text Body");
186 textBodyStyleOpenElement.addAttribute(
"style:family",
"paragraph");
187 textBodyStyleOpenElement.addAttribute(
"style:parent-style-name",
"Standard");
188 textBodyStyleOpenElement.addAttribute(
"style:class",
"text");
189 textBodyStyleOpenElement.write(xHandler);
190 TagCloseElement textBodyStyleCloseElement(
"style:style");
191 textBodyStyleCloseElement.write(xHandler);
193 TagOpenElement tableContentsStyleOpenElement(
"style:style");
194 tableContentsStyleOpenElement.addAttribute(
"style:name",
"Table Contents");
195 tableContentsStyleOpenElement.addAttribute(
"style:family",
"paragraph");
196 tableContentsStyleOpenElement.addAttribute(
"style:parent-style-name",
"Text Body");
197 tableContentsStyleOpenElement.addAttribute(
"style:class",
"extra");
198 tableContentsStyleOpenElement.write(xHandler);
199 TagCloseElement tableContentsStyleCloseElement(
"style:style");
200 tableContentsStyleCloseElement.write(xHandler);
202 TagOpenElement tableHeadingStyleOpenElement(
"style:style");
203 tableHeadingStyleOpenElement.addAttribute(
"style:name",
"Table Heading");
204 tableHeadingStyleOpenElement.addAttribute(
"style:family",
"paragraph");
205 tableHeadingStyleOpenElement.addAttribute(
"style:parent-style-name",
"Table Contents");
206 tableHeadingStyleOpenElement.addAttribute(
"style:class",
"extra");
207 tableHeadingStyleOpenElement.write(xHandler);
208 TagCloseElement tableHeadingStyleCloseElement(
"style:style");
209 tableHeadingStyleCloseElement.write(xHandler);
211 TagCloseElement stylesCloseElement(
"office:styles");
212 stylesCloseElement.write(xHandler);
217void WordPerfectCollector::_writeBegin()
221void WordPerfectCollector::_writeMasterPages(DocumentHandler &xHandler)
223 _SH_PropertyList xBlankAttrList;
225 xHandler.startElement(
"office:master-styles", xBlankAttrList);
227 for (
int i=0; i<mPageSpans.size(); i++)
230 (i == (mPageSpans.size() - 1)) ? bLastPage = true : bLastPage =
false;
231 mPageSpans[i]->writeMasterPages(pageNumber, i, bLastPage, xHandler);
232 pageNumber += mPageSpans[i]->getSpan();
234 xHandler.endElement(
"office:master-styles");
237void WordPerfectCollector::_writePageMasters(DocumentHandler &xHandler)
240 for (
int i=0; i<mPageSpans.size(); i++)
242 mPageSpans[i]->writePageMaster(i, xHandler);
246bool WordPerfectCollector::_writeTargetDocument(DocumentHandler &xHandler)
248 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: Printing out the header stuff..\n"));
249 _SH_PropertyList xBlankAttrList;
251 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: Start Document\n"));
252 mpHandler->startDocument();
254 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: preamble\n"));
255 _SH_PropertyList docContentPropList;
256 docContentPropList.insert(
"xmlns:office",
"http://openoffice.org/2000/office");
257 docContentPropList.insert(
"xmlns:style",
"http://openoffice.org/2000/style");
258 docContentPropList.insert(
"xmlns:text",
"http://openoffice.org/2000/text");
259 docContentPropList.insert(
"xmlns:table",
"http://openoffice.org/2000/table");
260 docContentPropList.insert(
"xmlns:draw",
"http://openoffice.org/2000/draw");
261 docContentPropList.insert(
"xmlns:fo",
"http://www.w3.org/1999/XSL/Format");
262 docContentPropList.insert(
"xmlns:xlink",
"http://www.w3.org/1999/xlink");
263 docContentPropList.insert(
"xmlns:number",
"http://openoffice.org/2000/datastyle");
264 docContentPropList.insert(
"xmlns:svg",
"http://www.w3.org/2000/svg");
265 docContentPropList.insert(
"xmlns:chart",
"http://openoffice.org/2000/chart");
266 docContentPropList.insert(
"xmlns:dr3d",
"http://openoffice.org/2000/dr3d");
267 docContentPropList.insert(
"xmlns:math",
"http://www.w3.org/1998/Math/MathML");
268 docContentPropList.insert(
"xmlns:form",
"http://openoffice.org/2000/form");
269 docContentPropList.insert(
"xmlns:script",
"http://openoffice.org/2000/script");
270 docContentPropList.insert(
"office:class",
"text");
271 docContentPropList.insert(
"office:version",
"1.0");
272 mpHandler->startElement(
"office:document-content", docContentPropList);
275 mpHandler->startElement(
"office:font-decls", xBlankAttrList);
276 for (std::map<_SH_String, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); iterFont++) {
277 iterFont->second->write(*mpHandler);
279 TagOpenElement symbolFontOpen(
"style:font-decl");
280 symbolFontOpen.addAttribute(
"style:name",
"StarSymbol");
281 symbolFontOpen.addAttribute(
"fo:font-family",
"StarSymbol");
282 symbolFontOpen.addAttribute(
"style:font-charset",
"x-symbol");
283 symbolFontOpen.write(*mpHandler);
284 mpHandler->endElement(
"style:font-decl");
286 mpHandler->endElement(
"office:font-decls");
289 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: Writing out the styles..\n"));
292 _writeDefaultStyles(*mpHandler);
294 mpHandler->startElement(
"office:automatic-styles", xBlankAttrList);
296 for (std::map<_SH_String, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin();
297 iterTextStyle != mTextStyleHash.end(); iterTextStyle++)
300 if (strcmp((iterTextStyle->second)->getName().cstr(),
"Standard"))
303 (iterTextStyle->second)->write(xHandler);
308 for (std::map<_SH_String, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin();
309 iterSpanStyle != mSpanStyleHash.end(); iterSpanStyle++)
311 (iterSpanStyle->second)->write(xHandler);
315 for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) {
316 (*iterSectionStyles)->write(xHandler);
320 for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) {
321 (*iterListStyles)->write(xHandler);
325 for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) {
326 (*iterTableStyles)->write(xHandler);
330 _writePageMasters(xHandler);
333 xHandler.endElement(
"office:automatic-styles");
335 _writeMasterPages(xHandler);
337 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: Writing out the document..\n"));
339 xHandler.startElement(
"office:body", xBlankAttrList);
341 for (std::vector<DocumentElement *>::iterator iterBodyElements = mBodyElements.begin(); iterBodyElements != mBodyElements.end(); iterBodyElements++) {
342 (*iterBodyElements)->write(xHandler);
344 WRITER_DEBUG_MSG((
"WriterWordPerfect: Document Body: Finished writing all doc els..\n"));
346 xHandler.endElement(
"office:body");
347 xHandler.endElement(
"office:document-content");
349 xHandler.endDocument();
355_SH_String propListToStyleKey(
const _SH_PropertyList & xPropList)
358 _SH_PropertyList::Iter i(xPropList);
359 for (i.rewind(); i.next(); )
362 sProp.sprintf(
"[%s:%s]", i.key(), i()->getStr().cstr());
369_SH_String getParagraphStyleKey(
const _SH_PropertyList & xPropList,
const _SH_PropertyListVector & xTabStops)
371 _SH_String sKey = propListToStyleKey(xPropList);
373 _SH_String sTabStops;
374 sTabStops.sprintf(
"[num-tab-stops:%i]", xTabStops.count());
375 _SH_PropertyListVector::Iter i(xTabStops);
376 for (i.rewind(); i.next();)
378 sTabStops.append(propListToStyleKey(i()));
380 sKey.append(sTabStops);
386void WordPerfectCollector::_allocateFontName(
const _SH_String & sFontName)
388 if (mFontHash.find(sFontName) == mFontHash.end())
390 FontStyle *pFontStyle =
new FontStyle(sFontName.cstr(), sFontName.cstr());
391 mFontHash[sFontName] = pFontStyle;
395void WordPerfectCollector::openPageSpan(
const _SH_PropertyList &propList)
397 PageSpan *pPageSpan =
new PageSpan(propList);
398 mPageSpans.push_back(pPageSpan);
399 mpCurrentPageSpan = pPageSpan;
402void WordPerfectCollector::openHeader(
const _SH_PropertyList &propList)
404 std::vector<DocumentElement *> * pHeaderFooterContentElements =
new std::vector<DocumentElement *>;
406 if (propList[
"libwpd:occurence"]->getStr() ==
"even")
407 mpCurrentPageSpan->setHeaderLeftContent(pHeaderFooterContentElements);
409 mpCurrentPageSpan->setHeaderContent(pHeaderFooterContentElements);
411 mpCurrentContentElements = pHeaderFooterContentElements;
414void WordPerfectCollector::closeHeader()
416 mpCurrentContentElements = &mBodyElements;
419void WordPerfectCollector::openFooter(
const _SH_PropertyList &propList)
421 std::vector<DocumentElement *> * pHeaderFooterContentElements =
new std::vector<DocumentElement *>;
423 if (propList[
"libwpd:occurence"]->getStr() ==
"even")
424 mpCurrentPageSpan->setFooterLeftContent(pHeaderFooterContentElements);
426 mpCurrentPageSpan->setFooterContent(pHeaderFooterContentElements);
428 mpCurrentContentElements = pHeaderFooterContentElements;
431void WordPerfectCollector::closeFooter()
433 mpCurrentContentElements = &mBodyElements;
436void WordPerfectCollector::openSection(
const _SH_PropertyList &propList,
const _SH_PropertyListVector &columns)
438 int iNumColumns = columns.count();
442#if defined(HAVE_LIBWPD_090) || defined(HAVE_LIBWPD_0100)
443 mfSectionSpaceAfter = propList[
"fo:margin-bottom"]->getDouble();
445 mfSectionSpaceAfter = propList[
"fo:margin-bottom"]->getFloat();
447 _SH_String sSectionName;
448 sSectionName.sprintf(
"Section%i", mSectionStyles.size());
450 SectionStyle *pSectionStyle =
new SectionStyle(propList, columns, sSectionName.cstr());
451 mSectionStyles.push_back(pSectionStyle);
453 TagOpenElement *pSectionOpenElement =
new TagOpenElement(
"text:section");
454 pSectionOpenElement->addAttribute(
"text:style-name", pSectionStyle->getName());
455 pSectionOpenElement->addAttribute(
"text:name", pSectionStyle->getName());
456 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pSectionOpenElement));
459 mWriterDocumentState.mbInFakeSection =
true;
462void WordPerfectCollector::closeSection()
464 if (!mWriterDocumentState.mbInFakeSection)
465 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:section")));
467 mWriterDocumentState.mbInFakeSection =
false;
472 for (
float f=0.0f; f<mfSectionSpaceAfter; f+=1.0f) {
473 vector<WPXTabStop> dummyTabStops;
474 openParagraph(WPX_PARAGRAPH_JUSTIFICATION_LEFT, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, dummyTabStops,
false,
false);
478 mfSectionSpaceAfter = 0.0f;
481void WordPerfectCollector::openParagraph(
const _SH_PropertyList &propList,
const _SH_PropertyListVector &tabStops)
486 _SH_PropertyList *pPersistPropList =
new _SH_PropertyList(propList);
487 ParagraphStyle *pStyle = NULL;
489 if (mWriterDocumentState.mbFirstElement && mpCurrentContentElements == &mBodyElements)
496 pPersistPropList->insert(
"style:parent-style-name",
"Standard");
500 _SH_String sParagraphHashKey(
"P|FS");
501 pPersistPropList->insert(
"style:master-page-name",
"Page Style 1");
502 pStyle =
new ParagraphStyle(pPersistPropList, tabStops, sName);
503 mTextStyleHash[sParagraphHashKey] = pStyle;
504 mWriterDocumentState.mbFirstElement =
false;
508 if (mWriterDocumentState.mbTableCellOpened)
510 if (mWriterDocumentState.mbHeaderRow)
511 pPersistPropList->insert(
"style:parent-style-name",
"Table Heading");
513 pPersistPropList->insert(
"style:parent-style-name",
"Table Contents");
516 pPersistPropList->insert(
"style:parent-style-name",
"Standard");
518 _SH_String sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
520 if (mTextStyleHash.find(sKey) == mTextStyleHash.end()) {
522 sName.sprintf(
"S%i", mTextStyleHash.size());
524 pStyle =
new ParagraphStyle(pPersistPropList, tabStops, sName);
526 mTextStyleHash[sKey] = pStyle;
530 pStyle = mTextStyleHash[sKey];
531 delete pPersistPropList;
535 TagOpenElement *pParagraphOpenElement =
new TagOpenElement(
"text:p");
536 pParagraphOpenElement->addAttribute(
"text:style-name", pStyle->getName());
537 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pParagraphOpenElement));
540void WordPerfectCollector::closeParagraph()
542 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:p")));
545void WordPerfectCollector::openSpan(
const _SH_PropertyList &propList)
547 if (propList[
"style:font-name"])
548 _allocateFontName(propList[
"style:font-name"]->getStr());
549 _SH_String sSpanHashKey = propListToStyleKey(propList);
550 WRITER_DEBUG_MSG((
"WriterWordPerfect: Span Hash Key: %s\n", sSpanHashKey.cstr()));
554 if (mSpanStyleHash.find(sSpanHashKey) == mSpanStyleHash.end())
557 sName.sprintf(
"Span%i", mSpanStyleHash.size());
558 SpanStyle *pStyle =
new SpanStyle(sName.cstr(), propList);
560 mSpanStyleHash[sSpanHashKey] = pStyle;
564 sName.sprintf(
"%s", mSpanStyleHash.find(sSpanHashKey)->second->getName().cstr());
568 TagOpenElement *pSpanOpenElement =
new TagOpenElement(
"text:span");
569 pSpanOpenElement->addAttribute(
"text:style-name", sName.cstr());
570 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pSpanOpenElement));
573void WordPerfectCollector::closeSpan()
575 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:span")));
578void WordPerfectCollector::defineOrderedListLevel(
const _SH_PropertyList &propList)
581 if (propList[
"libwpd:id"])
582 id = propList[
"libwpd:id"]->getInt();
584 OrderedListStyle *pOrderedListStyle = NULL;
585 if (mpCurrentListStyle && mpCurrentListStyle->getListID() ==
id)
586 pOrderedListStyle =
static_cast<OrderedListStyle *
>(mpCurrentListStyle);
592 if (pOrderedListStyle == NULL || pOrderedListStyle->getListID() !=
id ||
593 (propList[
"libwpd:level"] && propList[
"libwpd:level"]->getInt()==1 &&
594 (propList[
"text:start-value"] && propList[
"text:start-value"]->getInt() != (miLastListNumber+1))))
596 WRITER_DEBUG_MSG((
"Attempting to create a new ordered list style (listid: %i)\n",
id));
598 sName.sprintf(
"OL%i", miNumListStyles);
600 pOrderedListStyle =
new OrderedListStyle(sName.cstr(), propList[
"libwpd:id"]->getInt());
601 mListStyles.push_back(
static_cast<ListStyle *
>(pOrderedListStyle));
602 mpCurrentListStyle =
static_cast<ListStyle *
>(pOrderedListStyle);
603 mbListContinueNumbering =
false;
604 miLastListNumber = 0;
607 mbListContinueNumbering =
true;
612 for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mListStyles.begin(); iterOrderedListStyles != mListStyles.end(); iterOrderedListStyles++)
614 if ((* iterOrderedListStyles)->getListID() == propList[
"libwpd:id"]->getInt())
615 (* iterOrderedListStyles)->updateListLevel((propList[
"libwpd:level"]->getInt() - 1), propList);
619void WordPerfectCollector::defineUnorderedListLevel(
const _SH_PropertyList &propList)
622 if (propList[
"libwpd:id"])
623 id = propList[
"libwpd:id"]->getInt();
625 UnorderedListStyle *pUnorderedListStyle = NULL;
626 if (mpCurrentListStyle && mpCurrentListStyle->getListID() ==
id)
627 pUnorderedListStyle =
static_cast<UnorderedListStyle *
>(mpCurrentListStyle);
629 if (pUnorderedListStyle == NULL) {
630 WRITER_DEBUG_MSG((
"Attempting to create a new unordered list style (listid: %i)\n",
id));
632 sName.sprintf(
"UL%i", miNumListStyles);
633 pUnorderedListStyle =
new UnorderedListStyle(sName.cstr(),
id);
634 mListStyles.push_back(
static_cast<ListStyle *
>(pUnorderedListStyle));
635 mpCurrentListStyle =
static_cast<ListStyle *
>(pUnorderedListStyle);
639 for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mListStyles.begin(); iterUnorderedListStyles != mListStyles.end(); iterUnorderedListStyles++)
641 if ((* iterUnorderedListStyles)->getListID() == propList[
"libwpd:id"]->getInt())
642 (* iterUnorderedListStyles)->updateListLevel((propList[
"libwpd:level"]->getInt() - 1), propList);
646void WordPerfectCollector::openOrderedListLevel(
const _SH_PropertyList &propList)
648 miCurrentListLevel++;
649 TagOpenElement *pListLevelOpenElement =
new TagOpenElement(
"text:ordered-list");
650 _openListLevel(pListLevelOpenElement);
652 if (mbListContinueNumbering) {
653 pListLevelOpenElement->addAttribute(
"text:continue-numbering",
"true");
656 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pListLevelOpenElement));
659void WordPerfectCollector::openUnorderedListLevel(
const _SH_PropertyList &propList)
661 miCurrentListLevel++;
662 TagOpenElement *pListLevelOpenElement =
new TagOpenElement(
"text:unordered-list");
663 _openListLevel(pListLevelOpenElement);
665 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pListLevelOpenElement));
668void WordPerfectCollector::_openListLevel(TagOpenElement *pListLevelOpenElement)
670 if (!mbListElementOpened && miCurrentListLevel > 1)
672 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:list-item")));
674 else if (mbListElementParagraphOpened)
676 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:p")));
677 mbListElementParagraphOpened =
false;
680 if (miCurrentListLevel==1) {
681 pListLevelOpenElement->addAttribute(
"text:style-name", mpCurrentListStyle->getName());
684 mbListElementOpened =
false;
687void WordPerfectCollector::closeOrderedListLevel()
689 _closeListLevel(
"ordered-list");
692void WordPerfectCollector::closeUnorderedListLevel()
694 _closeListLevel(
"unordered-list");
697void WordPerfectCollector::_closeListLevel(
const char *szListType)
699 if (mbListElementOpened)
700 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:list-item")));
702 miCurrentListLevel--;
704 _SH_String sCloseElement;
705 sCloseElement.sprintf(
"text:%s", szListType);
706 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(sCloseElement.cstr())));
708 if (miCurrentListLevel > 0)
709 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:list-item")));
710 mbListElementOpened =
false;
713void WordPerfectCollector::openListElement(
const _SH_PropertyList &propList,
const _SH_PropertyListVector &tabStops)
715 miLastListLevel = miCurrentListLevel;
716 if (miCurrentListLevel == 1)
719 if (mbListElementOpened)
720 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:list-item")));
722 ParagraphStyle *pStyle = NULL;
724 _SH_PropertyList *pPersistPropList =
new _SH_PropertyList(propList);
725 pPersistPropList->insert(
"style:list-style-name", mpCurrentListStyle->getName());
726 pPersistPropList->insert(
"style:parent-style-name",
"Standard");
728 _SH_String sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
730 if (mTextStyleHash.find(sKey) == mTextStyleHash.end())
733 sName.sprintf(
"S%i", mTextStyleHash.size());
735 pStyle =
new ParagraphStyle(pPersistPropList, tabStops, sName);
737 mTextStyleHash[sKey] = pStyle;
741 pStyle = mTextStyleHash[sKey];
742 delete pPersistPropList;
745 TagOpenElement *pOpenListElement =
new TagOpenElement(
"text:list-item");
746 TagOpenElement *pOpenListElementParagraph =
new TagOpenElement(
"text:p");
748 pOpenListElementParagraph->addAttribute(
"text:style-name", pStyle->getName());
750 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pOpenListElement));
751 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pOpenListElementParagraph));
753 mbListElementOpened =
true;
754 mbListElementParagraphOpened =
true;
755 mbListContinueNumbering =
false;
758void WordPerfectCollector::closeListElement()
764 if (mbListElementParagraphOpened)
766 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:p")));
767 mbListElementParagraphOpened =
false;
771void WordPerfectCollector::openFootnote(
const _SH_PropertyList &propList)
773 TagOpenElement *pOpenFootNote =
new TagOpenElement(
"text:footnote");
774 if (propList[
"libwpd:number"])
776 _SH_String tmpString(
"ftn");
777 tmpString.append(propList[
"libwpd:number"]->getStr());
778 pOpenFootNote->addAttribute(
"text:id", tmpString);
780 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pOpenFootNote));
782 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:footnote-citation")));
783 if (propList[
"libwpd:number"])
784 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new CharDataElement(propList[
"libwpd:number"]->getStr().cstr())));
785 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:footnote-citation")));
787 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:footnote-body")));
789 mWriterDocumentState.mbInNote =
true;
792void WordPerfectCollector::closeFootnote()
794 mWriterDocumentState.mbInNote =
false;
796 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:footnote-body")));
797 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:footnote")));
800void WordPerfectCollector::openEndnote(
const _SH_PropertyList &propList)
802 TagOpenElement *pOpenEndNote =
new TagOpenElement(
"text:endnote");
803 if (propList[
"libwpd:number"])
805 _SH_String tmpString(
"edn");
806 tmpString.append(propList[
"libwpd:number"]->getStr());
807 pOpenEndNote->addAttribute(
"text:id", tmpString);
809 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pOpenEndNote));
811 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:endnote-citation")));
812 if (propList[
"libwpd:number"])
813 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new CharDataElement(propList[
"libwpd:number"]->getStr().cstr())));
814 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:endnote-citation")));
816 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:endnote-body")));
818 mWriterDocumentState.mbInNote =
true;
821void WordPerfectCollector::closeEndnote()
823 mWriterDocumentState.mbInNote =
false;
825 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:endnote-body")));
826 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:endnote")));
829void WordPerfectCollector::openTable(
const _SH_PropertyList &propList,
const _SH_PropertyListVector &columns)
831 if (!mWriterDocumentState.mbInNote)
833 _SH_String sTableName;
834 sTableName.sprintf(
"Table%i", mTableStyles.size());
839 TableStyle *pTableStyle =
new TableStyle(propList, columns, sTableName.cstr());
841 if (mWriterDocumentState.mbFirstElement && mpCurrentContentElements == &mBodyElements)
843 _SH_String sMasterPageName(
"Page Style 1");
844 pTableStyle->setMasterPageName(sMasterPageName);
845 mWriterDocumentState.mbFirstElement =
false;
848 mTableStyles.push_back(pTableStyle);
850 mpCurrentTableStyle = pTableStyle;
852 TagOpenElement *pTableOpenElement =
new TagOpenElement(
"table:table");
854 pTableOpenElement->addAttribute(
"table:name", sTableName.cstr());
855 pTableOpenElement->addAttribute(
"table:style-name", sTableName.cstr());
856 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pTableOpenElement));
858 for (
int i=0; i<pTableStyle->getNumColumns(); i++)
860 TagOpenElement *pTableColumnOpenElement =
new TagOpenElement(
"table:table-column");
861 _SH_String sColumnStyleName;
862 sColumnStyleName.sprintf(
"%s.Column%i", sTableName.cstr(), (i+1));
863 pTableColumnOpenElement->addAttribute(
"table:style-name", sColumnStyleName.cstr());
864 mpCurrentContentElements->push_back(pTableColumnOpenElement);
866 TagCloseElement *pTableColumnCloseElement =
new TagCloseElement(
"table:table-column");
867 mpCurrentContentElements->push_back(pTableColumnCloseElement);
872void WordPerfectCollector::openTableRow(
const _SH_PropertyList &propList)
874 if (!mWriterDocumentState.mbInNote)
876 if (propList[
"libwpd:is-header-row"] && (propList[
"libwpd:is-header-row"]->getInt()))
878 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"table:table-header-rows")));
879 mWriterDocumentState.mbHeaderRow =
true;
882 _SH_String sTableRowStyleName;
883 sTableRowStyleName.sprintf(
"%s.Row%i", mpCurrentTableStyle->getName().cstr(), mpCurrentTableStyle->getNumTableRowStyles());
884 TableRowStyle *pTableRowStyle =
new TableRowStyle(propList, sTableRowStyleName.cstr());
885 mpCurrentTableStyle->addTableRowStyle(pTableRowStyle);
887 TagOpenElement *pTableRowOpenElement =
new TagOpenElement(
"table:table-row");
888 pTableRowOpenElement->addAttribute(
"table:style-name", sTableRowStyleName);
889 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pTableRowOpenElement));
893void WordPerfectCollector::closeTableRow()
895 if (!mWriterDocumentState.mbInNote)
897 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"table:table-row")));
898 if (mWriterDocumentState.mbHeaderRow)
900 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"table:table-header-rows")));
901 mWriterDocumentState.mbHeaderRow =
false;
906void WordPerfectCollector::openTableCell(
const _SH_PropertyList &propList)
908 if (!mWriterDocumentState.mbInNote)
910 _SH_String sTableCellStyleName;
911 sTableCellStyleName.sprintf(
"%s.Cell%i", mpCurrentTableStyle->getName().cstr(), mpCurrentTableStyle->getNumTableCellStyles());
912 TableCellStyle *pTableCellStyle =
new TableCellStyle(propList, sTableCellStyleName.cstr());
913 mpCurrentTableStyle->addTableCellStyle(pTableCellStyle);
915 TagOpenElement *pTableCellOpenElement =
new TagOpenElement(
"table:table-cell");
916 pTableCellOpenElement->addAttribute(
"table:style-name", sTableCellStyleName);
917 if (propList[
"table:number-columns-spanned"])
918 pTableCellOpenElement->addAttribute(
"table:number-columns-spanned",
919 propList[
"table:number-columns-spanned"]->getStr().cstr());
920 if (propList[
"table:number-rows-spanned"])
921 pTableCellOpenElement->addAttribute(
"table:number-rows-spanned",
922 propList[
"table:number-rows-spanned"]->getStr().cstr());
923 pTableCellOpenElement->addAttribute(
"table:value-type",
"string");
924 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(pTableCellOpenElement));
926 mWriterDocumentState.mbTableCellOpened =
true;
930void WordPerfectCollector::closeTableCell()
932 if (!mWriterDocumentState.mbInNote)
934 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"table:table-cell")));
935 mWriterDocumentState.mbTableCellOpened =
false;
939void WordPerfectCollector::insertCoveredTableCell(
const _SH_PropertyList &propList)
941 if (!mWriterDocumentState.mbInNote)
943 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"table:covered-table-cell")));
944 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"table:covered-table-cell")));
948void WordPerfectCollector::closeTable()
950 if (!mWriterDocumentState.mbInNote)
952 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"table:table")));
957void WordPerfectCollector::insertTab()
959 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:tab-stop")));
960 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:tab-stop")));
963void WordPerfectCollector::insertLineBreak()
965 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagOpenElement(
"text:line-break")));
966 mpCurrentContentElements->push_back(
static_cast<DocumentElement *
>(
new TagCloseElement(
"text:line-break")));
969void WordPerfectCollector::insertText(
const _SH_String &text)
971 DocumentElement *pText =
new TextElement(text);
972 mpCurrentContentElements->push_back(pText);