sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 12 ++++++++++-- writerfilter/source/dmapper/GraphicImport.cxx | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
New commits: commit eacf8dc7ab850f2d00bd4b327f830c55cf2a0d92 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Tue Mar 5 19:22:34 2024 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Mar 6 11:23:59 2024 +0100 tdf#160049 dml import: use margins with left/right HoriOrientRelation I'm really surprised this wasn't found much earlier. Even DOC format isn't handling this. compat15 gets rid of this inconsistency. Surprisingly, there were no interesting unit tests matching this. make CppunitTest_sw_ooxmlexport21 \ CPPUNIT_TEST_NAME=testTdf160049_anchorMarginVML make CppunitTest_sw_ooxmlexport21 \ CPPUNIT_TEST_NAME=testTdf160049_anchorMargin15 Change-Id: Ic5c316569ad3640ba0e786d39a6e5c006c74d665 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164443 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx new file mode 100755 index 000000000000..0b80c9652fbe Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index d045e18efa32..8bae715cf4de 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -297,14 +297,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, "tdf160049_anchorMarginV { // given a VML (Word 2003) document with a LEFT "column/text" anchored image // (which will import as DML compat12 on the round-trip) - if (isExported()) - return; + // The image takes into account the margin, so it looks like it is in the middle of the doc, // which is "Paragraph text area"/PRINT_AREA/1, not "Entire paragraph area"/FRAME/0 CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PRINT_AREA, getProperty<sal_Int16>(getShape(1), "HoriOrientRelation")); } +DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMargin15, "tdf160049_anchorMargin15.docx") +{ + // given a DML compat15 (Word 2013) document with a LEFT "column/text" anchored image + + // The image ignores the margin, so it is at the left for compat15 (but middle-ish for compat14) + CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::FRAME, + getProperty<sal_Int16>(getShape(1), "HoriOrientRelation")); +} + DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, "tdf153909_followTextFlow.docx") { // Although MSO's UI reports "layoutInCell" for the rectangle, it isn't specified or honored diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index a2acdeb604cc..fb34152cda6f 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -1839,6 +1839,16 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer sal_Int32 nWidth = - m_pImpl->m_nLeftPosition; if (m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) { + if (m_pImpl->m_nHoriRelation == text::RelOrientation::FRAME + && m_pImpl->m_nHoriOrient > text::HoriOrientation::NONE + && m_pImpl->m_nHoriOrient != text::HoriOrientation::CENTER + && m_pImpl->m_nHoriOrient < text::HoriOrientation::FULL) + { + // before compat15, relative left/right/inside/outside honored margins. + if (m_pImpl->m_rDomainMapper.GetSettingsTable()->GetWordCompatibilityMode() < 15) + m_pImpl->m_nHoriRelation = text::RelOrientation::PRINT_AREA; + } + //adjust margins if( (m_pImpl->m_nHoriOrient == text::HoriOrientation::LEFT && (m_pImpl->m_nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA ||