[Libreoffice-commits] .: writerperfect/source

Fridrich Strba fridrich at kemper.freedesktop.org
Sat Sep 3 09:47:42 PDT 2011


 writerperfect/source/filter/FilterInternal.hxx |   40 +++++++++++
 writerperfect/source/filter/OdgGenerator.cxx   |   90 +++++++++++++++++++++++--
 writerperfect/source/filter/OdtGenerator.cxx   |   39 ----------
 writerperfect/source/filter/TextRunStyle.cxx   |    3 
 4 files changed, 127 insertions(+), 45 deletions(-)

New commits:
commit 1a4467ea3aee785243cca5270952103a5f55bf7c
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Sat Sep 3 18:46:26 2011 +0200

    try to use text properties

diff --git a/writerperfect/source/filter/FilterInternal.hxx b/writerperfect/source/filter/FilterInternal.hxx
index 1b80633..7bb7edb 100644
--- a/writerperfect/source/filter/FilterInternal.hxx
+++ b/writerperfect/source/filter/FilterInternal.hxx
@@ -28,9 +28,49 @@
 #else
 #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;
+   }
+};
+
+static 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;
+}
+
+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;
+}
+
 #endif
diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index a002ea6..bbd435c 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -27,9 +27,12 @@
 #include "OdgGenerator.hxx"
 #include "DocumentElement.hxx"
 #include "OdfDocumentHandler.hxx"
+#include "FilterInternal.hxx"
+#include "TextRunStyle.hxx"
 #include <locale.h>
 #include <math.h>
 #include <string>
+#include <map>
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
@@ -248,6 +251,12 @@ public:
     std::vector<DocumentElement *> mPageAutomaticStyles;
     std::vector<DocumentElement *> mPageMasterStyles;
 
+   // paragraph styles
+   std::map<WPXString, ParagraphStyle *, ltstr> mParagraphStyles;
+
+   // span styles
+   std::map<WPXString, SpanStyle *, ltstr> mSpanStyles;
+
     OdfDocumentHandler *mpHandler;
 
     ::WPXPropertyList mxStyle;
@@ -267,6 +276,14 @@ public:
 };
 
 OdgGeneratorPrivate::OdgGeneratorPrivate(OdfDocumentHandler *pHandler, const OdfStreamType streamType):
+   mBodyElements(),
+   mGraphicsStrokeDashStyles(),
+   mGraphicsGradientStyles(),
+   mGraphicsAutomaticStyles(),
+   mPageAutomaticStyles(),
+   mPageMasterStyles(),
+   mParagraphStyles(),
+   mSpanStyles(),
     mpHandler(pHandler),
     miGradientIndex(1),
     miDashIndex(1),
@@ -321,8 +338,21 @@ 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);
+   }
 }
 
+
 OdgGenerator::OdgGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType):
     mpImpl(new OdgGeneratorPrivate(pHandler, streamType))
 {
@@ -425,6 +455,16 @@ 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);
+      }
     }
 #ifdef MULTIPAGE_WORKAROUND
     if ((mpImpl->mxStreamType == ODF_FLAT_XML) || (mpImpl->mxStreamType == ODF_STYLES_XML))
@@ -1261,9 +1301,32 @@ void OdgGenerator::endTextObject()
     }
 }
 
-void OdgGenerator::startTextLine(WPXPropertyList const&)
+void OdgGenerator::startTextLine(WPXPropertyList const &propList)
 {
-    mpImpl->mBodyElements.push_back(new TagOpenElement("text:p"));
+   WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
+   ParagraphStyle *pStyle = 0;
+
+   WPXString sKey = propListToStyleKey(*pPersistPropList);
+
+   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());
+   mpImpl->mBodyElements.push_back(pParagraphOpenElement);
 }
 
 void OdgGenerator::endTextLine()
@@ -1271,14 +1334,31 @@ void OdgGenerator::endTextLine()
     mpImpl->mBodyElements.push_back(new TagCloseElement("text:p"));
 }
 
-void OdgGenerator::startTextSpan(WPXPropertyList const&)
+void OdgGenerator::startTextSpan(WPXPropertyList const&propList)
 {
-//    mpImpl->mBodyElements.push_back(new TagOpenElement("text:s"));
+   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());
+   }
+
+   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:s"));
+   mpImpl->mBodyElements.push_back(new TagCloseElement("text:span"));
 }
 
 void OdgGenerator::insertText(WPXString const &text)
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index 1ef6371..ba6d02f 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -32,7 +32,6 @@
 #include <vector>
 #include <map>
 #include <stack>
-#include <string.h> // for strcmp
 #include <string>
 
 #include "OdtGenerator.hxx"
@@ -81,14 +80,6 @@ struct _WriterListState
 
 enum WriterListType { unordered, ordered };
 
-struct ltstr
-{
-    bool operator()(const WPXString & s1, const WPXString & s2) const
-    {
-        return strcmp(s1.cstr(), s2.cstr()) < 0;
-    }
-};
-
 _WriterDocumentState::_WriterDocumentState() :
     mbFirstElement(true),
         mbFirstParagraphInPageSpan(true),
@@ -534,36 +525,6 @@ bool OdtGeneratorPrivate::_writeTargetDocument(OdfDocumentHandler *pHandler)
 }
 
 
-WPXString propListToStyleKey(const WPXPropertyList & xPropList)
-{
-    WPXString sKey;
-    WPXPropertyList::Iter i(xPropList);
-    for (i.rewind(); i.next(); )
-    {
-        WPXString sProp;
-        sProp.sprintf("[%s:%s]", i.key(), i()->getStr().cstr());
-        sKey.append(sProp);
-    }
-
-    return sKey;
-}
-
-WPXString getParagraphStyleKey(const WPXPropertyList & xPropList, const WPXPropertyListVector & xTabStops)
-{
-    WPXString sKey = propListToStyleKey(xPropList);
-
-    WPXString sTabStops;
-    sTabStops.sprintf("[num-tab-stops:%i]", xTabStops.count());
-    WPXPropertyListVector::Iter i(xTabStops);
-    for (i.rewind(); i.next();)
-    {
-        sTabStops.append(propListToStyleKey(i()));
-    }
-    sKey.append(sTabStops);
-
-    return sKey;
-}
-
 // _allocateFontName: add a (potentially mapped) font style to the hash if it's not already there, do nothing otherwise
 void OdtGeneratorPrivate::_allocateFontName(const WPXString & sFontName)
 {
diff --git a/writerperfect/source/filter/TextRunStyle.cxx b/writerperfect/source/filter/TextRunStyle.cxx
index 4b16988..e09d3a5 100644
--- a/writerperfect/source/filter/TextRunStyle.cxx
+++ b/writerperfect/source/filter/TextRunStyle.cxx
@@ -57,7 +57,8 @@ void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
     WPXPropertyList propList;
     propList.insert("style:name", msName.cstr());
     propList.insert("style:family", "paragraph");
-    propList.insert("style:parent-style-name", (*mpPropList)["style:parent-style-name"]->getStr());
+   if ((*mpPropList)["style: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);


More information about the Libreoffice-commits mailing list