[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sw/CppunitTest_sw_ooxmlimport.mk sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Mar 11 06:00:36 PDT 2014


 sw/CppunitTest_sw_ooxmlimport.mk                       |    1 
 sw/qa/extras/inc/swmodeltestbase.hxx                   |    4 +
 sw/qa/extras/ooxmlimport/data/strict-lockedcanvas.docx |binary
 sw/qa/extras/ooxmlimport/data/strict.docx              |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx               |   38 +++++++++++++++++
 writerfilter/source/ooxml/OOXMLFactory.cxx             |   12 +++++
 writerfilter/source/ooxml/OOXMLFactory.hxx             |    3 -
 writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx     |   34 +++++++++++++++
 writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx     |   15 ++++++
 writerfilter/source/ooxml/factoryimpl.xsl              |    4 +
 writerfilter/source/ooxml/model.xml                    |   15 +++++-
 writerfilter/source/ooxml/namespaceids.xsl             |    3 -
 12 files changed, 122 insertions(+), 7 deletions(-)

New commits:
commit 65909e07763e80031bfeb7bb3170e6c3b0029065
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 7 11:45:39 2014 +0100

    writerfilter: initial strict DOCX support
    
    The generate-id() code is just necessary avoid duplicated elements in
    the for-each loop. http://mahahegde.com/xslt-distinct-values/ has a
    detailed description of the technique used here.
    (cherry picked from commit f9bf15e19ec823a58ee32bf94da81f3bb1a147bc)
    
    writerfilter: introduce ooxml::OOXMLUniversalMeasureValue
    
    In transitional DOCX, ST_UniversalMeasure is in practice a simple integer,
    which means twips. But in case of strict, ST_UniversalMeasure is in points
    in practice -- which is perfectly valid, but we didn't handle it so far.
    
    Add a separate Value class that is used only for handling
    ST_UniversalMeasure, then there we can handle the various additional
    suffixes.
    (cherry picked from commit d5d7c7d3b281e1a9060d60bc4ac7738ae616f167)
    
    DOCX import: handle points in ST_TwipsMeasure and ST_SignedTwipsMeasure
    
    This fixes page size and margins in case of strict DOCX.
    (cherry picked from commit 37cc7e7471ba3b11cefcb0218c27e2c745886a6d)
    
    DOCX strict import: fix headers
    
    Now that the document has a header, better to just test the bottom
    margin, as in case there is a header, the top margin has different
    semantics in Word and Writer.
    (cherry picked from commit 195b8491d0299038fb64d19463e3ce90905bf346)
    
    DOCX strict import: fix pictures as well
    (cherry picked from commit aaef39de32442203d631a65aecf23eeb27dfbb12)
    
    DOCX strict import: handle charts
    (cherry picked from commit 49c3aff8d8d3030b2acbffb6ff000b5d44445cc9)
    
    DOCX strict import: handle SmartArt
    (cherry picked from commit f5985685ddc519f760a7324fa60fd662f25404c1)
    
    DOCX strict import: handle lockedCanvas
    (cherry picked from commit d795fb224e52c66c4585ed1e079a2b7601a07eda)
    
    DOCX strict import: handle math
    (cherry picked from commit c98d649117dc776ac51807be3376924d1fce2035)
    
    Conflicts:
    	sw/qa/extras/ooxmlimport/ooxmlimport.cxx
    
    Change-Id: I647efe9d4a0834d3756fe9fa6d706ba6ba4e00f1
    Reviewed-on: https://gerrit.libreoffice.org/8532
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sw/CppunitTest_sw_ooxmlimport.mk b/sw/CppunitTest_sw_ooxmlimport.mk
index fe1cefe..ad6155e 100644
--- a/sw/CppunitTest_sw_ooxmlimport.mk
+++ b/sw/CppunitTest_sw_ooxmlimport.mk
@@ -69,6 +69,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_ooxmlimport,\
     sw/util/swd \
     sw/util/msword \
     sfx2/util/sfx \
+	starmath/util/sm \
     svl/source/fsstor/fsstorage \
     svl/util/svl \
     svtools/util/svt \
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 8a2b8c4..316cb9c 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -351,9 +351,11 @@ protected:
         return xParagraph;
     }
 
-    uno::Reference<text::XTextRange> getParagraphOfText(int number, uno::Reference<text::XText> xText) const
+    uno::Reference<text::XTextRange> getParagraphOfText(int number, uno::Reference<text::XText> xText, OUString content = OUString()) const
     {
         uno::Reference<text::XTextRange> const xParagraph(getParagraphOrTable(number, xText), uno::UNO_QUERY_THROW);
+        if (!content.isEmpty())
+            CPPUNIT_ASSERT_EQUAL(content, xParagraph->getString());
         return xParagraph;
     }
 
diff --git a/sw/qa/extras/ooxmlimport/data/strict-lockedcanvas.docx b/sw/qa/extras/ooxmlimport/data/strict-lockedcanvas.docx
new file mode 100644
index 0000000..d31be7e
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/strict-lockedcanvas.docx differ
diff --git a/sw/qa/extras/ooxmlimport/data/strict.docx b/sw/qa/extras/ooxmlimport/data/strict.docx
new file mode 100644
index 0000000..b46ce94
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/strict.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 4c8a790..5e161cc 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1595,6 +1595,44 @@ DECLARE_OOXMLIMPORT_TEST(testFdo73389,"fdo73389.docx")
     // This was 9340, i.e. the width of the inner table was too large.
     CPPUNIT_ASSERT_EQUAL(sal_Int32(2842), getProperty<sal_Int32>(xTables->getByIndex(0), "Width"));
 }
+
+DECLARE_OOXMLIMPORT_TEST(testStrict, "strict.docx")
+{
+    uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
+    // This was only 127, pt suffix was ignored, so this got parsed as twips instead of points.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(72 * 20)), getProperty<sal_Int32>(xPageStyle, "BottomMargin"));
+    // This was only 1397, same issue
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(792 * 20)), getProperty<sal_Int32>(xPageStyle, "Height"));
+    // Text was missing, due to not handling the strict namespaces.
+    getParagraph(1, "Hello world!");
+
+    // Header in the document caused a crash on import.
+    uno::Reference<text::XText> xHeaderText(xPageStyle->getPropertyValue("HeaderText"), uno::UNO_QUERY);
+    getParagraphOfText(1, xHeaderText, "This is a header.");
+
+    // Picture was missing.
+    uno::Reference<lang::XServiceInfo> xServiceInfo(getShape(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextGraphicObject"));
+
+    // SmartArt was missing.
+    xServiceInfo.set(getShape(2), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"));
+
+    // Chart was missing.
+    xServiceInfo.set(getShape(3), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextEmbeddedObject"));
+
+    // Math was missing.
+    xServiceInfo.set(getShape(4), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextEmbeddedObject"));
+}
+
+DECLARE_OOXMLIMPORT_TEST(testStrictLockedcanvas, "strict-lockedcanvas.docx")
+{
+    // locked canvas shape was missing.
+    getShape(1);
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index 20fc82c..06115c3 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.cxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -202,6 +202,18 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
                         pFactory->attributeAction(pHandler, aIt->first, pValue);
                     }
                     break;
+                case RT_UniversalMeasure:
+                    {
+#ifdef DEBUG_FACTORY
+                        debug_logger->element("universalMeasure");
+#endif
+                        OUString aValue(Attribs->getValue(aIt->first));
+                        OOXMLFastHelper<OOXMLUniversalMeasureValue>::newProperty(pHandler, nId, aValue);
+
+                        OOXMLValue::Pointer_t pValue(new OOXMLUniversalMeasureValue(aValue));
+                        pFactory->attributeAction(pHandler, aIt->first, pValue);
+                    }
+                    break;
                 case RT_List:
                     {
 #ifdef DEBUG_FACTORY
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index 94039d3..346b023 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -54,7 +54,8 @@ enum ResourceType_t {
     RT_TextTable,
     RT_PropertyTable,
     RT_Math,
-    RT_Any
+    RT_Any,
+    RT_UniversalMeasure
 };
 
 struct AttributeInfo
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
index d77fdeb..6d227af1 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -661,6 +661,40 @@ string OOXMLHexValue::toString() const
     return buffer;
 }
 
+// OOXMLUniversalMeasureValue
+
+OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(sal_uInt32 nValue)
+    : mnValue(nValue)
+{
+}
+
+OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const OUString& rValue)
+{
+    if (rValue.endsWith("pt"))
+        mnValue = rValue.copy(0, rValue.getLength() - 2).toInt32() * 20;
+    else
+        mnValue = rValue.toInt32();
+}
+
+OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue()
+{
+}
+
+int OOXMLUniversalMeasureValue::getInt() const
+{
+    return mnValue;
+}
+
+OOXMLValue* OOXMLUniversalMeasureValue::clone() const
+{
+    return new OOXMLUniversalMeasureValue(*this);
+}
+
+string OOXMLUniversalMeasureValue::toString() const
+{
+    return OString::number(mnValue).getStr();
+}
+
 /*
   class OOXMLShapeValue
  */
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
index 8ea8d85..58815b6 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
@@ -214,6 +214,21 @@ public:
     virtual OOXMLValue * clone() const;
 };
 
+/// Handles OOXML's ST_UniversalMeasure value.
+class OOXMLUniversalMeasureValue : public OOXMLValue
+{
+protected:
+    sal_uInt32 mnValue;
+public:
+    explicit OOXMLUniversalMeasureValue(sal_uInt32 nValue);
+    explicit OOXMLUniversalMeasureValue(const OUString& rValue);
+    virtual ~OOXMLUniversalMeasureValue();
+
+    virtual int getInt() const;
+    virtual string toString() const;
+    virtual OOXMLValue* clone() const;
+};
+
 class OOXMLShapeValue : public OOXMLValue
 {
 protected:
diff --git a/writerfilter/source/ooxml/factoryimpl.xsl b/writerfilter/source/ooxml/factoryimpl.xsl
index 07571b0..48f7ef4 100644
--- a/writerfilter/source/ooxml/factoryimpl.xsl
+++ b/writerfilter/source/ooxml/factoryimpl.xsl
@@ -101,6 +101,7 @@ uno::Reference< xml::sax::XFastContextHandler > OOXMLFactory::createFastCh
                 <xsl:if test="generate-id(key('resources', @resource)) = generate-id(.)">
                     <xsl:if test="not(@resource = 'Hex' or 
                                       @resource = 'Integer' or 
+                                      @resource = 'UniversalMeasure' or
                                       @resource = 'Boolean' or
                                       @resource = 'List' or
                                       @resource = 'String')">
@@ -196,6 +197,7 @@ uno::Reference< xml::sax::XFastContextHandler > OOXMLFactory::createFastCh
 </xsl:text>
 </xsl:template>
 
+<xsl:key name="namespaces-by-id" match="namespace-alias" use="@id"/>
 <xsl:template name="fasttokentoid">
   <xsl:text>
 namespace tokenmap {
@@ -217,7 +219,7 @@ string fastTokenToId(sal_uInt32 nToken)
 
     switch (nToken & 0xffff0000)
     {</xsl:text>
-    <xsl:for-each select="//namespace-alias">
+    <xsl:for-each select="//namespace-alias[generate-id() = generate-id(key('namespaces-by-id', @id)[1])]">
       <xsl:text>
     case NS_</xsl:text>
     <xsl:value-of select="@alias"/>
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 6018582..2506511 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -19,19 +19,28 @@
 <model xmlns:rng="http://relaxng.org/ns/structure/1.0">
   <namespace-alias name="http://www.w3.org/XML/1998/namespace" alias="xml" id="xml"/>
   <namespace-alias name="http://schemas.openxmlformats.org/officeDocument/2006/relationships" alias="relationships" id="officeRel"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/officeDocument/relationships" alias="relationships" id="officeRel"/>
   <namespace-alias name="urn:schemas-microsoft-com:office:office" alias="office" id="vmlOffice"/>
   <namespace-alias name="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" alias="theme" id="officeRelTheme"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" alias="wordprocessingDrawing" id="dmlWordDr"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing" alias="wordprocessingDrawing" id="dmlWordDr"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/main" alias="drawingml" id="dml"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/main" alias="drawingml" id="dml"/>
   <namespace-alias name="urn:schemas-microsoft-com:vml" alias="vml" id="vml"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/picture" alias="picture" id="dmlPicture"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/picture" alias="picture" id="dmlPicture"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/diagram" alias="diagram" id="dmlDiagram"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/diagram" alias="diagram" id="dmlDiagram"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" alias="lockedCanvas" id="dmlLockedCanvas"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/lockedCanvas" alias="lockedCanvas" id="dmlLockedCanvas"/>
   <namespace-alias name="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" alias="wps" id="wps"/>
   <namespace-alias name="http://schemas.openxmlformats.org/drawingml/2006/chart" alias="chart" id="dmlChart"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/drawingml/chart" alias="chart" id="dmlChart"/>
   <namespace-alias name="urn:schemas-microsoft-com:office:word" alias="vml_wordprocessingDrawing" id="vmlWord"/>
   <namespace-alias name="http://schemas.openxmlformats.org/wordprocessingml/2006/main" alias="wordprocessingml" id="doc"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/wordprocessingml/main" alias="wordprocessingml" id="doc"/>
   <namespace-alias name="http://schemas.openxmlformats.org/officeDocument/2006/math" alias="math" id="officeMath"/>
+  <namespace-alias name="http://purl.oclc.org/ooxml/officeDocument/math" alias="math" id="officeMath"/>
   <namespace-alias name="http://schemas.openxmlformats.org/schemaLibrary/2006/main" alias="schemaLibrary" id="schema"/>
   <namespace-alias name="http://schemas.openxmlformats.org/markup-compatibility/2006" alias="mce" id="mce"/>
   <namespace-alias name="http://sprm" alias="sprm" id="sprm"/>
@@ -8343,7 +8352,7 @@
     <resource name="CT_OMathJc" resource="Value" generated="yes" tag="math">
       <attribute name="val" tokenid="ooxml:CT_OMathJc_val" action="setValue"/>
     </resource>
-    <resource name="ST_TwipsMeasure" resource="Integer" generated="yes"/>
+    <resource name="ST_TwipsMeasure" resource="UniversalMeasure"/>
     <resource name="CT_TwipsMeasure" resource="Value" generated="yes" tag="math">
       <attribute name="val" tokenid="ooxml:CT_TwipsMeasure_val" action="setValue"/>
       <action name="start" action="setDefaultIntegerValue"/>
@@ -21336,12 +21345,12 @@
       <action name="start" action="setDefaultIntegerValue"/>
     </resource>
     <resource name="ST_UnsignedDecimalNumber" resource="Integer" generated="yes"/>
-    <resource name="ST_TwipsMeasure" resource="Integer"/>
+    <resource name="ST_TwipsMeasure" resource="UniversalMeasure"/>
     <resource name="CT_TwipsMeasure" resource="Value" tag="attribute">
       <attribute name="val" tokenid="ooxml:CT_TwipsMeasure_val" action="setValue"/>
       <action name="start" action="setDefaultIntegerValue"/>
     </resource>
-    <resource name="ST_SignedTwipsMeasure" resource="Integer"/>
+    <resource name="ST_SignedTwipsMeasure" resource="UniversalMeasure"/>
     <resource name="CT_SignedTwipsMeasure" resource="Value" tag="attribute">
       <attribute name="val" tokenid="ooxml:CT_SignedTwipsMeasure_val" action="setValue"/>
       <action name="start" action="setDefaultIntegerValue"/>
diff --git a/writerfilter/source/ooxml/namespaceids.xsl b/writerfilter/source/ooxml/namespaceids.xsl
index ea56acc..d92593d 100644
--- a/writerfilter/source/ooxml/namespaceids.xsl
+++ b/writerfilter/source/ooxml/namespaceids.xsl
@@ -51,8 +51,9 @@
   
   <xsl:include href="factorytools.xsl"/>
 
+<xsl:key name="namespaces-by-id" match="namespace-alias" use="@id"/>
 <xsl:template name="namespaceids">
-  <xsl:for-each select="//namespace-alias">
+  <xsl:for-each select="//namespace-alias[generate-id() = generate-id(key('namespaces-by-id', @id)[1])]">
     <xsl:text>
 const sal_uInt32 </xsl:text>
 <xsl:call-template name="namespaceid"/>


More information about the Libreoffice-commits mailing list