writerperfect/StaticLibrary_writerperfect.mk | 2 writerperfect/source/filter/FilterInternal.cxx | 45 +++++++++ writerperfect/source/filter/FilterInternal.hxx | 44 ++++++++- writerperfect/source/filter/FontStyle.cxx | 24 ++--- writerperfect/source/filter/FontStyle.hxx | 8 + writerperfect/source/filter/ListStyle.hxx | 1 writerperfect/source/filter/OdgGenerator.cxx | 17 +-- writerperfect/source/filter/OdtGenerator.cxx | 71 ++++++-------- writerperfect/source/filter/SectionStyle.hxx | 1 writerperfect/source/filter/Style.hxx | 2 writerperfect/source/filter/TableStyle.hxx | 1 writerperfect/source/filter/TextRunStyle.cxx | 76 ++++++++-------- writerperfect/source/filter/TextRunStyle.hxx | 27 ++++- writerperfect/source/filter/libwriterperfect_filter.cxx | 48 ---------- writerperfect/source/filter/libwriterperfect_filter.hxx | 48 ---------- 15 files changed, 204 insertions(+), 211 deletions(-)
New commits: commit 68c6af8de59a265f695793a5820579a18e4255f7 Author: Fridrich Å trba <fridrich.st...@bluewin.ch> Date: Fri Oct 28 14:49:57 2011 +0200 Fix a memory leak with opacity gradients diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx index 6b08af8..f4d68dc 100644 --- a/writerperfect/source/filter/OdgGenerator.cxx +++ b/writerperfect/source/filter/OdgGenerator.cxx @@ -1033,7 +1033,6 @@ void OdgGeneratorPrivate::_writeGraphicsStyle() if(mxStyle["draw:fill"] && mxStyle["draw:fill"]->getStr() == "gradient") { - bUseOpacityGradient = true; TagOpenElement *pDrawGradientElement = new TagOpenElement("draw:gradient"); TagOpenElement *pDrawOpacityElement = new TagOpenElement("draw:opacity"); if (mxStyle["draw:style"]) @@ -1127,14 +1126,10 @@ void OdgGeneratorPrivate::_writeGraphicsStyle() // 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)) - { - delete pDrawOpacityElement; - bUseOpacityGradient = false; - } - else + 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")); } @@ -1162,6 +1157,9 @@ void OdgGeneratorPrivate::_writeGraphicsStyle() mGraphicsGradientStyles.push_back(pDrawGradientElement); mGraphicsGradientStyles.push_back(new TagCloseElement("draw:gradient")); } + + if(!bUseOpacityGradient) + delete pDrawOpacityElement; } TagOpenElement *pStyleStyleElement = new TagOpenElement("style:style"); commit 0faf9527701238d5de50b1a373dbc1de4b5808f3 Author: Fridrich Å trba <fridrich.st...@bluewin.ch> Date: Fri Oct 28 13:33:06 2011 +0200 Adapt the build bits diff --git a/writerperfect/StaticLibrary_writerperfect.mk b/writerperfect/StaticLibrary_writerperfect.mk index 2569cba..3c969a0 100644 --- a/writerperfect/StaticLibrary_writerperfect.mk +++ b/writerperfect/StaticLibrary_writerperfect.mk @@ -46,6 +46,7 @@ $(eval $(call gb_StaticLibrary_add_api,writerperfect,\ $(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect,\ writerperfect/source/filter/DocumentElement \ writerperfect/source/filter/DocumentHandler \ + writerperfect/source/filter/FilterInternal \ writerperfect/source/filter/FontStyle \ writerperfect/source/filter/InternalHandler \ writerperfect/source/filter/ListStyle \ @@ -55,7 +56,6 @@ $(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 \ )) commit 50398808552c3c79c7c4a32e6c3e1ab96ec7d425 Author: Laurent Alonso <alo...@loria.fr> Date: Fri Oct 28 13:15:55 2011 +0200 Use shared_ptr to avoid leaks diff --git a/writerperfect/source/filter/FilterInternal.cxx b/writerperfect/source/filter/FilterInternal.cxx new file mode 100644 index 0000000..898b9ce --- /dev/null +++ b/writerperfect/source/filter/FilterInternal.cxx @@ -0,0 +1,45 @@ +/* FilterInternal.hxx: define basic functions for libwriterperfect/fileter + * + * Copyright (C) 2002-2004 William Lachance (wrl...@gmail.com) + * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com) + * Copyright (C) 2004 Fridrich Strba (fridrich.st...@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 "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; +} \ No newline at end of file diff --git a/writerperfect/source/filter/FilterInternal.hxx b/writerperfect/source/filter/FilterInternal.hxx index eb8c6e6..880ad28 100644 --- a/writerperfect/source/filter/FilterInternal.hxx +++ b/writerperfect/source/filter/FilterInternal.hxx @@ -23,17 +23,53 @@ #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 -#include <libwpd/libwpd.h> -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 +#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 diff --git a/writerperfect/source/filter/FontStyle.cxx b/writerperfect/source/filter/FontStyle.cxx index de1bd2e..b2d0080 100644 --- a/writerperfect/source/filter/FontStyle.cxx +++ b/writerperfect/source/filter/FontStyle.cxx @@ -25,8 +25,11 @@ /* "This product is not manufactured, approved, or supported by * Corel Corporation or Corel Corporation Limited." */ + +#include "FilterInternal.hxx" + #include "FontStyle.hxx" -#include "WriterProperties.hxx" + #include "DocumentElement.hxx" FontStyle::FontStyle(const char *psName, const char *psFontFamily) : Style(psName), @@ -51,19 +54,14 @@ void FontStyle::write(OdfDocumentHandler *pHandler) const void FontStyleManager::clean() { - for (std::map<WPXString, FontStyle *, ltstr>::iterator iter = mHash.begin(); - iter != mHash.end(); ++iter) - { - delete(iter->second); - } - mHash.clear(); + mStyleHash.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) + std::map<WPXString, shared_ptr<FontStyle>, ltstr>::const_iterator iter; + for (iter = mStyleHash.begin(); iter != mStyleHash.end(); iter++) { (iter->second)->write(pHandler); } @@ -80,11 +78,13 @@ void FontStyleManager::writeFontsDeclaration(OdfDocumentHandler *pHandler) const 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(); + std::map<WPXString, shared_ptr<FontStyle>, ltstr>::const_iterator iter = + mStyleHash.find(psFontFamily); + if (iter!=mStyleHash.end()) return psFontFamily; // ok create a new font - mHash[psFontFamily] = new FontStyle(psFontFamily, psFontFamily); + shared_ptr<FontStyle> font(new FontStyle(psFontFamily, psFontFamily)); + mStyleHash[psFontFamily] = font; return psFontFamily; } diff --git a/writerperfect/source/filter/FontStyle.hxx b/writerperfect/source/filter/FontStyle.hxx index f58bdf6..82efa74 100644 --- a/writerperfect/source/filter/FontStyle.hxx +++ b/writerperfect/source/filter/FontStyle.hxx @@ -31,8 +31,9 @@ #include <libwpd/libwpd.h> +#include "FilterInternal.hxx" + #include "Style.hxx" -#include "WriterProperties.hxx" class FontStyle : public Style { @@ -53,7 +54,7 @@ private: class FontStyleManager : public StyleManager { public: - FontStyleManager() : mHash() {} + FontStyleManager() : mStyleHash() {} virtual ~FontStyleManager() { FontStyleManager::clean(); @@ -71,7 +72,8 @@ public: protected: - std::map<WPXString, FontStyle *, ltstr> mHash; + // style name -> SpanStyle + std::map<WPXString, shared_ptr<FontStyle>, ltstr> mStyleHash; }; #endif diff --git a/writerperfect/source/filter/ListStyle.hxx b/writerperfect/source/filter/ListStyle.hxx index 68d314f..759057d 100644 --- a/writerperfect/source/filter/ListStyle.hxx +++ b/writerperfect/source/filter/ListStyle.hxx @@ -32,7 +32,6 @@ #define WP6_NUM_LIST_LEVELS 8 // see WP6FileStructure.h (we shouldn't need to reference this) #include "Style.hxx" -#include "WriterProperties.hxx" class DocumentElement; diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx index 2ead68d..6b08af8 100644 --- a/writerperfect/source/filter/OdgGenerator.cxx +++ b/writerperfect/source/filter/OdgGenerator.cxx @@ -25,12 +25,11 @@ * Corel Corporation or Corel Corporation Limited." */ -#include "libwriterperfect_filter.hxx" +#include "FilterInternal.hxx" #include "OdgGenerator.hxx" #include "DocumentElement.hxx" #include "OdfDocumentHandler.hxx" -#include "FilterInternal.hxx" #include "TextRunStyle.hxx" #include "FontStyle.hxx" #include <locale.h> diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx index 9533803..7c1e19e 100644 --- a/writerperfect/source/filter/OdtGenerator.cxx +++ b/writerperfect/source/filter/OdtGenerator.cxx @@ -35,7 +35,6 @@ #include <stack> #include <string> -#include "libwriterperfect_filter.hxx" #include "OdtGenerator.hxx" #include "DocumentElement.hxx" #include "TextRunStyle.hxx" @@ -45,7 +44,6 @@ #include "SectionStyle.hxx" #include "TableStyle.hxx" #include "FilterInternal.hxx" -#include "WriterProperties.hxx" #include "InternalHandler.hxx" // the state we use for writing the final document @@ -122,7 +120,6 @@ public: OdfEmbeddedObject _findEmbeddedObjectHandler(const WPXString &mimeType); - WPXInputStream *mpInput; OdfDocumentHandler *mpHandler; bool mbUsed; // whether or not it has been before (you can only use me once!) @@ -185,7 +182,6 @@ public: }; OdtGeneratorPrivate::OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType) : - mpInput(0), mpHandler(pHandler), mbUsed(false), mWriterDocumentStates(), @@ -966,28 +962,27 @@ void OdtGenerator::openTable(const WPXPropertyList &propList, const WPXPropertyL 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 (!mpImpl->mWriterDocumentStates.top().mbInNote) + if (propList["libwpd:is-header-row"] && (propList["libwpd:is-header-row"]->getInt())) { - 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; - } + 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); + 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); - } + TagOpenElement *pTableRowOpenElement = new TagOpenElement("table:table-row"); + pTableRowOpenElement->addAttribute("table:style-name", sTableRowStyleName); + mpImpl->mpCurrentContentElements->push_back(pTableRowOpenElement); } void OdtGenerator::closeTableRow() @@ -1005,31 +1000,31 @@ void OdtGenerator::closeTableRow() 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; } - if (!mpImpl->mWriterDocumentStates.top().mbInNote) - { - WPXString sTableCellStyleName; - sTableCellStyleName.sprintf( "%s.Cell%i", mpImpl->mpCurrentTableStyle->getName().cstr(), mpImpl->mpCurrentTableStyle->getNumTableCellStyles()); - TableCellStyle *pTableCellStyle = new TableCellStyle(propList, sTableCellStyleName.cstr()); - mpImpl->mpCurrentTableStyle->addTableCellStyle(pTableCellStyle); - - TagOpenElement *pTableCellOpenElement = new TagOpenElement("table:table-cell"); - pTableCellOpenElement->addAttribute("table:style-name", sTableCellStyleName); - if (propList["table:number-columns-spanned"]) - pTableCellOpenElement->addAttribute("table:number-columns-spanned", - propList["table:number-columns-spanned"]->getStr().cstr()); - if (propList["table:number-rows-spanned"]) - pTableCellOpenElement->addAttribute("table:number-rows-spanned", - propList["table:number-rows-spanned"]->getStr().cstr()); - // pTableCellOpenElement->addAttribute("table:value-type", "string"); - mpImpl->mpCurrentContentElements->push_back(pTableCellOpenElement); - - mpImpl->mWriterDocumentStates.top().mbTableCellOpened = true; - } + + 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() diff --git a/writerperfect/source/filter/SectionStyle.hxx b/writerperfect/source/filter/SectionStyle.hxx index df9a576..2efaef1 100644 --- a/writerperfect/source/filter/SectionStyle.hxx +++ b/writerperfect/source/filter/SectionStyle.hxx @@ -31,7 +31,6 @@ #include <libwpd/WPXPropertyListVector.h> #include "Style.hxx" -#include "WriterProperties.hxx" class SectionStyle : public Style diff --git a/writerperfect/source/filter/Style.hxx b/writerperfect/source/filter/Style.hxx index 2dd41a4..0957e84 100644 --- a/writerperfect/source/filter/Style.hxx +++ b/writerperfect/source/filter/Style.hxx @@ -29,7 +29,7 @@ #ifndef _STYLE_H #define _STYLE_H #include <libwpd/libwpd.h> -#include "libwriterperfect_filter.hxx" + #include "DocumentElement.hxx" class TopLevelElementStyle diff --git a/writerperfect/source/filter/TableStyle.hxx b/writerperfect/source/filter/TableStyle.hxx index dd20f93..5e81601 100644 --- a/writerperfect/source/filter/TableStyle.hxx +++ b/writerperfect/source/filter/TableStyle.hxx @@ -32,7 +32,6 @@ #include <vector> #include "Style.hxx" -#include "WriterProperties.hxx" class DocumentElement; class OdfDocumentHandler; diff --git a/writerperfect/source/filter/TextRunStyle.cxx b/writerperfect/source/filter/TextRunStyle.cxx index e3ef8bb..092d3a2 100644 --- a/writerperfect/source/filter/TextRunStyle.cxx +++ b/writerperfect/source/filter/TextRunStyle.cxx @@ -1,4 +1,3 @@ -/* -*- 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. @@ -30,7 +29,6 @@ */ #include "FilterInternal.hxx" #include "TextRunStyle.hxx" -#include "WriterProperties.hxx" #include "DocumentElement.hxx" #ifdef _MSC_VER @@ -181,18 +179,14 @@ void SpanStyle::write(OdfDocumentHandler *pHandler) const void ParagraphStyleManager::clean() { - for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iter = mHash.begin(); - iter != mHash.end(); ++iter) - { - delete(iter->second); - } - mHash.clear(); + mNameHash.clear(); + mStyleHash.clear(); } void ParagraphStyleManager::write(OdfDocumentHandler *pHandler) const { - for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iter = mHash.begin(); - iter != mHash.end(); ++iter) + 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; @@ -200,7 +194,7 @@ void ParagraphStyleManager::write(OdfDocumentHandler *pHandler) const } } -WPXString ParagraphStyleManager::getKey(WPXPropertyList const &xPropList, WPXPropertyListVector const &tabStops) const +WPXString ParagraphStyleManager::getKey(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops) const { WPXString sKey = propListToStyleKey(xPropList); @@ -216,58 +210,70 @@ WPXString ParagraphStyleManager::getKey(WPXPropertyList const &xPropList, WPXPro return sKey; } -WPXString ParagraphStyleManager::findOrAdd(WPXPropertyList const &propList, WPXPropertyListVector const &tabStops) +WPXString ParagraphStyleManager::findOrAdd(const WPXPropertyList &propList, const WPXPropertyListVector &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(); + 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", mHash.size()); - ParagraphStyle *pStyle = - new ParagraphStyle(propList, tabStops, sName); - mHash[hashKey] = pStyle; + 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() { - for (std::map<WPXString, SpanStyle *, ltstr>::iterator iter = mHash.begin(); - iter != mHash.end(); ++iter) - { - delete(iter->second); - } - mHash.clear(); + mNameHash.clear(); + mStyleHash.clear(); } void SpanStyleManager::write(OdfDocumentHandler *pHandler) const { - for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iter = mHash.begin(); - iter != mHash.end(); ++iter) + for (std::map<WPXString, shared_ptr<SpanStyle>, ltstr>::const_iterator iter = mStyleHash.begin(); + iter != mStyleHash.end(); iter++) { (iter->second)->write(pHandler); } } -WPXString SpanStyleManager::findOrAdd(WPXPropertyList const &propList) +WPXString SpanStyleManager::findOrAdd(const WPXPropertyList &propList) { WPXString hashKey = propListToStyleKey(propList); - std::map<WPXString, SpanStyle *, ltstr>::const_iterator iter = mHash.find(hashKey); - if (iter!=mHash.end()) - return iter->second->getName(); + 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", mHash.size()); - SpanStyle *pStyle = new SpanStyle(sName.cstr(), propList); - mHash[hashKey] = pStyle; + sName.sprintf("Span%i", mStyleHash.size()); + shared_ptr<SpanStyle> span(new SpanStyle(sName.cstr(), propList)); + mStyleHash[sName] = span; + mNameHash[hashKey] = sName; return sName; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +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; +} + diff --git a/writerperfect/source/filter/TextRunStyle.hxx b/writerperfect/source/filter/TextRunStyle.hxx index 0ae670d..98fc6b4 100644 --- a/writerperfect/source/filter/TextRunStyle.hxx +++ b/writerperfect/source/filter/TextRunStyle.hxx @@ -35,6 +35,8 @@ #include <libwpd/libwpd.h> +#include "FilterInternal.hxx" + #include "Style.hxx" class TagOpenElement; @@ -71,7 +73,7 @@ private: class ParagraphStyleManager : public StyleManager { public: - ParagraphStyleManager() : mHash() {} + ParagraphStyleManager() : mNameHash(), mStyleHash() {} virtual ~ParagraphStyleManager() { ParagraphStyleManager::clean(); @@ -82,22 +84,27 @@ public: 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(WPXPropertyList const &xPropList, WPXPropertyListVector const &tabStops) const; + WPXString getKey(const WPXPropertyList &xPropList, const WPXPropertyListVector &tabStops) const; - // paragraph styles - std::map<WPXString, ParagraphStyle *, ltstr> mHash; + // 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() : mHash() {} + SpanStyleManager() : mNameHash(), mStyleHash() {} virtual ~SpanStyleManager() { SpanStyleManager::clean(); @@ -106,15 +113,19 @@ public: /* 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); + 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: - // span styles - std::map<WPXString, SpanStyle *, ltstr> mHash; + // hash key -> style name + std::map<WPXString, WPXString, ltstr> mNameHash; + // style name -> SpanStyle + std::map<WPXString, shared_ptr<SpanStyle>, ltstr> mStyleHash; }; #endif diff --git a/writerperfect/source/filter/libwriterperfect_filter.cxx b/writerperfect/source/filter/libwriterperfect_filter.cxx deleted file mode 100644 index db976ef..0000000 --- a/writerperfect/source/filter/libwriterperfect_filter.cxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* libwriterperfect_filter.hxx: define basic functions for libwriterperfect/fileter - * - * Copyright (C) 2002-2004 William Lachance (wrl...@gmail.com) - * Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com) - * Copyright (C) 2004 Fridrich Strba (fridrich.st...@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; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/filter/libwriterperfect_filter.hxx b/writerperfect/source/filter/libwriterperfect_filter.hxx deleted file mode 100644 index f99026c..0000000 --- a/writerperfect/source/filter/libwriterperfect_filter.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* libwriterperfect_filter.hxx: define basic functions for libwriterperfect/fileter - * - * Copyright (C) 2002-2003 William Lachance (wrl...@gmail.com) - * Copyright (C) 2004 Fridrich Strba (fridrich.st...@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> - -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: */
_______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits