[Libreoffice-commits] core.git: 2 commits - sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Mar 7 06:10:49 PST 2014


 sw/qa/extras/ooxmlimport/data/strict.docx          |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx           |   12 +++++++
 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          |    1 
 writerfilter/source/ooxml/model.xml                |    6 +--
 8 files changed, 79 insertions(+), 4 deletions(-)

New commits:
commit 37cc7e7471ba3b11cefcb0218c27e2c745886a6d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 7 14:44:10 2014 +0100

    DOCX import: handle points in ST_TwipsMeasure and ST_SignedTwipsMeasure
    
    This fixes page size and margins in case of strict DOCX.
    
    Change-Id: I65894eeef191a0f4bd92d1fa69a17e820aae3a43

diff --git a/sw/qa/extras/ooxmlimport/data/strict.docx b/sw/qa/extras/ooxmlimport/data/strict.docx
new file mode 100644
index 0000000..4195398
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 4f384d8..2503c81 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1903,6 +1903,18 @@ DECLARE_OOXMLIMPORT_TEST(testDMLGroupShapeRunFonts, "dml-groupshape-runfonts.doc
     CPPUNIT_ASSERT_EQUAL(OUString("Arial Unicode MS"), getProperty<OUString>(xRun, "CharFontNameComplex"));
     CPPUNIT_ASSERT_EQUAL(OUString("MS Mincho"), getProperty<OUString>(xRun, "CharFontNameAsian"));
 }
+
+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, "TopMargin"));
+    // 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!");
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
index cb7f1b7..6d227af1 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -670,7 +670,10 @@ OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(sal_uInt32 nValue)
 
 OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const OUString& rValue)
 {
-    mnValue = rValue.toInt32();
+    if (rValue.endsWith("pt"))
+        mnValue = rValue.copy(0, rValue.getLength() - 2).toInt32() * 20;
+    else
+        mnValue = rValue.toInt32();
 }
 
 OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue()
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 406609a..0a84d4f 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -22996,7 +22996,7 @@
       <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"/>
commit d5d7c7d3b281e1a9060d60bc4ac7738ae616f167
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Mar 7 14:27:11 2014 +0100

    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.
    
    Change-Id: Iebb1ee859076595594d1455a1f826841dae77a0b

diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
index 5d683cb..8e2fa15 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..cb7f1b7 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -661,6 +661,37 @@ string OOXMLHexValue::toString() const
     return buffer;
 }
 
+// OOXMLUniversalMeasureValue
+
+OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(sal_uInt32 nValue)
+    : mnValue(nValue)
+{
+}
+
+OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const OUString& rValue)
+{
+    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 2fb5139..fe45620 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')">
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 12c47c4..406609a 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -9902,7 +9902,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"/>
@@ -22991,7 +22991,7 @@
       <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"/>


More information about the Libreoffice-commits mailing list