[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - 3 commits - writerperfect/source

Laurent Alonso laurent.alonso at inria.fr
Mon Mar 11 01:32:04 PDT 2013


 writerperfect/source/filter/ListStyle.cxx    |   29 ++---
 writerperfect/source/filter/ListStyle.hxx    |   15 --
 writerperfect/source/filter/OdgGenerator.cxx |    8 +
 writerperfect/source/filter/OdtGenerator.cxx |  142 ++++++++++++++++++++-------
 4 files changed, 129 insertions(+), 65 deletions(-)

New commits:
commit 37d536b26710c7518d6d4358a395d73e11e773f4
Author: Laurent Alonso <laurent.alonso at inria.fr>
Date:   Mon Mar 11 08:33:17 2013 +0100

    Improve lists generation
    
    Change-Id: Ie910ecb8db1d33c41f450e6c9f297138aa821eee
    (cherry picked from commit 6874c25f98dcfe5116d96a1282c4231c3f2d623a)
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index 92ec8cc..ba14e92 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -61,6 +61,8 @@ struct _WriterListState
     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 };
@@ -85,7 +87,8 @@ _WriterListState::_WriterListState() :
     miLastListNumber(0),
     mbListContinueNumbering(false),
     mbListElementParagraphOpened(false),
-    mbListElementOpened()
+    mbListElementOpened(),
+    mIdListStyleMap()
 {
 }
 
@@ -102,6 +105,14 @@ public:
     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);
 
@@ -154,6 +165,8 @@ public:
 
     // list styles
     std::vector<ListStyle *> mListStyles;
+    // a map id -> last list style defined with id
+    std::map<int, ListStyle *> mIdListStyleMap;
 
     // object state
     unsigned miObjectNumber;
@@ -182,6 +195,7 @@ OdtGeneratorPrivate::OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const Odf
     mpCurrentPageSpan(0),
     miNumPageStyles(0),
     mListStyles(),
+    mIdListStyleMap(),
     miObjectNumber(0),
     mpCurrentTableStyle(0),
     mxStreamType(streamType),
@@ -634,6 +648,47 @@ 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;
@@ -644,11 +699,12 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
     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 (2) the prior list is actually definitively different
-    // from the list that is just being defined (listIDs differ) OR (3) we can tell that the user actually
-    // is starting a new list at level 1 (and only level 1)
-    if (pListStyle == 0 || pListStyle->getListID() != id  ||
+    // 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))))
     {
@@ -657,8 +713,7 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
         sName.sprintf("OL%i", mpImpl->miNumListStyles);
         mpImpl->miNumListStyles++;
         pListStyle = new ListStyle(sName.cstr(), id);
-        mpImpl->mListStyles.push_back(pListStyle);
-        mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
+        mpImpl->_storeListStyle(pListStyle);
         mpImpl->mWriterListStates.top().mbListContinueNumbering = false;
         mpImpl->mWriterListStates.top().miLastListNumber = 0;
     }
@@ -692,8 +747,7 @@ void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList)
         sName.sprintf("UL%i", mpImpl->miNumListStyles);
         mpImpl->miNumListStyles++;
         pListStyle = new ListStyle(sName.cstr(), id);
-        mpImpl->mListStyles.push_back(pListStyle);
-        mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
+        mpImpl->_storeListStyle(pListStyle);
     }
 
     // See comment in OdtGenerator::defineOrderedListLevel
@@ -704,13 +758,18 @@ void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList)
     }
 }
 
-void OdtGenerator::openOrderedListLevel(const WPXPropertyList &)
+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);
 
@@ -722,13 +781,18 @@ void OdtGenerator::openOrderedListLevel(const WPXPropertyList &)
     mpImpl->mpCurrentContentElements->push_back(pListLevelOpenElement);
 }
 
-void OdtGenerator::openUnorderedListLevel(const WPXPropertyList &)
+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);
 
@@ -798,12 +862,16 @@ void OdtGenerator::openListElement(const WPXPropertyList &propList, const WPXPro
     WPXPropertyList finalPropList(propList);
 #if 0
     // this property is ignored in TextRunStyle.c++
-    finalPropList.insert("style:list-style-name", mpImpl->mWriterListStates.top().mpCurrentListStyle->getName());
+    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);
 
-    mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("text:list-item"));
+    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);
commit 6030a9eb9c1c132aa2fd6ab951cd718fb5bf0cc1
Author: Laurent Alonso <laurent.alonso at inria.fr>
Date:   Mon Feb 18 13:20:14 2013 +0100

    Writerperfect: Improve list code
    
    Change-Id: I21fc40a0cb16e4f8295477cc2db50a58bc7287ea
    (cherry picked from commit f3929090a0b12018b629d0d65b89d17d0afdc7e3)
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/writerperfect/source/filter/ListStyle.cxx b/writerperfect/source/filter/ListStyle.cxx
index cf5900a..0625570 100644
--- a/writerperfect/source/filter/ListStyle.cxx
+++ b/writerperfect/source/filter/ListStyle.cxx
@@ -19,14 +19,6 @@ OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) :
 {
 }
 
-void OrderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
-{
-    if (iLevel < 0)
-        return;
-    if (!isListLevelDefined(iLevel))
-        setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
-}
-
 void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const
 {
     WPXString sLevel;
@@ -79,14 +71,6 @@ UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropLis
 {
 }
 
-void UnorderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
-{
-    if (iLevel < 0)
-        return;
-    if (!isListLevelDefined(iLevel))
-        setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
-}
-
 void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) const
 {
     WPXString sLevel;
@@ -163,6 +147,19 @@ void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
         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");
diff --git a/writerperfect/source/filter/ListStyle.hxx b/writerperfect/source/filter/ListStyle.hxx
index 44d090d..53ee67e 100644
--- a/writerperfect/source/filter/ListStyle.hxx
+++ b/writerperfect/source/filter/ListStyle.hxx
@@ -48,7 +48,7 @@ class ListStyle : public Style
 public:
     ListStyle(const char *psName, const int iListID);
     virtual ~ListStyle();
-    virtual void updateListLevel(const int iLevel, const WPXPropertyList &xPropList) = 0;
+    void updateListLevel(const int iLevel, const WPXPropertyList &xPropList, bool ordered);
     virtual void write(OdfDocumentHandler *pHandler) const;
     int getListID()
     {
@@ -64,19 +64,6 @@ private:
     const int miListID;
 };
 
-class OrderedListStyle : public ListStyle
-{
-public:
-    OrderedListStyle(const char *psName, const int iListID) : ListStyle(psName, iListID) {}
-    void updateListLevel(const int iLevel, const WPXPropertyList &xPropList);
-};
-
-class UnorderedListStyle : public ListStyle
-{
-public:
-    UnorderedListStyle(const char *psName, const int iListID) : ListStyle(psName, iListID) {}
-    void updateListLevel(const int iLevel, const WPXPropertyList &xPropList);
-};
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index 9ee2f67..92ec8cc 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -640,15 +640,15 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
     if (propList["libwpd:id"])
         id = propList["libwpd:id"]->getInt();
 
-    OrderedListStyle *pOrderedListStyle = 0;
+    ListStyle *pListStyle = 0;
     if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id)
-        pOrderedListStyle = static_cast<OrderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+        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 (2) the prior list is actually definitively different
     // from the list that is just being defined (listIDs differ) OR (3) we can tell that the user actually
     // is starting a new list at level 1 (and only level 1)
-    if (pOrderedListStyle == 0 || pOrderedListStyle->getListID() != id  ||
+    if (pListStyle == 0 || pListStyle->getListID() != id  ||
             (propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 &&
              (propList["text:start-value"] && propList["text:start-value"]->getInt() != int(mpImpl->mWriterListStates.top().miLastListNumber+1))))
     {
@@ -656,9 +656,9 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
         WPXString sName;
         sName.sprintf("OL%i", mpImpl->miNumListStyles);
         mpImpl->miNumListStyles++;
-        pOrderedListStyle = new OrderedListStyle(sName.cstr(), id);
-        mpImpl->mListStyles.push_back(pOrderedListStyle);
-        mpImpl->mWriterListStates.top().mpCurrentListStyle = pOrderedListStyle;
+        pListStyle = new ListStyle(sName.cstr(), id);
+        mpImpl->mListStyles.push_back(pListStyle);
+        mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
         mpImpl->mWriterListStates.top().mbListContinueNumbering = false;
         mpImpl->mWriterListStates.top().miLastListNumber = 0;
     }
@@ -668,10 +668,10 @@ void OdtGenerator::defineOrderedListLevel(const WPXPropertyList &propList)
     // Iterate through ALL list styles with the same WordPerfect list id and define a level if it is not already defined
     // This solves certain problems with lists that start and finish without reaching certain levels and then begin again
     // and reach those levels. See gradguide0405_PC.wpd in the regression suite
-    for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mpImpl->mListStyles.begin(); iterOrderedListStyles != mpImpl->mListStyles.end(); ++iterOrderedListStyles)
+    for (std::vector<ListStyle *>::iterator iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles)
     {
-        if ((* iterOrderedListStyles) && (* iterOrderedListStyles)->getListID() == id && propList["libwpd:level"])
-            (* iterOrderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
+        if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"])
+            (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, true);
     }
 }
 
@@ -681,26 +681,26 @@ void OdtGenerator::defineUnorderedListLevel(const WPXPropertyList &propList)
     if (propList["libwpd:id"])
         id = propList["libwpd:id"]->getInt();
 
-    UnorderedListStyle *pUnorderedListStyle = 0;
+    ListStyle *pListStyle = 0;
     if (mpImpl->mWriterListStates.top().mpCurrentListStyle && mpImpl->mWriterListStates.top().mpCurrentListStyle->getListID() == id)
-        pUnorderedListStyle = static_cast<UnorderedListStyle *>(mpImpl->mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+        pListStyle = mpImpl->mWriterListStates.top().mpCurrentListStyle;
 
-    if (pUnorderedListStyle == 0)
+    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++;
-        pUnorderedListStyle = new UnorderedListStyle(sName.cstr(), id);
-        mpImpl->mListStyles.push_back(pUnorderedListStyle);
-        mpImpl->mWriterListStates.top().mpCurrentListStyle = pUnorderedListStyle;
+        pListStyle = new ListStyle(sName.cstr(), id);
+        mpImpl->mListStyles.push_back(pListStyle);
+        mpImpl->mWriterListStates.top().mpCurrentListStyle = pListStyle;
     }
 
     // See comment in OdtGenerator::defineOrderedListLevel
-    for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mpImpl->mListStyles.begin(); iterUnorderedListStyles != mpImpl->mListStyles.end(); ++iterUnorderedListStyles)
+    for (std::vector<ListStyle *>::iterator iterListStyles = mpImpl->mListStyles.begin(); iterListStyles != mpImpl->mListStyles.end(); ++iterListStyles)
     {
-        if ((* iterUnorderedListStyles) && (* iterUnorderedListStyles)->getListID() == id && propList["libwpd:level"])
-            (* iterUnorderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
+        if ((* iterListStyles) && (* iterListStyles)->getListID() == id && propList["libwpd:level"])
+            (* iterListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList, false);
     }
 }
 
@@ -747,7 +747,11 @@ void OdtGeneratorPrivate::_openListLevel(TagOpenElement *pListLevelOpenElement)
     mWriterListStates.top().mbListElementOpened.push(false);
     if (mWriterListStates.top().mbListElementOpened.size() == 1)
     {
-        pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName());
+        // 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());
+        }
     }
 }
 
@@ -763,6 +767,12 @@ void OdtGenerator::closeUnorderedListLevel()
 
 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"));
@@ -770,11 +780,7 @@ void OdtGeneratorPrivate::_closeListLevel()
     }
 
     mpCurrentContentElements->push_back(new TagCloseElement("text:list"));
-
-    if (!mWriterListStates.top().mbListElementOpened.empty())
-    {
-        mWriterListStates.top().mbListElementOpened.pop();
-    }
+    mWriterListStates.top().mbListElementOpened.pop();
 }
 
 void OdtGenerator::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)
commit 83277f024e88519968376d076ce328f0adfde5a3
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date:   Sun Feb 17 13:10:03 2013 -0600

    coverity#983356 ressource leak
    
    Change-Id: Idcc2d548363ddab04dd8acaa1dfb854a19ca47ef
    Reviewed-on: https://gerrit.libreoffice.org/2200
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>
    (cherry picked from commit bf46dfdb45b1d6cd99a5c729ee98df89db363225)
    
    Signed-off-by: Fridrich Å trba <fridrich.strba at bluewin.ch>

diff --git a/writerperfect/source/filter/OdgGenerator.cxx b/writerperfect/source/filter/OdgGenerator.cxx
index 1caebdd..d166a09 100644
--- a/writerperfect/source/filter/OdgGenerator.cxx
+++ b/writerperfect/source/filter/OdgGenerator.cxx
@@ -1328,7 +1328,13 @@ void OdgGeneratorPrivate::_writeGraphicsStyle()
                 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;
     }


More information about the Libreoffice-commits mailing list