diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-05-02 20:25:51 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-05-02 20:26:23 +0200 |
commit | 93848e11ec7d28ddef35ee165e12d847f2fafcea (patch) | |
tree | c2728e1a902b21852469c97d5c8c1111f6b01154 /writerperfect | |
parent | 7de37ac7d633ba12cd90a38b2255130ef8e88b1a (diff) |
Splitting writerperfect into serializer and libodfgen
Change-Id: I69f12fb097dbc977e63463b6b764a3553bcf9271
Diffstat (limited to 'writerperfect')
40 files changed, 68 insertions, 5280 deletions
diff --git a/writerperfect/Library_wpftdraw.mk b/writerperfect/Library_wpftdraw.mk index de2da7e672ed..5bb7fdaf6014 100644 --- a/writerperfect/Library_wpftdraw.mk +++ b/writerperfect/Library_wpftdraw.mk @@ -45,17 +45,18 @@ $(eval $(call gb_Library_use_static_libraries,wpftdraw,\ )) $(eval $(call gb_Library_use_externals,wpftdraw,\ - wpd \ - wpg \ - visio \ cdr \ - mspub \ - lcms2 \ - libxml2 \ - zlib \ icui18n \ icuuc \ icudata \ + lcms2 \ + libxml2 \ + mspub \ + odfgen \ + visio \ + wpd \ + wpg \ + zlib \ )) $(eval $(call gb_Library_add_exception_objects,wpftdraw,\ diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index 00d8107ced0f..7dc5203d1a15 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -49,10 +49,11 @@ $(eval $(call gb_Library_use_static_libraries,wpftwriter,\ $(eval $(call gb_Library_use_externals,wpftwriter,\ boost_headers \ + mwaw \ + odfgen \ wpd \ wpg \ wps \ - mwaw \ zlib \ )) diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index 0a9b8b570514..b6a39909f656 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -21,17 +21,20 @@ $(eval $(call gb_Module_Module,writerperfect)) ifneq (,$(SYSTEM_WPD)) ifneq (,$(SYSTEM_WPS)) +ifneq (,$(SYSTEM_ODFGEN)) $(eval $(call gb_Module_add_targets,writerperfect,\ Library_wpftwriter \ )) endif endif +endif ifneq (,$(SYSTEM_WPD)) ifneq (,$(SYSTEM_WPG)) ifneq (,$(SYSTEM_VISIO)) ifneq (,$(SYSTEM_CDR)) ifneq (,$(SYSTEM_MSPUB)) +ifneq (,$(SYSTEM_ODFGEN)) $(eval $(call gb_Module_add_targets,writerperfect,\ Library_wpftdraw \ )) @@ -40,13 +43,16 @@ endif endif endif endif +endif ifneq (,$(SYSTEM_WPD)) ifneq (,$(SYSTEM_WPG)) +ifneq (,$(SYSTEM_ODFGEN)) $(eval $(call gb_Module_add_targets,writerperfect,\ StaticLibrary_writerperfect \ )) endif endif +endif # vim: set noet sw=4 ts=4: diff --git a/writerperfect/StaticLibrary_writerperfect.mk b/writerperfect/StaticLibrary_writerperfect.mk index e82fd0e7b0b1..5fcfb95339bb 100644 --- a/writerperfect/StaticLibrary_writerperfect.mk +++ b/writerperfect/StaticLibrary_writerperfect.mk @@ -26,6 +26,7 @@ $(eval $(call gb_StaticLibrary_set_include,writerperfect,\ $(eval $(call gb_StaticLibrary_use_externals,writerperfect,\ boost_headers \ + odfgen \ wpd \ wpg \ )) @@ -36,18 +37,7 @@ $(eval $(call gb_StaticLibrary_use_api,writerperfect,\ )) $(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect,\ - writerperfect/source/common/DocumentElement \ writerperfect/source/common/DocumentHandler \ - writerperfect/source/common/FilterInternal \ - writerperfect/source/common/FontStyle \ - writerperfect/source/common/InternalHandler \ - writerperfect/source/common/ListStyle \ - writerperfect/source/common/OdgGenerator \ - writerperfect/source/common/OdtGenerator \ - writerperfect/source/common/PageSpan \ - writerperfect/source/common/SectionStyle \ - writerperfect/source/common/TableStyle \ - writerperfect/source/common/TextRunStyle \ writerperfect/source/common/WPXSvStream \ )) diff --git a/writerperfect/source/common/DocumentElement.cxx b/writerperfect/source/common/DocumentElement.cxx deleted file mode 100644 index a396950973c3..000000000000 --- a/writerperfect/source/common/DocumentElement.cxx +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include "DocumentElement.hxx" -#include "OdfDocumentHandler.hxx" -#include "FilterInternal.hxx" -#include <string.h> - -void TagElement::print() const -{ - WRITER_DEBUG_MSG(("%s\n", msTagName.cstr())); -} - -void TagOpenElement::write(OdfDocumentHandler *pHandler) const -{ - pHandler->startElement(getTagName().cstr(), maAttrList); -} - -void TagOpenElement::print() const -{ - TagElement::print(); -} - -void TagOpenElement::addAttribute(const WPXString &szAttributeName, const WPXString &sAttributeValue) -{ - maAttrList.insert(szAttributeName.cstr(), sAttributeValue); -} - -void TagCloseElement::write(OdfDocumentHandler *pHandler) const -{ - WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr())); - - pHandler->endElement(getTagName().cstr()); -} - -void CharDataElement::write(OdfDocumentHandler *pHandler) const -{ - WRITER_DEBUG_MSG(("TextElement: write\n")); - pHandler->characters(msData); -} - -void TextElement::write(OdfDocumentHandler *pHandler) const -{ - if (msTextBuf.len() <= 0) - return; - pHandler->characters(msTextBuf); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/DocumentElement.hxx b/writerperfect/source/common/DocumentElement.hxx deleted file mode 100644 index 3edf85ebce66..000000000000 --- a/writerperfect/source/common/DocumentElement.hxx +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -#ifndef _DOCUMENTELEMENT_H -#define _DOCUMENTELEMENT_H -#include <libwpd/libwpd.h> -#include <libwpd/WPXProperty.h> -#include <libwpd/WPXString.h> -#include <vector> - -#include "OdfDocumentHandler.hxx" - -class DocumentElement -{ -public: - virtual ~DocumentElement() {} - virtual void write(OdfDocumentHandler *pHandler) const = 0; - virtual void print() const {} -}; - -class TagElement : public DocumentElement -{ -public: - virtual ~TagElement() {} - TagElement(const WPXString &szTagName) : msTagName(szTagName) {} - const WPXString &getTagName() const - { - return msTagName; - } - virtual void print() const; -private: - WPXString msTagName; -}; - -class TagOpenElement : public TagElement -{ -public: - TagOpenElement(const WPXString &szTagName) : TagElement(szTagName), maAttrList() {} - virtual ~TagOpenElement() {} - void addAttribute(const WPXString &szAttributeName, const WPXString &sAttributeValue); - virtual void write(OdfDocumentHandler *pHandler) const; - virtual void print () const; -private: - WPXPropertyList maAttrList; -}; - -class TagCloseElement : public TagElement -{ -public: - TagCloseElement(const WPXString &szTagName) : TagElement(szTagName) {} - virtual ~TagCloseElement() {} - virtual void write(OdfDocumentHandler *pHandler) const; -}; - -class CharDataElement : public DocumentElement -{ -public: - CharDataElement(const WPXString &sData) : DocumentElement(), msData(sData) {} - virtual ~CharDataElement() {} - virtual void write(OdfDocumentHandler *pHandler) const; -private: - WPXString msData; -}; - -class TextElement : public DocumentElement -{ -public: - TextElement(const WPXString &sTextBuf) : DocumentElement(), msTextBuf(sTextBuf, false) {} - virtual ~TextElement() {} - virtual void write(OdfDocumentHandler *pHandler) const; - -private: - WPXString msTextBuf; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/DocumentHandler.cxx b/writerperfect/source/common/DocumentHandler.cxx index 67d1b5e053ca..eae820b705e8 100644 --- a/writerperfect/source/common/DocumentHandler.cxx +++ b/writerperfect/source/common/DocumentHandler.cxx @@ -7,7 +7,7 @@ * For further information visit http://libwpd.sourceforge.net */ #include "DocumentHandler.hxx" -#include "FilterInternal.hxx" +#include "WriterPerfectDebug.hxx" #include <string.h> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> diff --git a/writerperfect/source/common/DocumentHandler.hxx b/writerperfect/source/common/DocumentHandler.hxx index 381b091662f4..be1e1f18b22d 100644 --- a/writerperfect/source/common/DocumentHandler.hxx +++ b/writerperfect/source/common/DocumentHandler.hxx @@ -24,7 +24,7 @@ #include <libwpd/libwpd.h> -#include "OdfDocumentHandler.hxx" +#include <libodfgen/libodfgen.hxx> using com::sun::star::uno::Reference; using com::sun::star::xml::sax::XDocumentHandler; diff --git a/writerperfect/source/common/FilterInternal.cxx b/writerperfect/source/common/FilterInternal.cxx deleted file mode 100644 index 462747336798..000000000000 --- a/writerperfect/source/common/FilterInternal.cxx +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* FilterInternal.hxx: define basic functions for libwriterperfect/fileter - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -#include <libwpd/WPXPropertyList.h> - -#include "FilterInternal.hxx" - -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; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/FilterInternal.hxx b/writerperfect/source/common/FilterInternal.hxx deleted file mode 100644 index 6b5b0ab6fcbc..000000000000 --- a/writerperfect/source/common/FilterInternal.hxx +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* FilterInternal: Debugging information - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ -#ifndef __FILTERINTERNAL_HXX__ -#define __FILTERINTERNAL_HXX__ - -#include <string.h> // for strcmp - -#include <libwpd/libwpd.h> -#include <libwpd/WPXString.h> - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -// used by FontStyle.cxx -#define IMP_DEFAULT_FONT_PITCH "variable" - -#if 0 -const double fDefaultSideMargin = 1.0; // inches -const double fDefaultPageWidth = 8.5f; // inches (OOo required default: we will handle this later) -const double fDefaultPageHeight = 11.0; // inches -#endif - -#ifdef DEBUG -#include <stdio.h> -#define WRITER_DEBUG_MSG(M) printf M -#else -#define WRITER_DEBUG_MSG(M) -#endif - -#if defined(SHAREDPTR_TR1) -#include <tr1/memory> -using std::tr1::shared_ptr; -#elif defined(SHAREDPTR_STD) -#include <memory> -using std::shared_ptr; -#else -#include <boost/shared_ptr.hpp> -using boost::shared_ptr; -#endif - - -class WPXPropertyList; -WPXString propListToStyleKey(const WPXPropertyList &xPropList); - -struct ltstr -{ - bool operator()(const WPXString &s1, const WPXString &s2) const - { - return strcmp(s1.cstr(), s2.cstr()) < 0; - } -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/FontStyle.cxx b/writerperfect/source/common/FontStyle.cxx deleted file mode 100644 index bc1a8e3af21c..000000000000 --- a/writerperfect/source/common/FontStyle.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -#include "FilterInternal.hxx" - -#include "FontStyle.hxx" - -#include "DocumentElement.hxx" - -FontStyle::FontStyle(const char *psName, const char *psFontFamily) : Style(psName), - msFontFamily(psFontFamily, true), - msFontPitch(IMP_DEFAULT_FONT_PITCH) -{ -} - -FontStyle::~FontStyle() -{ -} - -void FontStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement styleOpen("style:font-face"); - styleOpen.addAttribute("style:name", getName()); - styleOpen.addAttribute("svg:font-family", msFontFamily); - styleOpen.write(pHandler); - TagCloseElement styleClose("style:font-face"); - styleClose.write(pHandler); -} - -void FontStyleManager::clean() -{ - mStyleHash.clear(); -} - -void FontStyleManager::writeFontsDeclaration(OdfDocumentHandler *pHandler) const -{ - TagOpenElement("office:font-face-decls").write(pHandler); - std::map<WPXString, shared_ptr<FontStyle>, ltstr>::const_iterator iter; - for (iter = mStyleHash.begin(); iter != mStyleHash.end(); ++iter) - { - (iter->second)->write(pHandler); - } - - 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(pHandler); - pHandler->endElement("style:font-face"); - - pHandler->endElement("office:font-face-decls"); -} - -WPXString FontStyleManager::findOrAdd(const char *psFontFamily) -{ - std::map<WPXString, shared_ptr<FontStyle>, ltstr>::const_iterator iter = - mStyleHash.find(psFontFamily); - if (iter!=mStyleHash.end()) return psFontFamily; - - // ok create a new font - shared_ptr<FontStyle> font(new FontStyle(psFontFamily, psFontFamily)); - mStyleHash[psFontFamily] = font; - return psFontFamily; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/FontStyle.hxx b/writerperfect/source/common/FontStyle.hxx deleted file mode 100644 index b050cf6773e9..000000000000 --- a/writerperfect/source/common/FontStyle.hxx +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -#ifndef _FONTSTYLE_H -#define _FONTSTYLE_H -#include <map> - -#include <libwpd/libwpd.h> - -#include "FilterInternal.hxx" - -#include "Style.hxx" - -class FontStyle : public Style -{ -public: - FontStyle(const char *psName, const char *psFontFamily); - ~FontStyle(); - virtual void write(OdfDocumentHandler *pHandler) const; - const WPXString &getFontFamily() const - { - return msFontFamily; - } - -private: - WPXString msFontFamily; - WPXString msFontPitch; -}; - -class FontStyleManager : public StyleManager -{ -public: - FontStyleManager() : mStyleHash() {} - virtual ~FontStyleManager() - { - clean(); - } - - /* create a new font if the font does not exists and returns a font name - - Note: the returned font name is actually equalled to psFontFamily - */ - WPXString findOrAdd(const char *psFontFamily); - - virtual void clean(); - virtual void write(OdfDocumentHandler *) const {} - virtual void writeFontsDeclaration(OdfDocumentHandler *) const; - - -protected: - // style name -> SpanStyle - std::map<WPXString, shared_ptr<FontStyle>, ltstr> mStyleHash; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/InternalHandler.cxx b/writerperfect/source/common/InternalHandler.cxx deleted file mode 100644 index a901336607ec..000000000000 --- a/writerperfect/source/common/InternalHandler.cxx +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#include "InternalHandler.hxx" - -#include <string.h> - -InternalHandler::InternalHandler(std::vector<DocumentElement *> *elements): - mpElements(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()); - } - mpElements->push_back(element); -} - -void InternalHandler::endElement(const char *psName) -{ - mpElements->push_back(new TagCloseElement(psName)); -} - -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/common/InternalHandler.hxx b/writerperfect/source/common/InternalHandler.hxx deleted file mode 100644 index a07e83a977d9..000000000000 --- a/writerperfect/source/common/InternalHandler.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _INTERNALHANDLER_H -#define _INTERNALHANDLER_H -#include <libwpd/libwpd.h> -#include <libwpd/WPXProperty.h> -#include <libwpd/WPXString.h> -#include "DocumentElement.hxx" -#include "OdfDocumentHandler.hxx" - -class InternalHandler : public OdfDocumentHandler -{ -public: - InternalHandler(std::vector<DocumentElement *> *elements); - ~InternalHandler() {}; - - void startDocument() {}; - void endDocument() {}; - void startElement(const char *psName, const WPXPropertyList &xPropList); - void endElement(const char *psName); - void characters(const WPXString &sCharacters); -private: - InternalHandler(const InternalHandler &); - InternalHandler &operator=(const InternalHandler &); - std::vector<DocumentElement *> *mpElements; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/ListStyle.cxx b/writerperfect/source/common/ListStyle.cxx deleted file mode 100644 index 1b6cf5c7181a..000000000000 --- a/writerperfect/source/common/ListStyle.cxx +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include "FilterInternal.hxx" -#include "ListStyle.hxx" -#include "DocumentElement.hxx" - -OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) : - mPropList(xPropList) -{ -} - -void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const -{ - WPXString sLevel; - sLevel.sprintf("%i", (iLevel+1)); - - TagOpenElement listLevelStyleOpen("text:list-level-style-number"); - listLevelStyleOpen.addAttribute("text:level", sLevel); - listLevelStyleOpen.addAttribute("text:style-name", "Numbering_Symbols"); - if (mPropList["style:num-prefix"]) - { - WPXString sEscapedString(mPropList["style:num-prefix"]->getStr(), true); - listLevelStyleOpen.addAttribute("style:num-prefix", sEscapedString); - } - 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"]) - { - // 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()); - else - listLevelStyleOpen.addAttribute("text:start-value", "1"); - } - if (mPropList["text:display-levels"]) - listLevelStyleOpen.addAttribute("text:display-levels", mPropList["text:display-levels"]->getStr()); - listLevelStyleOpen.write(pHandler); - - 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()); - 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) - stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr()); - if (mPropList["fo:text-align"]) - stylePropertiesOpen.addAttribute("fo:text-align", mPropList["fo:text-align"]->getStr()); - stylePropertiesOpen.write(pHandler); - - pHandler->endElement("style:list-level-properties"); - pHandler->endElement("text:list-level-style-number"); -} - -UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropList) - : mPropList(xPropList) -{ -} - -void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const -{ - WPXString sLevel; - sLevel.sprintf("%i", (iLevel+1)); - TagOpenElement listLevelStyleOpen("text:list-level-style-bullet"); - listLevelStyleOpen.addAttribute("text:level", sLevel); - listLevelStyleOpen.addAttribute("text:style-name", "Bullet_Symbols"); - if (mPropList["text:bullet-char"] && (mPropList["text:bullet-char"]->getStr().len())) - { - // The following is needed because the ODF format does not accept bullet chars longer than one character - WPXString::Iter i(mPropList["text:bullet-char"]->getStr()); - i.rewind(); - WPXString sEscapedString("."); - if (i.next()) - sEscapedString = WPXString(i(), true); - listLevelStyleOpen.addAttribute("text:bullet-char", sEscapedString); - - } - else - listLevelStyleOpen.addAttribute("text:bullet-char", "."); - if (mPropList["text:display-levels"]) - listLevelStyleOpen.addAttribute("text:display-levels", mPropList["text:display-levels"]->getStr()); - listLevelStyleOpen.write(pHandler); - - 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()); - 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) - stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr()); - if (mPropList["fo:text-align"]) - stylePropertiesOpen.addAttribute("fo:text-align", mPropList["fo:text-align"]->getStr()); - stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol"); - stylePropertiesOpen.write(pHandler); - - pHandler->endElement("style:list-level-properties"); - pHandler->endElement("text:list-level-style-bullet"); -} - -ListStyle::ListStyle(const char *psName, const int iListID) : - Style(psName), - miListID(iListID) -{ - for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i) - mppListLevels[i] = 0; - -} - -ListStyle::~ListStyle() -{ - for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i) - { - if (mppListLevels[i]) - delete(mppListLevels[i]); - } - -} - -bool ListStyle::isListLevelDefined(int iLevel) const -{ - if (!mppListLevels[iLevel]) - return false; - - return true; -} - -void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle) -{ - // can't uncomment this next line without adding some extra logic. - // figure out which is best: use the initial message, or constantly - // update? - if (!mppListLevels[iLevel]) - mppListLevels[iLevel] = iListLevelStyle; -} - -void ListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList, bool ordered) -{ - if (iLevel < 0) - return; - if (!isListLevelDefined(iLevel)) - { - if (ordered) - setListLevel(iLevel, new OrderedListLevelStyle(xPropList)); - else - setListLevel(iLevel, new UnorderedListLevelStyle(xPropList)); - } -} - -void ListStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement listStyleOpenElement("text:list-style"); - listStyleOpenElement.addAttribute("style:name", getName()); - listStyleOpenElement.write(pHandler); - - for (int i=0; i<WP6_NUM_LIST_LEVELS; ++i) - { - if (mppListLevels[i]) - mppListLevels[i]->write(pHandler, i); - } - - pHandler->endElement("text:list-style"); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/ListStyle.hxx b/writerperfect/source/common/ListStyle.hxx deleted file mode 100644 index 53ee67ed33b4..000000000000 --- a/writerperfect/source/common/ListStyle.hxx +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#ifndef _LISTSTYLE_H -#define _LISTSTYLE_H -#include <libwpd/libwpd.h> - -#define WP6_NUM_LIST_LEVELS 8 // see WP6FileStructure.h (we shouldn't need to reference this) - -#include "Style.hxx" - -class ListLevelStyle -{ -public: - virtual ~ListLevelStyle() {}; - virtual void write(OdfDocumentHandler *pHandler, int iLevel) const = 0; -}; - -class OrderedListLevelStyle : public ListLevelStyle -{ -public: - OrderedListLevelStyle(const WPXPropertyList &xPropList); - void write(OdfDocumentHandler *pHandler, int iLevel) const; -private: - WPXPropertyList mPropList; -}; - -class UnorderedListLevelStyle : public ListLevelStyle -{ -public: - UnorderedListLevelStyle(const WPXPropertyList &xPropList); - void write(OdfDocumentHandler *pHandler, int iLevel) const; -private: - WPXPropertyList mPropList; -}; - -class ListStyle : public Style -{ -public: - ListStyle(const char *psName, const int iListID); - virtual ~ListStyle(); - void updateListLevel(const int iLevel, const WPXPropertyList &xPropList, bool ordered); - virtual void write(OdfDocumentHandler *pHandler) const; - int getListID() - { - return miListID; - } - bool isListLevelDefined(int iLevel) const; - -protected: - void setListLevel(int iLevel, ListLevelStyle *iListLevelStyle); - -private: - ListLevelStyle *mppListLevels[WP6_NUM_LIST_LEVELS]; - const int miListID; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/OdfDocumentHandler.hxx b/writerperfect/source/common/OdfDocumentHandler.hxx deleted file mode 100644 index 886e9b702bf5..000000000000 --- a/writerperfect/source/common/OdfDocumentHandler.hxx +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef _DOCUMENTHANDLER_H -#define _DOCUMENTHANDLER_H -#include <libwpd/libwpd.h> - -enum OdfStreamType { ODF_FLAT_XML, ODF_CONTENT_XML, ODF_STYLES_XML, ODF_SETTINGS_XML, ODF_META_XML }; - -class OdfDocumentHandler -{ -public: - 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; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/OdgGenerator.cxx b/writerperfect/source/common/OdgGenerator.cxx deleted file mode 100644 index d166a09bbda5..000000000000 --- a/writerperfect/source/common/OdgGenerator.cxx +++ /dev/null @@ -1,1756 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpg.sourceforge.net - */ - -#include "FilterInternal.hxx" - -#include "OdgGenerator.hxx" -#include "DocumentElement.hxx" -#include "OdfDocumentHandler.hxx" -#include "TextRunStyle.hxx" -#include "FontStyle.hxx" -#include <locale.h> -#include <math.h> -#include <string> -#include <map> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -// Workaround for the incapacity of draw to have multiple page -// sizes in the same document. Once that limitation is lifted, -// remove this -#define MULTIPAGE_WORKAROUND 1 - -namespace -{ - -static inline double getAngle(double bx, double by) -{ - return fmod(2*M_PI + (by > 0.0 ? 1.0 : -1.0) * acos( bx / sqrt(bx * bx + by * by) ), 2*M_PI); -} - -static void getEllipticalArcBBox(double x0, double y0, - double rx, double ry, double phi, bool largeArc, bool sweep, double x, double y, - double &xmin, double &ymin, double &xmax, double &ymax) -{ - phi *= M_PI/180; - if (rx < 0.0) - rx *= -1.0; - if (ry < 0.0) - ry *= -1.0; - - if (rx == 0.0 || ry == 0.0) - { - xmin = (x0 < x ? x0 : x); - xmax = (x0 > x ? x0 : x); - ymin = (y0 < y ? y0 : y); - ymax = (y0 > y ? y0 : y); - return; - } - - // F.6.5.1 - const double x1prime = cos(phi)*(x0 - x)/2 + sin(phi)*(y0 - y)/2; - const double y1prime = -sin(phi)*(x0 - x)/2 + cos(phi)*(y0 - y)/2; - - // F.6.5.2 - double radicant = (rx*rx*ry*ry - rx*rx*y1prime*y1prime - ry*ry*x1prime*x1prime)/(rx*rx*y1prime*y1prime + ry*ry*x1prime*x1prime); - double cxprime = 0.0; - double cyprime = 0.0; - if (radicant < 0.0) - { - double ratio = rx/ry; - radicant = y1prime*y1prime + x1prime*x1prime/(ratio*ratio); - if (radicant < 0.0) - { - xmin = (x0 < x ? x0 : x); - xmax = (x0 > x ? x0 : x); - ymin = (y0 < y ? y0 : y); - ymax = (y0 > y ? y0 : y); - return; - } - ry=sqrt(radicant); - rx=ratio*ry; - } - else - { - double factor = (largeArc==sweep ? -1.0 : 1.0)*sqrt(radicant); - - cxprime = factor*rx*y1prime/ry; - cyprime = -factor*ry*x1prime/rx; - } - - // F.6.5.3 - double cx = cxprime*cos(phi) - cyprime*sin(phi) + (x0 + x)/2; - double cy = cxprime*sin(phi) + cyprime*cos(phi) + (y0 + y)/2; - - // now compute bounding box of the whole ellipse - - // Parametric equation of an ellipse: - // x(theta) = cx + rx*cos(theta)*cos(phi) - ry*sin(theta)*sin(phi) - // y(theta) = cy + rx*cos(theta)*sin(phi) + ry*sin(theta)*cos(phi) - - // Compute local extrems - // 0 = -rx*sin(theta)*cos(phi) - ry*cos(theta)*sin(phi) - // 0 = -rx*sin(theta)*sin(phi) - ry*cos(theta)*cos(phi) - - // Local extrems for X: - // theta = -atan(ry*tan(phi)/rx) - // and - // theta = M_PI -atan(ry*tan(phi)/rx) - - // Local extrems for Y: - // theta = atan(ry/(tan(phi)*rx)) - // and - // theta = M_PI + atan(ry/(tan(phi)*rx)) - - double txmin, txmax, tymin, tymax; - - // First handle special cases - if (phi == 0 || phi == M_PI) - { - xmin = cx - rx; - txmin = getAngle(-rx, 0); - xmax = cx + rx; - txmax = getAngle(rx, 0); - ymin = cy - ry; - tymin = getAngle(0, -ry); - ymax = cy + ry; - tymax = getAngle(0, ry); - } - else if (phi == M_PI / 2.0 || phi == 3.0*M_PI/2.0) - { - xmin = cx - ry; - txmin = getAngle(-ry, 0); - xmax = cx + ry; - txmax = getAngle(ry, 0); - ymin = cy - rx; - tymin = getAngle(0, -rx); - ymax = cy + rx; - tymax = getAngle(0, rx); - } - else - { - txmin = -atan(ry*tan(phi)/rx); - txmax = M_PI - atan (ry*tan(phi)/rx); - xmin = cx + rx*cos(txmin)*cos(phi) - ry*sin(txmin)*sin(phi); - xmax = cx + rx*cos(txmax)*cos(phi) - ry*sin(txmax)*sin(phi); - double tmpY = cy + rx*cos(txmin)*sin(phi) + ry*sin(txmin)*cos(phi); - txmin = getAngle(xmin - cx, tmpY - cy); - tmpY = cy + rx*cos(txmax)*sin(phi) + ry*sin(txmax)*cos(phi); - txmax = getAngle(xmax - cx, tmpY - cy); - - tymin = atan(ry/(tan(phi)*rx)); - tymax = atan(ry/(tan(phi)*rx))+M_PI; - ymin = cy + rx*cos(tymin)*sin(phi) + ry*sin(tymin)*cos(phi); - ymax = cy + rx*cos(tymax)*sin(phi) + ry*sin(tymax)*cos(phi); - double tmpX = cx + rx*cos(tymin)*cos(phi) - ry*sin(tymin)*sin(phi); - tymin = getAngle(tmpX - cx, ymin - cy); - tmpX = cx + rx*cos(tymax)*cos(phi) - ry*sin(tymax)*sin(phi); - tymax = getAngle(tmpX - cx, ymax - cy); - } - if (xmin > xmax) - { - std::swap(xmin,xmax); - std::swap(txmin,txmax); - } - if (ymin > ymax) - { - std::swap(ymin,ymax); - std::swap(tymin,tymax); - } - double angle1 = getAngle(x0 - cx, y0 - cy); - double angle2 = getAngle(x - cx, y - cy); - - // for sweep == 0 it is normal to have delta theta < 0 - // but we don't care about the rotation direction for bounding box - if (!sweep) - std::swap(angle1, angle2); - - // We cannot check directly for whether an angle is included in - // an interval of angles that cross the 360/0 degree boundary - // So here we will have to check for their absence in the complementary - // angle interval - bool otherArc = false; - if (angle1 > angle2) - { - std::swap(angle1, angle2); - otherArc = true; - } - - // Check txmin - if ((!otherArc && (angle1 > txmin || angle2 < txmin)) || (otherArc && !(angle1 > txmin || angle2 < txmin))) - xmin = x0 < x ? x0 : x; - // Check txmax - if ((!otherArc && (angle1 > txmax || angle2 < txmax)) || (otherArc && !(angle1 > txmax || angle2 < txmax))) - xmax = x0 > x ? x0 : x; - // Check tymin - if ((!otherArc && (angle1 > tymin || angle2 < tymin)) || (otherArc && !(angle1 > tymin || angle2 < tymin))) - ymin = y0 < y ? y0 : y; - // Check tymax - if ((!otherArc && (angle1 > tymax || angle2 < tymax)) || (otherArc && !(angle1 > tymax || angle2 < tymax))) - ymax = y0 > y ? y0 : y; -} - -static inline double quadraticExtreme(double t, double a, double b, double c) -{ - return (1.0-t)*(1.0-t)*a + 2.0*(1.0-t)*t*b + t*t*c; -} - -static inline double quadraticDerivative(double a, double b, double c) -{ - double denominator = a - 2.0*b + c; - if (fabs(denominator) != 0.0) - return (a - b)/denominator; - return -1.0; -} - -static void getQuadraticBezierBBox(double x0, double y0, double x1, double y1, double x, double y, - double &xmin, double &ymin, double &xmax, double &ymax) -{ - xmin = x0 < x ? x0 : x; - xmax = x0 > x ? x0 : x; - ymin = y0 < y ? y0 : y; - ymax = y0 > y ? y0 : y; - - double t = quadraticDerivative(x0, x1, x); - if(t>=0 && t<=1) - { - double tmpx = quadraticExtreme(t, x0, x1, x); - xmin = tmpx < xmin ? tmpx : xmin; - xmax = tmpx > xmax ? tmpx : xmax; - } - - t = quadraticDerivative(y0, y1, y); - if(t>=0 && t<=1) - { - double tmpy = quadraticExtreme(t, y0, y1, y); - ymin = tmpy < ymin ? tmpy : ymin; - ymax = tmpy > ymax ? tmpy : ymax; - } -} - -static inline double cubicBase(double t, double a, double b, double c, double d) -{ - return (1.0-t)*(1.0-t)*(1.0-t)*a + 3.0*(1.0-t)*(1.0-t)*t*b + 3.0*(1.0-t)*t*t*c + t*t*t*d; -} - -static void getCubicBezierBBox(double x0, double y0, double x1, double y1, double x2, double y2, double x, double y, - double &xmin, double &ymin, double &xmax, double &ymax) -{ - xmin = x0 < x ? x0 : x; - xmax = x0 > x ? x0 : x; - ymin = y0 < y ? y0 : y; - ymax = y0 > y ? y0 : y; - - for (double t = 0.0; t <= 1.0; t+=0.01) - { - double tmpx = cubicBase(t, x0, x1, x2, x); - xmin = tmpx < xmin ? tmpx : xmin; - xmax = tmpx > xmax ? tmpx : xmax; - double tmpy = cubicBase(t, y0, y1, y2, y); - ymin = tmpy < ymin ? tmpy : ymin; - ymax = tmpy > ymax ? tmpy : ymax; - } -} - - -static WPXString doubleToString(const double value) -{ - WPXString tempString; - tempString.sprintf("%.4f", value); -#ifndef ANDROID - std::string decimalPoint(localeconv()->decimal_point); -#else - std::string decimalPoint("."); -#endif - if (decimalPoint.empty() || (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()); -} - -} // anonymous namespace - -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 *> mGraphicsBitmapStyles; - std::vector<DocumentElement *> mGraphicsMarkerStyles; - std::vector<DocumentElement *> mGraphicsAutomaticStyles; - - // page styles - std::vector<DocumentElement *> mPageAutomaticStyles; - std::vector<DocumentElement *> mPageMasterStyles; - - // paragraph styles - ParagraphStyleManager mParagraphManager; - - // span styles - SpanStyleManager mSpanManager; - - // font styles - FontStyleManager mFontManager; - - OdfDocumentHandler *mpHandler; - - ::WPXPropertyList mxStyle; - ::WPXPropertyListVector mxGradient; - ::WPXPropertyListVector mxMarker; - int miGradientIndex; - int miBitmapIndex; - int miStartMarkerIndex; - int miEndMarkerIndex; - int miDashIndex; - int miGraphicsStyleIndex; - int miPageIndex; - double mfWidth, mfMaxWidth; - double mfHeight, mfMaxHeight; - - const OdfStreamType mxStreamType; - - bool mbIsTextBox; - bool mbIsTextLine; - bool mbIsTextOnPath; -}; - -OdgGeneratorPrivate::OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType): - mBodyElements(), - mGraphicsStrokeDashStyles(), - mGraphicsGradientStyles(), - mGraphicsBitmapStyles(), - mGraphicsAutomaticStyles(), - mPageAutomaticStyles(), - mPageMasterStyles(), - mParagraphManager(), - mSpanManager(), - mFontManager(), - mpHandler(pHandler), - mxStyle(), mxGradient(), - mxMarker(), - miGradientIndex(1), - miBitmapIndex(1), - miStartMarkerIndex(1), - miEndMarkerIndex(1), - miDashIndex(1), - miGraphicsStyleIndex(1), - miPageIndex(1), - mfWidth(0.0), - mfMaxWidth(0.0), - mfHeight(0.0), - mfMaxHeight(0.0), - mxStreamType(streamType), - mbIsTextBox(false), - mbIsTextLine(false), - mbIsTextOnPath(false) -{ -} - -OdgGeneratorPrivate::~OdgGeneratorPrivate() -{ - - for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); ++iterBody) - { - delete (*iterBody); - (*iterBody) = 0; - } - - for (std::vector<DocumentElement *>::iterator iterGraphicsAutomaticStyles = mGraphicsAutomaticStyles.begin(); - iterGraphicsAutomaticStyles != mGraphicsAutomaticStyles.end(); ++iterGraphicsAutomaticStyles) - { - delete((*iterGraphicsAutomaticStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterGraphicsStrokeDashStyles = mGraphicsStrokeDashStyles.begin(); - iterGraphicsStrokeDashStyles != mGraphicsStrokeDashStyles.end(); ++iterGraphicsStrokeDashStyles) - { - delete((*iterGraphicsStrokeDashStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterGraphicsGradientStyles = mGraphicsGradientStyles.begin(); - iterGraphicsGradientStyles != mGraphicsGradientStyles.end(); ++iterGraphicsGradientStyles) - { - delete((*iterGraphicsGradientStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterGraphicsBitmapStyles = mGraphicsBitmapStyles.begin(); - iterGraphicsBitmapStyles != mGraphicsBitmapStyles.end(); ++iterGraphicsBitmapStyles) - { - delete((*iterGraphicsBitmapStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterGraphicsMarkerStyles = mGraphicsMarkerStyles.begin(); - iterGraphicsMarkerStyles != mGraphicsMarkerStyles.end(); ++iterGraphicsMarkerStyles) - { - delete((*iterGraphicsMarkerStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterPageAutomaticStyles = mPageAutomaticStyles.begin(); - iterPageAutomaticStyles != mPageAutomaticStyles.end(); ++iterPageAutomaticStyles) - { - delete((*iterPageAutomaticStyles)); - } - - for (std::vector<DocumentElement *>::iterator iterPageMasterStyles = mPageMasterStyles.begin(); - iterPageMasterStyles != mPageMasterStyles.end(); ++iterPageMasterStyles) - { - delete((*iterPageMasterStyles)); - } - - mParagraphManager.clean(); - mSpanManager.clean(); - mFontManager.clean(); -} - - -OdgGenerator::OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType): - mpImpl(new OdgGeneratorPrivate(pHandler, streamType)) -{ - 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"); - tmpOfficeDocumentContent.addAttribute("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"); - tmpOfficeDocumentContent.addAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); - tmpOfficeDocumentContent.addAttribute("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"); - tmpOfficeDocumentContent.addAttribute("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"); - 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"); - if (mpImpl->mxStreamType == ODF_FLAT_XML) - tmpOfficeDocumentContent.addAttribute("office:mimetype", "application/vnd.oasis.opendocument.graphics"); - tmpOfficeDocumentContent.write(mpImpl->mpHandler); -} - -OdgGenerator::~OdgGenerator() -{ - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_SETTINGS_XML)) - { - 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->mfMaxWidth)); - 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->mfMaxHeight)); - mpImpl->mpHandler->characters(sHeight); - mpImpl->mpHandler->endElement("config:config-item"); - - mpImpl->mpHandler->endElement("config:config-item-set"); - - mpImpl->mpHandler->endElement("office:settings"); - } - - - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) - { - 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); - } - - for (std::vector<DocumentElement *>::const_iterator iterGraphicsBitmapStyles = mpImpl->mGraphicsBitmapStyles.begin(); - iterGraphicsBitmapStyles != mpImpl->mGraphicsBitmapStyles.end(); ++iterGraphicsBitmapStyles) - { - (*iterGraphicsBitmapStyles)->write(mpImpl->mpHandler); - } - - for (std::vector<DocumentElement *>::const_iterator iterGraphicsMarkerStyles = mpImpl->mGraphicsMarkerStyles.begin(); - iterGraphicsMarkerStyles != mpImpl->mGraphicsMarkerStyles.end(); ++iterGraphicsMarkerStyles) - { - (*iterGraphicsMarkerStyles)->write(mpImpl->mpHandler); - } - mpImpl->mpHandler->endElement("office:styles"); - } - - - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) - { - mpImpl->mFontManager.writeFontsDeclaration(mpImpl->mpHandler); - - TagOpenElement("office:automatic-styles").write(mpImpl->mpHandler); - } - - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML)) - { - // writing out the graphics automatic styles - for (std::vector<DocumentElement *>::iterator iterGraphicsAutomaticStyles = mpImpl->mGraphicsAutomaticStyles.begin(); - iterGraphicsAutomaticStyles != mpImpl->mGraphicsAutomaticStyles.end(); ++iterGraphicsAutomaticStyles) - { - (*iterGraphicsAutomaticStyles)->write(mpImpl->mpHandler); - } - mpImpl->mParagraphManager.write(mpImpl->mpHandler); - mpImpl->mSpanManager.write(mpImpl->mpHandler); - } -#ifdef MULTIPAGE_WORKAROUND - 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->mfMaxWidth); - sValue.append("in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", sValue); - sValue = doubleToString(mpImpl->mfMaxHeight); - sValue.append("in"); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", sValue); - tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait"); - tmpStylePageLayoutPropertiesOpenElement.write(mpImpl->mpHandler); - - mpImpl->mpHandler->endElement("style:page-layout-properties"); - - mpImpl->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 tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties"); - // tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:background-size", "border"); - tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none"); - tmpStyleDrawingPagePropertiesOpenElement.write(mpImpl->mpHandler); - - mpImpl->mpHandler->endElement("style:drawing-page-properties"); - - mpImpl->mpHandler->endElement("style:style"); - } -#else - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) - { - // writing out the page automatic styles - for (std::vector<DocumentElement *>::iterator iterPageAutomaticStyles = mpImpl->mPageAutomaticStyles.begin(); - iterPageAutomaticStyles != mpImpl->mPageAutomaticStyles.end(); ++iterPageAutomaticStyles) - { - (*iterPageAutomaticStyles)->write(mpImpl->mpHandler); - } - } -#endif - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) - { - mpImpl->mpHandler->endElement("office:automatic-styles"); - } - - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML)) - { - TagOpenElement("office:master-styles").write(mpImpl->mpHandler); - - for (std::vector<DocumentElement *>::const_iterator pageMasterIter = mpImpl->mPageMasterStyles.begin(); - pageMasterIter != mpImpl->mPageMasterStyles.end(); ++pageMasterIter) - { - (*pageMasterIter)->write(mpImpl->mpHandler); - } - mpImpl->mpHandler->endElement("office:master-styles"); - } - - if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML)) - { - TagOpenElement("office:body").write(mpImpl->mpHandler); - - TagOpenElement("office:drawing").write(mpImpl->mpHandler); - - for (std::vector<DocumentElement *>::const_iterator bodyIter = mpImpl->mBodyElements.begin(); - bodyIter != mpImpl->mBodyElements.end(); ++bodyIter) - { - (*bodyIter)->write(mpImpl->mpHandler); - } - - mpImpl->mpHandler->endElement("office:drawing"); - mpImpl->mpHandler->endElement("office:body"); - } - - 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" ))))); - - mpImpl->mpHandler->endDocument(); - - if (mpImpl) - delete mpImpl; -} - -void OdgGenerator::startGraphics(const ::WPXPropertyList &propList) -{ - if (propList["svg:width"]) - { - mpImpl->mfWidth = propList["svg:width"]->getDouble(); - mpImpl->mfMaxWidth = mpImpl->mfMaxWidth < mpImpl->mfWidth ? mpImpl->mfWidth : mpImpl->mfMaxWidth; - } - - if (propList["svg:height"]) - { - mpImpl->mfHeight = propList["svg:height"]->getDouble(); - mpImpl->mfMaxHeight = mpImpl->mfMaxHeight < mpImpl->mfHeight ? mpImpl->mfHeight : mpImpl->mfMaxHeight; - } - - TagOpenElement *pStyleMasterPageOpenElement = new TagOpenElement("style:master-page"); - - TagOpenElement *pDrawPageOpenElement = new TagOpenElement("draw:page"); - - TagOpenElement *pStylePageLayoutOpenElement = new TagOpenElement("style:page-layout"); - - WPXString sValue; - if (propList["draw:name"]) - sValue = WPXString(propList["draw:name"]->getStr(), true); // escape special xml characters - else - sValue.sprintf("page%i", mpImpl->miPageIndex); - pDrawPageOpenElement->addAttribute("draw:name", sValue); -#ifdef MULTIPAGE_WORKAROUND - pStyleMasterPageOpenElement->addAttribute("style:page-layout-name", "PM0"); - pStylePageLayoutOpenElement->addAttribute("style:page-layout-name", "PM0"); -#else - sValue.sprintf("PM%i", mpImpl->miPageIndex); - pStyleMasterPageOpenElement->addAttribute("style:page-layout-name", sValue); - pStylePageLayoutOpenElement->addAttribute("style:name", sValue); -#endif - - mpImpl->mPageAutomaticStyles.push_back(pStylePageLayoutOpenElement); - - TagOpenElement *pStylePageLayoutPropertiesOpenElement = new TagOpenElement("style:page-layout-properties"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-top", "0in"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-bottom", "0in"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-left", "0in"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:margin-right", "0in"); - sValue.sprintf("%s%s", doubleToString(mpImpl->mfWidth).cstr(), "in"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:page-width", sValue); - sValue.sprintf("%s%s", doubleToString(mpImpl->mfHeight).cstr(), "in"); - pStylePageLayoutPropertiesOpenElement->addAttribute("fo:page-height", sValue); - pStylePageLayoutPropertiesOpenElement->addAttribute("style:print-orientation", "portrait"); - mpImpl->mPageAutomaticStyles.push_back(pStylePageLayoutPropertiesOpenElement); - - mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:page-layout-properties")); - - mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:page-layout")); - -#ifdef MULTIPAGE_WORKAROUND - pDrawPageOpenElement->addAttribute("draw:style-name", "dp1"); - pStyleMasterPageOpenElement->addAttribute("draw:style-name", "dp1"); -#else - sValue.sprintf("dp%i", mpImpl->miPageIndex); - pDrawPageOpenElement->addAttribute("draw:style-name", sValue); - pStyleMasterPageOpenElement->addAttribute("draw:style-name", sValue); -#endif - - TagOpenElement *pStyleStyleOpenElement = new TagOpenElement("style:style"); - pStyleStyleOpenElement->addAttribute("style:name", sValue); - pStyleStyleOpenElement->addAttribute("style:family", "drawing-page"); - mpImpl->mPageAutomaticStyles.push_back(pStyleStyleOpenElement); - -#ifdef MULTIPAGE_WORKAROUND - pDrawPageOpenElement->addAttribute("draw:master-page-name", "Default"); - pStyleMasterPageOpenElement->addAttribute("style:name", "Default"); -#else - sValue.sprintf("Page%i", mpImpl->miPageIndex); - pDrawPageOpenElement->addAttribute("draw:master-page-name", sValue); - pStyleMasterPageOpenElement->addAttribute("style:name", sValue); -#endif - - mpImpl->mBodyElements.push_back(pDrawPageOpenElement); - - mpImpl->mPageMasterStyles.push_back(pStyleMasterPageOpenElement); - mpImpl->mPageMasterStyles.push_back(new TagCloseElement("style:master-page")); - - - TagOpenElement *pStyleDrawingPagePropertiesOpenElement = new TagOpenElement("style:drawing-page-properties"); - pStyleDrawingPagePropertiesOpenElement->addAttribute("draw:fill", "none"); - mpImpl->mPageAutomaticStyles.push_back(pStyleDrawingPagePropertiesOpenElement); - - mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:drawing-page-properties")); - - mpImpl->mPageAutomaticStyles.push_back(new TagCloseElement("style:style")); -} - -void OdgGenerator::endGraphics() -{ - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:page")); - mpImpl->miPageIndex++; -} - -void OdgGenerator::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) -{ - mpImpl->mxStyle.clear(); - mpImpl->mxStyle = propList; - mpImpl->mxGradient = gradient; -} - -void OdgGenerator::startLayer(const ::WPXPropertyList & /* propList */) -{ - mpImpl->mBodyElements.push_back(new TagOpenElement("draw:g")); -} - -void OdgGenerator::endLayer() -{ - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:g")); -} - -void OdgGenerator::drawRectangle(const ::WPXPropertyList &propList) -{ - mpImpl->_writeGraphicsStyle(); - TagOpenElement *pDrawRectElement = new TagOpenElement("draw:rect"); - WPXString sValue; - 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()); - pDrawRectElement->addAttribute("svg:width", propList["svg:width"]->getStr()); - pDrawRectElement->addAttribute("svg:height", propList["svg:height"]->getStr()); - // FIXME: what to do when rx != ry ? - if (propList["svg:rx"]) - pDrawRectElement->addAttribute("draw:corner-radius", propList["svg:rx"]->getStr()); - else - pDrawRectElement->addAttribute("draw:corner-radius", "0.0000in"); - mpImpl->mBodyElements.push_back(pDrawRectElement); - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:rect")); -} - -void OdgGenerator::drawEllipse(const ::WPXPropertyList &propList) -{ - mpImpl->_writeGraphicsStyle(); - TagOpenElement *pDrawEllipseElement = new TagOpenElement("draw:ellipse"); - WPXString sValue; - 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); - sValue = doubleToString(2 * propList["svg:ry"]->getDouble()); - sValue.append("in"); - pDrawEllipseElement->addAttribute("svg:height", sValue); - if (propList["libwpg:rotate"] && propList["libwpg:rotate"]->getDouble() != 0.0) - { - double rotation = propList["libwpg:rotate"]->getDouble(); - while(rotation < -180) - rotation += 360; - while(rotation > 180) - rotation -= 360; - double radrotation = rotation*M_PI/180.0; - double deltax = sqrt(pow(propList["svg:rx"]->getDouble(), 2.0) - + pow(propList["svg:ry"]->getDouble(), 2.0))*cos(atan(propList["svg:ry"]->getDouble()/propList["svg:rx"]->getDouble()) - - radrotation ) - propList["svg:rx"]->getDouble(); - double deltay = sqrt(pow(propList["svg:rx"]->getDouble(), 2.0) - + pow(propList["svg:ry"]->getDouble(), 2.0))*sin(atan(propList["svg:ry"]->getDouble()/propList["svg:rx"]->getDouble()) - - radrotation ) - propList["svg:ry"]->getDouble(); - sValue = "rotate("; - sValue.append(doubleToString(radrotation)); - sValue.append(") "); - sValue.append("translate("); - sValue.append(doubleToString(propList["svg:cx"]->getDouble() - propList["svg:rx"]->getDouble() - deltax)); - sValue.append("in, "); - sValue.append(doubleToString(propList["svg:cy"]->getDouble() - propList["svg:ry"]->getDouble() - deltay)); - sValue.append("in)"); - pDrawEllipseElement->addAttribute("draw:transform", sValue); - } - else - { - sValue = doubleToString(propList["svg:cx"]->getDouble()-propList["svg:rx"]->getDouble()); - sValue.append("in"); - pDrawEllipseElement->addAttribute("svg:x", sValue); - sValue = doubleToString(propList["svg:cy"]->getDouble()-propList["svg:ry"]->getDouble()); - sValue.append("in"); - pDrawEllipseElement->addAttribute("svg:y", sValue); - } - mpImpl->mBodyElements.push_back(pDrawEllipseElement); - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:ellipse")); -} - -void OdgGenerator::drawPolyline(const ::WPXPropertyListVector &vertices) -{ - mpImpl->_drawPolySomething(vertices, false); -} - -void OdgGenerator::drawPolygon(const ::WPXPropertyListVector &vertices) -{ - mpImpl->_drawPolySomething(vertices, true); -} - -void OdgGeneratorPrivate::_drawPolySomething(const ::WPXPropertyListVector &vertices, bool isClosed) -{ - if(vertices.count() < 2) - return; - - if(vertices.count() == 2) - { - _writeGraphicsStyle(); - TagOpenElement *pDrawLineElement = new TagOpenElement("draw:line"); - WPXString sValue; - sValue.sprintf("gr%i", miGraphicsStyleIndex-1); - pDrawLineElement->addAttribute("draw:style-name", sValue); - pDrawLineElement->addAttribute("draw:layer", "layout"); - pDrawLineElement->addAttribute("svg:x1", vertices[0]["svg:x"]->getStr()); - pDrawLineElement->addAttribute("svg:y1", vertices[0]["svg:y"]->getStr()); - pDrawLineElement->addAttribute("svg:x2", vertices[1]["svg:x"]->getStr()); - pDrawLineElement->addAttribute("svg:y2", vertices[1]["svg:y"]->getStr()); - mBodyElements.push_back(pDrawLineElement); - mBodyElements.push_back(new TagCloseElement("draw:line")); - } - else - { - ::WPXPropertyListVector path; - ::WPXPropertyList element; - - for (unsigned long ii = 0; ii < vertices.count(); ++ii) - { - element = vertices[ii]; - if (ii == 0) - element.insert("libwpg:path-action", "M"); - else - element.insert("libwpg:path-action", "L"); - path.append(element); - element.clear(); - } - if (isClosed) - { - element.insert("libwpg:path-action", "Z"); - path.append(element); - } - _drawPath(path); - } -} - -void OdgGeneratorPrivate::_drawPath(const WPXPropertyListVector &path) -{ - if(path.count() == 0) - return; - // This must be a mistake and we do not want to crash lower - if(path[0]["libwpg:path-action"]->getStr() == "Z") - return; - - // try to find the bounding box - // this is simple convex hull technique, the bounding box might not be - // accurate but that should be enough for this purpose - bool isFirstPoint = true; - - double px = 0.0, py = 0.0, qx = 0.0, qy = 0.0; - double lastX = 0.0; - double lastY = 0.0; - - for(unsigned k = 0; k < path.count(); ++k) - { - if (!path[k]["svg:x"] || !path[k]["svg:y"]) - continue; - if (isFirstPoint) - { - px = path[k]["svg:x"]->getDouble(); - py = path[k]["svg:y"]->getDouble(); - qx = px; - qy = py; - lastX = px; - lastY = py; - isFirstPoint = false; - } - px = (px > path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : px; - py = (py > path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : py; - qx = (qx < path[k]["svg:x"]->getDouble()) ? path[k]["svg:x"]->getDouble() : qx; - qy = (qy < path[k]["svg:y"]->getDouble()) ? path[k]["svg:y"]->getDouble() : qy; - - double xmin, xmax, ymin, ymax; - - if(path[k]["libwpg:path-action"]->getStr() == "C") - { - getCubicBezierBBox(lastX, lastY, path[k]["svg:x1"]->getDouble(), path[k]["svg:y1"]->getDouble(), - path[k]["svg:x2"]->getDouble(), path[k]["svg:y2"]->getDouble(), - path[k]["svg:x"]->getDouble(), path[k]["svg:y"]->getDouble(), xmin, ymin, xmax, ymax); - - px = (px > xmin ? xmin : px); - py = (py > ymin ? ymin : py); - qx = (qx < xmax ? xmax : qx); - qy = (qy < ymax ? ymax : qy); - } - if(path[k]["libwpg:path-action"]->getStr() == "Q") - { - getQuadraticBezierBBox(lastX, lastY, path[k]["svg:x1"]->getDouble(), path[k]["svg:y1"]->getDouble(), - path[k]["svg:x"]->getDouble(), path[k]["svg:y"]->getDouble(), xmin, ymin, xmax, ymax); - - px = (px > xmin ? xmin : px); - py = (py > ymin ? ymin : py); - qx = (qx < xmax ? xmax : qx); - qy = (qy < ymax ? ymax : qy); - } - if(path[k]["libwpg:path-action"]->getStr() == "A") - { - getEllipticalArcBBox(lastX, lastY, path[k]["svg:rx"]->getDouble(), path[k]["svg:ry"]->getDouble(), - path[k]["libwpg:rotate"] ? path[k]["libwpg:rotate"]->getDouble() : 0.0, - path[k]["libwpg:large-arc"] ? path[k]["libwpg:large-arc"]->getInt() : 1, - path[k]["libwpg:sweep"] ? path[k]["libwpg:sweep"]->getInt() : 1, - path[k]["svg:x"]->getDouble(), path[k]["svg:y"]->getDouble(), xmin, ymin, xmax, ymax); - - px = (px > xmin ? xmin : px); - py = (py > ymin ? ymin : py); - qx = (qx < xmax ? xmax : qx); - qy = (qy < ymax ? ymax : qy); - } - lastX = path[k]["svg:x"]->getDouble(); - lastY = path[k]["svg:y"]->getDouble(); - } - - - WPXString sValue; - _writeGraphicsStyle(); - TagOpenElement *pDrawPathElement = new TagOpenElement("draw:path"); - sValue.sprintf("gr%i", miGraphicsStyleIndex-1); - pDrawPathElement->addAttribute("draw:style-name", sValue); - pDrawPathElement->addAttribute("draw:layer", "layout"); - sValue = doubleToString(px); - sValue.append("in"); - pDrawPathElement->addAttribute("svg:x", sValue); - sValue = doubleToString(py); - sValue.append("in"); - pDrawPathElement->addAttribute("svg:y", sValue); - sValue = doubleToString((qx - px)); - sValue.append("in"); - pDrawPathElement->addAttribute("svg:width", sValue); - sValue = doubleToString((qy - py)); - sValue.append("in"); - pDrawPathElement->addAttribute("svg:height", sValue); - sValue.sprintf("%i %i %i %i", 0, 0, (unsigned)(2540*(qx - px)), (unsigned)(2540*(qy - py))); - pDrawPathElement->addAttribute("svg:viewBox", sValue); - - sValue.clear(); - for(unsigned i = 0; i < path.count(); ++i) - { - WPXString sElement; - if (path[i]["libwpg:path-action"]->getStr() == "M") - { - // 2540 is 2.54*1000, 2.54 in = 1 inch - sElement.sprintf("M%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); - sValue.append(sElement); - } - else if (path[i]["libwpg:path-action"]->getStr() == "L") - { - sElement.sprintf("L%i %i", (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); - sValue.append(sElement); - } - else if (path[i]["libwpg:path-action"]->getStr() == "C") - { - sElement.sprintf("C%i %i %i %i %i %i", (unsigned)((path[i]["svg:x1"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y1"]->getDouble()-py)*2540), (unsigned)((path[i]["svg:x2"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y2"]->getDouble()-py)*2540), (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); - sValue.append(sElement); - } - else if (path[i]["libwpg:path-action"]->getStr() == "Q") - { - sElement.sprintf("Q%i %i %i %i", (unsigned)((path[i]["svg:x1"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y1"]->getDouble()-py)*2540), (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), - (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); - sValue.append(sElement); - } - else if (path[i]["libwpg:path-action"]->getStr() == "A") - { - sElement.sprintf("A%i %i %i %i %i %i %i", (unsigned)((path[i]["svg:rx"]->getDouble())*2540), - (unsigned)((path[i]["svg:ry"]->getDouble())*2540), (path[i]["libwpg:rotate"] ? path[i]["libwpg:rotate"]->getInt() : 0), - (path[i]["libwpg:large-arc"] ? path[i]["libwpg:large-arc"]->getInt() : 1), - (path[i]["libwpg:sweep"] ? path[i]["libwpg:sweep"]->getInt() : 1), - (unsigned)((path[i]["svg:x"]->getDouble()-px)*2540), (unsigned)((path[i]["svg:y"]->getDouble()-py)*2540)); - sValue.append(sElement); - } - else if (path[i]["libwpg:path-action"]->getStr() == "Z") - sValue.append(" Z"); - } - pDrawPathElement->addAttribute("svg:d", sValue); - mBodyElements.push_back(pDrawPathElement); - mBodyElements.push_back(new TagCloseElement("draw:path")); -} - -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; - if (!propList["svg:x"] || !propList["svg:y"] || !propList["svg:width"] || !propList["svg:height"]) - return; - - bool flipX(propList["draw:mirror-horizontal"] && propList["draw:mirror-horizontal"]->getInt()); - bool flipY(propList["draw:mirror-vertical"] && propList["draw:mirror-vertical"]->getInt()); - if ((flipX && !flipY) || (!flipX && flipY)) - mpImpl->mxStyle.insert("style:mirror", "horizontal"); - else - mpImpl->mxStyle.insert("style:mirror", "none"); - if (propList["draw:color-mode"]) - mpImpl->mxStyle.insert("draw:color-mode", propList["draw:color-mode"]->getStr()); - if (propList["draw:luminance"]) - mpImpl->mxStyle.insert("draw:luminance", propList["draw:luminance"]->getStr()); - if (propList["draw:contrast"]) - mpImpl->mxStyle.insert("draw:contrast", propList["draw:contrast"]->getStr()); - if (propList["draw:gamma"]) - mpImpl->mxStyle.insert("draw:gamma", propList["draw:gamma"]->getStr()); - if (propList["draw:red"]) - mpImpl->mxStyle.insert("draw:red", propList["draw:red"]->getStr()); - if (propList["draw:green"]) - mpImpl->mxStyle.insert("draw:green", propList["draw:green"]->getStr()); - if (propList["draw:blue"]) - mpImpl->mxStyle.insert("draw:blue", propList["draw:blue"]->getStr()); - - - mpImpl->_writeGraphicsStyle(); - - double x = propList["svg:x"]->getDouble(); - double y = propList["svg:y"]->getDouble(); - double height = propList["svg:height"]->getDouble(); - double width = propList["svg:width"]->getDouble(); - - if (flipY) - { - x += width; - y += height; - width *= -1.0; - height *= -1.0; - } - - double angle(propList["libwpg:rotate"] ? - M_PI * propList["libwpg:rotate"]->getDouble() / 180.0 : 0.0); - if (angle != 0.0) - { - double deltax((width*cos(angle)+height*sin(angle)-width)/2.0); - double deltay((-width*sin(angle)+height*cos(angle)-height)/2.0); - x -= deltax; - y -= deltay; - } - - WPXPropertyList framePropList; - - framePropList.insert("svg:x", x); - framePropList.insert("svg:y", y); - framePropList.insert("svg:height", height); - framePropList.insert("svg:width", width); - - TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame"); - - WPXString sValue; - sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex-1); - pDrawFrameElement->addAttribute("draw:style-name", sValue); - - pDrawFrameElement->addAttribute("svg:height", framePropList["svg:height"]->getStr()); - pDrawFrameElement->addAttribute("svg:width", framePropList["svg:width"]->getStr()); - - if (angle != 0.0) - { - framePropList.insert("libwpg:rotate", angle, WPX_GENERIC); - sValue.sprintf("rotate (%s) translate(%s, %s)", - framePropList["libwpg:rotate"]->getStr().cstr(), - framePropList["svg:x"]->getStr().cstr(), - framePropList["svg:y"]->getStr().cstr()); - pDrawFrameElement->addAttribute("draw:transform", sValue); - } - else - { - pDrawFrameElement->addAttribute("svg:x", framePropList["svg:x"]->getStr()); - pDrawFrameElement->addAttribute("svg:y", framePropList["svg:y"]->getStr()); - } - mpImpl->mBodyElements.push_back(pDrawFrameElement); - - if (propList["libwpg:mime-type"]->getStr() == "object/ole") - mpImpl->mBodyElements.push_back(new TagOpenElement("draw:object-ole")); - else - mpImpl->mBodyElements.push_back(new TagOpenElement("draw:image")); - - mpImpl->mBodyElements.push_back(new TagOpenElement("office:binary-data")); - - ::WPXString base64Binary = binaryData.getBase64Data(); - mpImpl->mBodyElements.push_back(new CharDataElement(base64Binary.cstr())); - - mpImpl->mBodyElements.push_back(new TagCloseElement("office:binary-data")); - - if (propList["libwpg:mime-type"]->getStr() == "object/ole") - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:object-ole")); - else - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:image")); - - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:frame")); -} - -void OdgGeneratorPrivate::_writeGraphicsStyle() -{ - bool bUseOpacityGradient = false; - - if (mxStyle["draw:stroke"] && mxStyle["draw:stroke"]->getStr() == "dash") - { - TagOpenElement *pDrawStrokeDashElement = new TagOpenElement("draw:stroke-dash"); - WPXString sValue; - sValue.sprintf("Dash_%i", miDashIndex++); - pDrawStrokeDashElement->addAttribute("draw:name", sValue); - if (mxStyle["svg:stoke-linecap"]) - pDrawStrokeDashElement->addAttribute("draw:style", mxStyle["svg:stroke-linecap"]->getStr()); - else - pDrawStrokeDashElement->addAttribute("draw:style", "rect"); - if (mxStyle["draw:distance"]) - pDrawStrokeDashElement->addAttribute("draw:distance", mxStyle["draw:distance"]->getStr()); - if (mxStyle["draw:dots1"]) - pDrawStrokeDashElement->addAttribute("draw:dots1", mxStyle["draw:dots1"]->getStr()); - if (mxStyle["draw:dots1-length"]) - pDrawStrokeDashElement->addAttribute("draw:dots1-length", mxStyle["draw:dots1-length"]->getStr()); - if (mxStyle["draw:dots2"]) - pDrawStrokeDashElement->addAttribute("draw:dots2", mxStyle["draw:dots2"]->getStr()); - if (mxStyle["draw:dots2-length"]) - pDrawStrokeDashElement->addAttribute("draw:dots2-length", mxStyle["draw:dots2-length"]->getStr()); - mGraphicsStrokeDashStyles.push_back(pDrawStrokeDashElement); - mGraphicsStrokeDashStyles.push_back(new TagCloseElement("draw:stroke-dash")); - } - - if (mxStyle["draw:marker-start-path"]) - { - WPXString sValue; - TagOpenElement *pDrawMarkerElement = new TagOpenElement("draw:marker"); - sValue.sprintf("StartMarker_%i", miStartMarkerIndex); - pDrawMarkerElement->addAttribute("draw:name", sValue); - if (mxStyle["draw:marker-start-viewbox"]) - pDrawMarkerElement->addAttribute("svg:viewBox", mxStyle["draw:marker-start-viewbox"]->getStr()); - pDrawMarkerElement->addAttribute("svg:d", mxStyle["draw:marker-start-path"]->getStr()); - mGraphicsMarkerStyles.push_back(pDrawMarkerElement); - mGraphicsMarkerStyles.push_back(new TagCloseElement("draw:marker")); - } - if(mxStyle["draw:marker-end-path"]) - { - WPXString sValue; - TagOpenElement *pDrawMarkerElement = new TagOpenElement("draw:marker"); - sValue.sprintf("EndMarker_%i", miEndMarkerIndex); - pDrawMarkerElement->addAttribute("draw:name", sValue); - if (mxStyle["draw:marker-end-viewbox"]) - pDrawMarkerElement->addAttribute("svg:viewBox", mxStyle["draw:marker-end-viewbox"]->getStr()); - pDrawMarkerElement->addAttribute("svg:d", mxStyle["draw:marker-end-path"]->getStr()); - mGraphicsMarkerStyles.push_back(pDrawMarkerElement); - mGraphicsMarkerStyles.push_back(new TagCloseElement("draw:marker")); - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "gradient") - { - TagOpenElement *pDrawGradientElement = new TagOpenElement("draw:gradient"); - TagOpenElement *pDrawOpacityElement = new TagOpenElement("draw:opacity"); - if (mxStyle["draw:style"]) - { - pDrawGradientElement->addAttribute("draw:style", mxStyle["draw:style"]->getStr()); - pDrawOpacityElement->addAttribute("draw:style", mxStyle["draw:style"]->getStr()); - } - else - { - pDrawGradientElement->addAttribute("draw:style", "linear"); - pDrawOpacityElement->addAttribute("draw:style", "linear"); - } - WPXString sValue; - sValue.sprintf("Gradient_%i", miGradientIndex); - pDrawGradientElement->addAttribute("draw:name", sValue); - sValue.sprintf("Transparency_%i", miGradientIndex++); - pDrawOpacityElement->addAttribute("draw:name", sValue); - - // ODG angle unit is 0.1 degree - double angle = mxStyle["draw:angle"] ? mxStyle["draw:angle"]->getDouble() : 0.0; - while(angle < 0) - angle += 360; - while(angle > 360) - angle -= 360; - sValue.sprintf("%i", (unsigned)(angle*10)); - pDrawGradientElement->addAttribute("draw:angle", sValue); - pDrawOpacityElement->addAttribute("draw:angle", sValue); - - if (!mxGradient.count()) - { - if (mxStyle["draw:start-color"]) - pDrawGradientElement->addAttribute("draw:start-color", mxStyle["draw:start-color"]->getStr()); - if (mxStyle["draw:end-color"]) - pDrawGradientElement->addAttribute("draw:end-color", mxStyle["draw:end-color"]->getStr()); - - if (mxStyle["draw:border"]) - { - pDrawGradientElement->addAttribute("draw:border", mxStyle["draw:border"]->getStr()); - pDrawOpacityElement->addAttribute("draw:border", mxStyle["draw:border"]->getStr()); - } - else - { - pDrawGradientElement->addAttribute("draw:border", "0%"); - pDrawOpacityElement->addAttribute("draw:border", "0%"); - } - - if (mxStyle["svg:cx"]) - { - pDrawGradientElement->addAttribute("draw:cx", mxStyle["svg:cx"]->getStr()); - pDrawOpacityElement->addAttribute("draw:cx", mxStyle["svg:cx"]->getStr()); - } - else if (mxStyle["draw:cx"]) - { - pDrawGradientElement->addAttribute("draw:cx", mxStyle["draw:cx"]->getStr()); - pDrawOpacityElement->addAttribute("draw:cx", mxStyle["draw:cx"]->getStr()); - } - - if (mxStyle["svg:cy"]) - { - pDrawGradientElement->addAttribute("draw:cy", mxStyle["svg:cy"]->getStr()); - pDrawOpacityElement->addAttribute("draw:cy", mxStyle["svg:cy"]->getStr()); - } - else if (mxStyle["draw:cx"]) - { - pDrawGradientElement->addAttribute("draw:cx", mxStyle["svg:cx"]->getStr()); - pDrawOpacityElement->addAttribute("draw:cx", mxStyle["svg:cx"]->getStr()); - } - - if (mxStyle["draw:start-intensity"]) - pDrawGradientElement->addAttribute("draw:start-intensity", mxStyle["draw:start-intensity"]->getStr()); - else - pDrawGradientElement->addAttribute("draw:start-intensity", "100%"); - - if (mxStyle["draw:end-intensity"]) - pDrawGradientElement->addAttribute("draw:end-intensity", mxStyle["draw:end-intensity"]->getStr()); - else - pDrawGradientElement->addAttribute("draw:end-intensity", "100%"); - - if (mxStyle["libwpg:start-opacity"]) - pDrawOpacityElement->addAttribute("draw:start", mxStyle["libwpg:start-opacity"]->getStr()); - else - pDrawOpacityElement->addAttribute("draw:start", "100%"); - - if (mxStyle["libwpg:end-opacity"]) - pDrawOpacityElement->addAttribute("draw:end", mxStyle["libwpg:end-opacity"]->getStr()); - else - pDrawOpacityElement->addAttribute("draw:end", "100%"); - - mGraphicsGradientStyles.push_back(pDrawGradientElement); - mGraphicsGradientStyles.push_back(new TagCloseElement("draw:gradient")); - - // Work around a mess in LibreOffice where both opacities of 100% are interpreted as complete transparency - // Nevertheless, when one is different, immediately, they are interpreted correctly - if (mxStyle["libwpg:start-opacity"] && mxStyle["libwpg:end-opacity"] - && (mxStyle["libwpg:start-opacity"]->getDouble() != 1.0 || mxStyle["libwpg:end-opacity"]->getDouble() != 1.0)) - { - bUseOpacityGradient = true; - mGraphicsGradientStyles.push_back(pDrawOpacityElement); - mGraphicsGradientStyles.push_back(new TagCloseElement("draw:opacity")); - } - } - else if(mxGradient.count() >= 2) - { - sValue.sprintf("%i", (unsigned)(angle*10)); - pDrawGradientElement->addAttribute("draw:angle", sValue); - - pDrawGradientElement->addAttribute("draw:start-color", mxGradient[1]["svg:stop-color"]->getStr()); - pDrawGradientElement->addAttribute("draw:end-color", mxGradient[0]["svg:stop-color"]->getStr()); - if (mxStyle["svg:cx"]) - pDrawGradientElement->addAttribute("draw:cx", mxStyle["svg:cx"]->getStr()); - if (mxStyle["svg:cy"]) - pDrawGradientElement->addAttribute("draw:cy", mxStyle["svg:cy"]->getStr()); - if (mxGradient[1]["svg:stop-opacity"]) - { - pDrawOpacityElement->addAttribute("draw:start", mxGradient[1]["svg:stop-opacity"]->getStr()); - bUseOpacityGradient = true; - } - else - pDrawOpacityElement->addAttribute("draw:start", "100%"); - if (mxGradient[0]["svg:stop-opacity"]) - { - pDrawOpacityElement->addAttribute("draw:end", mxGradient[0]["svg:stop-opacity"]->getStr()); - bUseOpacityGradient = true; - } - else - pDrawOpacityElement->addAttribute("draw:end", "100%"); - pDrawGradientElement->addAttribute("draw:border", "0%"); - mGraphicsGradientStyles.push_back(pDrawGradientElement); - mGraphicsGradientStyles.push_back(new TagCloseElement("draw:gradient")); - if (bUseOpacityGradient) - { - mGraphicsGradientStyles.push_back(pDrawOpacityElement); - mGraphicsGradientStyles.push_back(new TagCloseElement("draw:opacity")); - } - } - else - { - /* if mxGradient.count() == 1 for some reason we would leak - * pDrawGradientElement - */ - delete pDrawGradientElement; - } - if(!bUseOpacityGradient) - delete pDrawOpacityElement; - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "bitmap" && - mxStyle["draw:fill-image"] && mxStyle["libwpg:mime-type"]) - { - TagOpenElement *pDrawBitmapElement = new TagOpenElement("draw:fill-image"); - WPXString sValue; - sValue.sprintf("Bitmap_%i", miBitmapIndex++); - pDrawBitmapElement->addAttribute("draw:name", sValue); - mGraphicsBitmapStyles.push_back(pDrawBitmapElement); - mGraphicsBitmapStyles.push_back(new TagOpenElement("office:binary-data")); - mGraphicsBitmapStyles.push_back(new CharDataElement(mxStyle["draw:fill-image"]->getStr())); - mGraphicsBitmapStyles.push_back(new TagCloseElement("office:binary-data")); - mGraphicsBitmapStyles.push_back(new TagCloseElement("draw:fill-image")); - } - - TagOpenElement *pStyleStyleElement = new TagOpenElement("style:style"); - WPXString sValue; - sValue.sprintf("gr%i", miGraphicsStyleIndex); - pStyleStyleElement->addAttribute("style:name", sValue); - pStyleStyleElement->addAttribute("style:family", "graphic"); - pStyleStyleElement->addAttribute("style:parent-style-name", "standard"); - mGraphicsAutomaticStyles.push_back(pStyleStyleElement); - - TagOpenElement *pStyleGraphicsPropertiesElement = new TagOpenElement("style:graphic-properties"); - - if (mxStyle["draw:color-mode"] && mxStyle["draw:color-mode"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:color-mode", mxStyle["draw:color-mode"]->getStr()); - if (mxStyle["draw:luminance"] && mxStyle["draw:luminance"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:luminance", mxStyle["draw:luminance"]->getStr()); - if (mxStyle["draw:contrast"] && mxStyle["draw:contrast"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:contrast", mxStyle["draw:contrast"]->getStr()); - if (mxStyle["draw:gamma"] && mxStyle["draw:gamma"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:gamma", mxStyle["draw:gamma"]->getStr()); - if (mxStyle["draw:red"] && mxStyle["draw:red"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:red", mxStyle["draw:red"]->getStr()); - if (mxStyle["draw:green"] && mxStyle["draw:green"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:green", mxStyle["draw:green"]->getStr()); - if (mxStyle["draw:blue"] && mxStyle["draw:blue"]->getStr().len() > 0) - pStyleGraphicsPropertiesElement->addAttribute("draw:blue", mxStyle["draw:blue"]->getStr()); - - if (mxStyle["draw:stroke"] && mxStyle["draw:stroke"]->getStr() == "none") - pStyleGraphicsPropertiesElement->addAttribute("draw:stroke", "none"); - else - { - if (mxStyle["svg:stroke-width"]) - pStyleGraphicsPropertiesElement->addAttribute("svg:stroke-width", mxStyle["svg:stroke-width"]->getStr()); - - if (mxStyle["svg:stroke-color"]) - pStyleGraphicsPropertiesElement->addAttribute("svg:stroke-color", mxStyle["svg:stroke-color"]->getStr()); - - if (mxStyle["svg:stroke-opacity"]) - pStyleGraphicsPropertiesElement->addAttribute("svg:stroke-opacity", mxStyle["svg:stroke-opacity"]->getStr()); - - if (mxStyle["svg:stroke-linejoin"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:stroke-linejoin", mxStyle["svg:stroke-linejoin"]->getStr()); - - if (mxStyle["svg:stroke-linecap"]) - pStyleGraphicsPropertiesElement->addAttribute("svg:stoke-linecap", mxStyle["svg:stroke-linecap"]->getStr()); - - if (mxStyle["draw:stroke"] && mxStyle["draw:stroke"]->getStr() == "dash") - { - pStyleGraphicsPropertiesElement->addAttribute("draw:stroke", "dash"); - sValue.sprintf("Dash_%i", miDashIndex-1); - pStyleGraphicsPropertiesElement->addAttribute("draw:stroke-dash", sValue); - } - else - pStyleGraphicsPropertiesElement->addAttribute("draw:stroke", "solid"); - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "none") - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "none"); - else - { - if (mxStyle["draw:shadow"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow", mxStyle["draw:shadow"]->getStr()); - else - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow", "hidden"); - if (mxStyle["draw:shadow-offset-x"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow-offset-x", mxStyle["draw:shadow-offset-x"]->getStr()); - if (mxStyle["draw:shadow-offset-y"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow-offset-y", mxStyle["draw:shadow-offset-y"]->getStr()); - if (mxStyle["draw:shadow-color"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow-color", mxStyle["draw:shadow-color"]->getStr()); - if (mxStyle["draw:shadow-opacity"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:shadow-opacity", mxStyle["draw:shadow-opacity"]->getStr()); - if (mxStyle["svg:fill-rule"]) - pStyleGraphicsPropertiesElement->addAttribute("svg:fill-rule", mxStyle["svg:fill-rule"]->getStr()); - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "solid") - { - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "solid"); - if (mxStyle["draw:fill-color"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-color", mxStyle["draw:fill-color"]->getStr()); - if (mxStyle["draw:opacity"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:opacity", mxStyle["draw:opacity"]->getStr()); - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "gradient") - { - if (!mxGradient.count() || mxGradient.count() >= 2) - { - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "gradient"); - sValue.sprintf("Gradient_%i", miGradientIndex-1); - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-gradient-name", sValue); - if (bUseOpacityGradient) - { - sValue.sprintf("Transparency_%i", miGradientIndex-1); - pStyleGraphicsPropertiesElement->addAttribute("draw:opacity-name", sValue); - } - } - else - { - if (mxGradient[0]["svg:stop-color"]) - { - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "solid"); - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-color", mxGradient[0]["svg:stop-color"]->getStr()); - } - else - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "solid"); - } - } - - if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "bitmap") - { - if (mxStyle["draw:fill-image"] && mxStyle["libwpg:mime-type"]) - { - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "bitmap"); - sValue.sprintf("Bitmap_%i", miBitmapIndex-1); - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-name", sValue); - if (mxStyle["svg:width"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-width", mxStyle["svg:width"]->getStr()); - if (mxStyle["svg:height"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-height", mxStyle["svg:height"]->getStr()); - if (mxStyle["style:repeat"]) - pStyleGraphicsPropertiesElement->addAttribute("style:repeat", mxStyle["style:repeat"]->getStr()); - if (mxStyle["draw:fill-image-ref-point"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-ref-point", mxStyle["draw:fill-image-ref-point"]->getStr()); - if (mxStyle["draw:fill-image-ref-point-x"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-ref-point-x", mxStyle["draw:fill-image-ref-point-x"]->getStr()); - if (mxStyle["draw:fill-image-ref-point-y"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:fill-image-ref-point-y", mxStyle["draw:fill-image-ref-point-y"]->getStr()); - } - else - pStyleGraphicsPropertiesElement->addAttribute("draw:fill", "none"); - } - - - if(mxStyle["draw:marker-start-path"]) - { - sValue.sprintf("StartMarker_%i", miStartMarkerIndex++); - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-start", sValue); - if (mxStyle["draw:marker-start-width"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-start-width", mxStyle["draw:marker-start-width"]->getStr()); - else - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-start-width", "0.118in"); - } - if (mxStyle["draw:marker-end-path"]) - { - sValue.sprintf("EndMarker_%i", miEndMarkerIndex++); - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-end", sValue); - if (mxStyle["draw:marker-end-width"]) - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-end-width", mxStyle["draw:marker-end-width"]->getStr()); - else - pStyleGraphicsPropertiesElement->addAttribute("draw:marker-end-width", "0.118in"); - } - if (mxStyle["style:mirror"]) - pStyleGraphicsPropertiesElement->addAttribute("style:mirror", mxStyle["style:mirror"]->getStr()); - - mGraphicsAutomaticStyles.push_back(pStyleGraphicsPropertiesElement); - mGraphicsAutomaticStyles.push_back(new TagCloseElement("style:graphic-properties")); - - mGraphicsAutomaticStyles.push_back(new TagCloseElement("style:style")); - miGraphicsStyleIndex++; -} - -void OdgGenerator::startEmbeddedGraphics(const WPXPropertyList &) -{ -} - -void OdgGenerator::endEmbeddedGraphics() -{ -} - -void OdgGenerator::startTextObject(const WPXPropertyList &propList, const WPXPropertyListVector &) -{ - TagOpenElement *pDrawFrameOpenElement = new TagOpenElement("draw:frame"); - TagOpenElement *pStyleStyleOpenElement = new TagOpenElement("style:style"); - - WPXString sValue; - sValue.sprintf("gr%i", mpImpl->miGraphicsStyleIndex++); - pStyleStyleOpenElement->addAttribute("style:name", sValue); - pStyleStyleOpenElement->addAttribute("style:family", "graphic"); - pStyleStyleOpenElement->addAttribute("style:parent-style-name", "standard"); - mpImpl->mGraphicsAutomaticStyles.push_back(pStyleStyleOpenElement); - - pDrawFrameOpenElement->addAttribute("draw:style-name", sValue); - pDrawFrameOpenElement->addAttribute("draw:layer", "layout"); - - TagOpenElement *pStyleGraphicPropertiesOpenElement = new TagOpenElement("style:graphic-properties"); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:stroke", "none"); - pStyleGraphicPropertiesOpenElement->addAttribute("svg:stroke-color", "#000000"); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:fill", "none"); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:fill-color", "#ffffff"); - - double x = 0.0; - double y = 0.0; - double height = 0.0; - double width = 0.0; - if (propList["svg:x"]) - x = propList["svg:x"]->getDouble(); - if (propList["svg:y"]) - y = propList["svg:y"]->getDouble(); - if (propList["svg:width"]) - width = propList["svg:width"]->getDouble(); - if (propList["svg:height"]) - height = propList["svg:height"]->getDouble(); - - double angle(propList["libwpg:rotate"] ? - M_PI * propList["libwpg:rotate"]->getDouble() / 180.0 : 0.0); - if (angle != 0.0) - { - double deltax((width*cos(angle)+height*sin(angle)-width)/2.0); - double deltay((-width*sin(angle)+height*cos(angle)-height)/2.0); - x -= deltax; - y -= deltay; - } - - if (!propList["svg:width"] && !propList["svg:height"]) - { - if (!propList["fo:min-width"]) - { - pDrawFrameOpenElement->addAttribute("fo:min-width", "1in"); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:min-width", "1in"); - } - pDrawFrameOpenElement->addAttribute("svg:width", "10in"); - } - else - { - if(propList["svg:width"]) - pDrawFrameOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr()); - if(propList["svg:height"]) - pDrawFrameOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr()); - } - if (propList["fo:min-width"]) - { - pDrawFrameOpenElement->addAttribute("fo:min-width", propList["fo:min-width"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:min-width", propList["fo:min-width"]->getStr()); - } - if (propList["fo:min-height"]) - { - pDrawFrameOpenElement->addAttribute("fo:min-height", propList["fo:min-height"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:min-height", propList["fo:min-height"]->getStr()); - } - if (propList["fo:max-width"]) - { - pDrawFrameOpenElement->addAttribute("fo:max-width", propList["fo:max-height"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr()); - } - if (propList["fo:max-height"]) - { - pDrawFrameOpenElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr()); - } - if (propList["fo:padding-top"]) - { - pDrawFrameOpenElement->addAttribute("fo:padding-top", propList["fo:padding-top"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:padding-top", propList["fo:padding-top"]->getStr()); - } - if (propList["fo:padding-bottom"]) - { - pDrawFrameOpenElement->addAttribute("fo:padding-bottom", propList["fo:padding-bottom"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:padding-bottom", propList["fo:padding-bottom"]->getStr()); - } - if (propList["fo:padding-left"]) - { - pDrawFrameOpenElement->addAttribute("fo:padding-left", propList["fo:padding-left"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:padding-left", propList["fo:padding-left"]->getStr()); - } - if (propList["fo:padding-right"]) - { - pDrawFrameOpenElement->addAttribute("fo:padding-right", propList["fo:padding-right"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("fo:padding-right", propList["fo:padding-right"]->getStr()); - } - if (propList["draw:textarea-vertical-align"]) - { - pDrawFrameOpenElement->addAttribute("draw:textarea-vertical-align", propList["draw:textarea-vertical-align"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:textarea-vertical-align", propList["draw:textarea-vertical-align"]->getStr()); - } - if (propList["draw:fill"]) - { - pDrawFrameOpenElement->addAttribute("draw:fill", propList["draw:fill"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:fill", propList["draw:fill"]->getStr()); - } - if (propList["draw:fill-color"]) - { - pDrawFrameOpenElement->addAttribute("draw:fill-color", propList["draw:fill-color"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:fill-color", propList["draw:fill-color"]->getStr()); - } - if (propList["draw:opacity"]) - { - pDrawFrameOpenElement->addAttribute("draw:opacity", propList["draw:opacity"]->getStr()); - pStyleGraphicPropertiesOpenElement->addAttribute("draw:opacity", propList["draw:opacity"]->getStr()); - } - - WPXProperty *svg_x = WPXPropertyFactory::newInchProp(x); - WPXProperty *svg_y = WPXPropertyFactory::newInchProp(y); - if (angle != 0.0) - { - WPXProperty *libwpg_rotate = WPXPropertyFactory::newDoubleProp(angle); - sValue.sprintf("rotate (%s) translate(%s, %s)", - libwpg_rotate->getStr().cstr(), - svg_x->getStr().cstr(), - svg_y->getStr().cstr()); - delete libwpg_rotate; - pDrawFrameOpenElement->addAttribute("draw:transform", sValue); - } - else - { - if (propList["svg:x"]) - pDrawFrameOpenElement->addAttribute("svg:x", svg_x->getStr()); - if (propList["svg:y"]) - pDrawFrameOpenElement->addAttribute("svg:y", svg_y->getStr()); - } - delete svg_x; - delete svg_y; - mpImpl->mBodyElements.push_back(pDrawFrameOpenElement); - mpImpl->mBodyElements.push_back(new TagOpenElement("draw:text-box")); - mpImpl->mGraphicsAutomaticStyles.push_back(pStyleGraphicPropertiesOpenElement); - mpImpl->mGraphicsAutomaticStyles.push_back(new TagCloseElement("style:graphic-properties")); - mpImpl->mGraphicsAutomaticStyles.push_back(new TagCloseElement("style:style")); - mpImpl->mbIsTextBox = true; -} - -void OdgGenerator::endTextObject() -{ - if (mpImpl->mbIsTextBox) - { - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:text-box")); - mpImpl->mBodyElements.push_back(new TagCloseElement("draw:frame")); - mpImpl->mbIsTextBox = false; - } -} - -void OdgGenerator::startTextLine(const WPXPropertyList &propList) -{ - WPXPropertyList finalPropList(propList); - finalPropList.insert("style:parent-style-name", "Standard"); - WPXString paragName = mpImpl->mParagraphManager.findOrAdd(finalPropList, WPXPropertyListVector()); - - - // 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", paragName); - mpImpl->mBodyElements.push_back(pParagraphOpenElement); -} - -void OdgGenerator::endTextLine() -{ - mpImpl->mBodyElements.push_back(new TagCloseElement("text:p")); -} - -void OdgGenerator::startTextSpan(const WPXPropertyList &propList) -{ - if (propList["style:font-name"]) - mpImpl->mFontManager.findOrAdd(propList["style:font-name"]->getStr().cstr()); - - WPXString sName = mpImpl->mSpanManager.findOrAdd(propList); - - TagOpenElement *pSpanOpenElement = new TagOpenElement("text:span"); - pSpanOpenElement->addAttribute("text:style-name", sName.cstr()); - mpImpl->mBodyElements.push_back(pSpanOpenElement); -} - -void OdgGenerator::endTextSpan() -{ - mpImpl->mBodyElements.push_back(new TagCloseElement("text:span")); -} - -void OdgGenerator::insertText(const WPXString &text) -{ - WPXString out; - WPXString::Iter i(text); - for (i.rewind(); i.next();) - { - if ((*i()) == '\n' || (*i()) == '\t') - { - if (out.len() != 0) - { - DocumentElement *pText = new TextElement(out); - mpImpl->mBodyElements.push_back(pText); - out.clear(); - } - if ((*i()) == '\n') - { - mpImpl->mBodyElements.push_back(new TagOpenElement("text:line-break")); - mpImpl->mBodyElements.push_back(new TagCloseElement("text:line-break")); - } - else if ((*i()) == '\t') - { - mpImpl->mBodyElements.push_back(new TagOpenElement("text:tab")); - mpImpl->mBodyElements.push_back(new TagCloseElement("text:tab")); - } - } - else - { - out.append(i()); - } - } - if (out.len() != 0) - { - DocumentElement *pText = new TextElement(out); - mpImpl->mBodyElements.push_back(pText); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/OdgGenerator.hxx b/writerperfect/source/common/OdgGenerator.hxx deleted file mode 100644 index 589e66667707..000000000000 --- a/writerperfect/source/common/OdgGenerator.hxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpg.sourceforge.net - */ - -#ifndef __ODGEXPORTER_HXX__ -#define __ODGEXPORTER_HXX__ - -#include <libwpd/libwpd.h> -#include <libwpg/libwpg.h> - -#include "OdfDocumentHandler.hxx" - -class OdgGeneratorPrivate; - -class OdgGenerator : public libwpg::WPGPaintInterface -{ -public: - 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 setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient); - - void drawRectangle(const ::WPXPropertyList &propList); - void drawEllipse(const ::WPXPropertyList &propList); - void drawPolyline(const ::WPXPropertyListVector &vertices); - 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: - OdgGeneratorPrivate *mpImpl; -}; - -#endif // __ODGEXPORTER_HXX__ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/OdtGenerator.cxx b/writerperfect/source/common/OdtGenerator.cxx deleted file mode 100644 index ba14e921b989..000000000000 --- a/writerperfect/source/common/OdtGenerator.cxx +++ /dev/null @@ -1,1482 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* 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 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * 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> - -#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 "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; - // a map id -> last list style defined with such id - std::map<int, ListStyle *> mIdListStyleMap; -}; - -enum WriterListType { unordered, ordered }; - -_WriterDocumentState::_WriterDocumentState() : - mbFirstElement(true), - mbFirstParagraphInPageSpan(true), - mbInFakeSection(false), - mbListElementOpenedAtCurrentLevel(false), - mbTableCellOpened(false), - mbHeaderRow(false), - mbInNote(false), - mbInTextBox(false), - mbInFrame(false) -{ -} - -_WriterListState::_WriterListState() : - mpCurrentListStyle(0), - miCurrentListLevel(0), - miLastListLevel(0), - miLastListNumber(0), - mbListContinueNumbering(false), - mbListElementParagraphOpened(false), - mbListElementOpened(), - mIdListStyleMap() -{ -} - -class OdtGeneratorPrivate -{ -public: - OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType); - ~OdtGeneratorPrivate(); - bool _writeTargetDocument(OdfDocumentHandler *pHandler); - void _writeDefaultStyles(OdfDocumentHandler *pHandler); - void _writeMasterPages(OdfDocumentHandler *pHandler); - void _writePageLayouts(OdfDocumentHandler *pHandler); - - void _openListLevel(TagOpenElement *pListLevelOpenElement); - void _closeListLevel(); - - /** stores a list style: update mListStyles, - mWriterListStates.top().mpCurrentListStyle and the different - maps - */ - void _storeListStyle(ListStyle *listStyle); - /** retrieves the list style corresponding to a given id. */ - void _retrieveListStyle(int id); - - OdfEmbeddedObject _findEmbeddedObjectHandler(const WPXString &mimeType); - OdfEmbeddedImage _findEmbeddedImageHandler(const WPXString &mimeType); - - 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 - ParagraphStyleManager mParagraphManager; - - // span styles - SpanStyleManager mSpanManager; - - // font styles - FontStyleManager mFontManager; - - // section styles - std::vector<SectionStyle *> mSectionStyles; - - // table styles - std::vector<TableStyle *> mTableStyles; - - // frame styles - std::vector<DocumentElement *> mFrameStyles; - - std::vector<DocumentElement *> mFrameAutomaticStyles; - - // embedded object handlers - std::map<WPXString, OdfEmbeddedObject, ltstr > mObjectHandlers; - std::map<WPXString, OdfEmbeddedImage, ltstr > mImageHandlers; - - // metadata - std::vector<DocumentElement *> mMetaData; - - // list styles - unsigned int miNumListStyles; - - // 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; - // a map id -> last list style defined with id - std::map<int, ListStyle *> mIdListStyleMap; - - // 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(), - mParagraphManager(), mSpanManager(), mFontManager(), - mSectionStyles(), mTableStyles(), mFrameStyles(), mFrameAutomaticStyles(), - mObjectHandlers(), mImageHandlers(), mMetaData(), - miNumListStyles(0), - mBodyElements(), - mpCurrentContentElements(&mBodyElements), - mPageSpans(), - mpCurrentPageSpan(0), - miNumPageStyles(0), - mListStyles(), - mIdListStyleMap(), - miObjectNumber(0), - mpCurrentTableStyle(0), - mxStreamType(streamType), - mpPassword(0) -{ - 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) = 0; - } - - mParagraphManager.clean(); - mSpanManager.clean(); - mFontManager.clean(); - - 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; -} - -OdfEmbeddedImage OdtGeneratorPrivate::_findEmbeddedImageHandler(const WPXString &mimeType) -{ - std::map<WPXString, OdfEmbeddedImage, ltstr>::iterator i = mImageHandlers.find(mimeType); - if (i != mImageHandlers.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"); -} - -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", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"); - 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 - mFontManager.writeFontsDeclaration(mpHandler); - - 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); - } - - mFontManager.write(pHandler); // do nothing - mParagraphManager.write(pHandler); - mSpanManager.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; -} - - -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) - { - 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; -} - -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 finalPropList(propList); - if (mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements)) - { - WPXString sPageStyleName; - sPageStyleName.sprintf("Page_Style_%i", mpImpl->miNumPageStyles); - finalPropList.insert("style:master-page-name", sPageStyleName); - mpImpl->mWriterDocumentStates.top().mbFirstElement = false; - mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false; - } - - if (mpImpl->mWriterDocumentStates.top().mbTableCellOpened) - { - if (mpImpl->mWriterDocumentStates.top().mbHeaderRow) - finalPropList.insert("style:parent-style-name", "Table_Heading"); - else - finalPropList.insert("style:parent-style-name", "Table_Contents"); - } - else - finalPropList.insert("style:parent-style-name", "Standard"); - - WPXString sName = mpImpl->mParagraphManager.findOrAdd(finalPropList, tabStops); - - // 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", sName); - 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->mFontManager.findOrAdd(propList["style:font-name"]->getStr().cstr()); - - // Get the style - WPXString sName = mpImpl->mSpanManager.findOrAdd(propList); - - // 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 OdtGeneratorPrivate::_storeListStyle(ListStyle *listStyle) -{ - if (!listStyle || listStyle == mWriterListStates.top().mpCurrentListStyle) - { - return; - } - mListStyles.push_back(listStyle); - mWriterListStates.top().mpCurrentListStyle = listStyle; - mWriterListStates.top().mIdListStyleMap[listStyle->getListID()]=listStyle; - mIdListStyleMap[listStyle->getListID()]=listStyle; -} - -void OdtGeneratorPrivate::_retrieveListStyle(int id) -{ - // first look if the current style is ok - if (mWriterListStates.top().mpCurrentListStyle && - id == mWriterListStates.top().mpCurrentListStyle->getListID()) - { - return; - } - - // use the current map - if (mWriterListStates.top().mIdListStyleMap.find(id) != - mWriterListStates.top().mIdListStyleMap.end()) - { - mWriterListStates.top().mpCurrentListStyle = - mWriterListStates.top().mIdListStyleMap.find(id)->second; - return; - } - - // use the global map - if (mIdListStyleMap.find(id) != mIdListStyleMap.end()) - { - mWriterListStates.top().mpCurrentListStyle = - mIdListStyleMap.find(id)->second; - return; - } - - WRITER_DEBUG_MSG(("impossible to find a list with id=%d\n",id)); -} - -void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList) -{ - int id = 0; - if (propList["libwpd:id"]) - id = propList["libwpd:id"]->getInt(); - - ListStyle *pListStyle = 0; - if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id) - pListStyle = mpImpl->mWriterListStates.top().mpCurrentListStyle; - - // 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 the prior list has another listId OR (2) we can - // tell that the user actually is starting a new list at level 1 - // (and only level 1) - if (pListStyle == 0 || - (propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 && - (propList["text:start-value"] && propList["text:start-value"]->getInt() != int(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++; - pListStyle = new ListStyle(sName.cstr(), id); - mpImpl->_storeListStyle(pListStyle); - 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 iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles) - { - if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"]) - (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, true); - } -} - -void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList) -{ - int id = 0; - if (propList["libwpd:id"]) - id = propList["libwpd:id"]->getInt(); - - ListStyle *pListStyle = 0; - if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id) - pListStyle = mpImpl->mWriterListStates.top().mpCurrentListStyle; - - if (pListStyle == 0) - { - 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++; - pListStyle = new ListStyle(sName.cstr(), id); - mpImpl->_storeListStyle(pListStyle); - } - - // See comment in OdtGenerator::defineOrderedListLevel - for (std::vector<ListStyle *>::iterator iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles) - { - if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"]) - (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, false); - } -} - -void OdtGenerator::openOrderedListLevel(const WPXPropertyList &propList) -{ - if (mpImpl->mWriterListStates.top().mbListElementParagraphOpened) - { - mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); - mpImpl->mWriterListStates.top().mbListElementParagraphOpened = false; - } - if (mpImpl->mWriterListStates.top().mbListElementOpened.empty() && propList["libwpd:id"]) - { - // first item of a list, be sure to use the list with given id - mpImpl->_retrieveListStyle(propList["libwpd:id"]->getInt()); - } - 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 &propList) -{ - if (mpImpl->mWriterListStates.top().mbListElementParagraphOpened) - { - mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:p")); - mpImpl->mWriterListStates.top().mbListElementParagraphOpened = false; - } - if (mpImpl->mWriterListStates.top().mbListElementOpened.empty() && propList["libwpd:id"]) - { - // first item of a list, be sure to use the list with given id - mpImpl->_retrieveListStyle(propList["libwpd:id"]->getInt()); - } - 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) - { - // add a sanity check ( to avoid a crash if mpCurrentListStyle is NULL) - if (mWriterListStates.top().mpCurrentListStyle) - { - 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.empty()) - { - // this implies that openListLevel was not called, so it is better to stop here - WRITER_DEBUG_MSG(("attempting to close an unexisting level\n")); - return; - } - 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")); - 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; - } - - WPXPropertyList finalPropList(propList); -#if 0 - // this property is ignored in TextRunStyle.c++ - if (mpImpl->mWriterListStates.top().mpCurrentListStyle) - finalPropList.insert("style:list-style-name", mpImpl->mWriterListStates.top().mpCurrentListStyle->getName()); -#endif - finalPropList.insert("style:parent-style-name", "Standard"); - WPXString paragName = mpImpl->mParagraphManager.findOrAdd(finalPropList, tabStops); - - TagOpenElement *pOpenListItem = new TagOpenElement("text:list-item"); - if (propList["text:start-value"] && propList["text:start-value"]->getInt() > 0) - pOpenListItem->addAttribute("text:start-value", propList["text:start-value"]->getStr()); - mpImpl->mpCurrentContentElements->push_back(pOpenListItem); - - TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p"); - pOpenListElementParagraph->addAttribute("text:style-name", paragName); - 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); - - TagOpenElement *pOpenFootCitation = new TagOpenElement("text:note-citation"); - if (propList["text:label"]) - { - WPXString tmpString(propList["text:label"]->getStr(),true); - pOpenFootCitation->addAttribute("text:label", tmpString); - } - mpImpl->mpCurrentContentElements->push_back(pOpenFootCitation); - - if (propList["text:label"]) - mpImpl->mpCurrentContentElements->push_back(new CharDataElement(propList["text:label"]->getStr().cstr())); - else 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); - - TagOpenElement *pOpenEndCitation = new TagOpenElement("text:note-citation"); - if (propList["text:label"]) - { - WPXString tmpString(propList["text:label"]->getStr(),true); - pOpenEndCitation->addAttribute("text:label", tmpString); - } - mpImpl->mpCurrentContentElements->push_back(pOpenEndCitation); - - if (propList["text:label"]) - mpImpl->mpCurrentContentElements->push_back(new CharDataElement(propList["text:label"]->getStr().cstr())); - else 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) - return; - if (!mpImpl->mpCurrentTableStyle) - { - WRITER_DEBUG_MSG(("OdtGenerator::openTableRow called with no table\n")); - return; - } - 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->mpCurrentTableStyle) - { - 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) - return; - if (!mpImpl->mpCurrentTableStyle) - { - WRITER_DEBUG_MSG(("OdtGenerator::openTableCell called with no table\n")); - return; - } - - 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->mpCurrentTableStyle) - { - 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->mpCurrentTableStyle) - { - 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()); - - // check if the frame has border, background attributes - static char const *(bordersString[])= - {"fo:border","fo:border-top","fo:border-left","fo:border-bottom","fo:border-right"}; - for (int b = 0; b < 5; b++) - { - if (propList[bordersString[b]]) - frameAutomaticStylePropertiesElement->addAttribute(bordersString[b], propList[bordersString[b]]->getStr()); - } - if (propList["style:border-line-width"]) - frameAutomaticStylePropertiesElement->addAttribute("style:border-line-width", propList["style:border-line-width"]->getStr()); - if (propList["fo:background-color"]) - frameAutomaticStylePropertiesElement->addAttribute("fo:background-color", propList["fo:background-color"]->getStr()); - if (propList["style:background-transparency"]) - frameAutomaticStylePropertiesElement->addAttribute("style:background-transparency", propList["style:background-transparency"]->getStr()); - - if (propList["fo:clip"]) - frameAutomaticStylePropertiesElement->addAttribute("fo:clip", propList["fo:clip"]->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()); - OdfEmbeddedImage tmpImageHandler = mpImpl->_findEmbeddedImageHandler(propList["libwpd:mimetype"]->getStr()); - - if (tmpObjectHandler || tmpImageHandler) - { - 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")); - } - } - if (tmpImageHandler) - { - WPXBinaryData output; - if (tmpImageHandler(data, output)) - { - mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:image")); - - mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("office:binary-data")); - - WPXString binaryBase64Data = output.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")); - } - } - } - else - // assuming we have a binary image or a object_ole that we can just insert as it is - { - if (propList["libwpd:mimetype"]->getStr() == "object/ole") - mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:object-ole")); - else - 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")); - - if (propList["libwpd:mimetype"]->getStr() == "object/ole") - mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:object-ole")); - else - 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; -} - -void OdtGenerator::registerEmbeddedImageHandler(const WPXString &mimeType, OdfEmbeddedImage imageHandler) -{ - mpImpl->mImageHandlers[mimeType] = imageHandler; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/OdtGenerator.hxx b/writerperfect/source/common/OdtGenerator.hxx deleted file mode 100644 index 7876e39a47e7..000000000000 --- a/writerperfect/source/common/OdtGenerator.hxx +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* 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 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -#ifndef _ODTGENERATOR_H -#define _ODTGENERATOR_H - -#include <libwpd/libwpd.h> - -#include "OdfDocumentHandler.hxx" - - -typedef bool (*OdfEmbeddedObject)(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType); -typedef bool (*OdfEmbeddedImage)(const WPXBinaryData &input, WPXBinaryData &output); - -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); - void registerEmbeddedImageHandler(const WPXString &mimeType, OdfEmbeddedImage imageHandler); - -private: - OdtGeneratorPrivate *mpImpl; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/PageSpan.cxx b/writerperfect/source/common/PageSpan.cxx deleted file mode 100644 index f6626481bf16..000000000000 --- a/writerperfect/source/common/PageSpan.cxx +++ /dev/null @@ -1,247 +0,0 @@ -/* -*- 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 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include "FilterInternal.hxx" -#include "PageSpan.hxx" -#include "DocumentElement.hxx" - -PageSpan::PageSpan(const WPXPropertyList &xPropList) : - mxPropList(xPropList), - mpHeaderContent(0), - mpFooterContent(0), - mpHeaderLeftContent(0), - mpFooterLeftContent(0) -{ -} - -namespace -{ -typedef std::vector<DocumentElement *>::iterator DEVIter; -} - -PageSpan::~PageSpan() -{ - if (mpHeaderContent) - { - for (DEVIter iterHeaderContent = mpHeaderContent->begin(); - iterHeaderContent != mpHeaderContent->end(); - ++iterHeaderContent) - delete(*iterHeaderContent); - delete mpHeaderContent; - } - - if (mpHeaderLeftContent) - { - for (DEVIter iterHeaderLeftContent = mpHeaderLeftContent->begin(); - iterHeaderLeftContent != mpHeaderLeftContent->end(); - ++iterHeaderLeftContent) - delete(*iterHeaderLeftContent); - delete mpHeaderLeftContent; - } - - if (mpFooterContent) - { - for (DEVIter iterFooterContent = mpFooterContent->begin(); - iterFooterContent != mpFooterContent->end(); - ++iterFooterContent) - delete(*iterFooterContent); - delete mpFooterContent; - } - - if (mpFooterLeftContent) - { - for (DEVIter iterFooterLeftContent = mpFooterLeftContent->begin(); - iterFooterLeftContent != mpFooterLeftContent->end(); - ++iterFooterLeftContent) - delete(*iterFooterLeftContent); - delete mpFooterLeftContent; - } -} - -int PageSpan::getSpan() const -{ - if (mxPropList["libwpd:num-pages"]) - return mxPropList["libwpd:num-pages"]->getInt(); - - return 0; // should never happen -} - -void PageSpan::setHeaderContent(std::vector<DocumentElement *> * pHeaderContent) -{ - if (mpHeaderContent) - { - for (DEVIter iterHeaderContent = mpHeaderContent->begin(); - iterHeaderContent != mpHeaderContent->end(); - ++iterHeaderContent) - delete(*iterHeaderContent); - delete mpHeaderContent; - } - - mpHeaderContent = pHeaderContent; -} - -void PageSpan::setFooterContent(std::vector<DocumentElement *> * pFooterContent) -{ - if (mpFooterContent) - { - for (DEVIter iterFooterContent = mpFooterContent->begin(); - iterFooterContent != mpFooterContent->end(); - ++iterFooterContent) - delete(*iterFooterContent); - delete mpFooterContent; - } - - mpFooterContent = pFooterContent; -} - -void PageSpan::setHeaderLeftContent(std::vector<DocumentElement *> * pHeaderContent) -{ - if (mpHeaderLeftContent) - { - for (DEVIter iterHeaderLeftContent = mpHeaderLeftContent->begin(); - iterHeaderLeftContent != mpHeaderLeftContent->end(); - ++iterHeaderLeftContent) - delete(*iterHeaderLeftContent); - delete mpHeaderLeftContent; - } - - mpHeaderLeftContent = pHeaderContent; -} - -void PageSpan::setFooterLeftContent(std::vector<DocumentElement *> * pFooterContent) -{ - if (mpFooterLeftContent) - { - for (DEVIter iterFooterLeftContent = mpFooterLeftContent->begin(); - iterFooterLeftContent != mpFooterLeftContent->end(); - ++iterFooterLeftContent) - delete(*iterFooterLeftContent); - delete mpFooterLeftContent; - } - - mpFooterLeftContent = pFooterContent; -} - -void PageSpan::writePageLayout(const int iNum, OdfDocumentHandler *pHandler) const -{ - WPXPropertyList propList; - - WPXString sPageLayoutName; - sPageLayoutName.sprintf("PM%i", iNum+2); - propList.insert("style:name", sPageLayoutName); - pHandler->startElement("style:page-layout", propList); - - WPXPropertyList tempPropList = mxPropList; - if (!tempPropList["style:writing-mode"]) - tempPropList.insert("style:writing-mode", WPXString("lr-tb")); - if (!tempPropList["style:footnote-max-height"]) - tempPropList.insert("style:footnote-max-height", WPXString("0in")); - pHandler->startElement("style:page-layout-properties", tempPropList); - - WPXPropertyList footnoteSepPropList; - footnoteSepPropList.insert("style:width", WPXString("0.0071in")); - footnoteSepPropList.insert("style:distance-before-sep", WPXString("0.0398in")); - footnoteSepPropList.insert("style:distance-after-sep", WPXString("0.0398in")); - footnoteSepPropList.insert("style:adjustment", WPXString("left")); - footnoteSepPropList.insert("style:rel-width", WPXString("25%")); - footnoteSepPropList.insert("style:color", WPXString("#000000")); - pHandler->startElement("style:footnote-sep", footnoteSepPropList); - - pHandler->endElement("style:footnote-sep"); - pHandler->endElement("style:page-layout-properties"); - pHandler->endElement("style:page-layout"); -} - -void PageSpan::writeMasterPages(const int iStartingNum, const int iPageLayoutNum, const bool bLastPageSpan, - OdfDocumentHandler *pHandler) const -{ - int iSpan = 0; - (bLastPageSpan) ? iSpan = 1 : iSpan = getSpan(); - - for (int i=iStartingNum; i<(iStartingNum+iSpan); ++i) - { - TagOpenElement masterPageOpen("style:master-page"); - WPXString sMasterPageName, sMasterPageDisplayName; - sMasterPageName.sprintf("Page_Style_%i", i); - sMasterPageDisplayName.sprintf("Page Style %i", i); - WPXString sPageLayoutName; - WPXPropertyList propList; - sPageLayoutName.sprintf("PM%i", iPageLayoutNum+2); - propList.insert("style:name", sMasterPageName); - propList.insert("style:display-name", sMasterPageDisplayName); - propList.insert("style:page-layout-name", sPageLayoutName); - if (!bLastPageSpan) - { - WPXString sNextMasterPageName; - sNextMasterPageName.sprintf("Page_Style_%i", (i+1)); - propList.insert("style:next-style-name", sNextMasterPageName); - } - pHandler->startElement("style:master-page", propList); - - if (mpHeaderContent) - { - _writeHeaderFooter("style:header", *mpHeaderContent, pHandler); - pHandler->endElement("style:header"); - if (mpHeaderLeftContent) - { - _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler); - pHandler->endElement("style:header-left"); - } - } - else if (mpHeaderLeftContent) - { - TagOpenElement("style:header").write(pHandler); - pHandler->endElement("style:header"); - _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler); - pHandler->endElement("style:header-left"); - } - - if (mpFooterContent) - { - _writeHeaderFooter("style:footer", *mpFooterContent, pHandler); - pHandler->endElement("style:footer"); - if (mpFooterLeftContent) - { - _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler); - pHandler->endElement("style:footer-left"); - } - } - else if (mpFooterLeftContent) - { - TagOpenElement("style:footer").write(pHandler); - pHandler->endElement("style:footer"); - _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler); - pHandler->endElement("style:footer-left"); - } - - pHandler->endElement("style:master-page"); - } -} - -void PageSpan::_writeHeaderFooter(const char *headerFooterTagName, - const std::vector<DocumentElement *> & headerFooterContent, - OdfDocumentHandler *pHandler) const -{ - TagOpenElement headerFooterOpen(headerFooterTagName); - headerFooterOpen.write(pHandler); - for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin(); - iter != headerFooterContent.end(); - ++iter) - { - (*iter)->write(pHandler); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/PageSpan.hxx b/writerperfect/source/common/PageSpan.hxx deleted file mode 100644 index 0c7f72df82c5..000000000000 --- a/writerperfect/source/common/PageSpan.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- 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) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#ifndef _PAGESPAN_H -#define _PAGESPAN_H -#include <libwpd/libwpd.h> -#include <vector> - -class DocumentElement; -class OdfDocumentHandler; - -class PageSpan -{ -public: - PageSpan(const WPXPropertyList &xPropList); - virtual ~PageSpan(); - 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; - - void setHeaderContent(std::vector<DocumentElement *> * pHeaderContent); - void setFooterContent(std::vector<DocumentElement *> * pFooterContent); - void setHeaderLeftContent(std::vector<DocumentElement *> * pHeaderContent); - void setFooterLeftContent(std::vector<DocumentElement *> * pFooterContent); -protected: - void _writeHeaderFooter(const char *headerFooterTagName, const std::vector<DocumentElement *> & headerFooterContent, - OdfDocumentHandler *pHandler) const; -private: - WPXPropertyList mxPropList; - std::vector<DocumentElement *> * mpHeaderContent; - std::vector<DocumentElement *> * mpFooterContent; - std::vector<DocumentElement *> * mpHeaderLeftContent; - std::vector<DocumentElement *> * mpFooterLeftContent; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/SectionStyle.cxx b/writerperfect/source/common/SectionStyle.cxx deleted file mode 100644 index 5f8c17138d6c..000000000000 --- a/writerperfect/source/common/SectionStyle.cxx +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- 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 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include "FilterInternal.hxx" -#include "SectionStyle.hxx" -#include "DocumentElement.hxx" -#include <math.h> - -#ifdef _MSC_VER -double rint(double x); -#endif /* _WIN32 */ - -SectionStyle::SectionStyle(const WPXPropertyList &xPropList, - const WPXPropertyListVector &xColumns, - const char *psName) : - Style(psName), - mPropList(xPropList), - mColumns(xColumns) -{ -} - -void SectionStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement styleOpen("style:style"); - styleOpen.addAttribute("style:name", getName()); - styleOpen.addAttribute("style:family", "section"); - styleOpen.write(pHandler); - - // if the number of columns is <= 1, we will never come here. This is only an additional check - // style properties - pHandler->startElement("style:section-properties", mPropList); - - // column properties - WPXPropertyList columnProps; - - if (mColumns.count() > 1) - { - columnProps.insert("fo:column-count", (int)mColumns.count()); - pHandler->startElement("style:columns", columnProps); - - WPXPropertyListVector::Iter i(mColumns); - for (i.rewind(); i.next();) - { - pHandler->startElement("style:column", i()); - pHandler->endElement("style:column"); - } - } - else - { - columnProps.insert("fo:column-count", 0); - columnProps.insert("fo:column-gap", 0.0); - pHandler->startElement("style:columns", columnProps); - } - - pHandler->endElement("style:columns"); - - - pHandler->endElement("style:section-properties"); - - pHandler->endElement("style:style"); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/SectionStyle.hxx b/writerperfect/source/common/SectionStyle.hxx deleted file mode 100644 index d06a60604360..000000000000 --- a/writerperfect/source/common/SectionStyle.hxx +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#ifndef _SECTIONSTYLE_H -#define _SECTIONSTYLE_H -#include <libwpd/libwpd.h> -#include <libwpd/WPXPropertyListVector.h> - -#include "Style.hxx" - - -class SectionStyle : public Style -{ -public: - SectionStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &xColumns, const char *psName); - virtual void write(OdfDocumentHandler *pHandler) const; - -private: - WPXPropertyList mPropList; - WPXPropertyListVector mColumns; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/Style.hxx b/writerperfect/source/common/Style.hxx deleted file mode 100644 index 4c8cf5b82300..000000000000 --- a/writerperfect/source/common/Style.hxx +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _STYLE_H -#define _STYLE_H -#include <libwpd/libwpd.h> - -#include "DocumentElement.hxx" - -class TopLevelElementStyle -{ -public: - TopLevelElementStyle() : mpsMasterPageName(0) {} - virtual ~TopLevelElementStyle() - { - if (mpsMasterPageName) delete mpsMasterPageName; - } - void setMasterPageName(WPXString &sMasterPageName) - { - mpsMasterPageName = new WPXString(sMasterPageName); - } - const WPXString *getMasterPageName() const - { - return mpsMasterPageName; - } - -private: - TopLevelElementStyle(const TopLevelElementStyle &); - TopLevelElementStyle &operator=(const TopLevelElementStyle &); - WPXString *mpsMasterPageName; -}; - -class Style -{ -public: - Style(const WPXString &psName) : msName(psName) {} - virtual ~Style() {} - - virtual void write(OdfDocumentHandler *) const {}; - const WPXString &getName() const - { - return msName; - } - -private: - WPXString msName; -}; - -class StyleManager -{ -public: - StyleManager() {} - virtual ~StyleManager() {} - - virtual void clean() {}; - virtual void write(OdfDocumentHandler *) const = 0; - -private: - // forbide copy constructor/operator - StyleManager(const StyleManager &); - StyleManager &operator=(const StyleManager &); -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/TableStyle.cxx b/writerperfect/source/common/TableStyle.cxx deleted file mode 100644 index 856f578ff30e..000000000000 --- a/writerperfect/source/common/TableStyle.cxx +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include <math.h> -#include "FilterInternal.hxx" -#include "TableStyle.hxx" -#include "DocumentElement.hxx" - -#ifdef _MSC_VER -#include <minmax.h> -#endif - -#include <string.h> - -TableCellStyle::TableCellStyle(const WPXPropertyList &xPropList, const char *psName) : - Style(psName), - mPropList(xPropList) -{ -} - -void TableCellStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement styleOpen("style:style"); - styleOpen.addAttribute("style:name", getName()); - styleOpen.addAttribute("style:family", "table-cell"); - styleOpen.write(pHandler); - - // WLACH_REFACTORING: Only temporary.. a much better solution is to - // generalize this sort of thing into the "Style" superclass - WPXPropertyList stylePropList; - WPXPropertyList::Iter i(mPropList); - /* first set padding, so that mPropList can redefine, if - mPropList["fo:padding"] is defined */ - stylePropList.insert("fo:padding", "0.0382in"); - for (i.rewind(); i.next();) - { - if (strlen(i.key()) > 2 && strncmp(i.key(), "fo", 2) == 0) - stylePropList.insert(i.key(), i()->clone()); - else if (strcmp(i.key(), "style:vertical-align")==0) - stylePropList.insert(i.key(), i()->clone()); - } - pHandler->startElement("style:table-cell-properties", stylePropList); - pHandler->endElement("style:table-cell-properties"); - - pHandler->endElement("style:style"); -} - -TableRowStyle::TableRowStyle(const WPXPropertyList &propList, const char *psName) : - Style(psName), - mPropList(propList) -{ -} - -void TableRowStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement styleOpen("style:style"); - styleOpen.addAttribute("style:name", getName()); - styleOpen.addAttribute("style:family", "table-row"); - styleOpen.write(pHandler); - - TagOpenElement stylePropertiesOpen("style:table-row-properties"); - if (mPropList["style:min-row-height"]) - stylePropertiesOpen.addAttribute("style:min-row-height", mPropList["style:min-row-height"]->getStr()); - else if (mPropList["style:row-height"]) - stylePropertiesOpen.addAttribute("style:row-height", mPropList["style:row-height"]->getStr()); - stylePropertiesOpen.addAttribute("fo:keep-together", "auto"); - stylePropertiesOpen.write(pHandler); - pHandler->endElement("style:table-row-properties"); - - pHandler->endElement("style:style"); -} - - -TableStyle::TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName) : - Style(psName), - mPropList(xPropList), - mColumns(columns) -{ -} - -TableStyle::~TableStyle() -{ - typedef std::vector<TableCellStyle *>::iterator TCSVIter; - typedef std::vector<TableRowStyle *>::iterator TRSVIter; - for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); ++iterTableCellStyles) - delete(*iterTableCellStyles); - for (TRSVIter iterTableRowStyles = mTableRowStyles.begin() ; iterTableRowStyles != mTableRowStyles.end(); ++iterTableRowStyles) - delete(*iterTableRowStyles); -} - -void TableStyle::write(OdfDocumentHandler *pHandler) const -{ - TagOpenElement styleOpen("style:style"); - styleOpen.addAttribute("style:name", getName()); - styleOpen.addAttribute("style:family", "table"); - if (getMasterPageName()) - styleOpen.addAttribute("style:master-page-name", getMasterPageName()->cstr()); - styleOpen.write(pHandler); - - TagOpenElement stylePropertiesOpen("style:table-properties"); - if (mPropList["table:align"]) - stylePropertiesOpen.addAttribute("table:align", mPropList["table:align"]->getStr()); - if (mPropList["fo:margin-left"]) - stylePropertiesOpen.addAttribute("fo:margin-left", mPropList["fo:margin-left"]->getStr()); - if (mPropList["fo:margin-right"]) - stylePropertiesOpen.addAttribute("fo:margin-right", mPropList["fo:margin-right"]->getStr()); - if (mPropList["style:width"]) - stylePropertiesOpen.addAttribute("style:width", mPropList["style:width"]->getStr()); - if (mPropList["fo:break-before"]) - stylePropertiesOpen.addAttribute("fo:break-before", mPropList["fo:break-before"]->getStr()); - stylePropertiesOpen.write(pHandler); - - pHandler->endElement("style:table-properties"); - - pHandler->endElement("style:style"); - - int i=1; - WPXPropertyListVector::Iter j(mColumns); - for (j.rewind(); j.next();) - { - TagOpenElement columnStyleOpen("style:style"); - WPXString sColumnName; - sColumnName.sprintf("%s.Column%i", getName().cstr(), i); - columnStyleOpen.addAttribute("style:name", sColumnName); - columnStyleOpen.addAttribute("style:family", "table-column"); - columnStyleOpen.write(pHandler); - - pHandler->startElement("style:table-column-properties", j()); - pHandler->endElement("style:table-column-properties"); - - pHandler->endElement("style:style"); - - i++; - } - - typedef std::vector<TableRowStyle *>::const_iterator TRSVIter; - 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) - (*iterTableCell)->write(pHandler); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/TableStyle.hxx b/writerperfect/source/common/TableStyle.hxx deleted file mode 100644 index 8f1e83094eeb..000000000000 --- a/writerperfect/source/common/TableStyle.hxx +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#ifndef _TABLESTYLE_H -#define _TABLESTYLE_H -#include <libwpd/libwpd.h> -#include <vector> - -#include "Style.hxx" - -class OdfDocumentHandler; - -class TableCellStyle : public Style -{ -public: - virtual ~TableCellStyle() {}; - TableCellStyle(const WPXPropertyList &xPropList, const char *psName); - virtual void write(OdfDocumentHandler *pHandler) const; -private: - WPXPropertyList mPropList; -}; - -class TableRowStyle : public Style -{ -public: - virtual ~TableRowStyle() {}; - TableRowStyle(const WPXPropertyList &propList, const char *psName); - virtual void write(OdfDocumentHandler *pHandler) const; -private: - WPXPropertyList mPropList; -}; - -class TableStyle : public Style, public TopLevelElementStyle -{ -public: - TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName); - virtual ~TableStyle(); - 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(); - } - void addTableRowStyle(TableRowStyle *pTableRowStyle) - { - mTableRowStyles.push_back(pTableRowStyle); - } - int getNumTableRowStyles() - { - return mTableRowStyles.size(); - } -private: - WPXPropertyList mPropList; - WPXPropertyListVector mColumns; - std::vector<TableCellStyle *> mTableCellStyles; - std::vector<TableRowStyle *> mTableRowStyles; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/TextRunStyle.cxx b/writerperfect/source/common/TextRunStyle.cxx deleted file mode 100644 index 8bb34efc5518..000000000000 --- a/writerperfect/source/common/TextRunStyle.cxx +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ -#include "FilterInternal.hxx" -#include "TextRunStyle.hxx" -#include "DocumentElement.hxx" - -#ifdef _MSC_VER -#include <minmax.h> -#endif - -#include <string.h> - -ParagraphStyle::ParagraphStyle(const WPXPropertyList &pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) : - mpPropList(pPropList), - mxTabStops(xTabStops), - msName(sName) -{ -} - -ParagraphStyle::~ParagraphStyle() -{ -} - -void ParagraphStyle::write(OdfDocumentHandler *pHandler) const -{ - WRITER_DEBUG_MSG(("Writing a paragraph style..\n")); - - WPXPropertyList propList; - propList.insert("style:name", msName.cstr()); - propList.insert("style:family", "paragraph"); - if (mpPropList["style:parent-style-name"]) - 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); - - propList.clear(); - WPXPropertyList::Iter i(mpPropList); - for (i.rewind(); i.next(); ) - { - if (strncmp(i.key(), "fo:margin-",10) == 0) - { - if (strcmp(i.key(), "fo:margin-left") == 0 || - strcmp(i.key(), "fo:margin-right") == 0 || - strcmp(i.key(), "fo:margin-top") == 0) - propList.insert(i.key(), i()->getStr()); - else if (strcmp(i.key(), "fo:margin-bottom") == 0) - { - if (i()->getDouble() > 0.0) - propList.insert("fo:margin-bottom", i()->getStr()); - else - propList.insert("fo:margin-bottom", 0.0); - } - } - else if (strcmp(i.key(), "fo:text-indent") == 0) - propList.insert("fo:text-indent", i()->getStr()); - else if (strcmp(i.key(), "fo:line-height") == 0) - propList.insert("fo:line-height", i()->getStr()); - else if (strcmp(i.key(), "style:line-height-at-least") == 0) - propList.insert("style:line-height-at-least", i()->getStr()); - else if (strcmp(i.key(), "fo:break-before") == 0) - propList.insert("fo:break-before", i()->getStr()); - else if (strcmp(i.key(), "fo:text-align") == 0) - propList.insert("fo:text-align", i()->getStr()); - else if (strcmp(i.key(), "fo:text-align-last") == 0) - propList.insert("fo:text-align-last", i()->getStr()); - else if (strcmp(i.key(), "style:page-number") == 0) - propList.insert("style:page-number", i()->getStr()); - else if (strcmp(i.key(), "fo:background-color") == 0) - propList.insert("fo:background-color", i()->getStr()); - else if (strncmp(i.key(), "fo:border", 9) == 0) - { - if (strcmp(i.key(), "fo:border") == 0 || - strcmp(i.key(), "fo:border-left") == 0 || - strcmp(i.key(), "fo:border-right") == 0 || - strcmp(i.key(), "fo:border-top") == 0 || - strcmp(i.key(), "fo:border-bottom") == 0) - propList.insert(i.key(), i()->getStr()); - } - else if (strcmp(i.key(), "fo:keep-together") == 0) - propList.insert("fo:keep-together", i()->getStr()); - else if (strcmp(i.key(), "fo:keep-with-next") == 0) - propList.insert("fo:keep-with-next", i()->getStr()); - } - - propList.insert("style:justify-single-word", "false"); - pHandler->startElement("style:paragraph-properties", propList); - - if (mxTabStops.count() > 0) - { - TagOpenElement tabListOpen("style:tab-stops"); - tabListOpen.write(pHandler); - WPXPropertyListVector::Iter k(mxTabStops); - for (k.rewind(); k.next();) - { - if (k()["style:position"] && k()["style:position"]->getDouble() < 0.0) - continue; - 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"); -} - -SpanStyle::SpanStyle(const char *psName, const WPXPropertyList &xPropList) : - Style(psName), - mPropList(xPropList) -{ -} - -void SpanStyle::write(OdfDocumentHandler *pHandler) const -{ - WRITER_DEBUG_MSG(("Writing a span style..\n")); - WPXPropertyList styleOpenList; - styleOpenList.insert("style:name", getName()); - styleOpenList.insert("style:family", "text"); - pHandler->startElement("style:style", styleOpenList); - - WPXPropertyList propList(mPropList); - - if (mPropList["style:font-name"]) - { - propList.insert("style:font-name-asian", mPropList["style:font-name"]->getStr()); - propList.insert("style:font-name-complex", mPropList["style:font-name"]->getStr()); - } - - if (mPropList["fo:font-size"]) - { - 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()); - } - else - propList.remove("fo:font-size"); - } - - if (mPropList["fo:font-weight"]) - { - propList.insert("style:font-weight-asian", mPropList["fo:font-weight"]->getStr()); - propList.insert("style:font-weight-complex", mPropList["fo:font-weight"]->getStr()); - } - - if (mPropList["fo:font-style"]) - { - propList.insert("style:font-style-asian", mPropList["fo:font-style"]->getStr()); - propList.insert("style:font-style-complex", mPropList["fo:font-style"]->getStr()); - } - - pHandler->startElement("style:text-properties", propList); - - pHandler->endElement("style:text-properties"); - pHandler->endElement("style:style"); -} - -void ParagraphStyleManager::clean() -{ - mNameHash.clear(); - mStyleHash.clear(); -} - -void ParagraphStyleManager::write(OdfDocumentHandler *pHandler) const -{ - for (std::map<WPXString, shared_ptr<ParagraphStyle>, ltstr>::const_iterator iter = mStyleHash.begin(); - iter != mStyleHash.end(); ++iter) - { - if (strcmp(iter->second->getName().cstr(), "Standard") == 0) - continue; - (iter->second)->write(pHandler); - } -} - -WPXString ParagraphStyleManager::getKey(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops) const -{ - WPXString sKey = propListToStyleKey(xPropList); - - WPXString sTabStops; - sTabStops.sprintf("[num-tab-stops:%i]", tabStops.count()); - WPXPropertyListVector::Iter i(tabStops); - for (i.rewind(); i.next();) - { - sTabStops.append(propListToStyleKey(i())); - } - sKey.append(sTabStops); - - return sKey; -} - -WPXString ParagraphStyleManager::findOrAdd(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - WPXString hashKey = getKey(propList, tabStops); - std::map<WPXString, WPXString, ltstr>::const_iterator iter = - mNameHash.find(hashKey); - if (iter!=mNameHash.end()) return iter->second; - - // ok create a new list - WRITER_DEBUG_MSG(("ParagraphStyleManager::findOrAdd: Paragraph Hash Key: %s\n", hashKey.cstr())); - - WPXString sName; - sName.sprintf("S%i", mStyleHash.size()); - shared_ptr<ParagraphStyle> parag(new ParagraphStyle(propList, tabStops, sName)); - mStyleHash[sName] =parag; - mNameHash[hashKey] = sName; - return sName; -} - -shared_ptr<ParagraphStyle> const ParagraphStyleManager::get(const WPXString &name) const -{ - std::map<WPXString, shared_ptr<ParagraphStyle>, ltstr>::const_iterator iter - = mStyleHash.find(name); - if (iter == mStyleHash.end()) return shared_ptr<ParagraphStyle>(); - return iter->second; -} - -void SpanStyleManager::clean() -{ - mNameHash.clear(); - mStyleHash.clear(); -} - -void SpanStyleManager::write(OdfDocumentHandler *pHandler) const -{ - for (std::map<WPXString, shared_ptr<SpanStyle>, ltstr>::const_iterator iter = mStyleHash.begin(); - iter != mStyleHash.end(); ++iter) - { - (iter->second)->write(pHandler); - } -} - -WPXString SpanStyleManager::findOrAdd(const WPXPropertyList &propList) -{ - WPXString hashKey = propListToStyleKey(propList); - std::map<WPXString, WPXString, ltstr>::const_iterator iter = - mNameHash.find(hashKey); - if (iter!=mNameHash.end()) return iter->second; - - // ok create a new list - WRITER_DEBUG_MSG(("SpanStyleManager::findOrAdd: Span Hash Key: %s\n", hashKey.cstr())); - - WPXString sName; - sName.sprintf("Span%i", mStyleHash.size()); - shared_ptr<SpanStyle> span(new SpanStyle(sName.cstr(), propList)); - mStyleHash[sName] = span; - mNameHash[hashKey] = sName; - return sName; -} - -shared_ptr<SpanStyle> const SpanStyleManager::get(const WPXString &name) const -{ - std::map<WPXString, shared_ptr<SpanStyle>, ltstr>::const_iterator iter - = mStyleHash.find(name); - if (iter == mStyleHash.end()) return shared_ptr<SpanStyle>(); - return iter->second; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/TextRunStyle.hxx b/writerperfect/source/common/TextRunStyle.hxx deleted file mode 100644 index c8d3a26b70c1..000000000000 --- a/writerperfect/source/common/TextRunStyle.hxx +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- 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. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * For further information visit http://libwpd.sourceforge.net - */ - -/* "This product is not manufactured, approved, or supported by - * Corel Corporation or Corel Corporation Limited." - */ - -#ifndef _TEXTRUNSTYLE_H -#define _TEXTRUNSTYLE_H - -#include <map> - -#include <libwpd/libwpd.h> - -#include "FilterInternal.hxx" - -#include "Style.hxx" - -class OdfDocumentHandler; - -class ParagraphStyle -{ -public: - ParagraphStyle(WPXPropertyList const &propList, const WPXPropertyListVector &tabStops, const WPXString &sName); - virtual ~ParagraphStyle(); - virtual void write(OdfDocumentHandler *pHandler) const; - WPXString getName() const - { - return msName; - } -private: - WPXPropertyList mpPropList; - WPXPropertyListVector mxTabStops; - WPXString msName; -}; - - -class SpanStyle : public Style -{ -public: - SpanStyle(const char *psName, const WPXPropertyList &xPropList); - virtual void write(OdfDocumentHandler *pHandler) const; - -private: - WPXPropertyList mPropList; -}; - -class ParagraphStyleManager : public StyleManager -{ -public: - ParagraphStyleManager() : mNameHash(), mStyleHash() {} - virtual ~ParagraphStyleManager() - { - clean(); - } - - /* create a new style if it does not exists. In all case, returns the name of the style - - Note: using S%i as new name*/ - WPXString findOrAdd(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops); - - /* returns the style corresponding to a given name ( if it exists ) */ - shared_ptr<ParagraphStyle> const get(const WPXString &name) const; - - virtual void clean(); - virtual void write(OdfDocumentHandler *) const; - - -protected: - // return a unique key - WPXString getKey(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops) const; - - // hash key -> name - std::map<WPXString, WPXString, ltstr> mNameHash; - // style name -> paragraph style - std::map<WPXString, shared_ptr<ParagraphStyle>, ltstr> mStyleHash; -}; - -class SpanStyleManager : public StyleManager -{ -public: - SpanStyleManager() : mNameHash(), mStyleHash() {} - virtual ~SpanStyleManager() - { - clean(); - } - - /* create a new style if it does not exists. In all case, returns the name of the style - - Note: using Span%i as new name*/ - WPXString findOrAdd(const WPXPropertyList &xPropList); - - /* returns the style corresponding to a given name ( if it exists ) */ - shared_ptr<SpanStyle> const get(const WPXString &name) const; - - virtual void clean(); - virtual void write(OdfDocumentHandler *) const; - -protected: - // hash key -> style name - std::map<WPXString, WPXString, ltstr> mNameHash; - // style name -> SpanStyle - std::map<WPXString, shared_ptr<SpanStyle>, ltstr> mStyleHash; -}; -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/common/WPXSvStream.cxx b/writerperfect/source/common/WPXSvStream.cxx index 234b3993a21e..fca2364fb413 100644 --- a/writerperfect/source/common/WPXSvStream.cxx +++ b/writerperfect/source/common/WPXSvStream.cxx @@ -8,7 +8,7 @@ */ #include "WPXSvStream.hxx" -#include "FilterInternal.hxx" +#include "WriterPerfectDebug.hxx" #include <tools/stream.hxx> #include <unotools/streamwrap.hxx> #include <unotools/ucbstreamhelper.hxx> diff --git a/writerperfect/source/common/WriterPerfectDebug.hxx b/writerperfect/source/common/WriterPerfectDebug.hxx new file mode 100644 index 000000000000..da363eb087fb --- /dev/null +++ b/writerperfect/source/common/WriterPerfectDebug.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* WriterPerfectDebug: Debugging information + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information visit http://libwpd.sourceforge.net + */ +#ifndef __FILTERINTERNAL_HXX__ +#define __FILTERINTERNAL_HXX__ + +#include <string.h> // for strcmp + +#ifdef DEBUG +#include <stdio.h> +#define WRITER_DEBUG_MSG(M) printf M +#else +#define WRITER_DEBUG_MSG(M) +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/draw/CDRImportFilter.cxx b/writerperfect/source/draw/CDRImportFilter.cxx index 10cdcad56ca1..7f5287caaa0a 100644 --- a/writerperfect/source/draw/CDRImportFilter.cxx +++ b/writerperfect/source/draw/CDRImportFilter.cxx @@ -26,10 +26,11 @@ #include <xmloff/attrlist.hxx> #include <libcdr/libcdr.h> +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "CDRImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "CDRImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/draw/CMXImportFilter.cxx b/writerperfect/source/draw/CMXImportFilter.cxx index 7290acd45913..22d7b3cdf8b5 100644 --- a/writerperfect/source/draw/CMXImportFilter.cxx +++ b/writerperfect/source/draw/CMXImportFilter.cxx @@ -26,10 +26,11 @@ #include <xmloff/attrlist.hxx> #include <libcdr/libcdr.h> +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "CMXImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "CMXImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/draw/MSPUBImportFilter.cxx b/writerperfect/source/draw/MSPUBImportFilter.cxx index 820016026b40..d280c69869ee 100644 --- a/writerperfect/source/draw/MSPUBImportFilter.cxx +++ b/writerperfect/source/draw/MSPUBImportFilter.cxx @@ -22,10 +22,11 @@ #include <xmloff/attrlist.hxx> #include <libmspub/libmspub.h> +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "MSPUBImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "MSPUBImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/draw/VisioImportFilter.cxx b/writerperfect/source/draw/VisioImportFilter.cxx index 11d2c0c2f7fa..ee757e4fd686 100644 --- a/writerperfect/source/draw/VisioImportFilter.cxx +++ b/writerperfect/source/draw/VisioImportFilter.cxx @@ -22,10 +22,11 @@ #include <xmloff/attrlist.hxx> #include <libvisio/libvisio.h> +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "VisioImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "VisioImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/draw/WPGImportFilter.cxx b/writerperfect/source/draw/WPGImportFilter.cxx index f29ff5d448a4..929ac9d671b2 100644 --- a/writerperfect/source/draw/WPGImportFilter.cxx +++ b/writerperfect/source/draw/WPGImportFilter.cxx @@ -27,10 +27,11 @@ #include <comphelper/componentcontext.hxx> #include <xmloff/attrlist.hxx> +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "WPGImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "WPGImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/writer/MSWorksImportFilter.cxx b/writerperfect/source/writer/MSWorksImportFilter.cxx index c1d63c7317c8..0c71aaac42e7 100644 --- a/writerperfect/source/writer/MSWorksImportFilter.cxx +++ b/writerperfect/source/writer/MSWorksImportFilter.cxx @@ -26,11 +26,12 @@ #include <libwps/libwps.h> -#include "common/FilterInternal.hxx" +#include <libodfgen/libodfgen.hxx> + #include "common/DocumentHandler.hxx" -#include "common/OdtGenerator.hxx" -#include "MSWorksImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "common/WriterPerfectDebug.hxx" +#include "MSWorksImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/writer/MWAWImportFilter.cxx b/writerperfect/source/writer/MWAWImportFilter.cxx index ebd1b1959501..f6decf7ada7a 100644 --- a/writerperfect/source/writer/MWAWImportFilter.cxx +++ b/writerperfect/source/writer/MWAWImportFilter.cxx @@ -25,12 +25,12 @@ #include <ucbhelper/content.hxx> #include <libmwaw/libmwaw.hxx> +#include <libodfgen/libodfgen.hxx> -#include "common/FilterInternal.hxx" #include "common/DocumentHandler.hxx" -#include "common/OdtGenerator.hxx" -#include "MWAWImportFilter.hxx" #include "common/WPXSvStream.hxx" +#include "common/WriterPerfectDebug.hxx" +#include "MWAWImportFilter.hxx" #include <iostream> diff --git a/writerperfect/source/writer/WordPerfectImportFilter.cxx b/writerperfect/source/writer/WordPerfectImportFilter.cxx index 1c1e56c4e0d4..8364a99f43c5 100644 --- a/writerperfect/source/writer/WordPerfectImportFilter.cxx +++ b/writerperfect/source/writer/WordPerfectImportFilter.cxx @@ -26,12 +26,11 @@ #include <ucbhelper/content.hxx> #include <libwpd/libwpd.h> +#include <libodfgen/libodfgen.hxx> -#include "common/FilterInternal.hxx" #include "common/DocumentHandler.hxx" -#include "common/OdgGenerator.hxx" -#include "common/OdtGenerator.hxx" #include "common/WPXSvStream.hxx" +#include "common/WriterPerfectDebug.hxx" #include "WordPerfectImportFilter.hxx" using ::ucbhelper::Content; |