sw/qa/extras/ooxmlexport/data/tdf162541_notLayoutInCell_paraLeft.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 27 ++++++++++ sw/source/writerfilter/dmapper/GraphicImport.cxx | 16 +++++ 3 files changed, 42 insertions(+), 1 deletion(-)
New commits: commit a8125cd58309dfec84ea9d3de749fadb0f0505f8 Author: Justin Luth <jl...@mail.com> AuthorDate: Thu Aug 22 19:08:33 2024 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Sat Aug 24 14:37:17 2024 +0200 tdf#162541 docx import NOT-layoutInCell: hori-para => PAGE_PRINT_AREA This was copied from DOC import. Since compat15 is always layoutInCell, the impact for DOCX is minimal. If the fly is not layoutInCell, then MSO applies the para-orientation against the paragraph that contains the entire table, not the cell paragraph it is anchored to. For the horizontal case, this table-paragraph is equivalent to the page margin, so change it to a meaningful value. The vertical case cannot be meaningfully mapped to an equivalent, so someone will need to implement that in layout code. Wrap through has NOTHING to do with this. make CppunitTest_sw_ooxmlexport21 CPPUNIT_TEST_NAME=testTdf162541 Change-Id: I17b28f9d77cd85b4104e8c8f0c347e61b6c8f5a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172297 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf162541_notLayoutInCell_paraLeft.docx b/sw/qa/extras/ooxmlexport/data/tdf162541_notLayoutInCell_paraLeft.docx new file mode 100644 index 000000000000..765c87cd1519 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf162541_notLayoutInCell_paraLeft.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index a7c46b536f95..f07c93a04e0e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -676,6 +676,33 @@ DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, "tdf153909_followTextFlow CPPUNIT_ASSERT(nTableLeft > nRectLeft); } +DECLARE_OOXMLEXPORT_TEST(testTdf162541, "tdf162541_notLayoutInCell_paraLeft.docx") +{ + // given cell B2 with a para-left para-fromTop image that is NOT layoutInCell + xmlDocUniquePtr pDump = parseLayoutDump(); + sal_Int32 nShapeLeft + = getXPath(pDump, "//tab/row[2]/cell[2]/txt[8]/anchored/fly/SwAnchoredObject/bounds"_ostr, + "left"_ostr) + .toInt32(); + sal_Int32 nParaLeft + = getXPath(pDump, "//tab/row[2]/cell[2]/txt[8]/infos/bounds"_ostr, "left"_ostr).toInt32(); + sal_Int32 nTableLeft = getXPath(pDump, "//tab/infos/bounds"_ostr, "left"_ostr).toInt32(); + // The image uses the table-paragraph to orient to the left (bizarre MSO layout anomaly) + CPPUNIT_ASSERT(nShapeLeft < nParaLeft); // shape is located in column A, not column B + CPPUNIT_ASSERT_EQUAL(nTableLeft, nShapeLeft); + + // sal_Int32 nShapeBottom + // = getXPath(pDump, "//tab/row[2]/cell[2]/txt[8]/anchored/fly/SwAnchoredObject/bounds"_ostr, + // "bottom"_ostr) + // .toInt32(); + // sal_Int32 nPara8Top + // = getXPath(pDump, "//tab/row[2]/cell[2]/txt[8]/infos/bounds"_ostr, "top"_ostr).toInt32(); + // The image uses the table-paragraph to orient to the left (bizarre MSO layout anomaly) + // CPPUNIT_ASSERT(nShapeBottom < nPara8Top); // shape is located at the top of the table para // tdf#133522 + + CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), u"IsFollowingTextFlow"_ustr)); +} + DECLARE_OOXMLEXPORT_TEST(testTdf162551, "tdf162551_notLayoutInCell_charLeft_fromTop.docx") { // given cell B2 with a para-fromTop, char-left image that is NOT layoutInCell diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx b/sw/source/writerfilter/dmapper/GraphicImport.cxx index e7332d1245a8..396508332e51 100644 --- a/sw/source/writerfilter/dmapper/GraphicImport.cxx +++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx @@ -857,7 +857,21 @@ void GraphicImport::lcl_attribute(Id nName, const Value& rValue) if (m_pImpl->m_nVertOrient != text::VertOrientation::NONE) m_pImpl->m_nVertOrient = text::VertOrientation::TOP; } - + else if (!m_pImpl->m_bLayoutInCell && m_pImpl->m_rDomainMapper.IsInTable()) + { + // if the object is horizontally aligned to the paragraph, + // Microsoft strangely doesn't orient the object + // to the cell paragraph it is anchored to + // but to the paragraph that contains the entire table + // (which is equivalent to page margins). + // Amazingly, a VERT orientation to "line" can pin the horizontal alignment + // back to the cell paragraph. + if (m_pImpl->m_nHoriRelation == text::RelOrientation::FRAME + && m_pImpl->m_nVertRelation != text::RelOrientation::TEXT_LINE) + { + m_pImpl->m_nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA; + } + } // Is it a graphic image bool bUseShape = true; try