[Libreoffice-commits] core.git: 2 commits - writerperfect/source

Laurent Alonso laurent.alonso at inria.fr
Mon Mar 11 00:50:32 PDT 2013


 writerperfect/source/filter/ListStyle.cxx    |    8 +
 writerperfect/source/filter/OdtGenerator.cxx |  110 +++++++++++++++++++++++----
 writerperfect/source/filter/TableStyle.cxx   |    6 +
 writerperfect/source/filter/TextRunStyle.cxx |    8 +
 4 files changed, 115 insertions(+), 17 deletions(-)

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

    Improve lists generation
    
    Change-Id: Ie910ecb8db1d33c41f450e6c9f297138aa821eee

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 d242c4a441964837e6a68343dfef9eb530fb41f7
Author: Laurent Alonso <laurent.alonso at inria.fr>
Date:   Mon Mar 11 08:29:17 2013 +0100

    Support some new parameters
    
    Change-Id: I22857f57822bff39ef5fcd576bd29e374f1aa819

diff --git a/writerperfect/source/filter/ListStyle.cxx b/writerperfect/source/filter/ListStyle.cxx
index bb87a1c..1b6cf5c 100644
--- a/writerperfect/source/filter/ListStyle.cxx
+++ b/writerperfect/source/filter/ListStyle.cxx
@@ -47,6 +47,8 @@ void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) cons
         else
             listLevelStyleOpen.addAttribute("text:start-value", "1");
     }
+    if (mPropList["text:display-levels"])
+        listLevelStyleOpen.addAttribute("text:display-levels", mPropList["text:display-levels"]->getStr());
     listLevelStyleOpen.write(pHandler);
 
     TagOpenElement stylePropertiesOpen("style:list-level-properties");
@@ -56,6 +58,8 @@ void OrderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) cons
         stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
     if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0)
         stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
+    if (mPropList["fo:text-align"])
+        stylePropertiesOpen.addAttribute("fo:text-align", mPropList["fo:text-align"]->getStr());
     stylePropertiesOpen.write(pHandler);
 
     pHandler->endElement("style:list-level-properties");
@@ -87,6 +91,8 @@ void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) co
     }
     else
         listLevelStyleOpen.addAttribute("text:bullet-char", ".");
+    if (mPropList["text:display-levels"])
+        listLevelStyleOpen.addAttribute("text:display-levels", mPropList["text:display-levels"]->getStr());
     listLevelStyleOpen.write(pHandler);
 
     TagOpenElement stylePropertiesOpen("style:list-level-properties");
@@ -96,6 +102,8 @@ void UnorderedListLevelStyle::write(OdfDocumentHandler *pHandler, int iLevel) co
         stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
     if (mPropList["text:min-label-distance"] && mPropList["text:min-label-distance"]->getDouble() > 0.0)
         stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
+    if (mPropList["fo:text-align"])
+        stylePropertiesOpen.addAttribute("fo:text-align", mPropList["fo:text-align"]->getStr());
     stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol");
     stylePropertiesOpen.write(pHandler);
 
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index 88bcc18..92ec8cc 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -1202,12 +1202,22 @@ void OdtGenerator::openFrame(const WPXPropertyList &propList)
         frameAutomaticStylePropertiesElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr());
 
     // check if the frame has border, background attributes
-    if (propList["fo:border"])
-        frameAutomaticStylePropertiesElement->addAttribute("fo:border", propList["fo:border"]->getStr());
+    static char const *(bordersString[])=
+    {"fo:border","fo:border-top","fo:border-left","fo:border-bottom","fo:border-right"};
+    for (int b = 0; b < 5; b++)
+    {
+        if (propList[bordersString[b]])
+            frameAutomaticStylePropertiesElement->addAttribute(bordersString[b], propList[bordersString[b]]->getStr());
+    }
     if (propList["style:border-line-width"])
         frameAutomaticStylePropertiesElement->addAttribute("style:border-line-width", propList["style:border-line-width"]->getStr());
     if (propList["fo:background-color"])
         frameAutomaticStylePropertiesElement->addAttribute("fo:background-color", propList["fo:background-color"]->getStr());
+    if (propList["style:background-transparency"])
+        frameAutomaticStylePropertiesElement->addAttribute("style:background-transparency", propList["style:background-transparency"]->getStr());
+
+    if (propList["fo:clip"])
+        frameAutomaticStylePropertiesElement->addAttribute("fo:clip", propList["fo:clip"]->getStr());
 
     frameAutomaticStylePropertiesElement->addAttribute("draw:ole-draw-aspect", "1");
 
diff --git a/writerperfect/source/filter/TableStyle.cxx b/writerperfect/source/filter/TableStyle.cxx
index 18331c4..856f578 100644
--- a/writerperfect/source/filter/TableStyle.cxx
+++ b/writerperfect/source/filter/TableStyle.cxx
@@ -40,12 +40,16 @@ void TableCellStyle::write(OdfDocumentHandler *pHandler) const
     // generalize this sort of thing into the "Style" superclass
     WPXPropertyList stylePropList;
     WPXPropertyList::Iter i(mPropList);
+    /* first set padding, so that mPropList can redefine, if
+       mPropList["fo:padding"] is defined */
+    stylePropList.insert("fo:padding", "0.0382in");
     for (i.rewind(); i.next();)
     {
         if (strlen(i.key()) > 2 && strncmp(i.key(), "fo", 2) == 0)
             stylePropList.insert(i.key(), i()->clone());
+        else if (strcmp(i.key(), "style:vertical-align")==0)
+            stylePropList.insert(i.key(), i()->clone());
     }
-    stylePropList.insert("fo:padding", "0.0382in");
     pHandler->startElement("style:table-cell-properties", stylePropList);
     pHandler->endElement("style:table-cell-properties");
 
diff --git a/writerperfect/source/filter/TextRunStyle.cxx b/writerperfect/source/filter/TextRunStyle.cxx
index 4c461f9..8bb34ef 100644
--- a/writerperfect/source/filter/TextRunStyle.cxx
+++ b/writerperfect/source/filter/TextRunStyle.cxx
@@ -69,6 +69,8 @@ void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
             propList.insert("fo:text-indent", i()->getStr());
         else if (strcmp(i.key(), "fo:line-height") == 0)
             propList.insert("fo:line-height", i()->getStr());
+        else if (strcmp(i.key(), "style:line-height-at-least") == 0)
+            propList.insert("style:line-height-at-least", i()->getStr());
         else if (strcmp(i.key(), "fo:break-before") == 0)
             propList.insert("fo:break-before", i()->getStr());
         else if (strcmp(i.key(), "fo:text-align") == 0)
@@ -77,6 +79,8 @@ void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
             propList.insert("fo:text-align-last", i()->getStr());
         else if (strcmp(i.key(), "style:page-number") == 0)
             propList.insert("style:page-number", i()->getStr());
+        else if (strcmp(i.key(), "fo:background-color") == 0)
+            propList.insert("fo:background-color", i()->getStr());
         else if (strncmp(i.key(), "fo:border", 9) == 0)
         {
             if (strcmp(i.key(), "fo:border") == 0 ||
@@ -86,6 +90,10 @@ void ParagraphStyle::write(OdfDocumentHandler *pHandler) const
                     strcmp(i.key(), "fo:border-bottom") == 0)
                 propList.insert(i.key(), i()->getStr());
         }
+        else if (strcmp(i.key(), "fo:keep-together") == 0)
+            propList.insert("fo:keep-together", i()->getStr());
+        else if (strcmp(i.key(), "fo:keep-with-next") == 0)
+            propList.insert("fo:keep-with-next", i()->getStr());
     }
 
     propList.insert("style:justify-single-word", "false");


More information about the Libreoffice-commits mailing list