[Libreoffice-commits] core.git: 3 commits - include/xmloff sw/ooxmlexport_setup.mk sw/qa writerfilter/source xmloff/source

Michael Stahl mstahl at redhat.com
Wed Mar 12 16:00:07 PDT 2014


 include/xmloff/xmlimp.hxx                         |    7 ++
 sw/ooxmlexport_setup.mk                           |    1 
 sw/qa/extras/odfimport/data/fdo75872_aoo40.odt    |binary
 sw/qa/extras/odfimport/data/fdo75872_ooo33.odt    |binary
 sw/qa/extras/odfimport/odfimport.cxx              |   20 +++++++
 writerfilter/source/dmapper/DomainMapper.cxx      |   54 +++++++++++++-------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    2 
 xmloff/source/core/xmlimp.cxx                     |   25 ++++++++-
 xmloff/source/draw/XMLGraphicsDefaultStyle.cxx    |   59 +++++++++++++++++++++-
 9 files changed, 148 insertions(+), 20 deletions(-)

New commits:
commit b749a589bb2e111546fc9e4b4dd32791e424a37b
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Mar 12 22:52:30 2014 +0100

    writerfilter: assert that substream doesn't leave extra contexts
    
    ... on the stacks, to prevent problems like rhbz#988516.
    
    Change-Id: I76392586e5276e4b73941064875c0224834684b5

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index c5f761f..60208a3 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2763,11 +2763,25 @@ void DomainMapper::lcl_table(Id name, writerfilter::Reference<Table>::Pointer_t
 
 void DomainMapper::lcl_substream(Id rName, ::writerfilter::Reference<Stream>::Pointer_t ref)
 {
-    m_pImpl->appendTableManager( );
+    m_pImpl->substream(rName, ref);
+}
+
+void DomainMapper_Impl::substream(Id rName,
+        ::writerfilter::Reference<Stream>::Pointer_t const& ref)
+{
+#ifndef NDEBUG
+    size_t contextSize(m_aContextStack.size());
+    size_t propSize[NUMBER_OF_CONTEXTS];
+    for (int i = 0; i < NUMBER_OF_CONTEXTS; ++i) {
+        propSize[i] = m_aPropertyStacks[i].size();
+    }
+#endif
+
+    appendTableManager();
     // Appending a TableManager resets its TableHandler, so we need to append
     // that as well, or tables won't be imported properly in headers/footers.
-    m_pImpl->appendTableHandler( );
-    m_pImpl->getTableManager().startLevel();
+    appendTableHandler();
+    getTableManager().startLevel();
 
     //import of page header/footer
 
@@ -2775,37 +2789,37 @@ void DomainMapper::lcl_substream(Id rName, ::writerfilter::Reference<Stream>::Po
     {
     case NS_ooxml::LN_headerl:
 
-        m_pImpl->PushPageHeader(SectionPropertyMap::PAGE_LEFT);
+        PushPageHeader(SectionPropertyMap::PAGE_LEFT);
         break;
     case NS_ooxml::LN_headerr:
 
-        m_pImpl->PushPageHeader(SectionPropertyMap::PAGE_RIGHT);
+        PushPageHeader(SectionPropertyMap::PAGE_RIGHT);
         break;
     case NS_ooxml::LN_headerf:
 
-        m_pImpl->PushPageHeader(SectionPropertyMap::PAGE_FIRST);
+        PushPageHeader(SectionPropertyMap::PAGE_FIRST);
         break;
     case NS_ooxml::LN_footerl:
 
-        m_pImpl->PushPageFooter(SectionPropertyMap::PAGE_LEFT);
+        PushPageFooter(SectionPropertyMap::PAGE_LEFT);
         break;
     case NS_ooxml::LN_footerr:
 
-        m_pImpl->PushPageFooter(SectionPropertyMap::PAGE_RIGHT);
+        PushPageFooter(SectionPropertyMap::PAGE_RIGHT);
         break;
     case NS_ooxml::LN_footerf:
 
-        m_pImpl->PushPageFooter(SectionPropertyMap::PAGE_FIRST);
+        PushPageFooter(SectionPropertyMap::PAGE_FIRST);
         break;
     case NS_ooxml::LN_footnote:
     case NS_ooxml::LN_endnote:
-        m_pImpl->PushFootOrEndnote( NS_ooxml::LN_footnote == rName );
+        PushFootOrEndnote( NS_ooxml::LN_footnote == rName );
     break;
     case NS_ooxml::LN_annotation :
-        m_pImpl->PushAnnotation();
+        PushAnnotation();
     break;
     }
-    ref->resolve(*this);
+    ref->resolve(m_rDMapper);
     switch( rName )
     {
     case NS_ooxml::LN_headerl:
@@ -2814,19 +2828,25 @@ void DomainMapper::lcl_substream(Id rName, ::writerfilter::Reference<Stream>::Po
     case NS_ooxml::LN_footerl:
     case NS_ooxml::LN_footerr:
     case NS_ooxml::LN_footerf:
-        m_pImpl->PopPageHeaderFooter();
+        PopPageHeaderFooter();
     break;
     case NS_ooxml::LN_footnote:
     case NS_ooxml::LN_endnote:
-        m_pImpl->PopFootOrEndnote();
+        PopFootOrEndnote();
     break;
     case NS_ooxml::LN_annotation :
-        m_pImpl->PopAnnotation();
+        PopAnnotation();
     break;
     }
 
-    m_pImpl->getTableManager().endLevel();
-    m_pImpl->popTableManager( );
+    getTableManager().endLevel();
+    popTableManager();
+
+    // check that stacks are the same as before substream
+    assert(m_aContextStack.size() == contextSize);
+    for (int i = 0; i < NUMBER_OF_CONTEXTS; ++i) {
+        assert(m_aPropertyStacks[i].size() == propSize[i]);
+    }
 }
 
 void DomainMapper::lcl_info(const string & /*info_*/)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 2b54bb8..6b7ca58 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -771,6 +771,8 @@ public:
     bool isInIndexContext() { return m_bStartIndex;}
     bool isInBibliographyContext() { return m_bStartBibliography;}
 
+    void substream(Id rName, ::writerfilter::Reference<Stream>::Pointer_t const& ref);
+
 private:
     void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType);
 };
commit b234d816a6f4232f6aa4a16e2605fb0a0856dca4
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Mar 12 23:44:33 2014 +0100

    sw: the test_segfault_while_save.docx requires svl component...
    
    ... to create a com.sun.star.util.NumberFormatsSupplier; without that
    importing a header is interrupted by exception without calling
    endParagraphGroup().
    
    Change-Id: Ib5023329c9f944336582c05b1fa836bbce7813af

diff --git a/sw/ooxmlexport_setup.mk b/sw/ooxmlexport_setup.mk
index 6cc04b8..400bc83 100644
--- a/sw/ooxmlexport_setup.mk
+++ b/sw/ooxmlexport_setup.mk
@@ -47,6 +47,7 @@ define sw_ooxmlexport_components
 	sfx2/util/sfx \
 	starmath/util/sm \
 	svl/source/fsstor/fsstorage \
+	svl/util/svl \
 	svtools/util/svt \
 	svx/util/svx \
 	svx/util/svxcore \
commit 92cb21ebeda98c5193c50c4cf7ef3d60611c2a52
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Mar 12 22:21:16 2014 +0100

    fdo#75872: ODF import: fix up graphics defaults stroke/fill colors
    
    These have changed a few times, notably in LO 4.0 with commit
    895890563cb0cc5fa872bdfd06918a46cdda172d and AOO 4.0 with commit
    c0eb5e7772c848806db8ab461f77f9549c1d8b2b; unfortunately historic OOo and
    current AOO do not write the values into ODF files, whereas LO 4.x does
    (probably by accident, since 45d3577bc5726eee44f491fd30a7f11dc428431a
    by design).
    
    Try to set the defaults depending on the generator; since the defaults
    are not specified by ODF they are implementation defined anyway so this
    should be OK.
    
    Change-Id: I1270d6e0cdeea5cb493724a0998f661a0cf644f1

diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 97d832e..adbc455 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -428,9 +428,14 @@ public:
     static const sal_uInt16 OOo_32x = 32;
     static const sal_uInt16 OOo_33x = 33;
     static const sal_uInt16 OOo_34x = 34;
+    // for AOO, no release overlaps with OOo, so continue OOo version numbers
+    static const sal_uInt16 AOO_40x = 40;
+    static const sal_uInt16 AOO_4x = 41;
     static const sal_uInt16 LO_flag = 0x100;
     static const sal_uInt16 LO_3x = 30 | LO_flag;
-    static const sal_uInt16 LO_4x = 40 | LO_flag;
+    static const sal_uInt16 LO_41x = 41 | LO_flag;
+    static const sal_uInt16 LO_42x = 42 | LO_flag;
+    static const sal_uInt16 LO_4x = 43 | LO_flag;
     static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16;
 
     /** depending on whether the generator version indicates LO, compare
diff --git a/sw/qa/extras/odfimport/data/fdo75872_aoo40.odt b/sw/qa/extras/odfimport/data/fdo75872_aoo40.odt
new file mode 100644
index 0000000..549a567
Binary files /dev/null and b/sw/qa/extras/odfimport/data/fdo75872_aoo40.odt differ
diff --git a/sw/qa/extras/odfimport/data/fdo75872_ooo33.odt b/sw/qa/extras/odfimport/data/fdo75872_ooo33.odt
new file mode 100644
index 0000000..4cc3de7
Binary files /dev/null and b/sw/qa/extras/odfimport/data/fdo75872_ooo33.odt differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 8fa14b4..299fea7 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -279,6 +279,26 @@ DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
 }
 
+DECLARE_ODFIMPORT_TEST(testFdo75872_ooo33, "fdo75872_ooo33.odt")
+{
+    // graphics default style: line color and fill color changed
+    uno::Reference<drawing::XShape> xShape = getShape(1);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_BLACK),
+           getProperty<sal_Int32>(xShape, "LineColor"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(153, 204, 255)),
+           getProperty<sal_Int32>(xShape, "FillColor"));
+}
+
+DECLARE_ODFIMPORT_TEST(testFdo75872_aoo40, "fdo75872_aoo40.odt")
+{
+    // graphics default style: line color and fill color changed
+    uno::Reference<drawing::XShape> xShape = getShape(1);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(128, 128, 128)),
+           getProperty<sal_Int32>(xShape, "LineColor"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(0xCF, 0xE7, 0xF5)),
+           getProperty<sal_Int32>(xShape, "FillColor"));
+}
+
 DECLARE_ODFIMPORT_TEST(testFdo55814, "fdo55814.odt")
 {
     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index c0be300..2236d48 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -194,7 +194,20 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
                             else
                             {
                                 SAL_INFO_IF('4' != loVersion[0], "xmloff.core", "unknown LO version: " << loVersion);
-                                mnGeneratorVersion = SvXMLImport::LO_4x;
+                                if ('4' == loVersion[0] && loVersion.getLength() > 1
+                                    && (loVersion[1] == '0' || loVersion[1] == '1'))
+                                {
+                                    mnGeneratorVersion = SvXMLImport::LO_41x; // 4.0/4.1
+                                }
+                                else if ('4' == loVersion[0]
+                                    && loVersion.getLength() > 1 && loVersion[1] == '2')
+                                {
+                                    mnGeneratorVersion = SvXMLImport::LO_42x; // 4.2
+                                }
+                                else
+                                {
+                                    mnGeneratorVersion = SvXMLImport::LO_4x;
+                                }
                             }
                             return; // ignore buildIds
                         }
@@ -231,6 +244,16 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
                     {
                         mnGeneratorVersion = SvXMLImport::OOo_34x;
                     }
+                    else if (nUPD == 400)
+                    {
+                        mnGeneratorVersion = SvXMLImport::AOO_40x;
+                    }
+                    else if (nUPD >= 410)
+                    {
+                        // effectively this means "latest", see use
+                        // in XMLGraphicsDefaultStyle::SetDefaults()!
+                        mnGeneratorVersion = SvXMLImport::AOO_4x;
+                    }
                 }
             }
 
diff --git a/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx b/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx
index d5a2f79..aae02d4 100644
--- a/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx
+++ b/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx
@@ -17,7 +17,12 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <xmloff/XMLGraphicsDefaultStyle.hxx>
+
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <tools/color.hxx>
+
 #include <xmloff/xmlimp.hxx>
 #include <xmloff/nmspmap.hxx>
 #include <xmloff/xmlnmspe.hxx>
@@ -25,7 +30,6 @@
 
 #include <xmloff/families.hxx>
 #include "XMLShapePropertySetContext.hxx"
-#include <xmloff/XMLGraphicsDefaultStyle.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -76,6 +80,14 @@ SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPre
     return pContext;
 }
 
+struct XMLPropertyByIndex {
+    sal_Int32 const m_nIndex;
+    XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
+    bool operator()(XMLPropertyState const& rProp) {
+        return m_nIndex == rProp.mnIndex;
+    }
+};
+
 // This method is called for every default style
 void XMLGraphicsDefaultStyle::SetDefaults()
 {
@@ -113,6 +125,51 @@ void XMLGraphicsDefaultStyle::SetDefaults()
         xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
     }
 
+    bool const bIsAOO4(
+           GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
+        && GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
+
+    // fdo#75872: backward compatibility for pool defaults change
+    if (GetImport().isGeneratorVersionOlderThan(
+                SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
+        // argh... it turns out that LO has also changed defaults for these
+        // since LO 4.0, and so even the _new_ AOO 4.0+ default needs
+        // special handling since AOO still does _not_ write it into the file
+        || bIsAOO4)
+    {
+        UniReference<XMLPropertySetMapper> const pImpPrMap(
+            GetStyles()->GetImportPropertyMapper(GetFamily())
+                ->getPropertySetMapper());
+        sal_Int32 const nStrokeIndex(
+            pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
+        if (std::find_if(GetProperties().begin(), GetProperties().end(),
+                    XMLPropertyByIndex(nStrokeIndex)) == GetProperties().end())
+        {
+            sal_Int32 const nStroke(
+                    (bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
+            xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
+        }
+        sal_Int32 const nFillColor( (bIsAOO4)
+            ? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
+        sal_Int32 const nFillIndex(
+            pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
+        if (std::find_if(GetProperties().begin(), GetProperties().end(),
+                    XMLPropertyByIndex(nFillIndex)) == GetProperties().end())
+        {
+            xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
+        }
+        if (xInfo->hasPropertyByName("FillColor2"))
+        {
+            sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
+                        XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
+            if (std::find_if(GetProperties().begin(), GetProperties().end(),
+                    XMLPropertyByIndex(nFill2Index)) == GetProperties().end())
+            {
+                xDefaults->setPropertyValue("FillColor2", makeAny(nFillColor));
+            }
+        }
+    }
+
     FillPropertySet( xDefaults );
 }
 


More information about the Libreoffice-commits mailing list