sw/qa/extras/ooxmlexport/data/tdf166201_simplePosCM.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport22.cxx               |   13 +++++++++++++
 sw/source/writerfilter/ooxml/OOXMLFactory.cxx            |    3 +++
 sw/source/writerfilter/ooxml/OOXMLFactory.hxx            |    1 +
 sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx        |    6 ++++++
 sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx        |    2 ++
 sw/source/writerfilter/ooxml/factoryimpl.py              |    1 +
 sw/source/writerfilter/ooxml/model.xml                   |    2 +-
 8 files changed, 27 insertions(+), 1 deletion(-)

New commits:
commit a48bc1a44010e12da4ed8c3f66a4e255ef8f2513
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Apr 15 21:13:40 2025 -0400
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Wed Apr 16 16:18:45 2025 +0200

    tdf#166201 docx import: ST_Coordinates as UniversalMeasure
    
    Thankfully the plumbing is already there,
    although it is a bit surprising that I'm the first one
    to need a Universal Measure for EMUs.
    
    make CppunitTest_sw_ooxmlexport22 \
        CPPUNIT_TEST_NAME=testTdf166201_simplePosCM
    
    Change-Id: Ic2198be297e1ba8686b03ecc8b212cb9d887f5eb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184248
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf166201_simplePosCM.docx 
b/sw/qa/extras/ooxmlexport/data/tdf166201_simplePosCM.docx
new file mode 100644
index 000000000000..b16c2c910195
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf166201_simplePosCM.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
index 6675428407b9..c58845529817 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
@@ -58,6 +58,19 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf166201_simplePos)
                          getProperty<sal_Int32>(getShape(1), 
u"HoriOrientPosition"_ustr));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf166201_simplePosCM)
+{
+    // Given a document with an image at the bottom-right placed there by 
simplePos - in cm
+
+    loadAndSave("tdf166201_simplePosCM.docx");
+
+    CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PAGE_FRAME,
+                         getProperty<sal_Int16>(getShape(1), 
u"VertOrientRelation"_ustr));
+    // Without the fix, this was 0 - at the top left, instead of 5cm - at the 
bottom right
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(5001),
+                         getProperty<sal_Int32>(getShape(1), 
u"VertOrientPosition"_ustr));
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf165492_exactWithBottomSpacing)
 {
     // Given a document with "exact row height" of 2cm
diff --git a/sw/source/writerfilter/ooxml/OOXMLFactory.cxx 
b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
index 0d9185ef9601..9d305a07c43e 100644
--- a/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
+++ b/sw/source/writerfilter/ooxml/OOXMLFactory.cxx
@@ -73,6 +73,9 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * 
pHandler,
         case ResourceType::HexColor:
             xValue = 
OOXMLValue::createHexColor(rAttribs.getAsViewByIndex(nAttrIndex));
             break;
+        case ResourceType::EmuMeasure:
+            xValue = 
OOXMLValue::createEmuMeasure(rAttribs.getAsViewByIndex(nAttrIndex));
+            break;
         case ResourceType::TwipsMeasure_asSigned:
         case ResourceType::TwipsMeasure_asZero:
             xValue = 
OOXMLValue::createTwipsMeasure(rAttribs.getAsViewByIndex(nAttrIndex));
diff --git a/sw/source/writerfilter/ooxml/OOXMLFactory.hxx 
b/sw/source/writerfilter/ooxml/OOXMLFactory.hxx
index 9d55d919c5f9..1b0077af6e42 100644
--- a/sw/source/writerfilter/ooxml/OOXMLFactory.hxx
+++ b/sw/source/writerfilter/ooxml/OOXMLFactory.hxx
@@ -46,6 +46,7 @@ enum class ResourceType {
     PropertyTable,
     Math,
     Any,
+    EmuMeasure,
     TwipsMeasure_asSigned,
     TwipsMeasure_asZero,
     HpsMeasure,
diff --git a/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx 
b/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx
index dcd51e0c2186..1fea27645e40 100644
--- a/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx
+++ b/sw/source/writerfilter/ooxml/OOXMLPropertySet.cxx
@@ -468,6 +468,12 @@ OOXMLValue 
OOXMLValue::createUniversalMeasure(std::string_view pValue, sal_uInt3
     return OOXMLValue(VariantType(std::in_place_index_t<3>(), nValue));
 }
 
+// static
+OOXMLValue OOXMLValue::createEmuMeasure(std::string_view pValue)
+{
+    return createUniversalMeasure(pValue, 12700); // 12,700 English Metric 
Units (EMU) = 1 pt
+}
+
 // static
 OOXMLValue OOXMLValue::createTwipsMeasure(std::string_view pValue)
 {
diff --git a/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx 
b/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx
index c23d57ed8c71..f856a03a23f7 100644
--- a/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx
+++ b/sw/source/writerfilter/ooxml/OOXMLPropertySet.hxx
@@ -38,6 +38,8 @@ public:
     static OOXMLValue createBoolean(std::string_view);
     static OOXMLValue createInteger(int);
     static OOXMLValue createUniversalMeasure(std::string_view pValue, 
sal_uInt32 npPt);
+    /// Handles OOXML's ST_Coordinate value.
+    static OOXMLValue createEmuMeasure(std::string_view);
     /// Handles OOXML's ST_TwipsMeasure value.
     static OOXMLValue createTwipsMeasure(std::string_view);
     /// Handles OOXML's ST_HpsMeasure value.
diff --git a/sw/source/writerfilter/ooxml/factoryimpl.py 
b/sw/source/writerfilter/ooxml/factoryimpl.py
index 40618b95faca..f88e48b094c2 100644
--- a/sw/source/writerfilter/ooxml/factoryimpl.py
+++ b/sw/source/writerfilter/ooxml/factoryimpl.py
@@ -38,6 +38,7 @@ def createFastChildContextFromFactory(model):
             {""")
     resources = [
         "List", "Integer", "Hex", "HexColor", "String",
+        "EmuMeasure",
         "TwipsMeasure_asSigned", "TwipsMeasure_asZero",
         "HpsMeasure", "Boolean", "MeasurementOrPercent",
     ]
diff --git a/sw/source/writerfilter/ooxml/model.xml 
b/sw/source/writerfilter/ooxml/model.xml
index 2c4d3f1e510d..52ee1dadfbbd 100644
--- a/sw/source/writerfilter/ooxml/model.xml
+++ b/sw/source/writerfilter/ooxml/model.xml
@@ -3498,7 +3498,7 @@
     <resource name="adec_decorative_val" resource="Properties">
       <attribute name="val" tokenid="ooxml:OfficeArtExtension_Decorative_val"/>
     </resource>
-    <resource name="ST_Coordinate" resource="Integer"/>
+    <resource name="ST_Coordinate" resource="EmuMeasure"/>
     <resource name="ST_PositiveCoordinate" resource="Integer"/>
     <resource name="ST_Angle" resource="Integer"/>
     <resource name="CT_Angle" resource="Value">

Reply via email to