diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-05-06 23:34:35 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-05-06 23:34:35 +0200 |
commit | 42abd83000315430259cdec332e7175635324c8b (patch) | |
tree | ff2d7c7ecb3faecf83424554bdf6bf7cd0d6b61e /writerperfect | |
parent | Modify class FontList so it's no longer a child of List. (diff) | |
download | core-42abd83000315430259cdec332e7175635324c8b.tar.gz core-42abd83000315430259cdec332e7175635324c8b.zip |
Refactor writerperfect
Diffstat (limited to 'writerperfect')
39 files changed, 2116 insertions, 2367 deletions
diff --git a/writerperfect/source/filter/DocumentCollector.cxx b/writerperfect/source/filter/DocumentCollector.cxx deleted file mode 100644 index 7c3718303335..000000000000 --- a/writerperfect/source/filter/DocumentCollector.cxx +++ /dev/null @@ -1,1317 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* DocumentCollector: Collects sections and runs of text from a - * file (and styles to go along with them) and writes them - * to a Writer target document - * - * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) - * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com) - * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#if defined _MSC_VER -#pragma warning( push, 1 ) -#endif -#include <libwpd/libwpd.h> -#if defined _MSC_VER -#pragma warning( pop ) -#endif -#include <string.h> // for strcmp - -#include "DocumentCollector.hxx" -#include "DocumentElement.hxx" -#include "DocumentHandler.hxx" -#include "InternalHandler.hxx" -#include "TextRunStyle.hxx" -#include "FontStyle.hxx" -#include "ListStyle.hxx" -#include "PageSpan.hxx" -#include "SectionStyle.hxx" -#include "TableStyle.hxx" -#include "FilterInternal.hxx" -#include "WriterProperties.hxx" -#include "OdgExporter.hxx" - -_WriterDocumentState::_WriterDocumentState() : - mbFirstElement(true), - mbFirstParagraphInPageSpan(true), - mbInFakeSection(false), - mbListElementOpenedAtCurrentLevel(false), - mbTableCellOpened(false), - mbHeaderRow(false), - mbInNote(false), - mbInTextBox(false), - mbInFrame(false) -{ -} - -_WriterListState::_WriterListState() : - mpCurrentListStyle(NULL), - miCurrentListLevel(0), - miLastListLevel(0), - miLastListNumber(0), - mbListContinueNumbering(false), - mbListElementParagraphOpened(false), - mbListElementOpened() -{ -} - -DocumentCollector::DocumentCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler) : - mpInput(pInput), - mpHandler(pHandler), - mbUsed(false), - mWriterDocumentStates(), - mWriterListStates(), - mfSectionSpaceAfter(0.0), - miNumListStyles(0), - mpCurrentContentElements(&mBodyElements), - mpCurrentPageSpan(NULL), - miNumPageStyles(0), - miObjectNumber(0), - mbIsFlatXML(true), - mpPassword(NULL) -{ - mWriterDocumentStates.push(WriterDocumentState()); - mWriterListStates.push(WriterListState()); -} - -DocumentCollector::~DocumentCollector() -{ -} - -bool DocumentCollector::filter() -{ - // The contract for DocumentCollector is that it will only be used once after it is - // instantiated - if (mbUsed) - return false; - - mbUsed = true; - - // parse & write - // WLACH_REFACTORING: Remove these args.. - if (!parseSourceDocument(*mpInput)) - return false; - if (!_writeTargetDocument(mpHandler)) - return false; - - // clean up the mess we made - WRITER_DEBUG_MSG(("WriterWordPerfect: Cleaning up our mess..\n")); - - WRITER_DEBUG_MSG(("Destroying the body elements\n")); - for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); ++iterBody) { - delete (*iterBody); - (*iterBody) = NULL; - } - - WRITER_DEBUG_MSG(("Destroying the styles elements\n")); - for (std::vector<DocumentElement *>::iterator iterStyles = mStylesElements.begin(); iterStyles != mStylesElements.end(); ++iterStyles) { - delete (*iterStyles); - (*iterStyles) = NULL; // we may pass over the same element again (in the case of headers/footers spanning multiple pages) - // so make sure we don't do a double del - } - - WRITER_DEBUG_MSG(("Destroying the rest of the styles elements\n")); - for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin(); iterTextStyle != mTextStyleHash.end(); ++iterTextStyle) { - delete (iterTextStyle->second); - } - for (std::map<WPXString, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin(); iterSpanStyle != mSpanStyleHash.end(); ++iterSpanStyle) { - delete(iterSpanStyle->second); - } - - for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); ++iterFont) { - delete(iterFont->second); - } - - for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); ++iterListStyles) { - delete (*iterListStyles); - } - for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); ++iterSectionStyles) { - delete (*iterSectionStyles); - } - for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); ++iterTableStyles) { - delete((*iterTableStyles)); - } - - for (std::vector<PageSpan *>::iterator iterPageSpans = mPageSpans.begin(); iterPageSpans != mPageSpans.end(); ++iterPageSpans) { - delete (*iterPageSpans); - } - for (std::vector<DocumentElement *>::iterator iterFrameStyles = mFrameStyles.begin(); iterFrameStyles != mFrameStyles.end(); ++iterFrameStyles) { - delete(*iterFrameStyles); - } - for (std::vector<DocumentElement *>::iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin(); - iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); ++iterFrameAutomaticStyles) { - delete(*iterFrameAutomaticStyles); - } - for (std::vector<DocumentElement *>::iterator iterMetaData = mMetaData.begin(); iterMetaData != mMetaData.end(); ++iterMetaData) { - delete(*iterMetaData); - } - - return true; -} - -void DocumentCollector::_writeDefaultStyles(DocumentHandlerInterface *pHandler) -{ - TagOpenElement("office:styles").write(pHandler); - - TagOpenElement defaultParagraphStyleOpenElement("style:default-style"); - defaultParagraphStyleOpenElement.addAttribute("style:family", "paragraph"); - defaultParagraphStyleOpenElement.write(pHandler); - - TagOpenElement defaultParagraphStylePropertiesOpenElement("style:paragraph-properties"); - defaultParagraphStylePropertiesOpenElement.addAttribute("style:tab-stop-distance", "0.5in"); - defaultParagraphStylePropertiesOpenElement.write(pHandler); - TagCloseElement defaultParagraphStylePropertiesCloseElement("style:paragraph-properties"); - defaultParagraphStylePropertiesCloseElement.write(pHandler); - - pHandler->endElement("style:default-style"); - - TagOpenElement defaultTableRowStyleOpenElement("style:default-style"); - defaultTableRowStyleOpenElement.addAttribute("style:family", "table-row"); - defaultTableRowStyleOpenElement.write(pHandler); - - TagOpenElement defaultTableRowPropertiesOpenElement("style:table-row-properties"); - defaultTableRowPropertiesOpenElement.addAttribute("fo:keep-together", "auto"); - defaultTableRowPropertiesOpenElement.write(pHandler); - - pHandler->endElement("style:table-row-properties"); - pHandler->endElement("style:default-style"); - - TagOpenElement standardStyleOpenElement("style:style"); - standardStyleOpenElement.addAttribute("style:name", "Standard"); - standardStyleOpenElement.addAttribute("style:family", "paragraph"); - standardStyleOpenElement.addAttribute("style:class", "text"); - standardStyleOpenElement.write(pHandler); - - pHandler->endElement("style:style"); - - TagOpenElement textBodyStyleOpenElement("style:style"); - textBodyStyleOpenElement.addAttribute("style:name", "Text_Body"); - textBodyStyleOpenElement.addAttribute("style:display-name", "Text Body"); - textBodyStyleOpenElement.addAttribute("style:family", "paragraph"); - textBodyStyleOpenElement.addAttribute("style:parent-style-name", "Standard"); - textBodyStyleOpenElement.addAttribute("style:class", "text"); - textBodyStyleOpenElement.write(pHandler); - - pHandler->endElement("style:style"); - - TagOpenElement tableContentsStyleOpenElement("style:style"); - tableContentsStyleOpenElement.addAttribute("style:name", "Table_Contents"); - tableContentsStyleOpenElement.addAttribute("style:display-name", "Table Contents"); - tableContentsStyleOpenElement.addAttribute("style:family", "paragraph"); - tableContentsStyleOpenElement.addAttribute("style:parent-style-name", "Text_Body"); - tableContentsStyleOpenElement.addAttribute("style:class", "extra"); - tableContentsStyleOpenElement.write(pHandler); - - pHandler->endElement("style:style"); - - TagOpenElement tableHeadingStyleOpenElement("style:style"); - tableHeadingStyleOpenElement.addAttribute("style:name", "Table_Heading"); - tableHeadingStyleOpenElement.addAttribute("style:display-name", "Table Heading"); - tableHeadingStyleOpenElement.addAttribute("style:family", "paragraph"); - tableHeadingStyleOpenElement.addAttribute("style:parent-style-name", "Table_Contents"); - tableHeadingStyleOpenElement.addAttribute("style:class", "extra"); - tableHeadingStyleOpenElement.write(pHandler); - - pHandler->endElement("style:style"); - - for (std::vector<DocumentElement *>::const_iterator iter = mFrameStyles.begin(); - iter != mFrameStyles.end(); ++iter) - (*iter)->write(pHandler); - - pHandler->endElement("office:styles"); -} - -void DocumentCollector::_writeMasterPages(DocumentHandlerInterface *pHandler) -{ - TagOpenElement("office:master-styles").write(mpHandler); - int pageNumber = 1; - for (unsigned int i=0; i<mPageSpans.size(); i++) - { - bool bLastPage; - (i == (mPageSpans.size() - 1)) ? bLastPage = true : bLastPage = false; - mPageSpans[i]->writeMasterPages(pageNumber, i, bLastPage, pHandler); - pageNumber += mPageSpans[i]->getSpan(); - } - pHandler->endElement("office:master-styles"); -} - -void DocumentCollector::_writePageLayouts(DocumentHandlerInterface *pHandler) -{ - for (unsigned int i=0; i<mPageSpans.size(); i++) - { - mPageSpans[i]->writePageLayout(i, pHandler); - } -} - -bool DocumentCollector::_writeTargetDocument(DocumentHandlerInterface *pHandler) -{ - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Printing out the header stuff..\n")); - - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Start Document\n")); - mpHandler->startDocument(); - - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: preamble\n")); - WPXPropertyList docContentPropList; - docContentPropList.insert("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"); - docContentPropList.insert("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"); - docContentPropList.insert("xmlns:dc", "http://purl.org/dc/elements/1.1/"); - docContentPropList.insert("xmlns:config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"); - docContentPropList.insert("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"); - docContentPropList.insert("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0"); - docContentPropList.insert("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"); - docContentPropList.insert("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"); - docContentPropList.insert("xmlns:xlink", "http://www.w3.org/1999/xlink"); - docContentPropList.insert("xmlns:number", "http://openoffice.org/2000/datastyle"); - docContentPropList.insert("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"); - docContentPropList.insert("xmlns:chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"); - docContentPropList.insert("xmlns:dr3d", "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"); - docContentPropList.insert("xmlns:math", "http://www.w3.org/1998/Math/MathML"); - docContentPropList.insert("xmlns:form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0"); - docContentPropList.insert("xmlns:script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0"); - docContentPropList.insert("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0"); - docContentPropList.insert("office:version", "1.0"); - docContentPropList.insert("office:mimetype", "application/vnd.oasis.opendocument.text"); - mpHandler->startElement("office:document", docContentPropList); - - // write out the metadata - TagOpenElement("office:meta").write(mpHandler); - for (std::vector<DocumentElement *>::const_iterator iterMetaData = mMetaData.begin(); iterMetaData != mMetaData.end(); ++iterMetaData) { - (*iterMetaData)->write(mpHandler); - } - mpHandler->endElement("office:meta"); - - // write out the font styles - TagOpenElement("office:font-face-decls").write(mpHandler); - for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); ++iterFont) { - iterFont->second->write(mpHandler); - } - TagOpenElement symbolFontOpen("style:font-face"); - symbolFontOpen.addAttribute("style:name", "StarSymbol"); - symbolFontOpen.addAttribute("svg:font-family", "StarSymbol"); - symbolFontOpen.addAttribute("style:font-charset", "x-symbol"); - symbolFontOpen.write(mpHandler); - mpHandler->endElement("style:font-face"); - - mpHandler->endElement("office:font-face-decls"); - - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the styles..\n")); - - // write default styles - _writeDefaultStyles(mpHandler); - - TagOpenElement("office:automatic-styles").write(mpHandler); - - for (std::vector<DocumentElement *>::const_iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin(); - iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); ++iterFrameAutomaticStyles) - { - (*iterFrameAutomaticStyles)->write(pHandler); - } - - for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iterTextStyle = mTextStyleHash.begin(); - iterTextStyle != mTextStyleHash.end(); ++iterTextStyle) - { - // writing out the paragraph styles - if (strcmp((iterTextStyle->second)->getName().cstr(), "Standard")) - { - // don't write standard paragraph "no styles" style - (iterTextStyle->second)->write(pHandler); - } - } - - // span styles.. - for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iterSpanStyle = mSpanStyleHash.begin(); - iterSpanStyle != mSpanStyleHash.end(); ++iterSpanStyle) - { - (iterSpanStyle->second)->write(pHandler); - } - - // writing out the sections styles - for (std::vector<SectionStyle *>::const_iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); ++iterSectionStyles) { - (*iterSectionStyles)->write(pHandler); - } - - // writing out the lists styles - for (std::vector<ListStyle *>::const_iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); ++iterListStyles) { - (*iterListStyles)->write(pHandler); - } - - // writing out the table styles - for (std::vector<TableStyle *>::const_iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); ++iterTableStyles) { - (*iterTableStyles)->write(pHandler); - } - - // writing out the page masters - _writePageLayouts(pHandler); - - - pHandler->endElement("office:automatic-styles"); - - _writeMasterPages(pHandler); - - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the document..\n")); - // writing out the document - TagOpenElement("office:body").write(mpHandler); - TagOpenElement("office:text").write(mpHandler); - - for (std::vector<DocumentElement *>::const_iterator iterBodyElements = mBodyElements.begin(); iterBodyElements != mBodyElements.end(); ++iterBodyElements) { - (*iterBodyElements)->write(pHandler); - } - WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Finished writing all doc els..\n")); - - pHandler->endElement("office:text"); - pHandler->endElement("office:body"); - pHandler->endElement("office:document"); - - pHandler->endDocument(); - - return true; -} - - -WPXString propListToStyleKey(const WPXPropertyList & xPropList) -{ - WPXString sKey; - WPXPropertyList::Iter i(xPropList); - for (i.rewind(); i.next(); ) - { - WPXString sProp; - sProp.sprintf("[%s:%s]", i.key(), i()->getStr().cstr()); - sKey.append(sProp); - } - - return sKey; -} - -WPXString getParagraphStyleKey(const WPXPropertyList & xPropList, const WPXPropertyListVector & xTabStops) -{ - WPXString sKey = propListToStyleKey(xPropList); - - WPXString sTabStops; - sTabStops.sprintf("[num-tab-stops:%i]", xTabStops.count()); - WPXPropertyListVector::Iter i(xTabStops); - for (i.rewind(); i.next();) - { - sTabStops.append(propListToStyleKey(i())); - } - sKey.append(sTabStops); - - return sKey; -} - -// _allocateFontName: add a (potentially mapped) font style to the hash if it's not already there, do nothing otherwise -void DocumentCollector::_allocateFontName(const WPXString & sFontName) -{ - if (mFontHash.find(sFontName) == mFontHash.end()) - { - FontStyle *pFontStyle = new FontStyle(sFontName.cstr(), sFontName.cstr()); - mFontHash[sFontName] = pFontStyle; - } -} - -void DocumentCollector::setDocumentMetaData(const WPXPropertyList &propList) -{ - WPXPropertyList::Iter i(propList); - for (i.rewind(); i.next(); ) - { - // filter out libwpd elements - if (strncmp(i.key(), "libwpd", 6) != 0 && strncmp(i.key(), "dcterms", 7) != 0) - { - mMetaData.push_back(new TagOpenElement(i.key())); - WPXString sStringValue(i()->getStr(), true); - mMetaData.push_back(new CharDataElement(sStringValue.cstr())); - mMetaData.push_back(new TagCloseElement(i.key())); - } - } - -} - -void DocumentCollector::openPageSpan(const WPXPropertyList &propList) -{ - PageSpan *pPageSpan = new PageSpan(propList); - mPageSpans.push_back(pPageSpan); - mpCurrentPageSpan = pPageSpan; - miNumPageStyles++; - - mWriterDocumentStates.top().mbFirstParagraphInPageSpan = true; -} - -static bool -isOccurrenceEven (const WPXPropertyList &propList) -{ - const WPXProperty *occurance = propList["libwpd:occurence"]; - return occurance && occurance->getStr() == "even"; -} - -void DocumentCollector::openHeader(const WPXPropertyList &propList) -{ - std::vector<DocumentElement *> * pHeaderFooterContentElements = new std::vector<DocumentElement *>; - if (isOccurrenceEven (propList)) - mpCurrentPageSpan->setHeaderLeftContent(pHeaderFooterContentElements); - else - mpCurrentPageSpan->setHeaderContent(pHeaderFooterContentElements); - - mpCurrentContentElements = pHeaderFooterContentElements; -} - -void DocumentCollector::closeHeader() -{ - mpCurrentContentElements = &mBodyElements; -} - -void DocumentCollector::openFooter(const WPXPropertyList &propList) -{ - std::vector<DocumentElement *> * pHeaderFooterContentElements = new std::vector<DocumentElement *>; - - if (isOccurrenceEven (propList)) - mpCurrentPageSpan->setFooterLeftContent(pHeaderFooterContentElements); - else - mpCurrentPageSpan->setFooterContent(pHeaderFooterContentElements); - - mpCurrentContentElements = pHeaderFooterContentElements; -} - -void DocumentCollector::closeFooter() -{ - mpCurrentContentElements = &mBodyElements; -} - -void DocumentCollector::openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns) -{ - int iNumColumns = columns.count(); - double fSectionMarginLeft = 0.0; - double fSectionMarginRight = 0.0; - if (propList["fo:margin-left"]) - fSectionMarginLeft = propList["fo:margin-left"]->getDouble(); - if (propList["fo:margin-right"]) - fSectionMarginRight = propList["fo:margin-right"]->getDouble(); - - if (iNumColumns > 1 || fSectionMarginLeft != 0 || fSectionMarginRight != 0) - { - if (propList["fo:margin-bottom"]) - mfSectionSpaceAfter = propList["fo:margin-bottom"]->getDouble(); - else if (propList["libwpd:margin-bottom"]) - mfSectionSpaceAfter = propList["libwpd:margin-bottom"]->getDouble(); - - WPXString sSectionName; - sSectionName.sprintf("Section%i", mSectionStyles.size()); - - SectionStyle *pSectionStyle = new SectionStyle(propList, columns, sSectionName.cstr()); - mSectionStyles.push_back(pSectionStyle); - - TagOpenElement *pSectionOpenElement = new TagOpenElement("text:section"); - pSectionOpenElement->addAttribute("text:style-name", pSectionStyle->getName()); - pSectionOpenElement->addAttribute("text:name", pSectionStyle->getName()); - mpCurrentContentElements->push_back(pSectionOpenElement); - } - else - mWriterDocumentStates.top().mbInFakeSection = true; -} - -void DocumentCollector::closeSection() -{ - if (!mWriterDocumentStates.top().mbInFakeSection) - mpCurrentContentElements->push_back(new TagCloseElement("text:section")); - else - mWriterDocumentStates.top().mbInFakeSection = false; - - mfSectionSpaceAfter = 0.0; -} - -void DocumentCollector::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - // FIXMENOW: What happens if we open a footnote inside a table? do we then inherit the footnote's style - // from "Table Contents" - - WPXPropertyList *pPersistPropList = new WPXPropertyList(propList); - ParagraphStyle *pStyle = NULL; - - if (mWriterDocumentStates.top().mbFirstElement && mpCurrentContentElements == &mBodyElements) - { - // we don't have to go through the fuss of determining if the paragraph style is - // unique in this case, because if we are the first document element, then we - // are singular. Neither do we have to determine what our parent style is-- we can't - // be inside a table in this case (the table would be the first document element - //in that case) - pPersistPropList->insert("style:parent-style-name", "Standard"); - WPXString sName; - sName.sprintf("FS"); - - WPXString sParagraphHashKey("P|FS"); - pPersistPropList->insert("style:master-page-name", "Page_Style_1"); - pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); - mTextStyleHash[sParagraphHashKey] = pStyle; - mWriterDocumentStates.top().mbFirstElement = false; - mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; - } - else - { - if (mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpCurrentContentElements == &mBodyElements) - { - WPXString sPageStyleName; - sPageStyleName.sprintf("Page_Style_%i", miNumPageStyles); - pPersistPropList->insert("style:master-page-name", sPageStyleName); - mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; - } - - if (mWriterDocumentStates.top().mbTableCellOpened) - { - if (mWriterDocumentStates.top().mbHeaderRow) - pPersistPropList->insert("style:parent-style-name", "Table_Heading"); - else - pPersistPropList->insert("style:parent-style-name", "Table_Contents"); - } - else - pPersistPropList->insert("style:parent-style-name", "Standard"); - - WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops); - - if (mTextStyleHash.find(sKey) == mTextStyleHash.end()) - { - WPXString sName; - sName.sprintf("S%i", mTextStyleHash.size()); - - pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); - - mTextStyleHash[sKey] = pStyle; - } - else - { - pStyle = mTextStyleHash[sKey]; - delete pPersistPropList; - } - } - // create a document element corresponding to the paragraph, and append it to our list of document elements - TagOpenElement *pParagraphOpenElement = new TagOpenElement("text:p"); - pParagraphOpenElement->addAttribute("text:style-name", pStyle->getName()); - mpCurrentContentElements->push_back(pParagraphOpenElement); -} - -void DocumentCollector::closeParagraph() -{ - mpCurrentContentElements->push_back(new TagCloseElement("text:p")); -} - -void DocumentCollector::openSpan(const WPXPropertyList &propList) -{ - if (propList["style:font-name"]) - _allocateFontName(propList["style:font-name"]->getStr()); - WPXString sSpanHashKey = propListToStyleKey(propList); - WRITER_DEBUG_MSG(("WriterWordPerfect: Span Hash Key: %s\n", sSpanHashKey.cstr())); - - // Get the style - WPXString sName; - if (mSpanStyleHash.find(sSpanHashKey) == mSpanStyleHash.end()) - { - // allocate a new paragraph style - sName.sprintf("Span%i", mSpanStyleHash.size()); - SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList); - - mSpanStyleHash[sSpanHashKey] = pStyle; - } - else - { - sName.sprintf("%s", mSpanStyleHash.find(sSpanHashKey)->second->getName().cstr()); - } - - // create a document element corresponding to the paragraph, and append it to our list of document elements - TagOpenElement *pSpanOpenElement = new TagOpenElement("text:span"); - pSpanOpenElement->addAttribute("text:style-name", sName.cstr()); - mpCurrentContentElements->push_back(pSpanOpenElement); -} - -void DocumentCollector::closeSpan() -{ - mpCurrentContentElements->push_back(new TagCloseElement("text:span")); -} - -void DocumentCollector::defineOrderedListLevel(const WPXPropertyList &propList) -{ - int id = 0; - if (propList["libwpd:id"]) - id = propList["libwpd:id"]->getInt(); - - OrderedListStyle *pOrderedListStyle = NULL; - if (mWriterListStates.top().mpCurrentListStyle && mWriterListStates.top().mpCurrentListStyle->getListID() == id) - pOrderedListStyle = static_cast<OrderedListStyle *>(mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?! - - // this rather appalling conditional makes sure we only start a new list (rather than continue an old - // one) if: (1) we have no prior list OR (2) the prior list is actually definitively different - // from the list that is just being defined (listIDs differ) OR (3) we can tell that the user actually - // is starting a new list at level 1 (and only level 1) - if (pOrderedListStyle == NULL || pOrderedListStyle->getListID() != id || - (propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 && - (propList["text:start-value"] && propList["text:start-value"]->getInt() != static_cast<int>(mWriterListStates.top().miLastListNumber+1)))) - { - WRITER_DEBUG_MSG(("Attempting to create a new ordered list style (listid: %i)\n", id)); - WPXString sName; - sName.sprintf("OL%i", miNumListStyles); - miNumListStyles++; - pOrderedListStyle = new OrderedListStyle(sName.cstr(), id); - mListStyles.push_back(pOrderedListStyle); - mWriterListStates.top().mpCurrentListStyle = pOrderedListStyle; - mWriterListStates.top().mbListContinueNumbering = false; - mWriterListStates.top().miLastListNumber = 0; - } - else - mWriterListStates.top().mbListContinueNumbering = true; - - // Iterate through ALL list styles with the same WordPerfect list id and define a level if it is not already defined - // This solves certain problems with lists that start and finish without reaching certain levels and then begin again - // and reach those levels. See gradguide0405_PC.wpd in the regression suite - for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mListStyles.begin(); iterOrderedListStyles != mListStyles.end(); ++iterOrderedListStyles) - { - if ((* iterOrderedListStyles)->getListID() == id) - (* iterOrderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList); - } -} - -void DocumentCollector::defineUnorderedListLevel(const WPXPropertyList &propList) -{ - int id = 0; - if (propList["libwpd:id"]) - id = propList["libwpd:id"]->getInt(); - - UnorderedListStyle *pUnorderedListStyle = NULL; - if (mWriterListStates.top().mpCurrentListStyle && mWriterListStates.top().mpCurrentListStyle->getListID() == id) - pUnorderedListStyle = static_cast<UnorderedListStyle *>(mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?! - - if (pUnorderedListStyle == NULL) { - WRITER_DEBUG_MSG(("Attempting to create a new unordered list style (listid: %i)\n", id)); - WPXString sName; - sName.sprintf("UL%i", miNumListStyles); - miNumListStyles++; - pUnorderedListStyle = new UnorderedListStyle(sName.cstr(), id); - mListStyles.push_back(pUnorderedListStyle); - mWriterListStates.top().mpCurrentListStyle = pUnorderedListStyle; - } - - // See comment in DocumentCollector::defineOrderedListLevel - for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mListStyles.begin(); iterUnorderedListStyles != mListStyles.end(); ++iterUnorderedListStyles) - { - if ((* iterUnorderedListStyles)->getListID() == id) - (* iterUnorderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList); - } -} - -void DocumentCollector::openOrderedListLevel(const WPXPropertyList & /* propList */) -{ - if (mWriterListStates.top().mbListElementParagraphOpened) - { - mpCurrentContentElements->push_back(new TagCloseElement("text:p")); - mWriterListStates.top().mbListElementParagraphOpened = false; - } - TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list"); - _openListLevel(pListLevelOpenElement); - - if (mWriterListStates.top().mbListContinueNumbering) { - pListLevelOpenElement->addAttribute("text:continue-numbering", "true"); - } - - mpCurrentContentElements->push_back(pListLevelOpenElement); -} - -void DocumentCollector::openUnorderedListLevel(const WPXPropertyList & /* propList */) -{ - if (mWriterListStates.top().mbListElementParagraphOpened) - { - mpCurrentContentElements->push_back(new TagCloseElement("text:p")); - mWriterListStates.top().mbListElementParagraphOpened = false; - } - TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list"); - _openListLevel(pListLevelOpenElement); - - mpCurrentContentElements->push_back(pListLevelOpenElement); -} - -void DocumentCollector::_openListLevel(TagOpenElement *pListLevelOpenElement) -{ - if (!mWriterListStates.top().mbListElementOpened.empty() && - !mWriterListStates.top().mbListElementOpened.top()) - { - mpCurrentContentElements->push_back(new TagOpenElement("text:list-item")); - mWriterListStates.top().mbListElementOpened.top() = true; - } - - mWriterListStates.top().mbListElementOpened.push(false); - if (mWriterListStates.top().mbListElementOpened.size() == 1) { - pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName()); - } -} - -void DocumentCollector::closeOrderedListLevel() -{ - _closeListLevel(); -} - -void DocumentCollector::closeUnorderedListLevel() -{ - _closeListLevel(); -} - -void DocumentCollector::_closeListLevel() -{ - if (mWriterListStates.top().mbListElementOpened.top()) - { - mpCurrentContentElements->push_back(new TagCloseElement("text:list-item")); - mWriterListStates.top().mbListElementOpened.top() = false; - } - - mpCurrentContentElements->push_back(new TagCloseElement("text:list")); - - if (!mWriterListStates.top().mbListElementOpened.empty()) - { - mWriterListStates.top().mbListElementOpened.pop(); - } -} - -void DocumentCollector::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - mWriterListStates.top().miLastListLevel = mWriterListStates.top().miCurrentListLevel; - if (mWriterListStates.top().miCurrentListLevel == 1) - mWriterListStates.top().miLastListNumber++; - - if (mWriterListStates.top().mbListElementOpened.top()) - { - mpCurrentContentElements->push_back(new TagCloseElement("text:list-item")); - mWriterListStates.top().mbListElementOpened.top() = false; - } - - ParagraphStyle *pStyle = NULL; - - WPXPropertyList *pPersistPropList = new WPXPropertyList(propList); - pPersistPropList->insert("style:list-style-name", mWriterListStates.top().mpCurrentListStyle->getName()); - pPersistPropList->insert("style:parent-style-name", "Standard"); - - WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops); - - if (mTextStyleHash.find(sKey) == mTextStyleHash.end()) - { - WPXString sName; - sName.sprintf("S%i", mTextStyleHash.size()); - - pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); - - mTextStyleHash[sKey] = pStyle; - } - else - { - pStyle = mTextStyleHash[sKey]; - delete pPersistPropList; - } - - mpCurrentContentElements->push_back(new TagOpenElement("text:list-item")); - - TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p"); - pOpenListElementParagraph->addAttribute("text:style-name", pStyle->getName()); - mpCurrentContentElements->push_back(pOpenListElementParagraph); - - if (mpCurrentContentElements == &mBodyElements) - mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; - - mWriterListStates.top().mbListElementOpened.top() = true; - mWriterListStates.top().mbListElementParagraphOpened = true; - mWriterListStates.top().mbListContinueNumbering = false; -} - -void DocumentCollector::closeListElement() -{ - // this code is kind of tricky, because we don't actually close the list element (because this list element - // could contain another list level in OOo's implementation of lists). that is done in the closeListLevel - // code (or when we open another list element) - - if (mWriterListStates.top().mbListElementParagraphOpened) - { - mpCurrentContentElements->push_back(new TagCloseElement("text:p")); - mWriterListStates.top().mbListElementParagraphOpened = false; - } -} - -void DocumentCollector::openFootnote(const WPXPropertyList &propList) -{ - mWriterListStates.push(WriterListState()); - TagOpenElement *pOpenFootNote = new TagOpenElement("text:note"); - pOpenFootNote->addAttribute("text:note-class", "footnote"); - if (propList["libwpd:number"]) - { - WPXString tmpString("ftn"); - tmpString.append(propList["libwpd:number"]->getStr()); - pOpenFootNote->addAttribute("text:id", tmpString); - } - mpCurrentContentElements->push_back(pOpenFootNote); - - mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation")); - if (propList["libwpd:number"]) - mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr())); - mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation")); - - mpCurrentContentElements->push_back(new TagOpenElement("text:note-body")); - - mWriterDocumentStates.top().mbInNote = true; -} - -void DocumentCollector::closeFootnote() -{ - mWriterDocumentStates.top().mbInNote = false; - if (mWriterListStates.size() > 1) - mWriterListStates.pop(); - - mpCurrentContentElements->push_back(new TagCloseElement("text:note-body")); - mpCurrentContentElements->push_back(new TagCloseElement("text:note")); -} - -void DocumentCollector::openEndnote(const WPXPropertyList &propList) -{ - mWriterListStates.push(WriterListState()); - TagOpenElement *pOpenEndNote = new TagOpenElement("text:note"); - pOpenEndNote->addAttribute("text:note-class", "endnote"); - if (propList["libwpd:number"]) - { - WPXString tmpString("edn"); - tmpString.append(propList["libwpd:number"]->getStr()); - pOpenEndNote->addAttribute("text:id", tmpString); - } - mpCurrentContentElements->push_back(pOpenEndNote); - - mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation")); - if (propList["libwpd:number"]) - mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr())); - mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation")); - - mpCurrentContentElements->push_back(new TagOpenElement("text:note-body")); - - mWriterDocumentStates.top().mbInNote = true; -} - -void DocumentCollector::closeEndnote() -{ - mWriterDocumentStates.top().mbInNote = false; - if (mWriterListStates.size() > 1) - mWriterListStates.pop(); - - mpCurrentContentElements->push_back(new TagCloseElement("text:note-body")); - mpCurrentContentElements->push_back(new TagCloseElement("text:note")); -} - -void DocumentCollector::openComment(const WPXPropertyList & /*propList*/) -{ - mWriterListStates.push(WriterListState()); - mpCurrentContentElements->push_back(new TagOpenElement("office:annotation")); - - mWriterDocumentStates.top().mbInNote = true; -} - -void DocumentCollector::closeComment() -{ - mWriterDocumentStates.top().mbInNote = false; - if (mWriterListStates.size() > 1) - mWriterListStates.pop(); - - mpCurrentContentElements->push_back(new TagCloseElement("office:annotation")); -} - -void DocumentCollector::openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns) -{ - if (!mWriterDocumentStates.top().mbInNote) - { - WPXString sTableName; - sTableName.sprintf("Table%i", mTableStyles.size()); - - // FIXME: we base the table style off of the page's margin left, ignoring (potential) wordperfect margin - // state which is transmitted inside the page. could this lead to unacceptable behaviour? - // WLACH_REFACTORING: characterize this behaviour, probably should nip it at the bud within libwpd - TableStyle *pTableStyle = new TableStyle(propList, columns, sTableName.cstr()); - - if (mWriterDocumentStates.top().mbFirstElement && mpCurrentContentElements == &mBodyElements) - { - WPXString sMasterPageName("Page_Style_1"); - pTableStyle->setMasterPageName(sMasterPageName); - mWriterDocumentStates.top().mbFirstElement = false; - } - - mTableStyles.push_back(pTableStyle); - - mpCurrentTableStyle = pTableStyle; - - TagOpenElement *pTableOpenElement = new TagOpenElement("table:table"); - - pTableOpenElement->addAttribute("table:name", sTableName.cstr()); - pTableOpenElement->addAttribute("table:style-name", sTableName.cstr()); - mpCurrentContentElements->push_back(pTableOpenElement); - - for (int i=0; i<pTableStyle->getNumColumns(); i++) - { - TagOpenElement *pTableColumnOpenElement = new TagOpenElement("table:table-column"); - WPXString sColumnStyleName; - sColumnStyleName.sprintf("%s.Column%i", sTableName.cstr(), (i+1)); - pTableColumnOpenElement->addAttribute("table:style-name", sColumnStyleName.cstr()); - mpCurrentContentElements->push_back(pTableColumnOpenElement); - - TagCloseElement *pTableColumnCloseElement = new TagCloseElement("table:table-column"); - mpCurrentContentElements->push_back(pTableColumnCloseElement); - } -} -} - -void DocumentCollector::openTableRow(const WPXPropertyList &propList) -{ - if (!mWriterDocumentStates.top().mbInNote) - { - if (propList["libwpd:is-header-row"] && (propList["libwpd:is-header-row"]->getInt())) - { - mpCurrentContentElements->push_back(new TagOpenElement("table:table-header-rows")); - mWriterDocumentStates.top().mbHeaderRow = true; - } - - WPXString sTableRowStyleName; - sTableRowStyleName.sprintf("%s.Row%i", mpCurrentTableStyle->getName().cstr(), mpCurrentTableStyle->getNumTableRowStyles()); - TableRowStyle *pTableRowStyle = new TableRowStyle(propList, sTableRowStyleName.cstr()); - mpCurrentTableStyle->addTableRowStyle(pTableRowStyle); - - TagOpenElement *pTableRowOpenElement = new TagOpenElement("table:table-row"); - pTableRowOpenElement->addAttribute("table:style-name", sTableRowStyleName); - mpCurrentContentElements->push_back(pTableRowOpenElement); - } -} - -void DocumentCollector::closeTableRow() -{ - if (!mWriterDocumentStates.top().mbInNote) - { - mpCurrentContentElements->push_back(new TagCloseElement("table:table-row")); - if (mWriterDocumentStates.top().mbHeaderRow) - { - mpCurrentContentElements->push_back(new TagCloseElement("table:table-header-rows")); - mWriterDocumentStates.top().mbHeaderRow = false; - } - } -} - -void DocumentCollector::openTableCell(const WPXPropertyList &propList) -{ - if (!mWriterDocumentStates.top().mbInNote) - { - WPXString sTableCellStyleName; - sTableCellStyleName.sprintf( "%s.Cell%i", mpCurrentTableStyle->getName().cstr(), mpCurrentTableStyle->getNumTableCellStyles()); - TableCellStyle *pTableCellStyle = new TableCellStyle(propList, sTableCellStyleName.cstr()); - mpCurrentTableStyle->addTableCellStyle(pTableCellStyle); - - TagOpenElement *pTableCellOpenElement = new TagOpenElement("table:table-cell"); - pTableCellOpenElement->addAttribute("table:style-name", sTableCellStyleName); - if (propList["table:number-columns-spanned"]) - pTableCellOpenElement->addAttribute("table:number-columns-spanned", - propList["table:number-columns-spanned"]->getStr().cstr()); - if (propList["table:number-rows-spanned"]) - pTableCellOpenElement->addAttribute("table:number-rows-spanned", - propList["table:number-rows-spanned"]->getStr().cstr()); - mpCurrentContentElements->push_back(pTableCellOpenElement); - - mWriterDocumentStates.top().mbTableCellOpened = true; - } -} - -void DocumentCollector::closeTableCell() -{ - if (!mWriterDocumentStates.top().mbInNote) - { - mpCurrentContentElements->push_back(new TagCloseElement("table:table-cell")); - mWriterDocumentStates.top().mbTableCellOpened = false; - } -} - -void DocumentCollector::insertCoveredTableCell(const WPXPropertyList & /* propList */) -{ - if (!mWriterDocumentStates.top().mbInNote) - { - mpCurrentContentElements->push_back(new TagOpenElement("table:covered-table-cell")); - mpCurrentContentElements->push_back(new TagCloseElement("table:covered-table-cell")); - } -} - -void DocumentCollector::closeTable() -{ - if (!mWriterDocumentStates.top().mbInNote) - { - mpCurrentContentElements->push_back(new TagCloseElement("table:table")); - } -} - - -void DocumentCollector::insertTab() -{ - mpCurrentContentElements->push_back(new TagOpenElement("text:tab")); - mpCurrentContentElements->push_back(new TagCloseElement("text:tab")); -} - -void DocumentCollector::insertSpace() -{ - mpCurrentContentElements->push_back(new TagOpenElement("text:s")); - mpCurrentContentElements->push_back(new TagCloseElement("text:s")); -} - -void DocumentCollector::insertLineBreak() -{ - mpCurrentContentElements->push_back(new TagOpenElement("text:line-break")); - mpCurrentContentElements->push_back(new TagCloseElement("text:line-break")); -} - -void DocumentCollector::insertField(const WPXString &type, const WPXPropertyList &propList) -{ - if (!type.len()) - return; - - TagOpenElement *openElement = new TagOpenElement(type.cstr()); - if (type == "text:page-number") - openElement->addAttribute("text:select-page", "current"); - - if (propList["style:num-format"]) - openElement->addAttribute("style:num-format", propList["style:num-format"]->getStr()); - - mpCurrentContentElements->push_back(openElement); - mpCurrentContentElements->push_back(new TagCloseElement(type.cstr())); -} - -void DocumentCollector::insertText(const WPXString &text) -{ - DocumentElement *pText = new TextElement(text); - mpCurrentContentElements->push_back(pText); -} - -void DocumentCollector::openFrame(const WPXPropertyList &propList) -{ - mWriterListStates.push(WriterListState()); - - // First, let's create a Frame Style for this box - TagOpenElement *frameStyleOpenElement = new TagOpenElement("style:style"); - WPXString frameStyleName; - frameStyleName.sprintf("GraphicFrame_%i", miObjectNumber); - frameStyleOpenElement->addAttribute("style:name", frameStyleName); - frameStyleOpenElement->addAttribute("style:family", "graphic"); - - mFrameStyles.push_back(frameStyleOpenElement); - - TagOpenElement *frameStylePropertiesOpenElement = new TagOpenElement("style:graphic-properties"); - - if (propList["text:anchor-type"]) - frameStylePropertiesOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr()); - else - frameStylePropertiesOpenElement->addAttribute("text:anchor-type","paragraph"); - - if (propList["text:anchor-page-number"]) - frameStylePropertiesOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr()); - - if (propList["svg:x"]) - frameStylePropertiesOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr()); - - if (propList["svg:y"]) - frameStylePropertiesOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr()); - - if (propList["svg:width"]) - frameStylePropertiesOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr()); - - if (propList["svg:height"]) - frameStylePropertiesOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr()); - - if (propList["style:rel-width"]) - frameStylePropertiesOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr()); - - if (propList["style:rel-height"]) - frameStylePropertiesOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr()); - - if (propList["fo:max-width"]) - frameStylePropertiesOpenElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr()); - - if (propList["fo:max-height"]) - frameStylePropertiesOpenElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); - - if (propList["style:wrap"]) - frameStylePropertiesOpenElement->addAttribute("style:wrap", propList["style:wrap"]->getStr()); - - mFrameStyles.push_back(frameStylePropertiesOpenElement); - - mFrameStyles.push_back(new TagCloseElement("style:graphic-properties")); - - mFrameStyles.push_back(new TagCloseElement("style:style")); - - // Now, let's create an automatic style for this frame - TagOpenElement *frameAutomaticStyleElement = new TagOpenElement("style:style"); - WPXString frameAutomaticStyleName; - frameAutomaticStyleName.sprintf("fr%i", miObjectNumber); - frameAutomaticStyleElement->addAttribute("style:name", frameAutomaticStyleName); - frameAutomaticStyleElement->addAttribute("style:family", "graphic"); - frameAutomaticStyleElement->addAttribute("style:parent-style-name", frameStyleName); - - mFrameAutomaticStyles.push_back(frameAutomaticStyleElement); - - TagOpenElement *frameAutomaticStylePropertiesElement = new TagOpenElement("style:graphic-properties"); - if (propList["style:horizontal-pos"]) - frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", propList["style:horizontal-pos"]->getStr()); - else - frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", "left"); - - if (propList["style:horizontal-rel"]) - frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", propList["style:horizontal-rel"]->getStr()); - else - frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", "paragraph"); - - if (propList["style:vertical-pos"]) - frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", propList["style:vertical-pos"]->getStr()); - else - frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", "top"); - - if (propList["style:vertical-rel"]) - frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", propList["style:vertical-rel"]->getStr()); - else - frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", "page-content"); - - if (propList["fo:max-width"]) - frameAutomaticStylePropertiesElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr()); - - if (propList["fo:max-height"]) - frameAutomaticStylePropertiesElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); - - frameAutomaticStylePropertiesElement->addAttribute("draw:ole-draw-aspect", "1"); - - mFrameAutomaticStyles.push_back(frameAutomaticStylePropertiesElement); - - mFrameAutomaticStyles.push_back(new TagCloseElement("style:graphic-properties")); - - mFrameAutomaticStyles.push_back(new TagCloseElement("style:style")); - - // And write the frame itself - TagOpenElement *drawFrameOpenElement = new TagOpenElement("draw:frame"); - - drawFrameOpenElement->addAttribute("draw:style-name", frameAutomaticStyleName); - WPXString objectName; - objectName.sprintf("Object%i", miObjectNumber++); - drawFrameOpenElement->addAttribute("draw:name", objectName); - if (propList["text:anchor-type"]) - drawFrameOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr()); - else - drawFrameOpenElement->addAttribute("text:anchor-type","paragraph"); - - if (propList["text:anchor-page-number"]) - drawFrameOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr()); - - if (propList["svg:x"]) - drawFrameOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr()); - - if (propList["svg:y"]) - drawFrameOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr()); - - if (propList["svg:width"]) - drawFrameOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr()); - - if (propList["svg:height"]) - drawFrameOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr()); - - if (propList["style:rel-width"]) - drawFrameOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr()); - - if (propList["style:rel-height"]) - drawFrameOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr()); - - mpCurrentContentElements->push_back(drawFrameOpenElement); - - mWriterDocumentStates.top().mbInFrame = true; -} - -void DocumentCollector::closeFrame() -{ - if (mWriterListStates.size() > 1) - mWriterListStates.pop(); - - mpCurrentContentElements->push_back(new TagCloseElement("draw:frame")); - - mWriterDocumentStates.top().mbInFrame = false; -} - -void DocumentCollector::insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data) -{ - if (!data.size()) - return; - if (!mWriterDocumentStates.top().mbInFrame) // Embedded objects without a frame simply don't make sense for us - return; - if (!propList["libwpd:mimetype"]) - return; - - if (propList["libwpd:mimetype"]->getStr() == "image/x-wpg") - { - std::vector<DocumentElement *> tmpContentElements; - InternalHandler tmpHandler(&tmpContentElements); - OdgExporter exporter(&tmpHandler); - - libwpg::WPGFileFormat fileFormat = libwpg::WPG_AUTODETECT; - - if (!libwpg::WPGraphics::isSupported(const_cast<WPXInputStream *>(data.getDataStream()))) - fileFormat = libwpg::WPG_WPG1; - - if (libwpg::WPGraphics::parse(const_cast<WPXInputStream *>(data.getDataStream()), &exporter, fileFormat) && !tmpContentElements.empty()) - { - mpCurrentContentElements->push_back(new TagOpenElement("draw:object")); - for (std::vector<DocumentElement *>::const_iterator iter = tmpContentElements.begin(); iter != tmpContentElements.end(); ++iter) - mpCurrentContentElements->push_back(*iter); - mpCurrentContentElements->push_back(new TagCloseElement("draw:object")); - } - } - else - { - mpCurrentContentElements->push_back(new TagOpenElement("draw:image")); - - mpCurrentContentElements->push_back(new TagOpenElement("office:binary-data")); - - WPXString binaryBase64Data = data.getBase64Data(); - - mpCurrentContentElements->push_back(new CharDataElement(binaryBase64Data.cstr())); - - mpCurrentContentElements->push_back(new TagCloseElement("office:binary-data")); - - mpCurrentContentElements->push_back(new TagCloseElement("draw:image")); - } -} - -void DocumentCollector::openTextBox(const WPXPropertyList & /*propList*/) -{ - if (!mWriterDocumentStates.top().mbInFrame) // Text box without a frame simply doesn't make sense for us - return; - mWriterListStates.push(WriterListState()); - mWriterDocumentStates.push(WriterDocumentState()); - mpCurrentContentElements->push_back(new TagOpenElement("draw:text-box")); - mWriterDocumentStates.top().mbInTextBox = true; - mWriterDocumentStates.top().mbFirstElement = false; -} - -void DocumentCollector::closeTextBox() -{ - if (!mWriterDocumentStates.top().mbInTextBox) - return; - if (mWriterListStates.size() > 1) - mWriterListStates.pop(); - if (mWriterDocumentStates.size() > 1) - mWriterDocumentStates.pop(); - - mpCurrentContentElements->push_back(new TagCloseElement("draw:text-box")); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/DocumentCollector.hxx b/writerperfect/source/filter/DocumentCollector.hxx deleted file mode 100644 index 6d0d35396201..000000000000 --- a/writerperfect/source/filter/DocumentCollector.hxx +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* DocumentCollector: Collects sections and runs of text from a - * file (and styles to go along with them) and writes them - * to a target file - * - * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) - * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com) - * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _DOCUMENTCOLLECTOR_HXX -#define _DOCUMENTCOLLECTOR_HXX -#include "SectionStyle.hxx" - -#if defined _MSC_VER -#pragma warning( push, 1 ) -#endif -#include <libwps/libwps.h> -#include <libwpd/libwpd.h> -#if defined _MSC_VER -#pragma warning( pop ) -#endif -#include <vector> -#include <map> -#include <stack> -#include <string.h> - -#include "DocumentHandlerInterface.hxx" - -class DocumentElement; -class TagOpenElement; -class FontStyle; -class ListStyle; - -class ParagraphStyle; -class SpanStyle; -class TableStyle; -class PageSpan; - -// the state we use for writing the final document -typedef struct _WriterDocumentState WriterDocumentState; -struct _WriterDocumentState -{ - _WriterDocumentState(); - - bool mbFirstElement; - bool mbFirstParagraphInPageSpan; - bool mbInFakeSection; - bool mbListElementOpenedAtCurrentLevel; - bool mbTableCellOpened; - bool mbHeaderRow; - bool mbInNote; - bool mbInTextBox; - bool mbInFrame; -}; - -// list state -typedef struct _WriterListState WriterListState; -struct _WriterListState -{ - _WriterListState(); - - ListStyle *mpCurrentListStyle; - unsigned int miCurrentListLevel; - unsigned int miLastListLevel; - unsigned int miLastListNumber; - bool mbListContinueNumbering; - bool mbListElementParagraphOpened; - std::stack<bool> mbListElementOpened; -}; - -enum WriterListType { unordered, ordered }; - -struct ltstr -{ - bool operator()(const WPXString & s1, const WPXString & s2) const - { - return strcmp(s1.cstr(), s2.cstr()) < 0; - } -}; - -class DocumentCollector : public WPXDocumentInterface -{ -public: - DocumentCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler); - virtual ~DocumentCollector(); - bool filter(); - - // WPXDocumentInterface's callbacks - virtual void setDocumentMetaData(const WPXPropertyList &propList); - virtual void startDocument() {} - virtual void endDocument() {} - - virtual void definePageStyle(const WPXPropertyList&) {} - virtual void openPageSpan(const WPXPropertyList &propList); - virtual void closePageSpan() {} - - virtual void defineSectionStyle(const WPXPropertyList&, const WPXPropertyListVector&) {} - virtual void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void closeSection(); - - virtual void openHeader(const WPXPropertyList &propList); - virtual void closeHeader(); - virtual void openFooter(const WPXPropertyList &propList); - virtual void closeFooter(); - - virtual void defineParagraphStyle(const WPXPropertyList&, const WPXPropertyListVector&) {} - virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeParagraph(); - - virtual void defineCharacterStyle(const WPXPropertyList&) {} - virtual void openSpan(const WPXPropertyList &propList); - virtual void closeSpan(); - - virtual void insertTab(); - virtual void insertSpace(); - virtual void insertText(const WPXString &text); - virtual void insertLineBreak(); - virtual void insertField(const WPXString &type, const WPXPropertyList &propList); - - virtual void defineOrderedListLevel(const WPXPropertyList &propList); - virtual void defineUnorderedListLevel(const WPXPropertyList &propList); - virtual void openOrderedListLevel(const WPXPropertyList &propList); - virtual void openUnorderedListLevel(const WPXPropertyList &propList); - virtual void closeOrderedListLevel(); - virtual void closeUnorderedListLevel(); - virtual void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeListElement(); - - virtual void openFootnote(const WPXPropertyList &propList); - virtual void closeFootnote(); - virtual void openEndnote(const WPXPropertyList &propList); - virtual void closeEndnote(); - virtual void openComment(const WPXPropertyList &propList); - virtual void closeComment(); - virtual void openTextBox(const WPXPropertyList &propList); - virtual void closeTextBox(); - - virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void openTableRow(const WPXPropertyList &propList); - virtual void closeTableRow(); - virtual void openTableCell(const WPXPropertyList &propList); - virtual void closeTableCell(); - virtual void insertCoveredTableCell(const WPXPropertyList &propList); - virtual void closeTable(); - - virtual void openFrame(const WPXPropertyList & propList); - virtual void closeFrame(); - - virtual void insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data); - virtual void insertEquation(const WPXPropertyList & /* propList */, const WPXString & /* data */) {} - - virtual bool parseSourceDocument(WPXInputStream &input) = 0; - -protected: - void _resetDocumentState(); - bool _writeTargetDocument(DocumentHandlerInterface *pHandler); - void _writeDefaultStyles(DocumentHandlerInterface *pHandler); - void _writeMasterPages(DocumentHandlerInterface *pHandler); - void _writePageLayouts(DocumentHandlerInterface *pHandler); - void _allocateFontName(const WPXString &); - -private: - void _openListLevel(TagOpenElement *pListLevelOpenElement); - void _closeListLevel(); - - WPXInputStream *mpInput; - DocumentHandlerInterface *mpHandler; - bool mbUsed; // whether or not it has been before (you can only use me once!) - - std::stack<WriterDocumentState> mWriterDocumentStates; - - std::stack<WriterListState> mWriterListStates; - - // paragraph styles - std::map<WPXString, ParagraphStyle *, ltstr> mTextStyleHash; - - // span styles - std::map<WPXString, SpanStyle *, ltstr> mSpanStyleHash; - - // font styles - std::map<WPXString, FontStyle *, ltstr> mFontHash; - - // section styles - std::vector<SectionStyle *> mSectionStyles; - double mfSectionSpaceAfter; - - // table styles - std::vector<TableStyle *> mTableStyles; - - // frame styles - std::vector<DocumentElement *> mFrameStyles; - - std::vector<DocumentElement *> mFrameAutomaticStyles; - - // metadata - std::vector<DocumentElement *> mMetaData; - - // list styles - unsigned int miNumListStyles; - - // style elements - std::vector<DocumentElement *> mStylesElements; - // content elements - std::vector<DocumentElement *> mBodyElements; - // the current set of elements that we're writing to - std::vector<DocumentElement *> * mpCurrentContentElements; - - // page state - std::vector<PageSpan *> mPageSpans; - PageSpan *mpCurrentPageSpan; - int miNumPageStyles; - - // list styles - std::vector<ListStyle *> mListStyles; - - // object state - unsigned miObjectNumber; - - // table state - TableStyle *mpCurrentTableStyle; - - const bool mbIsFlatXML; - - const char * mpPassword; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/DocumentElement.cxx b/writerperfect/source/filter/DocumentElement.cxx index f330ab0ace47..f42331c527bc 100644 --- a/writerperfect/source/filter/DocumentElement.cxx +++ b/writerperfect/source/filter/DocumentElement.cxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* DocumentElement: The items we are collecting to be put into the Writer * document: paragraph and spans of text, as well as section breaks. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +26,7 @@ */ #include "DocumentElement.hxx" -#include "DocumentHandler.hxx" +#include "OdfDocumentHandler.hxx" #include "FilterInternal.hxx" #include <string.h> @@ -38,7 +37,7 @@ void TagElement::print() const WRITER_DEBUG_MSG(("%s\n", msTagName.cstr())); } -void TagOpenElement::write(DocumentHandlerInterface *pHandler) const +void TagOpenElement::write(OdfDocumentHandler *pHandler) const { pHandler->startElement(getTagName().cstr(), maAttrList); } @@ -48,61 +47,27 @@ void TagOpenElement::print() const TagElement::print(); } -void TagOpenElement::addAttribute(const char *szAttributeName, const WPXString &sAttributeValue) +void TagOpenElement::addAttribute(const WPXString &szAttributeName, const WPXString &sAttributeValue) { - maAttrList.insert(szAttributeName, sAttributeValue); + maAttrList.insert(szAttributeName.cstr(), sAttributeValue); } -void TagCloseElement::write(DocumentHandlerInterface *pHandler) const +void TagCloseElement::write(OdfDocumentHandler *pHandler) const { WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr())); pHandler->endElement(getTagName().cstr()); } -void CharDataElement::write(DocumentHandlerInterface *pHandler) const +void CharDataElement::write(OdfDocumentHandler *pHandler) const { WRITER_DEBUG_MSG(("TextElement: write\n")); pHandler->characters(msData); } -TextElement::TextElement(const WPXString & sTextBuf) : - msTextBuf(sTextBuf, false) -{ -} - -// write: writes a text run, appropriately converting spaces to <text:s> -// elements -void TextElement::write(DocumentHandlerInterface *pHandler) const +void TextElement::write(OdfDocumentHandler *pHandler) const { if (msTextBuf.len() <= 0) return; - WPXPropertyList xBlankAttrList; - - WPXString sTemp; - - int iNumConsecutiveSpaces = 0; - WPXString::Iter i(msTextBuf); - for (i.rewind(); i.next();) - { - if (*(i()) == ASCII_SPACE) - iNumConsecutiveSpaces++; - else - iNumConsecutiveSpaces = 0; - - if (iNumConsecutiveSpaces > 1) { - if (sTemp.len() > 0) { - pHandler->characters(sTemp); - sTemp.clear(); - } - pHandler->startElement("text:s", xBlankAttrList); - pHandler->endElement("text:s"); - } - else { - sTemp.append(i()); - } - } - pHandler->characters(sTemp); + pHandler->characters(msTextBuf); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/DocumentElement.hxx b/writerperfect/source/filter/DocumentElement.hxx index cb84777a278a..6de5db3d8eb2 100644 --- a/writerperfect/source/filter/DocumentElement.hxx +++ b/writerperfect/source/filter/DocumentElement.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* DocumentElement: The items we are collecting to be put into the Writer * document: paragraph and spans of text, as well as section breaks. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,13 +32,13 @@ #include <libwpd/WPXString.h> #include <vector> -#include "DocumentHandlerInterface.hxx" +#include "OdfDocumentHandler.hxx" class DocumentElement { public: virtual ~DocumentElement() {} - virtual void write(DocumentHandlerInterface *pHandler) const = 0; + virtual void write(OdfDocumentHandler *pHandler) const = 0; virtual void print() const {} }; @@ -47,7 +46,7 @@ class TagElement : public DocumentElement { public: virtual ~TagElement() {} - TagElement(const char *szTagName) : msTagName(szTagName) {} + TagElement(const WPXString &szTagName) : msTagName(szTagName) {} const WPXString & getTagName() const { return msTagName; } virtual void print() const; private: @@ -57,10 +56,10 @@ private: class TagOpenElement : public TagElement { public: - TagOpenElement(const char *szTagName) : TagElement(szTagName) {} + TagOpenElement(const WPXString &szTagName) : TagElement(szTagName) {} virtual ~TagOpenElement() {} - void addAttribute(const char *szAttributeName, const WPXString &sAttributeValue); - virtual void write(DocumentHandlerInterface *pHandler) const; + void addAttribute(const WPXString &szAttributeName, const WPXString &sAttributeValue); + virtual void write(OdfDocumentHandler *pHandler) const; virtual void print () const; private: WPXPropertyList maAttrList; @@ -69,17 +68,17 @@ private: class TagCloseElement : public TagElement { public: - TagCloseElement(const char *szTagName) : TagElement(szTagName) {} + TagCloseElement(const WPXString &szTagName) : TagElement(szTagName) {} virtual ~TagCloseElement() {} - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; }; class CharDataElement : public DocumentElement { public: - CharDataElement(const char *sData) : DocumentElement(), msData(sData) {} + CharDataElement(const WPXString &sData) : DocumentElement(), msData(sData) {} virtual ~CharDataElement() {} - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXString msData; }; @@ -87,14 +86,12 @@ private: class TextElement : public DocumentElement { public: - TextElement(const WPXString & sTextBuf); + TextElement(const WPXString &sTextBuf) : DocumentElement(), msTextBuf(sTextBuf, false) {} virtual ~TextElement() {} - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXString msTextBuf; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/DocumentHandler.hxx b/writerperfect/source/filter/DocumentHandler.hxx index 249f64ff4e7b..692c35e3b462 100644 --- a/writerperfect/source/filter/DocumentHandler.hxx +++ b/writerperfect/source/filter/DocumentHandler.hxx @@ -12,12 +12,12 @@ #pragma warning( pop ) #endif -#include "DocumentHandlerInterface.hxx" +#include "OdfDocumentHandler.hxx" using com::sun::star::uno::Reference; using com::sun::star::xml::sax::XDocumentHandler; -class DocumentHandler: public DocumentHandlerInterface +class DocumentHandler: public OdfDocumentHandler { public: DocumentHandler(Reference < XDocumentHandler > &xHandler); diff --git a/writerperfect/source/filter/FilterInternal.hxx b/writerperfect/source/filter/FilterInternal.hxx index fcac328c95a0..1b806337fffa 100644 --- a/writerperfect/source/filter/FilterInternal.hxx +++ b/writerperfect/source/filter/FilterInternal.hxx @@ -1,7 +1,6 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* FilterInternal: Debugging information * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,21 +19,18 @@ * For further information visit http://libwpd.sourceforge.net * */ +#ifndef __FILTERINTERNAL_HXX__ +#define __FILTERINTERNAL_HXX__ -#ifndef _FILTERINTERNAL_HXX -#define _FILTERINTERNAL_HXX - -#include <stdio.h> #ifdef DEBUG +#include <stdio.h> #define WRITER_DEBUG_MSG(M) printf M #else #define WRITER_DEBUG_MSG(M) #endif const double fDefaultSideMargin = 1.0; // inches -const double fDefaultPageWidth = 8.5; // inches (OOo required default: we will handle this later) +const double fDefaultPageWidth = 8.5f; // inches (OOo required default: we will handle this later) const double fDefaultPageHeight = 11.0; // inches #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/FontStyle.cxx b/writerperfect/source/filter/FontStyle.cxx index 3f4ce607d270..509fa16e02ec 100644 --- a/writerperfect/source/filter/FontStyle.cxx +++ b/writerperfect/source/filter/FontStyle.cxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* FontStyle: Stores (and writes) font-based information that is needed at * the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -39,14 +38,13 @@ FontStyle::~FontStyle() { } -void FontStyle::write(DocumentHandlerInterface *pHandler) const +void FontStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement styleOpen("style:font-face"); styleOpen.addAttribute("style:name", getName()); styleOpen.addAttribute("svg:font-family", msFontFamily); +// styleOpen.addAttribute("style:font-pitch", msFontPitch); styleOpen.write(pHandler); TagCloseElement styleClose("style:font-face"); styleClose.write(pHandler); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/FontStyle.hxx b/writerperfect/source/filter/FontStyle.hxx index aec430dbd43e..7f1a44e3f613 100644 --- a/writerperfect/source/filter/FontStyle.hxx +++ b/writerperfect/source/filter/FontStyle.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* FontStyle: Stores (and writes) font-based information that is needed at * the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,14 +30,13 @@ #include "Style.hxx" #include "WriterProperties.hxx" -#include "DocumentHandlerInterface.hxx" class FontStyle : public Style { public: FontStyle(const char *psName, const char *psFontFamily); ~FontStyle(); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; const WPXString &getFontFamily() const { return msFontFamily; } private: @@ -46,5 +44,3 @@ private: WPXString msFontPitch; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/GraphicsStyle.cxx b/writerperfect/source/filter/GraphicsStyle.cxx deleted file mode 100644 index abca6a851136..000000000000 --- a/writerperfect/source/filter/GraphicsStyle.cxx +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* GraphicsStyle: - * - * Copyright (C) 2007 Fridrich Strba .strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include "GraphicsStyle.hxx" -#include "WriterProperties.hxx" -#include "DocumentElement.hxx" - -GraphicsStyle::GraphicsStyle(const char *psName) : Style(psName) -{ -} - -GraphicsStyle::~GraphicsStyle() -{ -} - -void GraphicsStyle::write(DocumentHandlerInterface * /* pHandler */) const -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/GraphicsStyle.hxx b/writerperfect/source/filter/GraphicsStyle.hxx deleted file mode 100644 index bef9b5423151..000000000000 --- a/writerperfect/source/filter/GraphicsStyle.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* GraphicsStyle: - * - * Copyright (C) 2007 Fridrich Strba .strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#ifndef _GRAPHICSSTYLE_H -#define _GRAPHICSSTYLE_H - -#include "Style.hxx" -#include "WriterProperties.hxx" -#include "DocumentHandlerInterface.hxx" - -class GraphicsStyle : public Style -{ -public: - GraphicsStyle(const char *psName); - ~GraphicsStyle(); - virtual void write(DocumentHandlerInterface *pHandler) const; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/InternalHandler.cxx b/writerperfect/source/filter/InternalHandler.cxx index a0208277f5c6..8582047f0b0b 100644 --- a/writerperfect/source/filter/InternalHandler.cxx +++ b/writerperfect/source/filter/InternalHandler.cxx @@ -1,6 +1,5 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright (C) 2007 Fridrich Strba .strba@bluewin.ch) + * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,13 +33,13 @@ InternalHandler::InternalHandler(std::vector<DocumentElement *> *elements): void InternalHandler::startElement(const char *psName, const WPXPropertyList &xPropList) { TagOpenElement *element = new TagOpenElement(psName); - WPXPropertyList::Iter i(xPropList); - for (i.rewind(); i.next(); ) - { - // filter out libwpd elements - if (strncmp(i.key(), "libwpd", 6) != 0) - element->addAttribute(i.key(), i()->getStr()); - } + WPXPropertyList::Iter i(xPropList); + for (i.rewind(); i.next(); ) + { + // filter out libwpd elements + if (strncmp(i.key(), "libwpd", 6) != 0) + element->addAttribute(i.key(), i()->getStr()); + } mpElements->push_back(element); } @@ -53,5 +52,3 @@ void InternalHandler::characters(const WPXString &sCharacters) { mpElements->push_back(new CharDataElement(sCharacters.cstr())); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/InternalHandler.hxx b/writerperfect/source/filter/InternalHandler.hxx index 0869ad107e21..a0f16382e347 100644 --- a/writerperfect/source/filter/InternalHandler.hxx +++ b/writerperfect/source/filter/InternalHandler.hxx @@ -1,6 +1,5 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright (C) 2007 Fridrich Strba .strba@bluewin.ch) + * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,9 +27,9 @@ #include <libwpd/WPXProperty.h> #include <libwpd/WPXString.h> #include "DocumentElement.hxx" -#include "DocumentHandlerInterface.hxx" +#include "OdfDocumentHandler.hxx" -class InternalHandler : public DocumentHandlerInterface +class InternalHandler : public OdfDocumentHandler { public: InternalHandler(std::vector<DocumentElement *> *elements); @@ -45,5 +44,3 @@ private: std::vector<DocumentElement *> *mpElements; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/ListStyle.cxx b/writerperfect/source/filter/ListStyle.cxx index b991b12a236e..e59ad53f91d0 100644 --- a/writerperfect/source/filter/ListStyle.cxx +++ b/writerperfect/source/filter/ListStyle.cxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ListStyle: Stores (and writes) list-based information that is * needed at the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,7 +29,7 @@ #include "DocumentElement.hxx" OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) : - mPropList(xPropList) + mPropList(xPropList) { } @@ -42,7 +41,7 @@ void OrderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList & setListLevel(iLevel, new OrderedListLevelStyle(xPropList)); } -void OrderedListLevelStyle::write(DocumentHandlerInterface *pHandler, int iLevel) const +void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const { WPXString sLevel; sLevel.sprintf("%i", (iLevel+1)); @@ -50,23 +49,23 @@ void OrderedListLevelStyle::write(DocumentHandlerInterface *pHandler, int iLevel TagOpenElement listLevelStyleOpen("text:list-level-style-number"); listLevelStyleOpen.addAttribute("text:level", sLevel); listLevelStyleOpen.addAttribute("text:style-name", "Numbering_Symbols"); - if (mPropList["style:num-prefix"]) + if (mPropList["style:num-prefix"]) { WPXString sEscapedString(mPropList["style:num-prefix"]->getStr(), true); listLevelStyleOpen.addAttribute("style:num-prefix", sEscapedString); } - if (mPropList["style:num-suffix"]) + if (mPropList["style:num-suffix"]) { WPXString sEscapedString(mPropList["style:num-suffix"]->getStr(), true); listLevelStyleOpen.addAttribute("style:num-suffix", sEscapedString); } - if (mPropList["style:num-format"]) - listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr()); - if (mPropList["text:start-value"]) + if (mPropList["style:num-format"]) + listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr()); + if (mPropList["text:start-value"]) { // odf as to the version 1.1 does require the text:start-value to be a positive integer, means > 0 if (mPropList["text:start-value"]->getInt() > 0) - listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr()); + listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr()); else listLevelStyleOpen.addAttribute("text:start-value", "1"); } @@ -74,7 +73,7 @@ void OrderedListLevelStyle::write(DocumentHandlerInterface *pHandler, int iLevel TagOpenElement stylePropertiesOpen("style:list-level-properties"); if (mPropList["text:space-before"] && mPropList["text:space-before"]->getDouble() > 0.0) - stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr()); + stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr()); if (mPropList["text:min-label-width"] && mPropList["text:min-label-width"]->getDouble() > 0.0) stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr()); if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0) @@ -98,7 +97,7 @@ void UnorderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList setListLevel(iLevel, new UnorderedListLevelStyle(xPropList)); } -void UnorderedListLevelStyle::write(DocumentHandlerInterface *pHandler, int iLevel) const +void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const { WPXString sLevel; sLevel.sprintf("%i", (iLevel+1)); @@ -121,7 +120,7 @@ void UnorderedListLevelStyle::write(DocumentHandlerInterface *pHandler, int iLev TagOpenElement stylePropertiesOpen("style:list-level-properties"); if (mPropList["text:space-before"] && mPropList["text:space-before"]->getDouble() > 0.0) - stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr()); + stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr()); if (mPropList["text:min-label-width"] && mPropList["text:min-label-width"]->getDouble() > 0.0) stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr()); if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0) @@ -168,7 +167,7 @@ void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle) mppListLevels[iLevel] = iListLevelStyle; } -void ListStyle::write(DocumentHandlerInterface *pHandler) const +void ListStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement listStyleOpenElement("text:list-style"); listStyleOpenElement.addAttribute("style:name", getName()); @@ -181,5 +180,3 @@ void ListStyle::write(DocumentHandlerInterface *pHandler) const pHandler->endElement("text:list-style"); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/ListStyle.hxx b/writerperfect/source/filter/ListStyle.hxx index cbba20a8352e..32f2d9c65a3d 100644 --- a/writerperfect/source/filter/ListStyle.hxx +++ b/writerperfect/source/filter/ListStyle.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ListStyle: Stores (and writes) list-based information that is * needed at the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,7 +32,6 @@ #include "Style.hxx" #include "WriterProperties.hxx" -#include "DocumentHandlerInterface.hxx" class DocumentElement; @@ -41,14 +39,14 @@ class ListLevelStyle { public: virtual ~ListLevelStyle() {}; - virtual void write(DocumentHandlerInterface *pHandler, int iLevel) const = 0; + virtual void write(OdfDocumentHandler *pHandler, int iLevel) const = 0; }; class OrderedListLevelStyle : public ListLevelStyle { public: OrderedListLevelStyle(const WPXPropertyList &xPropList); - void write(DocumentHandlerInterface *pHandler, int iLevel) const; + void write(OdfDocumentHandler *pHandler, int iLevel) const; private: WPXPropertyList mPropList; }; @@ -57,7 +55,7 @@ class UnorderedListLevelStyle : public ListLevelStyle { public: UnorderedListLevelStyle(const WPXPropertyList &xPropList); - void write(DocumentHandlerInterface *pHandler, int iLevel) const; + void write(OdfDocumentHandler *pHandler, int iLevel) const; private: WPXPropertyList mPropList; }; @@ -68,8 +66,8 @@ public: ListStyle(const char *psName, const int iListID); virtual ~ListStyle(); virtual void updateListLevel(const int iLevel, const WPXPropertyList &xPropList) = 0; - virtual void write(DocumentHandlerInterface *pHandler) const; - int getListID() const { return miListID; } + virtual void write(OdfDocumentHandler *pHandler) const; + int getListID() { return miListID; } bool isListLevelDefined(int iLevel) const; protected: @@ -95,5 +93,3 @@ public: void updateListLevel(const int iLevel, const WPXPropertyList &xPropList); }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/DocumentHandlerInterface.hxx b/writerperfect/source/filter/OdfDocumentHandler.hxx index 0e9ee56349e6..0b7288cb09ef 100644 --- a/writerperfect/source/filter/DocumentHandlerInterface.hxx +++ b/writerperfect/source/filter/OdfDocumentHandler.hxx @@ -1,4 +1,3 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2004 William Lachance (wlach@interlog.com) * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com) @@ -25,24 +24,22 @@ /* "This product is not manufactured, approved, or supported by * Corel Corporation or Corel Corporation Limited." */ -#ifndef _DOCUMENTHANDLERINTERFACE_H -#define _DOCUMENTHANDLERINTERFACE_H +#ifndef _DOCUMENTHANDLER_H +#define _DOCUMENTHANDLER_H #include <libwpd/libwpd.h> -#include <libwpd/WPXProperty.h> -#include <libwpd/WPXString.h> -class DocumentHandlerInterface +enum OdfStreamType { ODF_FLAT_XML, ODF_CONTENT_XML, ODF_STYLES_XML, ODF_SETTINGS_XML, ODF_META_XML }; + +class OdfDocumentHandler { public: - DocumentHandlerInterface() {}; - virtual ~DocumentHandlerInterface() {}; + OdfDocumentHandler() {}; + virtual ~OdfDocumentHandler() {}; - virtual void startDocument() = 0; - virtual void endDocument() = 0; - virtual void startElement(const char *psName, const WPXPropertyList &xPropList) = 0; - virtual void endElement(const char *psName) = 0; - virtual void characters(const WPXString &sCharacters) = 0; + virtual void startDocument() = 0; + virtual void endDocument() = 0; + virtual void startElement(const char *psName, const WPXPropertyList &xPropList) = 0; + virtual void endElement(const char *psName) = 0; + virtual void characters(const WPXString &sCharacters) = 0; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/OdgExporter.cxx b/writerperfect/source/filter/OdgGenerator.cxx index c111cdb75dd5..3b085eb6e6d0 100644 --- a/writerperfect/source/filter/OdgExporter.cxx +++ b/writerperfect/source/filter/OdgGenerator.cxx @@ -1,4 +1,3 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* libwpg * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) @@ -25,9 +24,9 @@ * Corel Corporation or Corel Corporation Limited." */ -#include "OdgExporter.hxx" +#include "OdgGenerator.hxx" #include "DocumentElement.hxx" -#include "DocumentHandler.hxx" +#include "OdfDocumentHandler.hxx" #include <locale.h> #include <math.h> #include <string> @@ -36,60 +35,123 @@ #define M_PI 3.14159265358979323846 #endif -OdgExporter::OdgExporter(DocumentHandlerInterface *pHandler): +static WPXString doubleToString(const double value) +{ + WPXString tempString; + tempString.sprintf("%.4f", value); + std::string decimalPoint(localeconv()->decimal_point); + if ((decimalPoint.size() == 0) || (decimalPoint == ".")) + return tempString; + std::string stringValue(tempString.cstr()); + if (!stringValue.empty()) + { + std::string::size_type pos; + while ((pos = stringValue.find(decimalPoint)) != std::string::npos) + stringValue.replace(pos,decimalPoint.size(),"."); + } + return WPXString(stringValue.c_str()); +} + +class OdgGeneratorPrivate +{ +public: + OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType); + ~OdgGeneratorPrivate(); + void _writeGraphicsStyle(); + void _drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed); + void _drawPath(const WPXPropertyListVector& path); + // body elements + std::vector <DocumentElement *> mBodyElements; + + // graphics styles + std::vector<DocumentElement *> mGraphicsStrokeDashStyles; + std::vector<DocumentElement *> mGraphicsGradientStyles; + std::vector<DocumentElement *> mGraphicsAutomaticStyles; + + OdfDocumentHandler *mpHandler; + + ::WPXPropertyList mxStyle; + ::WPXPropertyListVector mxGradient; + int miGradientIndex; + int miDashIndex; + int miGraphicsStyleIndex; + double mfWidth; + double mfHeight; + + const OdfStreamType mxStreamType; +}; + +OdgGeneratorPrivate::OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType): mpHandler(pHandler), miGradientIndex(1), miDashIndex(1), miGraphicsStyleIndex(1), mfWidth(0.0), - mfHeight(0.0) + mfHeight(0.0), + mxStreamType(streamType) { } -OdgExporter::~OdgExporter() +OdgGeneratorPrivate::~OdgGeneratorPrivate() { - for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); ++iterBody) + for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); iterBody++) { delete (*iterBody); (*iterBody) = NULL; } for (std::vector<DocumentElement *>::iterator iterGraphicsAutomaticStyles = mGraphicsAutomaticStyles.begin(); - iterGraphicsAutomaticStyles != mGraphicsAutomaticStyles.end(); ++iterGraphicsAutomaticStyles) + iterGraphicsAutomaticStyles != mGraphicsAutomaticStyles.end(); iterGraphicsAutomaticStyles++) { delete((*iterGraphicsAutomaticStyles)); } for (std::vector<DocumentElement *>::iterator iterGraphicsStrokeDashStyles = mGraphicsStrokeDashStyles.begin(); - iterGraphicsStrokeDashStyles != mGraphicsStrokeDashStyles.end(); ++iterGraphicsStrokeDashStyles) + iterGraphicsStrokeDashStyles != mGraphicsStrokeDashStyles.end(); iterGraphicsStrokeDashStyles++) { delete((*iterGraphicsStrokeDashStyles)); } for (std::vector<DocumentElement *>::iterator iterGraphicsGradientStyles = mGraphicsGradientStyles.begin(); - iterGraphicsGradientStyles != mGraphicsGradientStyles.end(); ++iterGraphicsGradientStyles) + iterGraphicsGradientStyles != mGraphicsGradientStyles.end(); iterGraphicsGradientStyles++) { delete((*iterGraphicsGradientStyles)); } } -void OdgExporter::startGraphics(const ::WPXPropertyList &propList) +OdgGenerator::OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType): + mpImpl(new OdgGeneratorPrivate(pHandler, streamType)) +{ +} + +OdgGenerator::~OdgGenerator() +{ + if (mpImpl) + delete mpImpl; +} + +void OdgGenerator::startGraphics(const ::WPXPropertyList &propList) { - miGradientIndex = 1; - miDashIndex = 1; - miGraphicsStyleIndex = 1; - mfWidth = 0.0; - mfHeight = 0.0; + mpImpl->miGradientIndex = 1; + mpImpl->miDashIndex = 1; + mpImpl->miGraphicsStyleIndex = 1; + mpImpl->mfWidth = 0.0; + mpImpl->mfHeight = 0.0; if (propList["svg:width"]) - mfWidth = propList["svg:width"]->getDouble(); + mpImpl->mfWidth = propList["svg:width"]->getDouble(); if (propList["svg:height"]) - mfHeight = propList["svg:height"]->getDouble(); - - mpHandler->startDocument(); - TagOpenElement tmpOfficeDocumentContent("office:document"); + mpImpl->mfHeight = propList["svg:height"]->getDouble(); + + mpImpl->mpHandler->startDocument(); + TagOpenElement tmpOfficeDocumentContent( + (mpImpl->mxStreamType == ODF_FLAT_XML) ? "office:document" : ( + (mpImpl->mxStreamType == ODF_CONTENT_XML) ? "office:document-content" : ( + (mpImpl->mxStreamType == ODF_STYLES_XML) ? "office:document-styles" : ( + (mpImpl->mxStreamType == ODF_SETTINGS_XML) ? "office:document-settings" : ( + (mpImpl->mxStreamType == ODF_META_XML) ? "office:document-meta" : "office:document" ))))); tmpOfficeDocumentContent.addAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"); tmpOfficeDocumentContent.addAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0"); tmpOfficeDocumentContent.addAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"); @@ -100,168 +162,200 @@ void OdgExporter::startGraphics(const ::WPXPropertyList &propList) tmpOfficeDocumentContent.addAttribute("xmlns:config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"); tmpOfficeDocumentContent.addAttribute("xmlns:ooo", "http://openoffice.org/2004/office"); tmpOfficeDocumentContent.addAttribute("office:version", "1.0"); - tmpOfficeDocumentContent.addAttribute("office:mimetype", "application/vnd.oasis.opendocument.graphics"); - tmpOfficeDocumentContent.write(mpHandler); - - TagOpenElement("office:settings").write(mpHandler); - - TagOpenElement configItemSetOpenElement("config:config-item-set"); - configItemSetOpenElement.addAttribute("config:name", "ooo:view-settings"); - configItemSetOpenElement.write(mpHandler); - - TagOpenElement configItemOpenElement("config:config-item"); - - configItemOpenElement.addAttribute("config:name", "VisibleAreaTop"); - configItemOpenElement.addAttribute("config:type", "int"); - configItemOpenElement.write(mpHandler); - mpHandler->characters("0"); - mpHandler->endElement("config:config-item"); - - configItemOpenElement.addAttribute("config:name", "VisibleAreaLeft"); - configItemOpenElement.addAttribute("config:type", "int"); - configItemOpenElement.write(mpHandler); - mpHandler->characters("0"); - mpHandler->endElement("config:config-item"); - - configItemOpenElement.addAttribute("config:name", "VisibleAreaWidth"); - configItemOpenElement.addAttribute("config:type", "int"); - configItemOpenElement.write(mpHandler); - WPXString sWidth; sWidth.sprintf("%li", (unsigned long)(2540 * mfWidth)); - mpHandler->characters(sWidth); - mpHandler->endElement("config:config-item"); - - configItemOpenElement.addAttribute("config:name", "VisibleAreaHeight"); - configItemOpenElement.addAttribute("config:type", "int"); - configItemOpenElement.write(mpHandler); - WPXString sHeight; sHeight.sprintf("%li", (unsigned long)(2540 * mfHeight)); - mpHandler->characters(sHeight); - mpHandler->endElement("config:config-item"); - - mpHandler->endElement("config:config-item-set"); - - mpHandler->endElement("office:settings"); -} - -void OdgExporter::endGraphics() -{ - TagOpenElement("office:styles").write(mpHandler); + if (mpImpl->mxStreamType == ODF_FLAT_XML) + tmpOfficeDocumentContent.addAttribute("office:mimetype", "application/vnd.oasis.opendocument.graphics"); + tmpOfficeDocumentContent.write(mpImpl->mpHandler); - for (std::vector<DocumentElement *>::const_iterator iterGraphicsStrokeDashStyles = mGraphicsStrokeDashStyles.begin(); - iterGraphicsStrokeDashStyles != mGraphicsStrokeDashStyles.end(); ++iterGraphicsStrokeDashStyles) + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_SETTINGS_XML)) { - (*iterGraphicsStrokeDashStyles)->write(mpHandler); + TagOpenElement("office:settings").write(mpImpl->mpHandler); + + TagOpenElement configItemSetOpenElement("config:config-item-set"); + configItemSetOpenElement.addAttribute("config:name", "ooo:view-settings"); + configItemSetOpenElement.write(mpImpl->mpHandler); + + TagOpenElement configItemOpenElement("config:config-item"); + + configItemOpenElement.addAttribute("config:name", "VisibleAreaTop"); + configItemOpenElement.addAttribute("config:type", "int"); + configItemOpenElement.write(mpImpl->mpHandler); + mpImpl->mpHandler->characters("0"); + mpImpl->mpHandler->endElement("config:config-item"); + + configItemOpenElement.addAttribute("config:name", "VisibleAreaLeft"); + configItemOpenElement.addAttribute("config:type", "int"); + configItemOpenElement.write(mpImpl->mpHandler); + mpImpl->mpHandler->characters("0"); + mpImpl->mpHandler->endElement("config:config-item"); + + configItemOpenElement.addAttribute("config:name", "VisibleAreaWidth"); + configItemOpenElement.addAttribute("config:type", "int"); + configItemOpenElement.write(mpImpl->mpHandler); + WPXString sWidth; sWidth.sprintf("%li", (unsigned long)(2540 * mpImpl->mfWidth)); + mpImpl->mpHandler->characters(sWidth); + mpImpl->mpHandler->endElement("config:config-item"); + + configItemOpenElement.addAttribute("config:name", "VisibleAreaHeight"); + configItemOpenElement.addAttribute("config:type", "int"); + configItemOpenElement.write(mpImpl->mpHandler); + WPXString sHeight; sHeight.sprintf("%li", (unsigned long)(2540 * mpImpl->mfHeight)); + mpImpl->mpHandler->characters(sHeight); + mpImpl->mpHandler->endElement("config:config-item"); + + mpImpl->mpHandler->endElement("config:config-item-set"); + + mpImpl->mpHandler->endElement("office:settings"); } +} - for (std::vector<DocumentElement *>::const_iterator iterGraphicsGradientStyles = mGraphicsGradientStyles.begin(); - iterGraphicsGradientStyles != mGraphicsGradientStyles.end(); ++iterGraphicsGradientStyles) +void OdgGenerator::endGraphics() +{ + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) { - (*iterGraphicsGradientStyles)->write(mpHandler); + TagOpenElement("office:styles").write(mpImpl->mpHandler); + + for (std::vector<DocumentElement *>::const_iterator iterGraphicsStrokeDashStyles = mpImpl->mGraphicsStrokeDashStyles.begin(); + iterGraphicsStrokeDashStyles != mpImpl->mGraphicsStrokeDashStyles.end(); iterGraphicsStrokeDashStyles++) + { + (*iterGraphicsStrokeDashStyles)->write(mpImpl->mpHandler); + } + + for (std::vector<DocumentElement *>::const_iterator iterGraphicsGradientStyles = mpImpl->mGraphicsGradientStyles.begin(); + iterGraphicsGradientStyles != mpImpl->mGraphicsGradientStyles.end(); iterGraphicsGradientStyles++) + { + (*iterGraphicsGradientStyles)->write(mpImpl->mpHandler); + } + + mpImpl->mpHandler->endElement("office:styles"); } - mpHandler->endElement("office:styles"); - TagOpenElement("office:automatic-styles").write(mpHandler); + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) + { + TagOpenElement("office:automatic-styles").write(mpImpl->mpHandler); + } - // writing out the graphics automatic styles - for (std::vector<DocumentElement *>::iterator iterGraphicsAutomaticStyles = mGraphicsAutomaticStyles.begin(); - iterGraphicsAutomaticStyles != mGraphicsAutomaticStyles.end(); ++iterGraphicsAutomaticStyles) + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML)) { - (*iterGraphicsAutomaticStyles)->write(mpHandler); + // writing out the graphics automatic styles + for (std::vector<DocumentElement *>::iterator iterGraphicsAutomaticStyles = mpImpl->mGraphicsAutomaticStyles.begin(); + iterGraphicsAutomaticStyles != mpImpl->mGraphicsAutomaticStyles.end(); iterGraphicsAutomaticStyles++) + { + (*iterGraphicsAutomaticStyles)->write(mpImpl->mpHandler); + } } - TagOpenElement tmpStylePageLayoutOpenElement("style:page-layout"); - tmpStylePageLayoutOpenElement.addAttribute("style:name", "PM0"); - tmpStylePageLayoutOpenElement.write(mpHandler); + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) + { + TagOpenElement tmpStylePageLayoutOpenElement("style:page-layout"); + tmpStylePageLayoutOpenElement.addAttribute("style:name", "PM0"); + tmpStylePageLayoutOpenElement.write(mpImpl->mpHandler); + + TagOpenElement tmpStylePageLayoutPropertiesOpenElement("style:page-layout-properties"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-top", "0in"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-bottom", "0in"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-left", "0in"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-right", "0in"); + WPXString sValue; + sValue = doubleToString(mpImpl->mfWidth); sValue.append("in"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", sValue); + sValue = doubleToString(mpImpl->mfHeight); sValue.append("in"); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", sValue); + tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait"); + tmpStylePageLayoutPropertiesOpenElement.write(mpImpl->mpHandler); - TagOpenElement tmpStylePageLayoutPropertiesOpenElement("style:page-layout-properties"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-top", "0in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-bottom", "0in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-left", "0in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-right", "0in"); - WPXString sValue; - sValue = doubleToString(mfWidth); sValue.append("in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", sValue); - sValue = doubleToString(mfHeight); sValue.append("in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", sValue); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait"); - tmpStylePageLayoutPropertiesOpenElement.write(mpHandler); + mpImpl->mpHandler->endElement("style:page-layout-properties"); - mpHandler->endElement("style:page-layout-properties"); + mpImpl->mpHandler->endElement("style:page-layout"); - mpHandler->endElement("style:page-layout"); + TagOpenElement tmpStyleStyleOpenElement("style:style"); + tmpStyleStyleOpenElement.addAttribute("style:name", "dp1"); + tmpStyleStyleOpenElement.addAttribute("style:family", "drawing-page"); + tmpStyleStyleOpenElement.write(mpImpl->mpHandler); - TagOpenElement tmpStyleStyleOpenElement("style:style"); - tmpStyleStyleOpenElement.addAttribute("style:name", "dp1"); - tmpStyleStyleOpenElement.addAttribute("style:family", "drawing-page"); - tmpStyleStyleOpenElement.write(mpHandler); + TagOpenElement tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties"); + // tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:background-size", "border"); + tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none"); + tmpStyleDrawingPagePropertiesOpenElement.write(mpImpl->mpHandler); - TagOpenElement tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties"); - tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none"); - tmpStyleDrawingPagePropertiesOpenElement.write(mpHandler); + mpImpl->mpHandler->endElement("style:drawing-page-properties"); - mpHandler->endElement("style:drawing-page-properties"); + mpImpl->mpHandler->endElement("style:style"); + } - mpHandler->endElement("style:style"); + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) + { + mpImpl->mpHandler->endElement("office:automatic-styles"); + } - mpHandler->endElement("office:automatic-styles"); + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) + { + TagOpenElement("office:master-styles").write(mpImpl->mpHandler); - TagOpenElement("office:master-styles").write(mpHandler); + TagOpenElement tmpStyleMasterPageOpenElement("style:master-page"); + tmpStyleMasterPageOpenElement.addAttribute("style:name", "Default"); + tmpStyleMasterPageOpenElement.addAttribute("style:page-layout-name", "PM0"); + tmpStyleMasterPageOpenElement.addAttribute("draw:style-name", "dp1"); + tmpStyleMasterPageOpenElement.write(mpImpl->mpHandler); - TagOpenElement tmpStyleMasterPageOpenElement("style:master-page"); - tmpStyleMasterPageOpenElement.addAttribute("style:name", "Default"); - tmpStyleMasterPageOpenElement.addAttribute("style:page-layout-name", "PM0"); - tmpStyleMasterPageOpenElement.addAttribute("draw:style-name", "dp1"); - tmpStyleMasterPageOpenElement.write(mpHandler); + mpImpl->mpHandler->endElement("style:master-page"); - mpHandler->endElement("style:master-page"); + mpImpl->mpHandler->endElement("office:master-styles"); + } - mpHandler->endElement("office:master-styles"); + if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML)) + { + TagOpenElement("office:body").write(mpImpl->mpHandler); - TagOpenElement("office:body").write(mpHandler); + TagOpenElement("office:drawing").write(mpImpl->mpHandler); - TagOpenElement("office:drawing").write(mpHandler); + TagOpenElement tmpDrawPageOpenElement("draw:page"); + tmpDrawPageOpenElement.addAttribute("draw:name", "page1"); + tmpDrawPageOpenElement.addAttribute("draw:style-name", "dp1"); + tmpDrawPageOpenElement.addAttribute("draw:master-page-name", "Default"); + tmpDrawPageOpenElement.write(mpImpl->mpHandler); - TagOpenElement tmpDrawPageOpenElement("draw:page"); - tmpDrawPageOpenElement.addAttribute("draw:name", "page1"); - tmpDrawPageOpenElement.addAttribute("draw:style-name", "dp1"); - tmpDrawPageOpenElement.addAttribute("draw:master-page-name", "Default"); - tmpDrawPageOpenElement.write(mpHandler); + for (std::vector<DocumentElement *>::const_iterator bodyIter = mpImpl->mBodyElements.begin(); + bodyIter != mpImpl->mBodyElements.end(); bodyIter++) + { + (*bodyIter)->write(mpImpl->mpHandler); + } - for (std::vector<DocumentElement *>::const_iterator bodyIter = mBodyElements.begin(); - bodyIter != mBodyElements.end(); ++bodyIter) - { - (*bodyIter)->write(mpHandler); + mpImpl->mpHandler->endElement("draw:page"); + mpImpl->mpHandler->endElement("office:drawing"); + mpImpl->mpHandler->endElement("office:body"); } - mpHandler->endElement("draw:page"); - mpHandler->endElement("office:drawing"); - mpHandler->endElement("office:body"); - - mpHandler->endElement("office:document"); + mpImpl->mpHandler->endElement( + (mpImpl->mxStreamType == ODF_FLAT_XML) ? "office:document" : ( + (mpImpl->mxStreamType == ODF_CONTENT_XML) ? "office:document-content" : ( + (mpImpl->mxStreamType == ODF_STYLES_XML) ? "office:document-styles" : ( + (mpImpl->mxStreamType == ODF_SETTINGS_XML) ? "office:document-settings" : ( + (mpImpl->mxStreamType == ODF_META_XML) ? "office:document-meta" : "office:document" ))))); - mpHandler->endDocument(); + mpImpl->mpHandler->endDocument(); } -void OdgExporter::setStyle(const ::WPXPropertyList & propList, const ::WPXPropertyListVector& gradient) +void OdgGenerator::setStyle(const ::WPXPropertyList & propList, const ::WPXPropertyListVector& gradient) { - mxStyle = propList; - mxGradient = gradient; + mpImpl->mxStyle = propList; + mpImpl->mxGradient = gradient; } -void OdgExporter::startLayer(const ::WPXPropertyList & /* propList */) +void OdgGenerator::startLayer(const ::WPXPropertyList & /* propList */) { } -void OdgExporter::endLayer() +void OdgGenerator::endLayer() { } -void OdgExporter::drawRectangle(const ::WPXPropertyList &propList) +void OdgGenerator::drawRectangle(const ::WPXPropertyList &propList) { - writeGraphicsStyle(); + mpImpl->_writeGraphicsStyle(); TagOpenElement *pDrawRectElement = new TagOpenElement("draw:rect"); WPXString sValue; - sValue.sprintf("gr%i", miGraphicsStyleIndex-1); + sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex-1); pDrawRectElement->addAttribute("draw:style-name", sValue); pDrawRectElement->addAttribute("svg:x", propList["svg:x"]->getStr()); pDrawRectElement->addAttribute("svg:y", propList["svg:y"]->getStr()); @@ -272,16 +366,16 @@ void OdgExporter::drawRectangle(const ::WPXPropertyList &propList) pDrawRectElement->addAttribute("draw:corner-radius", propList["svg:rx"]->getStr()); else pDrawRectElement->addAttribute("draw:corner-radius", "0.0000in"); - mBodyElements.push_back(pDrawRectElement); - mBodyElements.push_back(new TagCloseElement("draw:rect")); + mpImpl->mBodyElements.push_back(pDrawRectElement); + mpImpl->mBodyElements.push_back(new TagCloseElement("draw:rect")); } -void OdgExporter::drawEllipse(const ::WPXPropertyList &propList) +void OdgGenerator::drawEllipse(const ::WPXPropertyList &propList) { - writeGraphicsStyle(); + mpImpl->_writeGraphicsStyle(); TagOpenElement *pDrawEllipseElement = new TagOpenElement("draw:ellipse"); WPXString sValue; - sValue.sprintf("gr%i", miGraphicsStyleIndex-1); + sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex-1); pDrawEllipseElement->addAttribute("draw:style-name", sValue); sValue = doubleToString(2 * propList["svg:rx"]->getDouble()); sValue.append("in"); pDrawEllipseElement->addAttribute("svg:width", sValue); @@ -314,28 +408,28 @@ void OdgExporter::drawEllipse(const ::WPXPropertyList &propList) sValue = doubleToString(propList["svg:cy"]->getDouble()-propList["svg:ry"]->getDouble()); sValue.append("in"); pDrawEllipseElement->addAttribute("svg:y", sValue); } - mBodyElements.push_back(pDrawEllipseElement); - mBodyElements.push_back(new TagCloseElement("draw:ellipse")); + mpImpl->mBodyElements.push_back(pDrawEllipseElement); + mpImpl->mBodyElements.push_back(new TagCloseElement("draw:ellipse")); } -void OdgExporter::drawPolyline(const ::WPXPropertyListVector& vertices) +void OdgGenerator::drawPolyline(const ::WPXPropertyListVector& vertices) { - drawPolySomething(vertices, false); + mpImpl->_drawPolySomething(vertices, false); } -void OdgExporter::drawPolygon(const ::WPXPropertyListVector& vertices) +void OdgGenerator::drawPolygon(const ::WPXPropertyListVector& vertices) { - drawPolySomething(vertices, true); + mpImpl->_drawPolySomething(vertices, true); } -void OdgExporter::drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed) +void OdgGeneratorPrivate::_drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed) { if(vertices.count() < 2) return; if(vertices.count() == 2) { - writeGraphicsStyle(); + _writeGraphicsStyle(); TagOpenElement *pDrawLineElement = new TagOpenElement("draw:line"); WPXString sValue; sValue.sprintf("gr%i", miGraphicsStyleIndex-1); @@ -369,11 +463,11 @@ void OdgExporter::drawPolySomething(const ::WPXPropertyListVector& vertices, boo element.insert("libwpg:path-action", "Z"); path.append(element); } - drawPath(path); + _drawPath(path); } } -void OdgExporter::drawPath(const WPXPropertyListVector& path) +void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector& path) { if(path.count() == 0) return; @@ -415,7 +509,7 @@ void OdgExporter::drawPath(const WPXPropertyListVector& path) double vw = qx - px; double vh = qy - py; - writeGraphicsStyle(); + _writeGraphicsStyle(); TagOpenElement *pDrawPathElement = new TagOpenElement("draw:path"); WPXString sValue; @@ -474,7 +568,12 @@ void OdgExporter::drawPath(const WPXPropertyListVector& path) mBodyElements.push_back(new TagCloseElement("draw:path")); } -void OdgExporter::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) +void OdgGenerator::drawPath(const WPXPropertyListVector& path) +{ + mpImpl->_drawPath(path); +} + +void OdgGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) { if (!propList["libwpg:mime-type"] && propList["libwpg:mime-type"]->getStr().len() <= 0) return; @@ -490,23 +589,23 @@ void OdgExporter::drawGraphicObject(const ::WPXPropertyList &propList, const ::W pDrawFrameElement->addAttribute("svg:height", propList["svg:height"]->getStr()); if (propList["svg:width"]) pDrawFrameElement->addAttribute("svg:width", propList["svg:width"]->getStr()); - mBodyElements.push_back(pDrawFrameElement); + mpImpl->mBodyElements.push_back(pDrawFrameElement); - mBodyElements.push_back(new TagOpenElement("draw:image")); + mpImpl->mBodyElements.push_back(new TagOpenElement("draw:image")); - mBodyElements.push_back(new TagOpenElement("office:binary-data")); + mpImpl->mBodyElements.push_back(new TagOpenElement("office:binary-data")); ::WPXString base64Binary = binaryData.getBase64Data(); - mBodyElements.push_back(new CharDataElement(base64Binary.cstr())); + mpImpl->mBodyElements.push_back(new CharDataElement(base64Binary.cstr())); - mBodyElements.push_back(new TagCloseElement("office:binary-data")); + mpImpl->mBodyElements.push_back(new TagCloseElement("office:binary-data")); - mBodyElements.push_back(new TagCloseElement("draw:image")); + mpImpl->mBodyElements.push_back(new TagCloseElement("draw:image")); - mBodyElements.push_back(new TagCloseElement("draw:frame")); + mpImpl->mBodyElements.push_back(new TagCloseElement("draw:frame")); } -void OdgExporter::writeGraphicsStyle() +void OdgGeneratorPrivate::_writeGraphicsStyle() { #if 0 if(mxStyle["libwpg:stroke-solid"] && !mxStyle["libwpg:stroke-solid"]->getInt() && (mxDashArray.count() >=2 ) ) @@ -630,21 +729,39 @@ void OdgExporter::writeGraphicsStyle() miGraphicsStyleIndex++; } -WPXString OdgExporter::doubleToString(const double value) +void OdgGenerator::startEmbeddedGraphics(WPXPropertyList const&) +{ +} + +void OdgGenerator::endEmbeddedGraphics() +{ +} + +void OdgGenerator::startTextObject(WPXPropertyList const&, WPXPropertyListVector const&) +{ +} + +void OdgGenerator::endTextObject() +{ +} + +void OdgGenerator::startTextLine(WPXPropertyList const&) +{ +} + +void OdgGenerator::endTextLine() +{ +} + +void OdgGenerator::startTextSpan(WPXPropertyList const&) +{ +} + +void OdgGenerator::endTextSpan() +{ +} + +void OdgGenerator::insertText(WPXString const&) { - WPXString tempString; - tempString.sprintf("%.4f", value); - std::string decimalPoint(localeconv()->decimal_point); - if ((decimalPoint.size() == 0) || (decimalPoint == ".")) - return tempString; - std::string stringValue(tempString.cstr()); - if (!stringValue.empty()) - { - std::string::size_type pos; - while ((pos = stringValue.find(decimalPoint)) != std::string::npos) - stringValue.replace(pos,decimalPoint.size(),"."); - } - return WPXString(stringValue.c_str()); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/OdgExporter.hxx b/writerperfect/source/filter/OdgGenerator.hxx index f3ff92b80a28..7296935b8ae1 100644 --- a/writerperfect/source/filter/OdgExporter.hxx +++ b/writerperfect/source/filter/OdgGenerator.hxx @@ -1,4 +1,3 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* libwpg * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) * @@ -26,27 +25,23 @@ #ifndef __ODGEXPORTER_HXX__ #define __ODGEXPORTER_HXX__ -#include <iostream> -#include <sstream> -#include <string> - #include <libwpd/libwpd.h> #include <libwpg/libwpg.h> -#include "DocumentElement.hxx" -#include "DocumentHandler.hxx" -#include "FilterInternal.hxx" +#include "OdfDocumentHandler.hxx" + +class OdgGeneratorPrivate; -class OdgExporter : public libwpg::WPGPaintInterface { +class OdgGenerator : public libwpg::WPGPaintInterface { public: - OdgExporter(DocumentHandlerInterface *pHandler); - ~OdgExporter(); + OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType); + ~OdgGenerator(); void startGraphics(const ::WPXPropertyList &propList); void endGraphics(); void startLayer(const ::WPXPropertyList &propList); void endLayer(); - void startEmbeddedGraphics(const ::WPXPropertyList& /*propList*/) {} - void endEmbeddedGraphics() {} + void startEmbeddedGraphics(const ::WPXPropertyList&propList); + void endEmbeddedGraphics(); void setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector& gradient); @@ -56,38 +51,17 @@ public: void drawPolygon(const ::WPXPropertyListVector& vertices); void drawPath(const ::WPXPropertyListVector& path); void drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData); - void startTextObject(const ::WPXPropertyList & /*propList*/, const ::WPXPropertyListVector &/*path*/) {} - void endTextObject() {} - void startTextLine(const ::WPXPropertyList & /*propList*/) {} - void endTextLine() {} - void startTextSpan(const ::WPXPropertyList & /*propList*/) {} - void endTextSpan() {} - void insertText(const ::WPXString & /*str*/) {} - -private: - void writeGraphicsStyle(); - WPXString doubleToString(const double value); - void drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed); - // body elements - std::vector <DocumentElement *> mBodyElements; + void startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &path); + void endTextObject(); + void startTextLine(const ::WPXPropertyList &propList); + void endTextLine(); + void startTextSpan(const ::WPXPropertyList &propList); + void endTextSpan(); + void insertText(const ::WPXString &str); - // graphics styles - std::vector<DocumentElement *> mGraphicsStrokeDashStyles; - std::vector<DocumentElement *> mGraphicsGradientStyles; - std::vector<DocumentElement *> mGraphicsAutomaticStyles; - - DocumentHandlerInterface *mpHandler; - - ::WPXPropertyList mxStyle; - ::WPXPropertyListVector mxGradient; - int miGradientIndex; - int miDashIndex; - int miGraphicsStyleIndex; - double mfWidth; - double mfHeight; +private: + OdgGeneratorPrivate *mpImpl; }; #endif // __ODGEXPORTER_HXX__ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx new file mode 100644 index 000000000000..241e3992b60e --- /dev/null +++ b/writerperfect/source/filter/OdtGenerator.cxx @@ -0,0 +1,1487 @@ +/* OdtGenerator: Collects sections and runs of text from a + * wordperfect file (and styles to go along with them) and writes them + * to a Writer target document + * + * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com) + * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com) + * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information visit http://libwpd.sourceforge.net + * + */ + +/* "This product is not manufactured, approved, or supported by + * Corel Corporation or Corel Corporation Limited." + */ + +#include <libwpd/libwpd.h> +#include <vector> +#include <map> +#include <stack> +#include <string.h> // for strcmp +#include <string> + +#include "OdtGenerator.hxx" +#include "DocumentElement.hxx" +#include "TextRunStyle.hxx" +#include "FontStyle.hxx" +#include "ListStyle.hxx" +#include "PageSpan.hxx" +#include "SectionStyle.hxx" +#include "TableStyle.hxx" +#include "FilterInternal.hxx" +#include "WriterProperties.hxx" +#include "InternalHandler.hxx" + +// the state we use for writing the final document +typedef struct _WriterDocumentState WriterDocumentState; +struct _WriterDocumentState +{ + _WriterDocumentState(); + + bool mbFirstElement; + bool mbFirstParagraphInPageSpan; + bool mbInFakeSection; + bool mbListElementOpenedAtCurrentLevel; + bool mbTableCellOpened; + bool mbHeaderRow; + bool mbInNote; + bool mbInTextBox; + bool mbInFrame; +}; + +// list state +typedef struct _WriterListState WriterListState; +struct _WriterListState +{ + _WriterListState(); + + ListStyle *mpCurrentListStyle; + unsigned int miCurrentListLevel; + unsigned int miLastListLevel; + unsigned int miLastListNumber; + bool mbListContinueNumbering; + bool mbListElementParagraphOpened; + std::stack<bool> mbListElementOpened; +}; + +enum WriterListType { unordered, ordered }; + +struct ltstr +{ + bool operator()(const WPXString & s1, const WPXString & s2) const + { + return strcmp(s1.cstr(), s2.cstr()) < 0; + } +}; + +_WriterDocumentState::_WriterDocumentState() : + mbFirstElement(true), + mbFirstParagraphInPageSpan(true), + mbInFakeSection(false), + mbListElementOpenedAtCurrentLevel(false), + mbTableCellOpened(false), + mbHeaderRow(false), + mbInNote(false), + mbInTextBox(false), + mbInFrame(false) +{ +} + +_WriterListState::_WriterListState() : + mpCurrentListStyle(NULL), + miCurrentListLevel(0), + miLastListLevel(0), + miLastListNumber(0), + mbListContinueNumbering(false), + mbListElementParagraphOpened(false), + mbListElementOpened() +{ +} + +class OdtGeneratorPrivate +{ +public: + OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType); + ~OdtGeneratorPrivate(); + void _resetDocumentState(); + bool _parseSourceDocument(WPXInputStream &input, const char *password); + bool _writeTargetDocument(OdfDocumentHandler *pHandler); + void _writeBegin(); + void _writeDefaultStyles(OdfDocumentHandler *pHandler); + void _writeMasterPages(OdfDocumentHandler *pHandler); + void _writePageLayouts(OdfDocumentHandler *pHandler); + void _allocateFontName(const WPXString &); + + void _openListLevel(TagOpenElement *pListLevelOpenElement); + void _closeListLevel(); + + OdfEmbeddedObject _findEmbeddedObjectHandler(const WPXString& mimeType); + + WPXInputStream *mpInput; + OdfDocumentHandler *mpHandler; + bool mbUsed; // whether or not it has been before (you can only use me once!) + + std::stack<WriterDocumentState> mWriterDocumentStates; + + std::stack<WriterListState> mWriterListStates; + + // paragraph styles + std::map<WPXString, ParagraphStyle *, ltstr> mTextStyleHash; + + // span styles + std::map<WPXString, SpanStyle *, ltstr> mSpanStyleHash; + + // font styles + std::map<WPXString, FontStyle *, ltstr> mFontHash; + + // embedded object handlers + std::map<WPXString, OdfEmbeddedObject, ltstr > mObjectHandlers; + + // section styles + std::vector<SectionStyle *> mSectionStyles; + double mfSectionSpaceAfter; + + // table styles + std::vector<TableStyle *> mTableStyles; + + // frame styles + std::vector<DocumentElement *> mFrameStyles; + + std::vector<DocumentElement *> mFrameAutomaticStyles; + + // metadata + std::vector<DocumentElement *> mMetaData; + + // list styles + unsigned int miNumListStyles; + + // style elements + std::vector<DocumentElement *> mStylesElements; + // content elements + std::vector<DocumentElement *> mBodyElements; + // the current set of elements that we're writing to + std::vector<DocumentElement *> * mpCurrentContentElements; + + // page state + std::vector<PageSpan *> mPageSpans; + PageSpan *mpCurrentPageSpan; + int miNumPageStyles; + + // list styles + std::vector<ListStyle *> mListStyles; + + // object state + unsigned miObjectNumber; + + // table state + TableStyle *mpCurrentTableStyle; + + const OdfStreamType mxStreamType; + + const char * mpPassword; + +}; + +OdtGeneratorPrivate::OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType) : + mpHandler(pHandler), + mbUsed(false), + mWriterDocumentStates(), + mWriterListStates(), + mfSectionSpaceAfter(0.0), + miNumListStyles(0), + mpCurrentContentElements(&mBodyElements), + mpCurrentPageSpan(NULL), + miNumPageStyles(0), + miObjectNumber(0), + mxStreamType(streamType) +{ + mWriterDocumentStates.push(WriterDocumentState()); + mWriterListStates.push(WriterListState()); +} + +OdtGeneratorPrivate::~OdtGeneratorPrivate() +{ + // clean up the mess we made + WRITER_DEBUG_MSG(("WriterWordPerfect: Cleaning up our mess..\n")); + + WRITER_DEBUG_MSG(("Destroying the body elements\n")); + for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); iterBody++) { + delete (*iterBody); + (*iterBody) = NULL; + } + + WRITER_DEBUG_MSG(("Destroying the styles elements\n")); + for (std::vector<DocumentElement *>::iterator iterStyles = mStylesElements.begin(); iterStyles != mStylesElements.end(); iterStyles++) { + delete (*iterStyles); + (*iterStyles) = NULL; // we may pass over the same element again (in the case of headers/footers spanning multiple pages) + // so make sure we don't do a double del + } + + WRITER_DEBUG_MSG(("Destroying the rest of the styles elements\n")); + for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin(); + iterTextStyle != mTextStyleHash.end(); iterTextStyle++) { + delete (iterTextStyle->second); + } + + for (std::map<WPXString, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin(); + iterSpanStyle != mSpanStyleHash.end(); iterSpanStyle++) { + delete(iterSpanStyle->second); + } + + for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); + iterFont != mFontHash.end(); iterFont++) { + delete(iterFont->second); + } + + for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); + iterListStyles != mListStyles.end(); iterListStyles++) { + delete(*iterListStyles); + } + for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin(); + iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) { + delete(*iterSectionStyles); + } + for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); + iterTableStyles != mTableStyles.end(); iterTableStyles++) { + delete((*iterTableStyles)); + } + + for (std::vector<PageSpan *>::iterator iterPageSpans = mPageSpans.begin(); + iterPageSpans != mPageSpans.end(); iterPageSpans++) { + delete(*iterPageSpans); + } + for (std::vector<DocumentElement *>::iterator iterFrameStyles = mFrameStyles.begin(); + iterFrameStyles != mFrameStyles.end(); iterFrameStyles++) { + delete(*iterFrameStyles); + } + for (std::vector<DocumentElement *>::iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin(); + iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); iterFrameAutomaticStyles++) { + delete(*iterFrameAutomaticStyles); + } + for (std::vector<DocumentElement *>::iterator iterMetaData = mMetaData.begin(); + iterMetaData != mMetaData.end(); iterMetaData++) { + delete(*iterMetaData); + } +} + +OdfEmbeddedObject OdtGeneratorPrivate::_findEmbeddedObjectHandler(const WPXString& mimeType) +{ + std::map<WPXString, OdfEmbeddedObject, ltstr>::iterator i = mObjectHandlers.find(mimeType); + if (i != mObjectHandlers.end()) + return i->second; + + return 0; +} + +OdtGenerator::OdtGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType) : + mpImpl(new OdtGeneratorPrivate(pHandler, streamType)) +{ +} + +OdtGenerator::~OdtGenerator() +{ + if (mpImpl) + delete mpImpl; +} + +void OdtGeneratorPrivate::_writeDefaultStyles(OdfDocumentHandler *pHandler) +{ + TagOpenElement("office:styles").write(pHandler); + + TagOpenElement defaultParagraphStyleOpenElement("style:default-style"); + defaultParagraphStyleOpenElement.addAttribute("style:family", "paragraph"); + defaultParagraphStyleOpenElement.write(pHandler); + + TagOpenElement defaultParagraphStylePropertiesOpenElement("style:paragraph-properties"); + defaultParagraphStylePropertiesOpenElement.addAttribute("style:tab-stop-distance", "0.5in"); + defaultParagraphStylePropertiesOpenElement.write(pHandler); + TagCloseElement defaultParagraphStylePropertiesCloseElement("style:paragraph-properties"); + defaultParagraphStylePropertiesCloseElement.write(pHandler); + + pHandler->endElement("style:default-style"); + + TagOpenElement defaultTableRowStyleOpenElement("style:default-style"); + defaultTableRowStyleOpenElement.addAttribute("style:family", "table-row"); + defaultTableRowStyleOpenElement.write(pHandler); + + TagOpenElement defaultTableRowPropertiesOpenElement("style:table-row-properties"); + defaultTableRowPropertiesOpenElement.addAttribute("fo:keep-together", "auto"); + defaultTableRowPropertiesOpenElement.write(pHandler); + + pHandler->endElement("style:table-row-properties"); + pHandler->endElement("style:default-style"); + + TagOpenElement standardStyleOpenElement("style:style"); + standardStyleOpenElement.addAttribute("style:name", "Standard"); + standardStyleOpenElement.addAttribute("style:family", "paragraph"); + standardStyleOpenElement.addAttribute("style:class", "text"); + standardStyleOpenElement.write(pHandler); + + pHandler->endElement("style:style"); + + TagOpenElement textBodyStyleOpenElement("style:style"); + textBodyStyleOpenElement.addAttribute("style:name", "Text_Body"); + textBodyStyleOpenElement.addAttribute("style:display-name", "Text Body"); + textBodyStyleOpenElement.addAttribute("style:family", "paragraph"); + textBodyStyleOpenElement.addAttribute("style:parent-style-name", "Standard"); + textBodyStyleOpenElement.addAttribute("style:class", "text"); + textBodyStyleOpenElement.write(pHandler); + + pHandler->endElement("style:style"); + + TagOpenElement tableContentsStyleOpenElement("style:style"); + tableContentsStyleOpenElement.addAttribute("style:name", "Table_Contents"); + tableContentsStyleOpenElement.addAttribute("style:display-name", "Table Contents"); + tableContentsStyleOpenElement.addAttribute("style:family", "paragraph"); + tableContentsStyleOpenElement.addAttribute("style:parent-style-name", "Text_Body"); + tableContentsStyleOpenElement.addAttribute("style:class", "extra"); + tableContentsStyleOpenElement.write(pHandler); + + pHandler->endElement("style:style"); + + TagOpenElement tableHeadingStyleOpenElement("style:style"); + tableHeadingStyleOpenElement.addAttribute("style:name", "Table_Heading"); + tableHeadingStyleOpenElement.addAttribute("style:display-name", "Table Heading"); + tableHeadingStyleOpenElement.addAttribute("style:family", "paragraph"); + tableHeadingStyleOpenElement.addAttribute("style:parent-style-name", "Table_Contents"); + tableHeadingStyleOpenElement.addAttribute("style:class", "extra"); + tableHeadingStyleOpenElement.write(pHandler); + + pHandler->endElement("style:style"); + + for (std::vector<DocumentElement *>::const_iterator iter = mFrameStyles.begin(); + iter != mFrameStyles.end(); iter++) + (*iter)->write(pHandler); + + pHandler->endElement("office:styles"); +} + +// writes everything up to the automatic styles declarations.. +void OdtGeneratorPrivate::_writeBegin() +{ +} + +void OdtGeneratorPrivate::_writeMasterPages(OdfDocumentHandler *pHandler) +{ + TagOpenElement("office:master-styles").write(mpHandler); + int pageNumber = 1; + for (unsigned int i=0; i<mPageSpans.size(); i++) + { + bool bLastPage; + (i == (mPageSpans.size() - 1)) ? bLastPage = true : bLastPage = false; + mPageSpans[i]->writeMasterPages(pageNumber, i, bLastPage, pHandler); + pageNumber += mPageSpans[i]->getSpan(); + } + pHandler->endElement("office:master-styles"); +} + +void OdtGeneratorPrivate::_writePageLayouts(OdfDocumentHandler *pHandler) +{ + for (unsigned int i=0; i<mPageSpans.size(); i++) + { + mPageSpans[i]->writePageLayout(i, pHandler); + } +} + +bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler) +{ + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Printing out the header stuff..\n")); + + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Start Document\n")); + mpHandler->startDocument(); + + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: preamble\n")); + WPXPropertyList docContentPropList; + docContentPropList.insert("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"); + docContentPropList.insert("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"); + docContentPropList.insert("xmlns:dc", "http://purl.org/dc/elements/1.1/"); + docContentPropList.insert("xmlns:config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"); + docContentPropList.insert("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"); + docContentPropList.insert("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0"); + docContentPropList.insert("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"); + docContentPropList.insert("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"); + docContentPropList.insert("xmlns:xlink", "http://www.w3.org/1999/xlink"); + docContentPropList.insert("xmlns:number", "http://openoffice.org/2000/datastyle"); + docContentPropList.insert("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"); + docContentPropList.insert("xmlns:chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"); + docContentPropList.insert("xmlns:dr3d", "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"); + docContentPropList.insert("xmlns:math", "http://www.w3.org/1998/Math/MathML"); + docContentPropList.insert("xmlns:form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0"); + docContentPropList.insert("xmlns:script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0"); + docContentPropList.insert("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0"); + docContentPropList.insert("office:version", "1.0"); + if (mxStreamType == ODF_FLAT_XML) + { + docContentPropList.insert("office:mimetype", "application/vnd.oasis.opendocument.text"); + mpHandler->startElement("office:document", docContentPropList); + } + else + mpHandler->startElement("office:document-content", docContentPropList); + + // write out the metadata + TagOpenElement("office:meta").write(mpHandler); + for (std::vector<DocumentElement *>::const_iterator iterMetaData = mMetaData.begin(); iterMetaData != mMetaData.end(); iterMetaData++) { + (*iterMetaData)->write(mpHandler); + } + mpHandler->endElement("office:meta"); + + // write out the font styles + TagOpenElement("office:font-face-decls").write(mpHandler); + for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); iterFont++) { + iterFont->second->write(mpHandler); + } + TagOpenElement symbolFontOpen("style:font-face"); + symbolFontOpen.addAttribute("style:name", "StarSymbol"); + symbolFontOpen.addAttribute("svg:font-family", "StarSymbol"); + symbolFontOpen.addAttribute("style:font-charset", "x-symbol"); + symbolFontOpen.write(mpHandler); + mpHandler->endElement("style:font-face"); + + mpHandler->endElement("office:font-face-decls"); + + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the styles..\n")); + + // write default styles + _writeDefaultStyles(mpHandler); + + TagOpenElement("office:automatic-styles").write(mpHandler); + + for (std::vector<DocumentElement *>::const_iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin(); + iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); iterFrameAutomaticStyles++) + { + (*iterFrameAutomaticStyles)->write(pHandler); + } + + for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iterTextStyle = mTextStyleHash.begin(); + iterTextStyle != mTextStyleHash.end(); iterTextStyle++) + { + // writing out the paragraph styles + if (strcmp((iterTextStyle->second)->getName().cstr(), "Standard")) + { + // don't write standard paragraph "no styles" style + (iterTextStyle->second)->write(pHandler); + } + } + + // span styles.. + for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iterSpanStyle = mSpanStyleHash.begin(); + iterSpanStyle != mSpanStyleHash.end(); iterSpanStyle++) + { + (iterSpanStyle->second)->write(pHandler); + } + + // writing out the sections styles + for (std::vector<SectionStyle *>::const_iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) { + (*iterSectionStyles)->write(pHandler); + } + + // writing out the lists styles + for (std::vector<ListStyle *>::const_iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) { + (*iterListStyles)->write(pHandler); + } + + // writing out the table styles + for (std::vector<TableStyle *>::const_iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) { + (*iterTableStyles)->write(pHandler); + } + + // writing out the page masters + _writePageLayouts(pHandler); + + + pHandler->endElement("office:automatic-styles"); + + _writeMasterPages(pHandler); + + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the document..\n")); + // writing out the document + TagOpenElement("office:body").write(mpHandler); + TagOpenElement("office:text").write(mpHandler); + + for (std::vector<DocumentElement *>::const_iterator iterBodyElements = mBodyElements.begin(); iterBodyElements != mBodyElements.end(); iterBodyElements++) { + (*iterBodyElements)->write(pHandler); + } + WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Finished writing all doc els..\n")); + + pHandler->endElement("office:text"); + pHandler->endElement("office:body"); + if (mxStreamType == ODF_FLAT_XML) + pHandler->endElement("office:document"); + else + pHandler->endElement("office:document-content"); + + pHandler->endDocument(); + + return true; +} + + +WPXString propListToStyleKey(const WPXPropertyList & xPropList) +{ + WPXString sKey; + WPXPropertyList::Iter i(xPropList); + for (i.rewind(); i.next(); ) + { + WPXString sProp; + sProp.sprintf("[%s:%s]", i.key(), i()->getStr().cstr()); + sKey.append(sProp); + } + + return sKey; +} + +WPXString getParagraphStyleKey(const WPXPropertyList & xPropList, const WPXPropertyListVector & xTabStops) +{ + WPXString sKey = propListToStyleKey(xPropList); + + WPXString sTabStops; + sTabStops.sprintf("[num-tab-stops:%i]", xTabStops.count()); + WPXPropertyListVector::Iter i(xTabStops); + for (i.rewind(); i.next();) + { + sTabStops.append(propListToStyleKey(i())); + } + sKey.append(sTabStops); + + return sKey; +} + +// _allocateFontName: add a (potentially mapped) font style to the hash if it's not already there, do nothing otherwise +void OdtGeneratorPrivate::_allocateFontName(const WPXString & sFontName) +{ + if (mFontHash.find(sFontName) == mFontHash.end()) + { + FontStyle *pFontStyle = new FontStyle(sFontName.cstr(), sFontName.cstr()); + mFontHash[sFontName] = pFontStyle; + } +} + +void OdtGenerator::setDocumentMetaData(const WPXPropertyList &propList) +{ + WPXPropertyList::Iter i(propList); + for (i.rewind(); i.next(); ) + { + // filter out libwpd elements + if (strncmp(i.key(), "libwpd", 6) != 0 && strncmp(i.key(), "dcterms", 7) != 0) + { + mpImpl->mMetaData.push_back(new TagOpenElement(i.key())); + WPXString sStringValue(i()->getStr(), true); + mpImpl->mMetaData.push_back(new CharDataElement(sStringValue.cstr())); + mpImpl->mMetaData.push_back(new TagCloseElement(i.key())); + } + } + +} + +void OdtGenerator::openPageSpan(const WPXPropertyList &propList) +{ + PageSpan *pPageSpan = new PageSpan(propList); + mpImpl->mPageSpans.push_back(pPageSpan); + mpImpl->mpCurrentPageSpan = pPageSpan; + mpImpl->miNumPageStyles++; + + mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = true; +} + +void OdtGenerator::openHeader(const WPXPropertyList &propList) +{ + std::vector<DocumentElement *> * pHeaderFooterContentElements = new std::vector<DocumentElement *>; + + if (propList["libwpd:occurence"]->getStr() == "even") + mpImpl->mpCurrentPageSpan->setHeaderLeftContent(pHeaderFooterContentElements); + else + mpImpl->mpCurrentPageSpan->setHeaderContent(pHeaderFooterContentElements); + + mpImpl->mpCurrentContentElements = pHeaderFooterContentElements; +} + +void OdtGenerator::closeHeader() +{ + mpImpl->mpCurrentContentElements = &(mpImpl->mBodyElements); +} + +void OdtGenerator::openFooter(const WPXPropertyList &propList) +{ + std::vector<DocumentElement *> * pHeaderFooterContentElements = new std::vector<DocumentElement *>; + + if (propList["libwpd:occurence"]->getStr() == "even") + mpImpl->mpCurrentPageSpan->setFooterLeftContent(pHeaderFooterContentElements); + else + mpImpl->mpCurrentPageSpan->setFooterContent(pHeaderFooterContentElements); + + mpImpl->mpCurrentContentElements = pHeaderFooterContentElements; +} + +void OdtGenerator::closeFooter() +{ + mpImpl->mpCurrentContentElements = &(mpImpl->mBodyElements); +} + +void OdtGenerator::openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns) +{ + int iNumColumns = columns.count(); + double fSectionMarginLeft = 0.0; + double fSectionMarginRight = 0.0; + if (propList["fo:margin-left"]) + fSectionMarginLeft = propList["fo:margin-left"]->getDouble(); + if (propList["fo:margin-right"]) + fSectionMarginRight = propList["fo:margin-right"]->getDouble(); + + if (iNumColumns > 1 || fSectionMarginLeft != 0 || fSectionMarginRight != 0) + { + if (propList["fo:margin-bottom"]) + mpImpl->mfSectionSpaceAfter = propList["fo:margin-bottom"]->getDouble(); + else if (propList["libwpd:margin-bottom"]) + mpImpl->mfSectionSpaceAfter = propList["libwpd:margin-bottom"]->getDouble(); + + WPXString sSectionName; + sSectionName.sprintf("Section%i", mpImpl->mSectionStyles.size()); + + SectionStyle *pSectionStyle = new SectionStyle(propList, columns, sSectionName.cstr()); + mpImpl->mSectionStyles.push_back(pSectionStyle); + + TagOpenElement *pSectionOpenElement = new TagOpenElement("text:section"); + pSectionOpenElement->addAttribute("text:style-name", pSectionStyle->getName()); + pSectionOpenElement->addAttribute("text:name", pSectionStyle->getName()); + mpImpl->mpCurrentContentElements->push_back(pSectionOpenElement); + } + else + mpImpl->mWriterDocumentStates.top().mbInFakeSection = true; +} + +void OdtGenerator::closeSection() +{ + if (!mpImpl->mWriterDocumentStates.top().mbInFakeSection) + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:section")); + else + mpImpl->mWriterDocumentStates.top().mbInFakeSection = false; + + mpImpl->mfSectionSpaceAfter = 0.0; +} + +void OdtGenerator::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) +{ + // FIXMENOW: What happens if we open a footnote inside a table? do we then inherit the footnote's style + // from "Table Contents" + + WPXPropertyList *pPersistPropList = new WPXPropertyList(propList); + ParagraphStyle *pStyle = NULL; + + if (mpImpl->mWriterDocumentStates.top().mbFirstElement && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements)) + { + // we don't have to go through the fuss of determining if the paragraph style is + // unique in this case, because if we are the first document element, then we + // are singular. Neither do we have to determine what our parent style is-- we can't + // be inside a table in this case (the table would be the first document element + //in that case) + pPersistPropList->insert("style:parent-style-name", "Standard"); + WPXString sName; + sName.sprintf("FS"); + + WPXString sParagraphHashKey("P|FS"); + pPersistPropList->insert("style:master-page-name", "Page_Style_1"); + pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); + mpImpl->mTextStyleHash[sParagraphHashKey] = pStyle; + mpImpl->mWriterDocumentStates.top().mbFirstElement = false; + mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; + } + else + { + if (mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements)) + { + WPXString sPageStyleName; + sPageStyleName.sprintf("Page_Style_%i", mpImpl->miNumPageStyles); + pPersistPropList->insert("style:master-page-name", sPageStyleName); + mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; + } + + if (mpImpl->mWriterDocumentStates.top().mbTableCellOpened) + { + if (mpImpl->mWriterDocumentStates.top().mbHeaderRow) + pPersistPropList->insert("style:parent-style-name", "Table_Heading"); + else + pPersistPropList->insert("style:parent-style-name", "Table_Contents"); + } + else + pPersistPropList->insert("style:parent-style-name", "Standard"); + + WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops); + + if (mpImpl->mTextStyleHash.find(sKey) == mpImpl->mTextStyleHash.end()) + { + WPXString sName; + sName.sprintf("S%i", mpImpl->mTextStyleHash.size()); + + pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); + + mpImpl->mTextStyleHash[sKey] = pStyle; + } + else + { + pStyle = mpImpl->mTextStyleHash[sKey]; + delete pPersistPropList; + } + } + // create a document element corresponding to the paragraph, and append it to our list of document elements + TagOpenElement *pParagraphOpenElement = new TagOpenElement("text:p"); + pParagraphOpenElement->addAttribute("text:style-name", pStyle->getName()); + mpImpl->mpCurrentContentElements->push_back(pParagraphOpenElement); +} + +void OdtGenerator::closeParagraph() +{ + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); +} + +void OdtGenerator::openSpan(const WPXPropertyList &propList) +{ + if (propList["style:font-name"]) + mpImpl->_allocateFontName(propList["style:font-name"]->getStr()); + WPXString sSpanHashKey = propListToStyleKey(propList); + WRITER_DEBUG_MSG(("WriterWordPerfect: Span Hash Key: %s\n", sSpanHashKey.cstr())); + + // Get the style + WPXString sName; + if (mpImpl->mSpanStyleHash.find(sSpanHashKey) == mpImpl->mSpanStyleHash.end()) + { + // allocate a new paragraph style + sName.sprintf("Span%i", mpImpl->mSpanStyleHash.size()); + SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList); + + mpImpl->mSpanStyleHash[sSpanHashKey] = pStyle; + } + else + { + sName.sprintf("%s", mpImpl->mSpanStyleHash.find(sSpanHashKey)->second->getName().cstr()); + } + + // create a document element corresponding to the paragraph, and append it to our list of document elements + TagOpenElement *pSpanOpenElement = new TagOpenElement("text:span"); + pSpanOpenElement->addAttribute("text:style-name", sName.cstr()); + mpImpl->mpCurrentContentElements->push_back(pSpanOpenElement); +} + +void OdtGenerator::closeSpan() +{ + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:span")); +} + +void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList) +{ + int id = 0; + if (propList["libwpd:id"]) + id = propList["libwpd:id"]->getInt(); + + OrderedListStyle *pOrderedListStyle = NULL; + if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id) + pOrderedListStyle = static_cast<OrderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?! + + // this rather appalling conditional makes sure we only start a new list (rather than continue an old + // one) if: (1) we have no prior list OR (2) the prior list is actually definitively different + // from the list that is just being defined (listIDs differ) OR (3) we can tell that the user actually + // is starting a new list at level 1 (and only level 1) + if (pOrderedListStyle == NULL || pOrderedListStyle->getListID() != id || + (propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 && + (propList["text:start-value"] && propList["text:start-value"]->getInt() != (mpImpl->mWriterListStates.top().miLastListNumber+1)))) + { + WRITER_DEBUG_MSG(("Attempting to create a new ordered list style (listid: %i)\n", id)); + WPXString sName; + sName.sprintf("OL%i", mpImpl->miNumListStyles); + mpImpl->miNumListStyles++; + pOrderedListStyle = new OrderedListStyle(sName.cstr(), id); + mpImpl->mListStyles.push_back(pOrderedListStyle); + mpImpl->mWriterListStates.top().mpCurrentListStyle = pOrderedListStyle; + mpImpl->mWriterListStates.top().mbListContinueNumbering = false; + mpImpl->mWriterListStates.top().miLastListNumber = 0; + } + else + mpImpl->mWriterListStates.top().mbListContinueNumbering = true; + + // Iterate through ALL list styles with the same WordPerfect list id and define a level if it is not already defined + // This solves certain problems with lists that start and finish without reaching certain levels and then begin again + // and reach those levels. See gradguide0405_PC.wpd in the regression suite + for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mpImpl->mListStyles.begin(); iterOrderedListStyles != mpImpl->mListStyles.end(); iterOrderedListStyles++) + { + if ((* iterOrderedListStyles)->getListID() == id) + (* iterOrderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList); + } +} + +void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList) +{ + int id = 0; + if (propList["libwpd:id"]) + id = propList["libwpd:id"]->getInt(); + + UnorderedListStyle *pUnorderedListStyle = NULL; + if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id) + pUnorderedListStyle = static_cast<UnorderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?! + + if (pUnorderedListStyle == NULL) { + WRITER_DEBUG_MSG(("Attempting to create a new unordered list style (listid: %i)\n", id)); + WPXString sName; + sName.sprintf("UL%i", mpImpl->miNumListStyles); + mpImpl->miNumListStyles++; + pUnorderedListStyle = new UnorderedListStyle(sName.cstr(), id); + mpImpl->mListStyles.push_back(pUnorderedListStyle); + mpImpl->mWriterListStates.top().mpCurrentListStyle = pUnorderedListStyle; + } + + // See comment in OdtGenerator::defineOrderedListLevel + for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mpImpl->mListStyles.begin(); iterUnorderedListStyles != mpImpl->mListStyles.end(); iterUnorderedListStyles++) + { + if ((* iterUnorderedListStyles)->getListID() == id) + (* iterUnorderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList); + } +} + +void OdtGenerator::openOrderedListLevel(const WPXPropertyList&) +{ + if (mpImpl->mWriterListStates.top().mbListElementParagraphOpened) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); + mpImpl->mWriterListStates.top().mbListElementParagraphOpened = false; + } + TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list"); + mpImpl->_openListLevel(pListLevelOpenElement); + + if (mpImpl->mWriterListStates.top().mbListContinueNumbering) { + pListLevelOpenElement->addAttribute("text:continue-numbering", "true"); + } + + mpImpl->mpCurrentContentElements->push_back(pListLevelOpenElement); +} + +void OdtGenerator::openUnorderedListLevel(const WPXPropertyList&) +{ + if (mpImpl->mWriterListStates.top().mbListElementParagraphOpened) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); + mpImpl->mWriterListStates.top().mbListElementParagraphOpened = false; + } + TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list"); + mpImpl->_openListLevel(pListLevelOpenElement); + + mpImpl->mpCurrentContentElements->push_back(pListLevelOpenElement); +} + +void OdtGeneratorPrivate::_openListLevel(TagOpenElement *pListLevelOpenElement) +{ + if (!mWriterListStates.top().mbListElementOpened.empty() && + !mWriterListStates.top().mbListElementOpened.top()) + { + mpCurrentContentElements->push_back(new TagOpenElement("text:list-item")); + mWriterListStates.top().mbListElementOpened.top() = true; + } + + mWriterListStates.top().mbListElementOpened.push(false); + if (mWriterListStates.top().mbListElementOpened.size() == 1) { + pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName()); + } +} + +void OdtGenerator::closeOrderedListLevel() +{ + mpImpl->_closeListLevel(); +} + +void OdtGenerator::closeUnorderedListLevel() +{ + mpImpl->_closeListLevel(); +} + +void OdtGeneratorPrivate::_closeListLevel() +{ + if (mWriterListStates.top().mbListElementOpened.top()) + { + mpCurrentContentElements->push_back(new TagCloseElement("text:list-item")); + mWriterListStates.top().mbListElementOpened.top() = false; + } + + mpCurrentContentElements->push_back(new TagCloseElement("text:list")); + + if (!mWriterListStates.top().mbListElementOpened.empty()) + { + mWriterListStates.top().mbListElementOpened.pop(); + } +} + +void OdtGenerator::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) +{ + mpImpl->mWriterListStates.top().miLastListLevel = mpImpl->mWriterListStates.top().miCurrentListLevel; + if (mpImpl->mWriterListStates.top().miCurrentListLevel == 1) + mpImpl->mWriterListStates.top().miLastListNumber++; + + if (mpImpl->mWriterListStates.top().mbListElementOpened.top()) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:list-item")); + mpImpl->mWriterListStates.top().mbListElementOpened.top() = false; + } + + ParagraphStyle *pStyle = NULL; + + WPXPropertyList *pPersistPropList = new WPXPropertyList(propList); + pPersistPropList->insert("style:list-style-name", mpImpl->mWriterListStates.top().mpCurrentListStyle->getName()); + pPersistPropList->insert("style:parent-style-name", "Standard"); + + WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops); + + if (mpImpl->mTextStyleHash.find(sKey) == mpImpl->mTextStyleHash.end()) + { + WPXString sName; + sName.sprintf("S%i", mpImpl->mTextStyleHash.size()); + + pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName); + + mpImpl->mTextStyleHash[sKey] = pStyle; + } + else + { + pStyle = mpImpl->mTextStyleHash[sKey]; + delete pPersistPropList; + } + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:list-item")); + + TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p"); + pOpenListElementParagraph->addAttribute("text:style-name", pStyle->getName()); + mpImpl->mpCurrentContentElements->push_back(pOpenListElementParagraph); + + if (mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements)) + mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; + + mpImpl->mWriterListStates.top().mbListElementOpened.top() = true; + mpImpl->mWriterListStates.top().mbListElementParagraphOpened = true; + mpImpl->mWriterListStates.top().mbListContinueNumbering = false; +} + +void OdtGenerator::closeListElement() +{ + // this code is kind of tricky, because we don't actually close the list element (because this list element + // could contain another list level in OOo's implementation of lists). that is done in the closeListLevel + // code (or when we open another list element) + + if (mpImpl->mWriterListStates.top().mbListElementParagraphOpened) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); + mpImpl->mWriterListStates.top().mbListElementParagraphOpened = false; + } +} + +void OdtGenerator::openFootnote(const WPXPropertyList &propList) +{ + mpImpl->mWriterListStates.push(WriterListState()); + TagOpenElement *pOpenFootNote = new TagOpenElement("text:note"); + pOpenFootNote->addAttribute("text:note-class", "footnote"); + if (propList["libwpd:number"]) + { + WPXString tmpString("ftn"); + tmpString.append(propList["libwpd:number"]->getStr()); + pOpenFootNote->addAttribute("text:id", tmpString); + } + mpImpl->mpCurrentContentElements->push_back(pOpenFootNote); + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation")); + if (propList["libwpd:number"]) + mpImpl->mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr())); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation")); + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:note-body")); + + mpImpl->mWriterDocumentStates.top().mbInNote = true; +} + +void OdtGenerator::closeFootnote() +{ + mpImpl->mWriterDocumentStates.top().mbInNote = false; + if (mpImpl->mWriterListStates.size() > 1) + mpImpl->mWriterListStates.pop(); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note-body")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note")); +} + +void OdtGenerator::openEndnote(const WPXPropertyList &propList) +{ + mpImpl->mWriterListStates.push(WriterListState()); + TagOpenElement *pOpenEndNote = new TagOpenElement("text:note"); + pOpenEndNote->addAttribute("text:note-class", "endnote"); + if (propList["libwpd:number"]) + { + WPXString tmpString("edn"); + tmpString.append(propList["libwpd:number"]->getStr()); + pOpenEndNote->addAttribute("text:id", tmpString); + } + mpImpl->mpCurrentContentElements->push_back(pOpenEndNote); + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation")); + if (propList["libwpd:number"]) + mpImpl->mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr())); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation")); + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:note-body")); + + mpImpl->mWriterDocumentStates.top().mbInNote = true; +} + +void OdtGenerator::closeEndnote() +{ + mpImpl->mWriterDocumentStates.top().mbInNote = false; + if (mpImpl->mWriterListStates.size() > 1) + mpImpl->mWriterListStates.pop(); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note-body")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:note")); +} + +void OdtGenerator::openComment(const WPXPropertyList &) +{ + mpImpl->mWriterListStates.push(WriterListState()); + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("office:annotation")); + + mpImpl->mWriterDocumentStates.top().mbInNote = true; +} + +void OdtGenerator::closeComment() +{ + mpImpl->mWriterDocumentStates.top().mbInNote = false; + if (mpImpl->mWriterListStates.size() > 1) + mpImpl->mWriterListStates.pop(); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("office:annotation")); +} + +void OdtGenerator::openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns) +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + WPXString sTableName; + sTableName.sprintf("Table%i", mpImpl->mTableStyles.size()); + + // FIXME: we base the table style off of the page's margin left, ignoring (potential) wordperfect margin + // state which is transmitted inside the page. could this lead to unacceptable behaviour? + // WLACH_REFACTORING: characterize this behaviour, probably should nip it at the bud within libwpd + TableStyle *pTableStyle = new TableStyle(propList, columns, sTableName.cstr()); + + if (mpImpl->mWriterDocumentStates.top().mbFirstElement && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements)) + { + WPXString sMasterPageName("Page_Style_1"); + pTableStyle->setMasterPageName(sMasterPageName); + mpImpl->mWriterDocumentStates.top().mbFirstElement = false; + } + + mpImpl->mTableStyles.push_back(pTableStyle); + + mpImpl->mpCurrentTableStyle = pTableStyle; + + TagOpenElement *pTableOpenElement = new TagOpenElement("table:table"); + + pTableOpenElement->addAttribute("table:name", sTableName.cstr()); + pTableOpenElement->addAttribute("table:style-name", sTableName.cstr()); + mpImpl->mpCurrentContentElements->push_back(pTableOpenElement); + + for (int i=0; i<pTableStyle->getNumColumns(); i++) + { + TagOpenElement *pTableColumnOpenElement = new TagOpenElement("table:table-column"); + WPXString sColumnStyleName; + sColumnStyleName.sprintf("%s.Column%i", sTableName.cstr(), (i+1)); + pTableColumnOpenElement->addAttribute("table:style-name", sColumnStyleName.cstr()); + mpImpl->mpCurrentContentElements->push_back(pTableColumnOpenElement); + + TagCloseElement *pTableColumnCloseElement = new TagCloseElement("table:table-column"); + mpImpl->mpCurrentContentElements->push_back(pTableColumnCloseElement); + } + } +} + +void OdtGenerator::openTableRow(const WPXPropertyList &propList) +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + if (propList["libwpd:is-header-row"] && (propList["libwpd:is-header-row"]->getInt())) + { + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("table:table-header-rows")); + mpImpl->mWriterDocumentStates.top().mbHeaderRow = true; + } + + WPXString sTableRowStyleName; + sTableRowStyleName.sprintf("%s.Row%i", mpImpl->mpCurrentTableStyle->getName().cstr(), mpImpl->mpCurrentTableStyle->getNumTableRowStyles()); + TableRowStyle *pTableRowStyle = new TableRowStyle(propList, sTableRowStyleName.cstr()); + mpImpl->mpCurrentTableStyle->addTableRowStyle(pTableRowStyle); + + TagOpenElement *pTableRowOpenElement = new TagOpenElement("table:table-row"); + pTableRowOpenElement->addAttribute("table:style-name", sTableRowStyleName); + mpImpl->mpCurrentContentElements->push_back(pTableRowOpenElement); + } +} + +void OdtGenerator::closeTableRow() +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("table:table-row")); + if (mpImpl->mWriterDocumentStates.top().mbHeaderRow) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("table:table-header-rows")); + mpImpl->mWriterDocumentStates.top().mbHeaderRow = false; + } + } +} + +void OdtGenerator::openTableCell(const WPXPropertyList &propList) +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + WPXString sTableCellStyleName; + sTableCellStyleName.sprintf( "%s.Cell%i", mpImpl->mpCurrentTableStyle->getName().cstr(), mpImpl->mpCurrentTableStyle->getNumTableCellStyles()); + TableCellStyle *pTableCellStyle = new TableCellStyle(propList, sTableCellStyleName.cstr()); + mpImpl->mpCurrentTableStyle->addTableCellStyle(pTableCellStyle); + + TagOpenElement *pTableCellOpenElement = new TagOpenElement("table:table-cell"); + pTableCellOpenElement->addAttribute("table:style-name", sTableCellStyleName); + if (propList["table:number-columns-spanned"]) + pTableCellOpenElement->addAttribute("table:number-columns-spanned", + propList["table:number-columns-spanned"]->getStr().cstr()); + if (propList["table:number-rows-spanned"]) + pTableCellOpenElement->addAttribute("table:number-rows-spanned", + propList["table:number-rows-spanned"]->getStr().cstr()); + // pTableCellOpenElement->addAttribute("table:value-type", "string"); + mpImpl->mpCurrentContentElements->push_back(pTableCellOpenElement); + + mpImpl->mWriterDocumentStates.top().mbTableCellOpened = true; + } +} + +void OdtGenerator::closeTableCell() +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("table:table-cell")); + mpImpl->mWriterDocumentStates.top().mbTableCellOpened = false; + } +} + +void OdtGenerator::insertCoveredTableCell(const WPXPropertyList &) +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("table:covered-table-cell")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("table:covered-table-cell")); + } +} + +void OdtGenerator::closeTable() +{ + if (!mpImpl->mWriterDocumentStates.top().mbInNote) + { + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("table:table")); + } +} + + +void OdtGenerator::insertTab() +{ + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:tab")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:tab")); +} + +void OdtGenerator::insertSpace() +{ + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:s")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:s")); +} + +void OdtGenerator::insertLineBreak() +{ + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:line-break")); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:line-break")); +} + +void OdtGenerator::insertField(const WPXString &type, const WPXPropertyList &propList) +{ + if (!type.len()) + return; + + TagOpenElement *openElement = new TagOpenElement(type); + if (type == "text:page-number") + openElement->addAttribute("text:select-page", "current"); + + if (propList["style:num-format"]) + openElement->addAttribute("style:num-format", propList["style:num-format"]->getStr()); + + mpImpl->mpCurrentContentElements->push_back(openElement); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement(type)); +} + +void OdtGenerator::insertText(const WPXString &text) +{ + DocumentElement *pText = new TextElement(text); + mpImpl->mpCurrentContentElements->push_back(pText); +} + +void OdtGenerator::openFrame(const WPXPropertyList &propList) +{ + mpImpl->mWriterListStates.push(WriterListState()); + + // First, let's create a Frame Style for this box + TagOpenElement *frameStyleOpenElement = new TagOpenElement("style:style"); + WPXString frameStyleName; + frameStyleName.sprintf("GraphicFrame_%i", mpImpl->miObjectNumber); + frameStyleOpenElement->addAttribute("style:name", frameStyleName); + frameStyleOpenElement->addAttribute("style:family", "graphic"); + + mpImpl->mFrameStyles.push_back(frameStyleOpenElement); + + TagOpenElement *frameStylePropertiesOpenElement = new TagOpenElement("style:graphic-properties"); + + if (propList["text:anchor-type"]) + frameStylePropertiesOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr()); + else + frameStylePropertiesOpenElement->addAttribute("text:anchor-type","paragraph"); + + if (propList["text:anchor-page-number"]) + frameStylePropertiesOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr()); + + if (propList["svg:x"]) + frameStylePropertiesOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr()); + + if (propList["svg:y"]) + frameStylePropertiesOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr()); + + if (propList["svg:width"]) + frameStylePropertiesOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr()); + + if (propList["svg:height"]) + frameStylePropertiesOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr()); + + if (propList["style:rel-width"]) + frameStylePropertiesOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr()); + + if (propList["style:rel-height"]) + frameStylePropertiesOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr()); + + if (propList["fo:max-width"]) + frameStylePropertiesOpenElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr()); + + if (propList["fo:max-height"]) + frameStylePropertiesOpenElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); + + if (propList["style:wrap"]) + frameStylePropertiesOpenElement->addAttribute("style:wrap", propList["style:wrap"]->getStr()); + + mpImpl->mFrameStyles.push_back(frameStylePropertiesOpenElement); + + mpImpl->mFrameStyles.push_back(new TagCloseElement("style:graphic-properties")); + + mpImpl->mFrameStyles.push_back(new TagCloseElement("style:style")); + + // Now, let's create an automatic style for this frame + TagOpenElement *frameAutomaticStyleElement = new TagOpenElement("style:style"); + WPXString frameAutomaticStyleName; + frameAutomaticStyleName.sprintf("fr%i", mpImpl->miObjectNumber); + frameAutomaticStyleElement->addAttribute("style:name", frameAutomaticStyleName); + frameAutomaticStyleElement->addAttribute("style:family", "graphic"); + frameAutomaticStyleElement->addAttribute("style:parent-style-name", frameStyleName); + + mpImpl->mFrameAutomaticStyles.push_back(frameAutomaticStyleElement); + + TagOpenElement *frameAutomaticStylePropertiesElement = new TagOpenElement("style:graphic-properties"); + if (propList["style:horizontal-pos"]) + frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", propList["style:horizontal-pos"]->getStr()); + else + frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", "left"); + + if (propList["style:horizontal-rel"]) + frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", propList["style:horizontal-rel"]->getStr()); + else + frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", "paragraph"); + + if (propList["style:vertical-pos"]) + frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", propList["style:vertical-pos"]->getStr()); + else + frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", "top"); + + if (propList["style:vertical-rel"]) + frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", propList["style:vertical-rel"]->getStr()); + else + frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", "page-content"); + + if (propList["fo:max-width"]) + frameAutomaticStylePropertiesElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr()); + + if (propList["fo:max-height"]) + frameAutomaticStylePropertiesElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); + + frameAutomaticStylePropertiesElement->addAttribute("draw:ole-draw-aspect", "1"); + + mpImpl->mFrameAutomaticStyles.push_back(frameAutomaticStylePropertiesElement); + + mpImpl->mFrameAutomaticStyles.push_back(new TagCloseElement("style:graphic-properties")); + + mpImpl->mFrameAutomaticStyles.push_back(new TagCloseElement("style:style")); + + // And write the frame itself + TagOpenElement *drawFrameOpenElement = new TagOpenElement("draw:frame"); + + drawFrameOpenElement->addAttribute("draw:style-name", frameAutomaticStyleName); + WPXString objectName; + objectName.sprintf("Object%i", mpImpl->miObjectNumber++); + drawFrameOpenElement->addAttribute("draw:name", objectName); + if (propList["text:anchor-type"]) + drawFrameOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr()); + else + drawFrameOpenElement->addAttribute("text:anchor-type","paragraph"); + + if (propList["text:anchor-page-number"]) + drawFrameOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr()); + + if (propList["svg:x"]) + drawFrameOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr()); + + if (propList["svg:y"]) + drawFrameOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr()); + + if (propList["svg:width"]) + drawFrameOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr()); + + if (propList["svg:height"]) + drawFrameOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr()); + + if (propList["style:rel-width"]) + drawFrameOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr()); + + if (propList["style:rel-height"]) + drawFrameOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr()); + + mpImpl->mpCurrentContentElements->push_back(drawFrameOpenElement); + + mpImpl->mWriterDocumentStates.top().mbInFrame = true; +} + +void OdtGenerator::closeFrame() +{ + if (mpImpl->mWriterListStates.size() > 1) + mpImpl->mWriterListStates.pop(); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:frame")); + + mpImpl->mWriterDocumentStates.top().mbInFrame = false; +} + +void OdtGenerator::insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data) +{ + if (!data.size()) + return; + if (!mpImpl->mWriterDocumentStates.top().mbInFrame) // Embedded objects without a frame simply don't make sense for us + return; + if (!propList["libwpd:mimetype"]) + return; + + OdfEmbeddedObject tmpObjectHandler = mpImpl->_findEmbeddedObjectHandler(propList["libwpd:mimetype"]->getStr()); + + if (tmpObjectHandler) + { + std::vector<DocumentElement *> tmpContentElements; + InternalHandler tmpHandler(&tmpContentElements); + + if (tmpObjectHandler(data, &tmpHandler, ODF_FLAT_XML) && !tmpContentElements.empty()) + { + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:object")); + for (std::vector<DocumentElement *>::const_iterator iter = tmpContentElements.begin(); iter != tmpContentElements.end(); iter++) + mpImpl->mpCurrentContentElements->push_back(*iter); + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:object")); + } + } + else + // assuming we have a binary image that we can just insert as it is + { + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:image")); + + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("office:binary-data")); + + WPXString binaryBase64Data = data.getBase64Data(); + + mpImpl->mpCurrentContentElements->push_back(new CharDataElement(binaryBase64Data.cstr())); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("office:binary-data")); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:image")); + } +} + +void OdtGenerator::openTextBox(const WPXPropertyList &) +{ + if (!mpImpl->mWriterDocumentStates.top().mbInFrame) // Text box without a frame simply doesn't make sense for us + return; + mpImpl->mWriterListStates.push(WriterListState()); + mpImpl->mWriterDocumentStates.push(WriterDocumentState()); + mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:text-box")); + mpImpl->mWriterDocumentStates.top().mbInTextBox = true; + mpImpl->mWriterDocumentStates.top().mbFirstElement = false; +} + +void OdtGenerator::closeTextBox() +{ + if (!mpImpl->mWriterDocumentStates.top().mbInTextBox) + return; + if (mpImpl->mWriterListStates.size() > 1) + mpImpl->mWriterListStates.pop(); + if (mpImpl->mWriterDocumentStates.size() > 1) + mpImpl->mWriterDocumentStates.pop(); + + mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:text-box")); +} + +void OdtGenerator::defineSectionStyle(WPXPropertyList const&, WPXPropertyListVector const&) +{ +} + +void OdtGenerator::insertEquation(WPXPropertyList const&, WPXString const&) +{ +} + +void OdtGenerator::endDocument() +{ + // Write out the collected document + mpImpl->_writeTargetDocument(mpImpl->mpHandler); +} + +void OdtGenerator::startDocument() +{ +} + +void OdtGenerator::closePageSpan() +{ +} + +void OdtGenerator::definePageStyle(WPXPropertyList const&) +{ +} + +void OdtGenerator::defineParagraphStyle(WPXPropertyList const&, WPXPropertyListVector const&) +{ +} + +void OdtGenerator::defineCharacterStyle(WPXPropertyList const&) +{ +} + +void OdtGenerator::registerEmbeddedObjectHandler(const WPXString &mimeType, OdfEmbeddedObject objectHandler) +{ + mpImpl->mObjectHandlers[mimeType] = objectHandler; +} diff --git a/writerperfect/source/filter/OdtGenerator.hxx b/writerperfect/source/filter/OdtGenerator.hxx new file mode 100644 index 000000000000..1b7f5268f88b --- /dev/null +++ b/writerperfect/source/filter/OdtGenerator.hxx @@ -0,0 +1,119 @@ +/* OdtGenerator: Collects sections and runs of text from a + * wordperfect file (and styles to go along with them) and writes them + * to a target file + * + * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com) + * Copyright (C) 2003-2004 Net Integration Technologies (http://www.net-itech.com) + * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information visit http://libwpd.sourceforge.net + * + */ + +/* "This product is not manufactured, approved, or supported by + * Corel Corporation or Corel Corporation Limited." + */ + +#ifndef _ODTGENERATOR_H +#define _ODTGENERATOR_H + +#include <libwpd/libwpd.h> + +#include "OdfDocumentHandler.hxx" + + +typedef bool (*OdfEmbeddedObject)(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType); + +class OdtGeneratorPrivate; + +class OdtGenerator : public WPXDocumentInterface +{ +public: + OdtGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType); + ~OdtGenerator(); + + // WPXDocumentInterface's implementation + void setDocumentMetaData(const WPXPropertyList &propList); + void startDocument(); + void endDocument(); + + void definePageStyle(const WPXPropertyList&); + void openPageSpan(const WPXPropertyList &propList); + void closePageSpan(); + + void defineSectionStyle(const WPXPropertyList&, const WPXPropertyListVector&); + void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns); + void closeSection(); + + void openHeader(const WPXPropertyList &propList); + void closeHeader(); + void openFooter(const WPXPropertyList &propList); + void closeFooter(); + + void defineParagraphStyle(const WPXPropertyList&, const WPXPropertyListVector&); + void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); + void closeParagraph(); + + void defineCharacterStyle(const WPXPropertyList&); + void openSpan(const WPXPropertyList &propList); + void closeSpan(); + + void insertTab(); + void insertSpace(); + void insertText(const WPXString &text); + void insertLineBreak(); + void insertField(const WPXString &type, const WPXPropertyList &propList); + + void defineOrderedListLevel(const WPXPropertyList &propList); + void defineUnorderedListLevel(const WPXPropertyList &propList); + void openOrderedListLevel(const WPXPropertyList &propList); + void openUnorderedListLevel(const WPXPropertyList &propList); + void closeOrderedListLevel(); + void closeUnorderedListLevel(); + void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); + void closeListElement(); + + void openFootnote(const WPXPropertyList &propList); + void closeFootnote(); + void openEndnote(const WPXPropertyList &propList); + void closeEndnote(); + void openComment(const WPXPropertyList &propList); + void closeComment(); + void openTextBox(const WPXPropertyList &propList); + void closeTextBox(); + + void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns); + void openTableRow(const WPXPropertyList &propList); + void closeTableRow(); + void openTableCell(const WPXPropertyList &propList); + void closeTableCell(); + void insertCoveredTableCell(const WPXPropertyList &propList); + void closeTable(); + + void openFrame(const WPXPropertyList & propList); + void closeFrame(); + + void insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data); + void insertEquation(const WPXPropertyList &propList, const WPXString &data); + + // Register special converter for certain embedded binary objects + void registerEmbeddedObjectHandler(const WPXString &mimeType, OdfEmbeddedObject objectHandler); + +private: + OdtGeneratorPrivate *mpImpl; +}; +#endif diff --git a/writerperfect/source/filter/PageSpan.cxx b/writerperfect/source/filter/PageSpan.cxx index 7ff4d1ce6977..95b74f96640c 100644 --- a/writerperfect/source/filter/PageSpan.cxx +++ b/writerperfect/source/filter/PageSpan.cxx @@ -1,9 +1,8 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SectionStyle: Stores (and writes) section-based information (e.g.: a column * break needs a new section) that is needed at the head of an OO document and * is referenced throughout the entire document * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,7 +28,6 @@ #include "FilterInternal.hxx" #include "PageSpan.hxx" #include "DocumentElement.hxx" -#include "DocumentHandler.hxx" PageSpan::PageSpan(const WPXPropertyList &xPropList) : mxPropList(xPropList), @@ -163,7 +161,7 @@ void PageSpan::setFooterLeftContent(std::vector<DocumentElement *> * pFooterCont mpFooterLeftContent = pFooterContent; } -void PageSpan::writePageLayout(const int iNum, DocumentHandlerInterface *pHandler) const +void PageSpan::writePageLayout(const int iNum, OdfDocumentHandler *pHandler) const { WPXPropertyList propList; @@ -194,7 +192,7 @@ void PageSpan::writePageLayout(const int iNum, DocumentHandlerInterface *pHandle } void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum, const bool bLastPageSpan, - DocumentHandlerInterface *pHandler) const + OdfDocumentHandler *pHandler) const { int iSpan = 0; (bLastPageSpan) ? iSpan = 1 : iSpan = getSpan(); @@ -223,9 +221,9 @@ void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum { _writeHeaderFooter("style:header", *mpHeaderContent, pHandler); pHandler->endElement("style:header"); - if (mpHeaderLeftContent) + if (mpHeaderLeftContent) { - _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler); + _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler); pHandler->endElement("style:header-left"); } } @@ -241,9 +239,9 @@ void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum { _writeHeaderFooter("style:footer", *mpFooterContent, pHandler); pHandler->endElement("style:footer"); - if (mpFooterLeftContent) + if (mpFooterLeftContent) { - _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler); + _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler); pHandler->endElement("style:footer-left"); } } @@ -257,20 +255,17 @@ void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum pHandler->endElement("style:master-page"); } - } void PageSpan::_writeHeaderFooter(const char *headerFooterTagName, const std::vector<DocumentElement *> & headerFooterContent, - DocumentHandlerInterface *pHandler) const + OdfDocumentHandler *pHandler) const { TagOpenElement headerFooterOpen(headerFooterTagName); headerFooterOpen.write(pHandler); for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin(); iter != headerFooterContent.end(); - ++iter) { + iter++) { (*iter)->write(pHandler); } } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/PageSpan.hxx b/writerperfect/source/filter/PageSpan.hxx index 92eba26fe4a4..c991fd41f0ff 100644 --- a/writerperfect/source/filter/PageSpan.hxx +++ b/writerperfect/source/filter/PageSpan.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* PageSpan: Stores (and writes) page-based information (e.g.: margins, * headers/footers) * - * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,15 +30,15 @@ #include <vector> class DocumentElement; -class DocumentHandlerInterface; +class OdfDocumentHandler; class PageSpan { public: PageSpan(const WPXPropertyList &xPropList); virtual ~PageSpan(); - void writePageLayout(const int iNum, DocumentHandlerInterface *pHandler) const; - void writeMasterPages(const int iStartingNum, const int iPageLayoutNum, const bool bLastPageSpan, DocumentHandlerInterface *pHandler) const; + void writePageLayout(const int iNum, OdfDocumentHandler *pHandler) const; + void writeMasterPages(const int iStartingNum, const int iPageLayoutNum, const bool bLastPageSpan, OdfDocumentHandler *pHandler) const; int getSpan() const; double getMarginLeft() const; double getMarginRight() const; @@ -50,7 +49,7 @@ public: void setFooterLeftContent(std::vector<DocumentElement *> * pFooterContent); protected: void _writeHeaderFooter(const char *headerFooterTagName, const std::vector<DocumentElement *> & headerFooterContent, - DocumentHandlerInterface *pHandler) const; + OdfDocumentHandler *pHandler) const; private: WPXPropertyList mxPropList; std::vector<DocumentElement *> * mpHeaderContent; @@ -59,5 +58,3 @@ private: std::vector<DocumentElement *> * mpFooterLeftContent; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/SectionStyle.cxx b/writerperfect/source/filter/SectionStyle.cxx index fadc190ab9b6..8d49ef5004c3 100644 --- a/writerperfect/source/filter/SectionStyle.cxx +++ b/writerperfect/source/filter/SectionStyle.cxx @@ -1,9 +1,8 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SectionStyle: Stores (and writes) section-based information (e.g.: a column * break needs a new section) that is needed at the head of an OO document and * is referenced throughout the entire document * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * Copyright (c) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) * * This program is free software; you can redistribute it and/or @@ -45,7 +44,7 @@ SectionStyle::SectionStyle(const WPXPropertyList &xPropList, { } -void SectionStyle::write(DocumentHandlerInterface *pHandler) const +void SectionStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement styleOpen("style:style"); styleOpen.addAttribute("style:name", getName()); @@ -61,8 +60,8 @@ void SectionStyle::write(DocumentHandlerInterface *pHandler) const if (mColumns.count() > 1) { - columnProps.insert("fo:column-count", (int)mColumns.count()); - pHandler->startElement("style:columns", columnProps); + columnProps.insert("fo:column-count", (int)mColumns.count()); + pHandler->startElement("style:columns", columnProps); WPXPropertyListVector::Iter i(mColumns); for (i.rewind(); i.next();) @@ -85,5 +84,3 @@ void SectionStyle::write(DocumentHandlerInterface *pHandler) const pHandler->endElement("style:style"); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/SectionStyle.hxx b/writerperfect/source/filter/SectionStyle.hxx index ee7a003fffae..7b5379af29be 100644 --- a/writerperfect/source/filter/SectionStyle.hxx +++ b/writerperfect/source/filter/SectionStyle.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SectionStyle: Stores (and writes) section-based information (e.g.: a column * change needs a new section) that is needed at the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,12 +37,10 @@ class SectionStyle : public Style { public: SectionStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &xColumns, const char *psName); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXPropertyList mPropList; WPXPropertyListVector mColumns; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/Style.hxx b/writerperfect/source/filter/Style.hxx index d54f0c8116ca..41afe5241104 100644 --- a/writerperfect/source/filter/Style.hxx +++ b/writerperfect/source/filter/Style.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Style: A base class from which all other styles are inherited, includes * a name. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,7 +33,7 @@ class TopLevelElementStyle { public: - TopLevelElementStyle() : mpsMasterPageName(0) { } + TopLevelElementStyle() : mpsMasterPageName(NULL) { } virtual ~TopLevelElementStyle() { if (mpsMasterPageName) delete mpsMasterPageName; } void setMasterPageName(WPXString &sMasterPageName) { mpsMasterPageName = new WPXString(sMasterPageName); } const WPXString * getMasterPageName() const { return mpsMasterPageName; } @@ -49,12 +48,10 @@ class Style Style(const WPXString &psName) : msName(psName) {} virtual ~Style() {} - virtual void write(DocumentHandlerInterface * /* pHandler */) const {}; + virtual void write(OdfDocumentHandler *) const {}; const WPXString &getName() const { return msName; } private: WPXString msName; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/TableStyle.cxx b/writerperfect/source/filter/TableStyle.cxx index 0a17023260c1..9429acfbf9b2 100644 --- a/writerperfect/source/filter/TableStyle.cxx +++ b/writerperfect/source/filter/TableStyle.cxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* TableStyle: Stores (and writes) table-based information that is * needed at the head of an OO document. * - * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com) * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com) * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) * @@ -44,7 +43,7 @@ TableCellStyle::TableCellStyle(const WPXPropertyList &xPropList, const char *psN { } -void TableCellStyle::write(DocumentHandlerInterface *pHandler) const +void TableCellStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement styleOpen("style:style"); styleOpen.addAttribute("style:name", getName()); @@ -73,7 +72,7 @@ TableRowStyle::TableRowStyle(const WPXPropertyList &propList, const char *psName { } -void TableRowStyle::write(DocumentHandlerInterface *pHandler) const +void TableRowStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement styleOpen("style:style"); styleOpen.addAttribute("style:name", getName()); @@ -104,13 +103,13 @@ TableStyle::~TableStyle() { typedef std::vector<TableCellStyle *>::iterator TCSVIter; typedef std::vector<TableRowStyle *>::iterator TRSVIter; - for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); ++iterTableCellStyles) + for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); iterTableCellStyles++) delete(*iterTableCellStyles); - for (TRSVIter iterTableRowStyles = mTableRowStyles.begin() ; iterTableRowStyles != mTableRowStyles.end(); ++iterTableRowStyles) + for (TRSVIter iterTableRowStyles = mTableRowStyles.begin() ; iterTableRowStyles != mTableRowStyles.end(); iterTableRowStyles++) delete(*iterTableRowStyles); } -void TableStyle::write(DocumentHandlerInterface *pHandler) const +void TableStyle::write(OdfDocumentHandler *pHandler) const { TagOpenElement styleOpen("style:style"); styleOpen.addAttribute("style:name", getName()); @@ -140,14 +139,14 @@ void TableStyle::write(DocumentHandlerInterface *pHandler) const WPXPropertyListVector::Iter j(mColumns); for (j.rewind(); j.next();) { - TagOpenElement styleOpen2("style:style"); + TagOpenElement columnStyleOpen("style:style"); WPXString sColumnName; sColumnName.sprintf("%s.Column%i", getName().cstr(), i); - styleOpen2.addAttribute("style:name", sColumnName); - styleOpen2.addAttribute("style:family", "table-column"); - styleOpen2.write(pHandler); + columnStyleOpen.addAttribute("style:name", sColumnName); + columnStyleOpen.addAttribute("style:family", "table-column"); + columnStyleOpen.write(pHandler); - pHandler->startElement("style:table-column-properties", j()); + pHandler->startElement("style:table-column-properties", j()); pHandler->endElement("style:table-column-properties"); pHandler->endElement("style:style"); @@ -156,12 +155,10 @@ void TableStyle::write(DocumentHandlerInterface *pHandler) const } typedef std::vector<TableRowStyle *>::const_iterator TRSVIter; - for (TRSVIter iterTableRow = mTableRowStyles.begin() ; iterTableRow != mTableRowStyles.end(); ++iterTableRow) + for (TRSVIter iterTableRow = mTableRowStyles.begin() ; iterTableRow != mTableRowStyles.end(); iterTableRow++) (*iterTableRow)->write(pHandler); typedef std::vector<TableCellStyle *>::const_iterator TCSVIter; - for (TCSVIter iterTableCell = mTableCellStyles.begin() ; iterTableCell != mTableCellStyles.end(); ++iterTableCell) + for (TCSVIter iterTableCell = mTableCellStyles.begin() ; iterTableCell != mTableCellStyles.end(); iterTableCell++) (*iterTableCell)->write(pHandler); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/TableStyle.hxx b/writerperfect/source/filter/TableStyle.hxx index 95c30892faf5..f60993d7ea38 100644 --- a/writerperfect/source/filter/TableStyle.hxx +++ b/writerperfect/source/filter/TableStyle.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* TableStyle: Stores (and writes) table-based information that is * needed at the head of an OO document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) * * This program is free software; you can redistribute it and/or @@ -28,27 +27,21 @@ */ #ifndef _TABLESTYLE_H #define _TABLESTYLE_H -#if defined _MSC_VER -#pragma warning( push, 1 ) -#endif #include <libwpd/libwpd.h> -#if defined _MSC_VER -#pragma warning( pop ) -#endif #include <vector> #include "Style.hxx" #include "WriterProperties.hxx" -#include "DocumentHandlerInterface.hxx" class DocumentElement; +class OdfDocumentHandler; class TableCellStyle : public Style { public: virtual ~TableCellStyle() {}; TableCellStyle(const WPXPropertyList &xPropList, const char *psName); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXPropertyList mPropList; }; @@ -58,7 +51,7 @@ class TableRowStyle : public Style public: virtual ~TableRowStyle() {}; TableRowStyle(const WPXPropertyList &propList, const char *psName); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXPropertyList mPropList; }; @@ -68,7 +61,7 @@ class TableStyle : public Style, public TopLevelElementStyle public: TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName); virtual ~TableStyle(); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; int getNumColumns() const { return mColumns.count(); } void addTableCellStyle(TableCellStyle *pTableCellStyle) { mTableCellStyles.push_back(pTableCellStyle); } int getNumTableCellStyles() { return mTableCellStyles.size(); } @@ -81,5 +74,3 @@ private: std::vector<TableRowStyle *> mTableRowStyles; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/TextRunStyle.cxx b/writerperfect/source/filter/TextRunStyle.cxx index 96101a0a7608..4b169883c392 100644 --- a/writerperfect/source/filter/TextRunStyle.cxx +++ b/writerperfect/source/filter/TextRunStyle.cxx @@ -1,9 +1,8 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* TextRunStyle: Stores (and writes) paragraph/span-style-based information * (e.g.: a paragraph might be bold) that is needed at the head of an OO * document. * - * Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com) * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com) * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) * @@ -51,19 +50,19 @@ ParagraphStyle::~ParagraphStyle() delete mpPropList; } -void ParagraphStyle::write(DocumentHandlerInterface *pHandler) const +void ParagraphStyle::write(OdfDocumentHandler *pHandler) const { WRITER_DEBUG_MSG(("Writing a paragraph style..\n")); - WPXPropertyList propList; + WPXPropertyList propList; propList.insert("style:name", msName.cstr()); propList.insert("style:family", "paragraph"); propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr()); if ((*mpPropList)["style:master-page-name"]) propList.insert("style:master-page-name", (*mpPropList)["style:master-page-name"]->getStr()); - pHandler->startElement("style:style", propList); + pHandler->startElement("style:style", propList); - propList.clear(); + propList.clear(); WPXPropertyList::Iter i((*mpPropList)); for (i.rewind(); i.next(); ) { @@ -94,32 +93,35 @@ void ParagraphStyle::write(DocumentHandlerInterface *pHandler) const propList.insert("fo:text-align", i()->getStr()); if (strcmp(i.key(), "fo:text-align-last") == 0) propList.insert("fo:text-align-last", i()->getStr()); + if (strcmp(i.key(), "style:page-number") == 0) + propList.insert("style:page-number", i()->getStr()); + } propList.insert("style:justify-single-word", "false"); pHandler->startElement("style:paragraph-properties", propList); - if (mxTabStops.count() > 0) + if (mxTabStops.count() > 0) + { + TagOpenElement tabListOpen("style:tab-stops"); + tabListOpen.write(pHandler); + WPXPropertyListVector::Iter k(mxTabStops); + for (k.rewind(); k.next();) { - TagOpenElement tabListOpen("style:tab-stops"); - tabListOpen.write(pHandler); - WPXPropertyListVector::Iter i2(mxTabStops); - for (i2.rewind(); i2.next();) - { - if (i2()["style:position"] && i2()["style:position"]->getDouble() < 0) + if (k()["style:position"] && k()["style:position"]->getDouble() < 0.0) continue; - TagOpenElement tabStopOpen("style:tab-stop"); - - WPXPropertyList::Iter j(i2()); - for (j.rewind(); j.next(); ) - { - tabStopOpen.addAttribute(j.key(), j()->getStr().cstr()); - } - tabStopOpen.write(pHandler); - pHandler->endElement("style:tab-stop"); - } - pHandler->endElement("style:tab-stops"); + TagOpenElement tabStopOpen("style:tab-stop"); + + WPXPropertyList::Iter j(k()); + for (j.rewind(); j.next(); ) + { + tabStopOpen.addAttribute(j.key(), j()->getStr().cstr()); + } + tabStopOpen.write(pHandler); + pHandler->endElement("style:tab-stop"); } + pHandler->endElement("style:tab-stops"); + } pHandler->endElement("style:paragraph-properties"); pHandler->endElement("style:style"); @@ -127,19 +129,19 @@ void ParagraphStyle::write(DocumentHandlerInterface *pHandler) const SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) : Style(psName), - mPropList(xPropList) + mPropList(xPropList) { } -void SpanStyle::write(DocumentHandlerInterface *pHandler) const +void SpanStyle::write(OdfDocumentHandler *pHandler) const { WRITER_DEBUG_MSG(("Writing a span style..\n")); - WPXPropertyList styleOpenList; + WPXPropertyList styleOpenList; styleOpenList.insert("style:name", getName()); styleOpenList.insert("style:family", "text"); - pHandler->startElement("style:style", styleOpenList); + pHandler->startElement("style:style", styleOpenList); - WPXPropertyList propList(mPropList); + WPXPropertyList propList(mPropList); if (mPropList["style:font-name"]) { @@ -151,9 +153,9 @@ void SpanStyle::write(DocumentHandlerInterface *pHandler) const { if (mPropList["fo:font-size"]->getDouble() > 0.0) { - propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr()); - propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr()); - } + propList.insert("style:font-size-asian", mPropList["fo:font-size"]->getStr()); + propList.insert("style:font-size-complex", mPropList["fo:font-size"]->getStr()); + } else propList.remove("fo:font-size"); } @@ -175,5 +177,3 @@ void SpanStyle::write(DocumentHandlerInterface *pHandler) const pHandler->endElement("style:text-properties"); pHandler->endElement("style:style"); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/TextRunStyle.hxx b/writerperfect/source/filter/TextRunStyle.hxx index 492132cfc54d..b9b5763805b3 100644 --- a/writerperfect/source/filter/TextRunStyle.hxx +++ b/writerperfect/source/filter/TextRunStyle.hxx @@ -1,9 +1,8 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* TextRunStyle: Stores (and writes) paragraph/span-style-based information * (e.g.: a paragraph might be bold) that is needed at the head of an OO * document. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch) * * This program is free software; you can redistribute it and/or @@ -36,13 +35,14 @@ class TagOpenElement; class DocumentElement; +class OdfDocumentHandler; class ParagraphStyle { public: ParagraphStyle(WPXPropertyList *propList, const WPXPropertyListVector &tabStops, const WPXString &sName); virtual ~ParagraphStyle(); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; WPXString getName() const { return msName; } private: WPXPropertyList *mpPropList; @@ -55,11 +55,9 @@ class SpanStyle : public Style { public: SpanStyle(const char *psName, const WPXPropertyList &xPropList); - virtual void write(DocumentHandlerInterface *pHandler) const; + virtual void write(OdfDocumentHandler *pHandler) const; private: WPXPropertyList mPropList; }; #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/WriterProperties.hxx b/writerperfect/source/filter/WriterProperties.hxx index 3889b21e2be8..8b61b65ced43 100644 --- a/writerperfect/source/filter/WriterProperties.hxx +++ b/writerperfect/source/filter/WriterProperties.hxx @@ -1,8 +1,7 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* WriterProperties: A grab bag of writer-specific properties which we use * define here for later use. * - * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca) + * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,10 +28,8 @@ #define _WRITER_PROPERTIES_H #define IMP_DEFAULT_SUPER_SUB_SCRIPT "58%" -#define IMP_NUM_CENTIMETERES_PER_INCH 2.54 +#define IMP_NUM_CENTIMETERES_PER_INCH 2.54f #define IMP_DEFAULT_FONT_NAME "Times New Roman" #define IMP_DEFAULT_FONT_SIZE 12.0 #define IMP_DEFAULT_FONT_PITCH "variable" #endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/makefile.mk b/writerperfect/source/filter/makefile.mk index f211101f706e..eda3ec7e3f0a 100644 --- a/writerperfect/source/filter/makefile.mk +++ b/writerperfect/source/filter/makefile.mk @@ -22,17 +22,16 @@ INCPRE+=$(LIBWPS_CFLAGS) INCPRE+= -I.. SLOFILES= \ - $(SLO)$/DocumentCollector.obj \ - $(SLO)$/DocumentElement.obj \ + $(SLO)$/DocumentElement.obj \ $(SLO)$/DocumentHandler.obj \ - $(SLO)$/FontStyle.obj \ - $(SLO)$/GraphicsStyle.obj \ + $(SLO)$/FontStyle.obj \ $(SLO)$/InternalHandler.obj \ - $(SLO)$/ListStyle.obj \ - $(SLO)$/OdgExporter.obj \ - $(SLO)$/PageSpan.obj \ - $(SLO)$/SectionStyle.obj \ - $(SLO)$/TableStyle.obj \ + $(SLO)$/ListStyle.obj \ + $(SLO)$/OdgGenerator.obj \ + $(SLO)$/OdtGenerator.obj \ + $(SLO)$/PageSpan.obj \ + $(SLO)$/SectionStyle.obj \ + $(SLO)$/TableStyle.obj \ $(SLO)$/TextRunStyle.obj .INCLUDE : target.mk diff --git a/writerperfect/source/wpdimp/WordPerfectCollector.cxx b/writerperfect/source/wpdimp/WordPerfectCollector.cxx deleted file mode 100644 index 83fdec5ff9cd..000000000000 --- a/writerperfect/source/wpdimp/WordPerfectCollector.cxx +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* WordPerfectCollector: Collects sections and runs of text from a - * wordperfect file (and styles to go along with them) and writes them - * to a Writer target document - * - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#if defined _MSC_VER -#pragma warning( push, 1 ) -#endif -#include "WordPerfectCollector.hxx" -#include <libwpd/WPDocument.h> -#if defined _MSC_VER -#pragma warning( pop ) -#endif - -WordPerfectCollector::WordPerfectCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler, const rtl::OString& password) : - DocumentCollector(pInput, pHandler), - maUtf8Password(password) -{ -} - -WordPerfectCollector::~WordPerfectCollector() -{ -} - -bool WordPerfectCollector::parseSourceDocument(WPXInputStream &input) -{ - WPDResult result; - if (maUtf8Password.getLength()) - result = WPDocument::parse(&input, static_cast<WPXDocumentInterface *>(this), maUtf8Password.getStr()); - else - result = WPDocument::parse(&input, static_cast<WPXDocumentInterface *>(this), NULL); - if (result != WPD_OK) - return false; - - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/wpdimp/WordPerfectCollector.hxx b/writerperfect/source/wpdimp/WordPerfectCollector.hxx deleted file mode 100644 index fce25691e951..000000000000 --- a/writerperfect/source/wpdimp/WordPerfectCollector.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* WordPerfectCollector: Collects sections and runs of text from a - * wordperfect file (and styles to go along with them) and writes them - * to a Writer target document - * - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _WORDPERFECTCOLLECTOR_HXX -#define _WORDPERFECTCOLLECTOR_HXX - -#include "filter/DocumentCollector.hxx" -#include "filter/DocumentHandlerInterface.hxx" -#include <rtl/ustring.hxx> - -class WordPerfectCollector : public DocumentCollector -{ -public: - WordPerfectCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler, const rtl::OString& password); - virtual ~WordPerfectCollector(); - bool parseSourceDocument(WPXInputStream &pInput); -private: - rtl::OString maUtf8Password; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx index b177f74d9bdd..d1ff550a3973 100644 --- a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx +++ b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx @@ -43,7 +43,6 @@ #include "filter/FilterInternal.hxx" #include "filter/DocumentHandler.hxx" -#include "filter/DocumentCollector.hxx" #include "stream/WPXSvStream.h" #if defined _MSC_VER @@ -54,7 +53,8 @@ #pragma warning( pop ) #endif -#include "WordPerfectCollector.hxx" +#include "filter/OdtGenerator.hxx" +#include "filter/OdgGenerator.hxx" #include "WordPerfectImportFilter.hxx" using namespace ::rtl; @@ -84,6 +84,19 @@ using com::sun::star::xml::sax::XParser; void callHandler(uno::Reference < XDocumentHandler > xDocHandler); + +static bool handleEmbeddedWPG(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) +{ + OdgGenerator exporter(pHandler, streamType); + + libwpg::WPGFileFormat fileFormat = libwpg::WPG_AUTODETECT; + + if (!libwpg::WPGraphics::isSupported(const_cast<WPXInputStream *>(data.getDataStream()))) + fileFormat = libwpg::WPG_WPG1; + + return libwpg::WPGraphics::parse(const_cast<WPXInputStream *>(data.getDataStream()), &exporter, fileFormat); +} + sal_Bool SAL_CALL WordPerfectImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (RuntimeException) { @@ -143,14 +156,15 @@ sal_Bool SAL_CALL WordPerfectImportFilter::importImpl( const Sequence< ::com::su uno::Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY); xImporter->setTargetDocument(mxDoc); - // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here - // writes to in-memory target doc - DocumentHandler xHandler(xInternalHandler); - - WordPerfectCollector collector(&input, &xHandler, aUtf8Passwd); - collector.filter(); + // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here + // writes to in-memory target doc + DocumentHandler xHandler(xInternalHandler); - return true; + OdtGenerator collector(&xHandler, ODF_FLAT_XML); + collector.registerEmbeddedObjectHandler("image/x-wpg", &handleEmbeddedWPG); + if (WPD_OK == WPDocument::parse(&input, static_cast<WPXDocumentInterface*>(&collector), (const char*)(aUtf8Passwd.getStr()))) + return sal_True; + return sal_False; } sal_Bool SAL_CALL WordPerfectImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) diff --git a/writerperfect/source/wpdimp/makefile.mk b/writerperfect/source/wpdimp/makefile.mk index e2dd8d746546..1b7bdcf5997b 100644 --- a/writerperfect/source/wpdimp/makefile.mk +++ b/writerperfect/source/wpdimp/makefile.mk @@ -22,7 +22,6 @@ INCPRE+=$(LIBWPS_CFLAGS) INCPRE+= -I.. SLOFILES= \ - $(SLO)$/WordPerfectCollector.obj \ $(SLO)$/WordPerfectImportFilter.obj \ $(SLO)$/wpft_genericfilter.obj diff --git a/writerperfect/source/wpgimp/WPGImportFilter.cxx b/writerperfect/source/wpgimp/WPGImportFilter.cxx index 1d6859088e15..cf00a99b1105 100644 --- a/writerperfect/source/wpgimp/WPGImportFilter.cxx +++ b/writerperfect/source/wpgimp/WPGImportFilter.cxx @@ -47,7 +47,7 @@ #include <xmloff/attrlist.hxx> #include "filter/DocumentHandler.hxx" -#include "filter/OdgExporter.hxx" +#include "filter/OdgGenerator.hxx" #include "WPGImportFilter.hxx" #include "stream/WPXSvStream.h" @@ -120,7 +120,7 @@ sal_Bool SAL_CALL WPGImportFilter::filter( const Sequence< ::com::sun::star::bea WPXInputStream* input = new WPXSvInputStream( xInputStream ); - OdgExporter exporter(&xHandler); + OdgGenerator exporter(&xHandler, ODF_FLAT_XML); bool tmpParseResult = libwpg::WPGraphics::parse(input, &exporter); if (input) delete input; diff --git a/writerperfect/source/wpsimp/MSWorksCollector.cxx b/writerperfect/source/wpsimp/MSWorksCollector.cxx deleted file mode 100644 index bed21d8bed73..000000000000 --- a/writerperfect/source/wpsimp/MSWorksCollector.cxx +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* MSWorksCollector: Collects sections and runs of text from a - * wordperfect file (and styles to go along with them) and writes them - * to a Writer target document - * - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#include "MSWorksCollector.hxx" -#include <libwps/WPSDocument.h> - -MSWorksCollector::MSWorksCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler) : - DocumentCollector(pInput, pHandler) -{ -} - -MSWorksCollector::~MSWorksCollector() -{ -} - -bool MSWorksCollector::parseSourceDocument(WPXInputStream &input) -{ - WPSResult result = WPSDocument::parse(&input, static_cast<WPXDocumentInterface *>(this)); - if (result != WPS_OK) - return false; - - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/wpsimp/MSWorksCollector.hxx b/writerperfect/source/wpsimp/MSWorksCollector.hxx deleted file mode 100644 index 9db02532a5f1..000000000000 --- a/writerperfect/source/wpsimp/MSWorksCollector.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* MSWorksCollector: Collects sections and runs of text from a - * wordperfect file (and styles to go along with them) and writes them - * to a Writer target document - * - * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For further information visit http://libwpd.sourceforge.net - * - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _MSWORKSCOLLECTOR_HXX -#define _MSWORKSCOLLECTOR_HXX - -#include "filter/DocumentCollector.hxx" -#include "filter/DocumentHandlerInterface.hxx" - -class MSWorksCollector : public DocumentCollector -{ -public: - MSWorksCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler); - virtual ~MSWorksCollector(); - bool parseSourceDocument(WPXInputStream &input); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/wpsimp/MSWorksImportFilter.cxx b/writerperfect/source/wpsimp/MSWorksImportFilter.cxx index 211d3ae33fd3..152caba37549 100644 --- a/writerperfect/source/wpsimp/MSWorksImportFilter.cxx +++ b/writerperfect/source/wpsimp/MSWorksImportFilter.cxx @@ -45,12 +45,11 @@ #include "filter/FilterInternal.hxx" #include "filter/DocumentHandler.hxx" -#include "filter/DocumentCollector.hxx" +#include "filter/OdtGenerator.hxx" #include "stream/WPXSvStream.h" #include <libwps/WPSDocument.h> #include "MSWorksImportFilter.hxx" -#include "MSWorksCollector.hxx" // using namespace ::rtl; using rtl::OString; @@ -109,16 +108,16 @@ sal_Bool SAL_CALL MSWorksImportFilter::importImpl( const Sequence< ::com::sun::s Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY); xImporter->setTargetDocument(mxDoc); - // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here - // writes to in-memory target doc - DocumentHandler xHandler(xInternalHandler); + // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here + // writes to in-memory target doc + DocumentHandler xHandler(xInternalHandler); WPXSvInputStream input( xInputStream ); - MSWorksCollector collector(&input, &xHandler); - collector.filter(); - - return true; + OdtGenerator collector(&xHandler, ODF_FLAT_XML); + if (WPS_OK == WPSDocument::parse(&input, static_cast<WPXDocumentInterface*>(&collector))) + return sal_True; + return sal_False; } sal_Bool SAL_CALL MSWorksImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) diff --git a/writerperfect/source/wpsimp/makefile.mk b/writerperfect/source/wpsimp/makefile.mk index c3dfe20bdd6b..4d6aa7714432 100644 --- a/writerperfect/source/wpsimp/makefile.mk +++ b/writerperfect/source/wpsimp/makefile.mk @@ -22,7 +22,6 @@ INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwps INCPRE+= -I.. SLOFILES= \ - $(SLO)$/MSWorksCollector.obj \ $(SLO)$/MSWorksImportFilter.obj \ $(SLO)$/msworks_genericfilter.obj |