sw/qa/extras/ooxmlexport/data/tdf166201_simplePos.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport22.cxx             |   13 +++++++++++++
 sw/source/writerfilter/dmapper/GraphicImport.cxx       |    4 ++--
 3 files changed, 15 insertions(+), 2 deletions(-)

New commits:
commit 356f916d0e7dbab7f871c3feb19c6e1292c2a2f5
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Apr 15 18:30:12 2025 -0400
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Wed Apr 16 01:55:31 2025 +0200

    tdf#166201 docx import: simplePos is defined in EMUs, not TWIPs
    
    The normal values of simplePos are usually larger than
    ConversionHelper::convertTwipToMm100_Limited allows,
    so it typically returned 0,
    so usually the anchor was positioned at the top left of the page.
    
    There were no existing unit tests with non-zero simplePos.
    
    Although LN_CT_Point2D_x sounds very generic,
    commit history suggests that it has only been used for simplePos.
       (handle wp:simplePos properly)
    I also checked model.xml, and didn't notice anything else
    actually being imported that could share it.
    Based on the documentation, they all would also be defined
    in EMUs or "Universal Measurement".
    
    make CppunitTest_sw_ooxmlexport22 \
        CPPUNIT_TEST_NAME=testTdf166201_simplePos
    
    Change-Id: I65f49408262c8f68107fa1614f70ff2f8365e5c6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184244
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/tdf166201_simplePos.docx 
b/sw/qa/extras/ooxmlexport/data/tdf166201_simplePos.docx
new file mode 100644
index 000000000000..76f243a97189
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf166201_simplePos.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
index f6db65e8ca1e..6675428407b9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
@@ -45,6 +45,19 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf165642_glossaryFootnote)
     parseExport(u"word/glossary/footnotes.xml"_ustr);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf166201_simplePos)
+{
+    // Given a document with an image at the bottom-right placed there by 
simplePos
+
+    loadAndSave("tdf166201_simplePos.docx");
+
+    CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PAGE_FRAME,
+                         getProperty<sal_Int16>(getShape(1), 
u"HoriOrientRelation"_ustr));
+    // Without the fix, this was 0 - at the top left, instead of 10.5cm - at 
the bottom right
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(10478),
+                         getProperty<sal_Int32>(getShape(1), 
u"HoriOrientPosition"_ustr));
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf165492_exactWithBottomSpacing)
 {
     // Given a document with "exact row height" of 2cm
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx 
b/sw/source/writerfilter/dmapper/GraphicImport.cxx
index a9f6a48428b4..d7768ff5eed2 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx
@@ -795,12 +795,12 @@ void GraphicImport::lcl_attribute(Id nName, const Value& 
rValue)
         }
         break;
         case NS_ooxml::LN_CT_Point2D_x:
-            m_pImpl->m_nLeftPosition = 
ConversionHelper::convertTwipToMm100_Limited(nIntValue);
+            m_pImpl->m_nLeftPosition = 
oox::drawingml::convertEmuToHmm(nIntValue);
             m_pImpl->m_nHoriRelation = text::RelOrientation::PAGE_FRAME;
             m_pImpl->m_nHoriOrient = text::HoriOrientation::NONE;
         break;
         case NS_ooxml::LN_CT_Point2D_y:
-            m_pImpl->m_nTopPosition = 
ConversionHelper::convertTwipToMm100_Limited(nIntValue);
+            m_pImpl->m_nTopPosition = 
oox::drawingml::convertEmuToHmm(nIntValue);
             m_pImpl->m_nVertRelation = text::RelOrientation::PAGE_FRAME;
             m_pImpl->m_nVertOrient = text::VertOrientation::NONE;
         break;

Reply via email to