summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Alonso <alonso@loria.fr>2011-10-23 21:02:14 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2011-10-23 21:02:14 +0200
commit55170dd7a0cfd552a89b4bea6c7f4a9854971161 (patch)
tree4813a4cb861988fbd35347bff03ca4d68804d562
parentc77a9254dde41f222bc65af957c91fa5bc166103 (diff)
Handle styles in a more intelligent way
-rw-r--r--writerperfect/StaticLibrary_writerperfect.mk1
-rw-r--r--writerperfect/source/filter/DocumentElement.hxx2
-rw-r--r--writerperfect/source/filter/FilterInternal.hxx9
-rw-r--r--writerperfect/source/filter/FontStyle.cxx42
-rw-r--r--writerperfect/source/filter/FontStyle.hxx24
-rw-r--r--writerperfect/source/filter/InternalHandler.hxx2
-rw-r--r--writerperfect/source/filter/OdgGenerator.cxx110
-rw-r--r--writerperfect/source/filter/OdgGenerator.hxx1
-rw-r--r--writerperfect/source/filter/OdtGenerator.cxx277
-rw-r--r--writerperfect/source/filter/Style.hxx22
-rw-r--r--writerperfect/source/filter/TextRunStyle.cxx107
-rw-r--r--writerperfect/source/filter/TextRunStyle.hxx49
-rw-r--r--writerperfect/source/filter/libwriterperfect_filter.cxx47
-rw-r--r--writerperfect/source/filter/libwriterperfect_filter.hxx48
14 files changed, 411 insertions, 330 deletions
diff --git a/writerperfect/StaticLibrary_writerperfect.mk b/writerperfect/StaticLibrary_writerperfect.mk
index 67e6afc2e6cd..2569cba96ae1 100644
--- a/writerperfect/StaticLibrary_writerperfect.mk
+++ b/writerperfect/StaticLibrary_writerperfect.mk
@@ -55,6 +55,7 @@ $(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect,\
writerperfect/source/filter/SectionStyle \
writerperfect/source/filter/TableStyle \
writerperfect/source/filter/TextRunStyle \
+ writerperfect/source/filter/libwriterperfect_filter \
writerperfect/source/stream/WPXSvStream \
))
diff --git a/writerperfect/source/filter/DocumentElement.hxx b/writerperfect/source/filter/DocumentElement.hxx
index b191de50b678..f56cfb25772a 100644
--- a/writerperfect/source/filter/DocumentElement.hxx
+++ b/writerperfect/source/filter/DocumentElement.hxx
@@ -57,7 +57,7 @@ private:
class TagOpenElement : public TagElement
{
public:
- TagOpenElement(const WPXString &szTagName) : TagElement(szTagName) {}
+ TagOpenElement(const WPXString &szTagName) : TagElement(szTagName), maAttrList() {}
virtual ~TagOpenElement() {}
void addAttribute(const WPXString &szAttributeName, const WPXString &sAttributeValue);
virtual void write(OdfDocumentHandler *pHandler) const;
diff --git a/writerperfect/source/filter/FilterInternal.hxx b/writerperfect/source/filter/FilterInternal.hxx
index 04a0561a25b1..eb8c6e6a879a 100644
--- a/writerperfect/source/filter/FilterInternal.hxx
+++ b/writerperfect/source/filter/FilterInternal.hxx
@@ -30,20 +30,11 @@
#define WRITER_DEBUG_MSG(M)
#endif
#include <libwpd/libwpd.h>
-#include <string.h> // for strcmp
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
-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/filter/FontStyle.cxx b/writerperfect/source/filter/FontStyle.cxx
index e9a5be195d84..a3f0ef7e8fd7 100644
--- a/writerperfect/source/filter/FontStyle.cxx
+++ b/writerperfect/source/filter/FontStyle.cxx
@@ -44,10 +44,50 @@ void FontStyle::write(OdfDocumentHandler *pHandler) const
TagOpenElement styleOpen("style:font-face");
styleOpen.addAttribute("style:name", getName());
styleOpen.addAttribute("svg:font-family", msFontFamily);
-// styleOpen.addAttribute("style:font-pitch", msFontPitch);
styleOpen.write(pHandler);
TagCloseElement styleClose("style:font-face");
styleClose.write(pHandler);
}
+////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////
+void FontStyleManager::clean()
+{
+ for (std::map<WPXString, FontStyle *, ltstr>::iterator iter = mHash.begin();
+ iter != mHash.end(); iter++) {
+ delete(iter->second);
+ }
+ mHash.clear();
+}
+
+void FontStyleManager::writeFontsDeclaration(OdfDocumentHandler *pHandler) const
+{
+ TagOpenElement("office:font-face-decls").write(pHandler);
+ for (std::map<WPXString, FontStyle *, ltstr>::const_iterator iter = mHash.begin();
+ iter != mHash.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, FontStyle *, ltstr>::const_iterator iter = mHash.find(psFontFamily);
+ if (iter!=mHash.end()) return iter->second->getName();
+
+ // ok create a new font
+ mHash[psFontFamily] = new FontStyle(psFontFamily, psFontFamily);
+ return psFontFamily;
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/FontStyle.hxx b/writerperfect/source/filter/FontStyle.hxx
index c146eed9acc2..129846ef9e35 100644
--- a/writerperfect/source/filter/FontStyle.hxx
+++ b/writerperfect/source/filter/FontStyle.hxx
@@ -27,6 +27,8 @@
*/
#ifndef _FONTSTYLE_H
#define _FONTSTYLE_H
+#include <map>
+
#include <libwpd/libwpd.h>
#include "Style.hxx"
@@ -44,6 +46,28 @@ private:
WPXString msFontFamily;
WPXString msFontPitch;
};
+
+class FontStyleManager : public StyleManager
+{
+public:
+ FontStyleManager() : mHash() {}
+ virtual ~FontStyleManager() { 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:
+ std::map<WPXString, FontStyle *, ltstr> mHash;
+};
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/InternalHandler.hxx b/writerperfect/source/filter/InternalHandler.hxx
index dde0c7679991..f2255966f2d2 100644
--- a/writerperfect/source/filter/InternalHandler.hxx
+++ b/writerperfect/source/filter/InternalHandler.hxx
@@ -42,6 +42,8 @@ public:
void endElement(const char *psName);
void characters(const WPXString &sCharacters);
private:
+ InternalHandler(InternalHandler const &orig) : mpElements(0) { *this = orig; }
+ InternalHandler &operator=(InternalHandler const &) { mpElements=0L; return *this; }
std::vector<DocumentElement *> *mpElements;
};
#endif
diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index 56a9c6ba2729..79653fa98c3a 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -25,6 +25,8 @@
* Corel Corporation or Corel Corporation Limited."
*/
+#include "libwriterperfect_filter.hxx"
+
#include "OdgGenerator.hxx"
#include "DocumentElement.hxx"
#include "OdfDocumentHandler.hxx"
@@ -254,13 +256,13 @@ public:
std::vector<DocumentElement *> mPageMasterStyles;
// paragraph styles
- std::map<WPXString, ParagraphStyle *, ltstr> mParagraphStyles;
+ ParagraphStyleManager mParagraphManager;
// span styles
- std::map<WPXString, SpanStyle *, ltstr> mSpanStyles;
+ SpanStyleManager mSpanManager;
// font styles
- std::map<WPXString, FontStyle *, ltstr> mFontStyles;
+ FontStyleManager mFontManager;
OdfDocumentHandler *mpHandler;
@@ -287,10 +289,11 @@ OdgGeneratorPrivate::OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const Odf
mGraphicsAutomaticStyles(),
mPageAutomaticStyles(),
mPageMasterStyles(),
- mParagraphStyles(),
- mSpanStyles(),
- mFontStyles(),
+ mParagraphManager(),
+ mSpanManager(),
+ mFontManager(),
mpHandler(pHandler),
+ mxStyle(), mxGradient(),
miGradientIndex(1),
miDashIndex(1),
miGraphicsStyleIndex(1),
@@ -345,23 +348,9 @@ OdgGeneratorPrivate::~OdgGeneratorPrivate()
delete((*iterPageMasterStyles));
}
- for (std::map<WPXString, ParagraphStyle*, ltstr>::iterator iterParagraphStyles = mParagraphStyles.begin();
- iterParagraphStyles != mParagraphStyles.end(); ++iterParagraphStyles)
- {
- delete(iterParagraphStyles->second);
- }
-
- for (std::map<WPXString, SpanStyle*, ltstr>::iterator iterSpanStyles = mSpanStyles.begin();
- iterSpanStyles != mSpanStyles.end(); ++iterSpanStyles)
- {
- delete(iterSpanStyles->second);
- }
-
- for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontStyles.begin();
- iterFont != mFontStyles.end(); ++iterFont)
- {
- delete(iterFont->second);
- }
+ mParagraphManager.clean();
+ mSpanManager.clean();
+ mFontManager.clean();
}
@@ -456,22 +445,7 @@ OdgGenerator::~OdgGenerator()
if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_CONTENT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML))
{
- TagOpenElement("office:font-face-decls").write(mpImpl->mpHandler);
-
- for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mpImpl->mFontStyles.begin();
- iterFont != mpImpl->mFontStyles.end(); ++iterFont)
- {
- iterFont->second->write(mpImpl->mpHandler);
- }
-
- TagOpenElement symbolFontOpen("style:font-face");
- symbolFontOpen.addAttribute("style:name", "StarSymbol");
- symbolFontOpen.addAttribute("svg:font-family", "StarSymbol");
- symbolFontOpen.addAttribute("style:font-charset", "x-symbol");
- symbolFontOpen.write(mpImpl->mpHandler);
- TagCloseElement("style:font-face").write(mpImpl->mpHandler);
-
- TagCloseElement("office:font-face-decls").write(mpImpl->mpHandler);
+ mpImpl->mFontManager.writeFontsDeclaration(mpImpl->mpHandler);
TagOpenElement("office:automatic-styles").write(mpImpl->mpHandler);
}
@@ -484,16 +458,8 @@ OdgGenerator::~OdgGenerator()
{
(*iterGraphicsAutomaticStyles)->write(mpImpl->mpHandler);
}
- for (std::map<WPXString, ParagraphStyle*, ltstr>::iterator iterParagraphStyles = mpImpl->mParagraphStyles.begin();
- iterParagraphStyles != mpImpl->mParagraphStyles.end(); ++iterParagraphStyles)
- {
- (iterParagraphStyles->second)->write(mpImpl->mpHandler);
- }
- for (std::map<WPXString, SpanStyle*, ltstr>::iterator iterSpanStyles = mpImpl->mSpanStyles.begin();
- iterSpanStyles != mpImpl->mSpanStyles.end(); ++iterSpanStyles)
- {
- (iterSpanStyles->second)->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))
@@ -1369,31 +1335,14 @@ void OdgGenerator::endTextObject()
void OdgGenerator::startTextLine(WPXPropertyList const &propList)
{
- WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
- ParagraphStyle *pStyle = 0;
-
- WPXString sKey = propListToStyleKey(*pPersistPropList);
-
- pPersistPropList->insert("style:parent-style-name", "Standard");
+ WPXPropertyList finalPropList(propList);
+ finalPropList.insert("style:parent-style-name", "Standard");
+ WPXString paragName = mpImpl->mParagraphManager.findOrAdd(finalPropList, WPXPropertyListVector());
- if (mpImpl->mParagraphStyles.find(sKey) == mpImpl->mParagraphStyles.end())
- {
- WPXString sName;
- sName.sprintf("S%i", mpImpl->mParagraphStyles.size());
-
- pStyle = new ParagraphStyle(pPersistPropList, WPXPropertyListVector(), sName);
-
- mpImpl->mParagraphStyles[sKey] = pStyle;
- }
- else
- {
- pStyle = mpImpl->mParagraphStyles[sKey];
- delete pPersistPropList;
- }
// create a document element corresponding to the paragraph, and append it to our list of document elements
TagOpenElement *pParagraphOpenElement = new TagOpenElement("text:p");
- pParagraphOpenElement->addAttribute("text:style-name", pStyle->getName());
+ pParagraphOpenElement->addAttribute("text:style-name", paragName);
mpImpl->mBodyElements.push_back(pParagraphOpenElement);
}
@@ -1405,26 +1354,9 @@ void OdgGenerator::endTextLine()
void OdgGenerator::startTextSpan(WPXPropertyList const&propList)
{
if (propList["style:font-name"])
- {
- WPXString sFontName = propList["style:font-name"]->getStr();
- if (mpImpl->mFontStyles.find(sFontName) == mpImpl->mFontStyles.end())
- mpImpl->mFontStyles[sFontName] = new FontStyle(sFontName.cstr(), sFontName.cstr());
- }
+ mpImpl->mFontManager.findOrAdd(propList["style:font-name"]->getStr().cstr());
- WPXString sName;
- WPXString sSpanHashKey = propListToStyleKey(propList);
- if (mpImpl->mSpanStyles.find(sSpanHashKey) == mpImpl->mSpanStyles.end())
- {
- // allocate a new paragraph style
- sName.sprintf("Span%i", mpImpl->mSpanStyles.size());
- SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList);
-
- mpImpl->mSpanStyles[sSpanHashKey] = pStyle;
- }
- else
- {
- sName.sprintf("%s", mpImpl->mSpanStyles.find(sSpanHashKey)->second->getName().cstr());
- }
+ WPXString sName = mpImpl->mSpanManager.findOrAdd(propList);
TagOpenElement *pSpanOpenElement = new TagOpenElement("text:span");
pSpanOpenElement->addAttribute("text:style-name", sName.cstr());
diff --git a/writerperfect/source/filter/OdgGenerator.hxx b/writerperfect/source/filter/OdgGenerator.hxx
index 55d8eea77d9a..fb3ca5ee2359 100644
--- a/writerperfect/source/filter/OdgGenerator.hxx
+++ b/writerperfect/source/filter/OdgGenerator.hxx
@@ -28,6 +28,7 @@
#include <libwpd/libwpd.h>
#include <libwpg/libwpg.h>
+
#include "OdfDocumentHandler.hxx"
class OdgGeneratorPrivate;
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index 008871a358fa..e681a395ba7c 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -35,6 +35,7 @@
#include <stack>
#include <string>
+#include "libwriterperfect_filter.hxx"
#include "OdtGenerator.hxx"
#include "DocumentElement.hxx"
#include "TextRunStyle.hxx"
@@ -110,14 +111,11 @@ class OdtGeneratorPrivate
public:
OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType);
~OdtGeneratorPrivate();
- void _resetDocumentState();
- bool _parseSourceDocument(WPXInputStream &input, const char *password);
bool _writeTargetDocument(OdfDocumentHandler *pHandler);
void _writeBegin();
void _writeDefaultStyles(OdfDocumentHandler *pHandler);
void _writeMasterPages(OdfDocumentHandler *pHandler);
void _writePageLayouts(OdfDocumentHandler *pHandler);
- void _allocateFontName(const WPXString &);
void _openListLevel(TagOpenElement *pListLevelOpenElement);
void _closeListLevel();
@@ -133,20 +131,16 @@ public:
std::stack<WriterListState> mWriterListStates;
// paragraph styles
- std::map<WPXString, ParagraphStyle *, ltstr> mTextStyleHash;
+ ParagraphStyleManager mParagraphManager;
// span styles
- std::map<WPXString, SpanStyle *, ltstr> mSpanStyleHash;
+ SpanStyleManager mSpanManager;
// font styles
- std::map<WPXString, FontStyle *, ltstr> mFontHash;
-
- // embedded object handlers
- std::map<WPXString, OdfEmbeddedObject, ltstr > mObjectHandlers;
+ FontStyleManager mFontManager;
// section styles
std::vector<SectionStyle *> mSectionStyles;
- double mfSectionSpaceAfter;
// table styles
std::vector<TableStyle *> mTableStyles;
@@ -156,14 +150,15 @@ public:
std::vector<DocumentElement *> mFrameAutomaticStyles;
+ // embedded object handlers
+ std::map<WPXString, OdfEmbeddedObject, ltstr > mObjectHandlers;
+
// metadata
std::vector<DocumentElement *> mMetaData;
// list styles
unsigned int miNumListStyles;
- // style elements
- std::vector<DocumentElement *> mStylesElements;
// content elements
std::vector<DocumentElement *> mBodyElements;
// the current set of elements that we're writing to
@@ -190,20 +185,25 @@ public:
};
OdtGeneratorPrivate::OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType) :
- mpInput(NULL),
+ mpInput(0),
mpHandler(pHandler),
mbUsed(false),
mWriterDocumentStates(),
mWriterListStates(),
- mfSectionSpaceAfter(0.0),
+ mParagraphManager(), mSpanManager(), mFontManager(),
+ mSectionStyles(), mTableStyles(), mFrameStyles(), mFrameAutomaticStyles(),
+ mObjectHandlers(), mMetaData(),
miNumListStyles(0),
+ mBodyElements(),
mpCurrentContentElements(&mBodyElements),
- mpCurrentPageSpan(NULL),
+ mPageSpans(),
+ mpCurrentPageSpan(0),
miNumPageStyles(0),
+ mListStyles(),
miObjectNumber(0),
- mpCurrentTableStyle(NULL),
+ mpCurrentTableStyle(0),
mxStreamType(streamType),
- mpPassword(NULL)
+ mpPassword(0)
{
mWriterDocumentStates.push(WriterDocumentState());
mWriterListStates.push(WriterListState());
@@ -215,61 +215,42 @@ OdtGeneratorPrivate::~OdtGeneratorPrivate()
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) {
+ for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); iterBody++) {
delete (*iterBody);
- (*iterBody) = NULL;
- }
-
- WRITER_DEBUG_MSG(("Destroying the styles elements\n"));
- for (std::vector<DocumentElement *>::iterator iterStyles = mStylesElements.begin(); iterStyles != mStylesElements.end(); ++iterStyles) {
- delete (*iterStyles);
- (*iterStyles) = NULL; // we may pass over the same element again (in the case of headers/footers spanning multiple pages)
- // so make sure we don't do a double del
- }
-
- WRITER_DEBUG_MSG(("Destroying the rest of the styles elements\n"));
- for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin();
- iterTextStyle != mTextStyleHash.end(); ++iterTextStyle) {
- delete (iterTextStyle->second);
+ (*iterBody) = 0;
}
- for (std::map<WPXString, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin();
- iterSpanStyle != mSpanStyleHash.end(); ++iterSpanStyle) {
- delete(iterSpanStyle->second);
- }
-
- for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin();
- iterFont != mFontHash.end(); ++iterFont) {
- delete(iterFont->second);
- }
+ mParagraphManager.clean();
+ mSpanManager.clean();
+ mFontManager.clean();
for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin();
- iterListStyles != mListStyles.end(); ++iterListStyles) {
+ iterListStyles != mListStyles.end(); iterListStyles++) {
delete(*iterListStyles);
}
for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin();
- iterSectionStyles != mSectionStyles.end(); ++iterSectionStyles) {
+ iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) {
delete(*iterSectionStyles);
}
for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin();
- iterTableStyles != mTableStyles.end(); ++iterTableStyles) {
+ iterTableStyles != mTableStyles.end(); iterTableStyles++) {
delete((*iterTableStyles));
}
for (std::vector<PageSpan *>::iterator iterPageSpans = mPageSpans.begin();
- iterPageSpans != mPageSpans.end(); ++iterPageSpans) {
+ iterPageSpans != mPageSpans.end(); iterPageSpans++) {
delete(*iterPageSpans);
}
for (std::vector<DocumentElement *>::iterator iterFrameStyles = mFrameStyles.begin();
- iterFrameStyles != mFrameStyles.end(); ++iterFrameStyles) {
+ iterFrameStyles != mFrameStyles.end(); iterFrameStyles++) {
delete(*iterFrameStyles);
}
for (std::vector<DocumentElement *>::iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin();
- iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); ++iterFrameAutomaticStyles) {
+ iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); iterFrameAutomaticStyles++) {
delete(*iterFrameAutomaticStyles);
}
for (std::vector<DocumentElement *>::iterator iterMetaData = mMetaData.begin();
- iterMetaData != mMetaData.end(); ++iterMetaData) {
+ iterMetaData != mMetaData.end(); iterMetaData++) {
delete(*iterMetaData);
}
}
@@ -411,7 +392,7 @@ bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler)
docContentPropList.insert("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
docContentPropList.insert("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
docContentPropList.insert("xmlns:xlink", "http://www.w3.org/1999/xlink");
- docContentPropList.insert("xmlns:number", "http://openoffice.org/2000/datastyle");
+ docContentPropList.insert("xmlns: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");
@@ -435,21 +416,9 @@ bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler)
}
mpHandler->endElement("office:meta");
- // write out the font styles
- TagOpenElement("office:font-face-decls").write(mpHandler);
- for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); ++iterFont) {
- iterFont->second->write(mpHandler);
- }
- TagOpenElement symbolFontOpen("style:font-face");
- symbolFontOpen.addAttribute("style:name", "StarSymbol");
- symbolFontOpen.addAttribute("svg:font-family", "StarSymbol");
- symbolFontOpen.addAttribute("style:font-charset", "x-symbol");
- symbolFontOpen.write(mpHandler);
- mpHandler->endElement("style:font-face");
-
- mpHandler->endElement("office:font-face-decls");
+ mFontManager.writeFontsDeclaration(mpHandler);
- WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the styles..\n"));
+ WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the styles..\n"));
// write default styles
_writeDefaultStyles(mpHandler);
@@ -462,23 +431,9 @@ bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler)
(*iterFrameAutomaticStyles)->write(pHandler);
}
- for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iterTextStyle = mTextStyleHash.begin();
- iterTextStyle != mTextStyleHash.end(); ++iterTextStyle)
- {
- // writing out the paragraph styles
- if (strcmp((iterTextStyle->second)->getName().cstr(), "Standard"))
- {
- // don't write standard paragraph "no styles" style
- (iterTextStyle->second)->write(pHandler);
- }
- }
-
- // span styles..
- for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iterSpanStyle = mSpanStyleHash.begin();
- iterSpanStyle != mSpanStyleHash.end(); ++iterSpanStyle)
- {
- (iterSpanStyle->second)->write(pHandler);
- }
+ 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) {
@@ -526,16 +481,6 @@ bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler)
}
-// _allocateFontName: add a (potentially mapped) font style to the hash if it's not already there, do nothing otherwise
-void OdtGeneratorPrivate::_allocateFontName(const WPXString & sFontName)
-{
- if (mFontHash.find(sFontName) == mFontHash.end())
- {
- FontStyle *pFontStyle = new FontStyle(sFontName.cstr(), sFontName.cstr());
- mFontHash[sFontName] = pFontStyle;
- }
-}
-
void OdtGenerator::setDocumentMetaData(const WPXPropertyList &propList)
{
WPXPropertyList::Iter i(propList);
@@ -602,18 +547,19 @@ void OdtGenerator::openSection(const WPXPropertyList &propList, const WPXPropert
int iNumColumns = columns.count();
double fSectionMarginLeft = 0.0;
double fSectionMarginRight = 0.0;
+ double fSectionSpaceAfter = 0.0;
if (propList["fo:margin-left"])
fSectionMarginLeft = propList["fo:margin-left"]->getDouble();
if (propList["fo:margin-right"])
fSectionMarginRight = propList["fo:margin-right"]->getDouble();
-
- if (iNumColumns > 1 || fSectionMarginLeft != 0 || fSectionMarginRight != 0)
- {
if (propList["fo:margin-bottom"])
- mpImpl->mfSectionSpaceAfter = propList["fo:margin-bottom"]->getDouble();
+ fSectionSpaceAfter = propList["fo:margin-bottom"]->getDouble();
else if (propList["libwpd:margin-bottom"])
- mpImpl->mfSectionSpaceAfter = propList["libwpd:margin-bottom"]->getDouble();
+ fSectionSpaceAfter = propList["libwpd:margin-bottom"]->getDouble();
+
+ if (iNumColumns > 1 || fSectionMarginLeft != 0 || fSectionMarginRight != 0)
+ {
WPXString sSectionName;
sSectionName.sprintf("Section%i", mpImpl->mSectionStyles.size());
@@ -635,24 +581,6 @@ void OdtGenerator::closeSection()
mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("text:section"));
else
mpImpl->mWriterDocumentStates.top().mbInFakeSection = false;
-
- mpImpl->mfSectionSpaceAfter = 0.0;
-}
-
-static WPXString getParagraphStyleKey(const WPXPropertyList & xPropList, const WPXPropertyListVector & xTabStops)
-{
- WPXString sKey = propListToStyleKey(xPropList);
-
- WPXString sTabStops;
- sTabStops.sprintf("[num-tab-stops:%i]", xTabStops.count());
- WPXPropertyListVector::Iter i(xTabStops);
- for (i.rewind(); i.next();)
- {
- sTabStops.append(propListToStyleKey(i()));
- }
- sKey.append(sTabStops);
-
- return sKey;
}
void OdtGenerator::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)
@@ -660,67 +588,31 @@ void OdtGenerator::openParagraph(const WPXPropertyList &propList, const WPXPrope
// FIXMENOW: What happens if we open a footnote inside a table? do we then inherit the footnote's style
// from "Table Contents"
- WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
- ParagraphStyle *pStyle = NULL;
-
- if (mpImpl->mWriterDocumentStates.top().mbFirstElement && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements))
+ WPXPropertyList finalPropList(propList);
+ if (mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements))
{
- // we don't have to go through the fuss of determining if the paragraph style is
- // unique in this case, because if we are the first document element, then we
- // are singular. Neither do we have to determine what our parent style is-- we can't
- // be inside a table in this case (the table would be the first document element
- //in that case)
- pPersistPropList->insert("style:parent-style-name", "Standard");
- WPXString sName;
- sName.sprintf("FS");
-
- WPXString sParagraphHashKey("P|FS");
- pPersistPropList->insert("style:master-page-name", "Page_Style_1");
- pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName);
- mpImpl->mTextStyleHash[sParagraphHashKey] = pStyle;
+ 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;
- }
- else
- {
- if (mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements))
- {
- WPXString sPageStyleName;
- sPageStyleName.sprintf("Page_Style_%i", mpImpl->miNumPageStyles);
- pPersistPropList->insert("style:master-page-name", sPageStyleName);
- mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false;
- }
+ }
- if (mpImpl->mWriterDocumentStates.top().mbTableCellOpened)
- {
- if (mpImpl->mWriterDocumentStates.top().mbHeaderRow)
- pPersistPropList->insert("style:parent-style-name", "Table_Heading");
- else
- pPersistPropList->insert("style:parent-style-name", "Table_Contents");
- }
+ if (mpImpl->mWriterDocumentStates.top().mbTableCellOpened)
+ {
+ if (mpImpl->mWriterDocumentStates.top().mbHeaderRow)
+ finalPropList.insert("style:parent-style-name", "Table_Heading");
else
- pPersistPropList->insert("style:parent-style-name", "Standard");
-
- WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
-
- if (mpImpl->mTextStyleHash.find(sKey) == mpImpl->mTextStyleHash.end())
- {
- WPXString sName;
- sName.sprintf("S%i", mpImpl->mTextStyleHash.size());
+ finalPropList.insert("style:parent-style-name", "Table_Contents");
+ }
+ else
+ finalPropList.insert("style:parent-style-name", "Standard");
- pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName);
+ WPXString sName = mpImpl->mParagraphManager.findOrAdd(finalPropList, tabStops);
- mpImpl->mTextStyleHash[sKey] = pStyle;
- }
- else
- {
- pStyle = mpImpl->mTextStyleHash[sKey];
- delete pPersistPropList;
- }
- }
// create a document element corresponding to the paragraph, and append it to our list of document elements
TagOpenElement *pParagraphOpenElement = new TagOpenElement("text:p");
- pParagraphOpenElement->addAttribute("text:style-name", pStyle->getName());
+ pParagraphOpenElement->addAttribute("text:style-name", sName);
mpImpl->mpCurrentContentElements->push_back(pParagraphOpenElement);
}
@@ -732,24 +624,10 @@ void OdtGenerator::closeParagraph()
void OdtGenerator::openSpan(const WPXPropertyList &propList)
{
if (propList["style:font-name"])
- mpImpl->_allocateFontName(propList["style:font-name"]->getStr());
- WPXString sSpanHashKey = propListToStyleKey(propList);
- WRITER_DEBUG_MSG(("WriterWordPerfect: Span Hash Key: %s\n", sSpanHashKey.cstr()));
+ mpImpl->mFontManager.findOrAdd(propList["style:font-name"]->getStr().cstr());
// Get the style
- WPXString sName;
- if (mpImpl->mSpanStyleHash.find(sSpanHashKey) == mpImpl->mSpanStyleHash.end())
- {
- // allocate a new paragraph style
- sName.sprintf("Span%i", mpImpl->mSpanStyleHash.size());
- SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList);
-
- mpImpl->mSpanStyleHash[sSpanHashKey] = pStyle;
- }
- else
- {
- sName.sprintf("%s", mpImpl->mSpanStyleHash.find(sSpanHashKey)->second->getName().cstr());
- }
+ 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");
@@ -778,7 +656,7 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
// is starting a new list at level 1 (and only level 1)
if (pOrderedListStyle == NULL || pOrderedListStyle->getListID() != id ||
(propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 &&
- (propList["text:start-value"] && static_cast<unsigned>(propList["text:start-value"]->getInt()) != (mpImpl->mWriterListStates.top().miLastListNumber+1))))
+ (propList["text:start-value"] && static_cast<unsigned>(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;
@@ -914,36 +792,21 @@ void OdtGenerator::openListElement(const WPXPropertyList &propList, const WPXPro
mpImpl->mWriterListStates.top().mbListElementOpened.top() = false;
}
- ParagraphStyle *pStyle = NULL;
-
- WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
- pPersistPropList->insert("style:list-style-name", mpImpl->mWriterListStates.top().mpCurrentListStyle->getName());
- pPersistPropList->insert("style:parent-style-name", "Standard");
-
- WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
-
- if (mpImpl->mTextStyleHash.find(sKey) == mpImpl->mTextStyleHash.end())
- {
- WPXString sName;
- sName.sprintf("S%i", mpImpl->mTextStyleHash.size());
-
- pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName);
-
- mpImpl->mTextStyleHash[sKey] = pStyle;
- }
- else
- {
- pStyle = mpImpl->mTextStyleHash[sKey];
- delete pPersistPropList;
- }
+ WPXPropertyList finalPropList(propList);
+#if 0
+ // this property is ignored in TextRunStyle.c++
+ 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);
mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:list-item"));
- TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p");
- pOpenListElementParagraph->addAttribute("text:style-name", pStyle->getName());
+ TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p");
+ pOpenListElementParagraph->addAttribute("text:style-name", paragName);
mpImpl->mpCurrentContentElements->push_back(pOpenListElementParagraph);
- if (mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements))
+ if (mpImpl->mpCurrentContentElements == &(mpImpl->mBodyElements))
mpImpl->mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false;
mpImpl->mWriterListStates.top().mbListElementOpened.top() = true;
diff --git a/writerperfect/source/filter/Style.hxx b/writerperfect/source/filter/Style.hxx
index 4d4177667944..83fb2b510d9d 100644
--- a/writerperfect/source/filter/Style.hxx
+++ b/writerperfect/source/filter/Style.hxx
@@ -30,6 +30,7 @@
#define _STYLE_H
#include <cstdlib>
#include <libwpd/libwpd.h>
+#include "libwriterperfect_filter.hxx"
#include "DocumentElement.hxx"
class TopLevelElementStyle
@@ -41,21 +42,38 @@ public:
const WPXString * getMasterPageName() const { return mpsMasterPageName; }
private:
+ TopLevelElementStyle(TopLevelElementStyle const &orig) : mpsMasterPageName(0) { *this = orig; }
+ TopLevelElementStyle &operator=(TopLevelElementStyle const &) { mpsMasterPageName=0L; return *this; }
WPXString *mpsMasterPageName;
};
class Style
{
- public:
+public:
Style(const WPXString &psName) : msName(psName) {}
virtual ~Style() {}
virtual void write(OdfDocumentHandler *) const {};
const WPXString &getName() const { return msName; }
- private:
+private:
WPXString msName;
};
+
+class StyleManager
+{
+public:
+ StyleManager() {}
+ virtual ~StyleManager() {}
+
+ virtual void clean() {};
+ virtual void write(OdfDocumentHandler *) const = 0;
+
+private:
+ // forbide copy constructor/operator
+ StyleManager(StyleManager const &orig);
+ StyleManager &operator=(StyleManager const &);
+};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/TextRunStyle.cxx b/writerperfect/source/filter/TextRunStyle.cxx
index c4f9d2558314..6a1eec6de751 100644
--- a/writerperfect/source/filter/TextRunStyle.cxx
+++ b/writerperfect/source/filter/TextRunStyle.cxx
@@ -39,7 +39,7 @@
#include <string.h>
-ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
+ParagraphStyle::ParagraphStyle(WPXPropertyList const &pPropList, const WPXPropertyListVector &xTabStops, const WPXString &sName) :
mpPropList(pPropList),
mxTabStops(xTabStops),
msName(sName)
@@ -48,7 +48,6 @@ ParagraphStyle::ParagraphStyle(WPXPropertyList *pPropList, const WPXPropertyList
ParagraphStyle::~ParagraphStyle()
{
- delete mpPropList;
}
void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
@@ -58,14 +57,14 @@ void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
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());
+ 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));
+ WPXPropertyList::Iter i(mpPropList);
for (i.rewind(); i.next(); )
{
#if 0
@@ -180,19 +179,91 @@ void SpanStyle::write(OdfDocumentHandler *pHandler) const
pHandler->endElement("style:style");
}
-WPXString propListToStyleKey(const WPXPropertyList & xPropList)
+////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////
+void ParagraphStyleManager::clean()
{
- 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;
+ for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iter = mHash.begin();
+ iter != mHash.end(); iter++) {
+ delete(iter->second);
+ }
+ mHash.clear();
}
+void ParagraphStyleManager::write(OdfDocumentHandler *pHandler) const
+{
+ for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iter = mHash.begin();
+ iter != mHash.end(); iter++)
+ {
+ if (strcmp(iter->second->getName().cstr(), "Standard") == 0)
+ continue;
+ (iter->second)->write(pHandler);
+ }
+}
+
+WPXString ParagraphStyleManager::getKey(WPXPropertyList const &xPropList, WPXPropertyListVector const &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 (WPXPropertyList const &propList, WPXPropertyListVector const &tabStops)
+{
+ WPXString hashKey = getKey(propList, tabStops);
+ std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iter = mHash.find(hashKey);
+ if (iter!=mHash.end())
+ return iter->second->getName();
+
+ // ok create a new list
+ WRITER_DEBUG_MSG(("ParagraphStyleManager::findOrAdd: Paragraph Hash Key: %s\n", hasKey.cstr()));
+
+ WPXString sName;
+ sName.sprintf("S%i", mHash.size());
+ ParagraphStyle *pStyle = new ParagraphStyle(propList, tabStops, sName);
+ mHash[hashKey] = pStyle;
+ return sName;
+}
+
+////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////
+void SpanStyleManager::clean()
+{
+ for (std::map<WPXString, SpanStyle *, ltstr>::iterator iter = mHash.begin();
+ iter != mHash.end(); iter++)
+ delete(iter->second);
+ mHash.clear();
+}
+
+void SpanStyleManager::write(OdfDocumentHandler *pHandler) const
+{
+ for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iter = mHash.begin();
+ iter != mHash.end(); iter++)
+ iter->second->write(pHandler);
+}
+
+WPXString SpanStyleManager::findOrAdd(WPXPropertyList const &propList)
+{
+ WPXString hashKey = propListToStyleKey(propList);
+ std::map<WPXString, SpanStyle *, ltstr>::const_iterator iter = mHash.find(hashKey);
+ if (iter!=mHash.end())
+ return iter->second->getName();
+
+ // ok create a new list
+ WRITER_DEBUG_MSG(("SpanStyleManager::findOrAdd: Span Hash Key: %s\n", hasKey.cstr()));
+
+ WPXString sName;
+ sName.sprintf("Span%i", mHash.size());
+ SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList);
+ mHash[hashKey] = pStyle;
+ return sName;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/TextRunStyle.hxx b/writerperfect/source/filter/TextRunStyle.hxx
index 88f47cc756ac..5bd1381ac375 100644
--- a/writerperfect/source/filter/TextRunStyle.hxx
+++ b/writerperfect/source/filter/TextRunStyle.hxx
@@ -30,6 +30,9 @@
#ifndef _TEXTRUNSTYLE_H
#define _TEXTRUNSTYLE_H
+
+#include <map>
+
#include <libwpd/libwpd.h>
#include "Style.hxx"
@@ -41,12 +44,12 @@ class OdfDocumentHandler;
class ParagraphStyle
{
public:
- ParagraphStyle(WPXPropertyList *propList, const WPXPropertyListVector &tabStops, const WPXString &sName);
+ 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;
+ WPXPropertyList mpPropList;
WPXPropertyListVector mxTabStops;
WPXString msName;
};
@@ -62,8 +65,48 @@ private:
WPXPropertyList mPropList;
};
-WPXString propListToStyleKey(const WPXPropertyList & xPropList);
+class ParagraphStyleManager : public StyleManager
+{
+public:
+ ParagraphStyleManager() : mHash() {}
+ virtual ~ParagraphStyleManager() { 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(WPXPropertyList const &xPropList, WPXPropertyListVector const &tabStops);
+
+ virtual void clean();
+ virtual void write(OdfDocumentHandler *) const;
+
+
+protected:
+ // return a unique key
+ WPXString getKey(WPXPropertyList const &xPropList, WPXPropertyListVector const &tabStops) const;
+
+ // paragraph styles
+ std::map<WPXString, ParagraphStyle *, ltstr> mHash;
+};
+
+class SpanStyleManager : public StyleManager
+{
+public:
+ SpanStyleManager() : mHash() {}
+ virtual ~SpanStyleManager() { 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(WPXPropertyList const &xPropList);
+
+
+ virtual void clean();
+ virtual void write(OdfDocumentHandler *) const;
+
+protected:
+ // span styles
+ std::map<WPXString, SpanStyle *, ltstr> mHash;
+};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/libwriterperfect_filter.cxx b/writerperfect/source/filter/libwriterperfect_filter.cxx
new file mode 100644
index 000000000000..684c034ce416
--- /dev/null
+++ b/writerperfect/source/filter/libwriterperfect_filter.cxx
@@ -0,0 +1,47 @@
+/* libwriterperfect_filter.hxx: define basic functions for libwriterperfect/fileter
+ *
+ * Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com)
+ * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
+ * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information visit http://libwpd.sourceforge.net
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include <libwpd/WPXPropertyList.h>
+
+#include "libwriterperfect_filter.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;
+}
+
+
diff --git a/writerperfect/source/filter/libwriterperfect_filter.hxx b/writerperfect/source/filter/libwriterperfect_filter.hxx
new file mode 100644
index 000000000000..b908da300864
--- /dev/null
+++ b/writerperfect/source/filter/libwriterperfect_filter.hxx
@@ -0,0 +1,48 @@
+/* libwriterperfect_filter.hxx: define basic functions for libwriterperfect/fileter
+ *
+ * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com)
+ * Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information visit http://libwpd.sourceforge.net
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef _LIBWRITERPERFECT_FILTER_H
+#define _LIBWRITERPERFECT_FILTER_H
+#include <string.h> // for strcmp
+
+#include <libwpd/libwpd.h>
+#include <libwpd/WPXString.h>
+
+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