sw/qa/extras/ooxmlexport/data/tdf160077_layoutInCell.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 27 ++++++++++++++ writerfilter/source/dmapper/GraphicImport.cxx | 13 ++++++ 3 files changed, 40 insertions(+)
New commits: commit d210667c72ff821b8cb50b386a83ed55d65ae9bf Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Wed Mar 6 18:56:55 2024 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Mar 8 10:59:36 2024 +0100 tdf#160077 writerfilter: shape vertRelation is FRAME for layoutinCell When layoutInCell is active, then the offset must be applied against the paragraph instead of the page or page margins. There were only two unit tests that matched this, and both were off-sheet positioned. -tdf151704_thinColumnHeight.docx -tdf92157.docx make CppunitTest_sw_ooxmlexport21 \ CPPUNIT_TEST_NAME=testTdf160077_layoutInCell Change-Id: I28241136c0c0be12d3f2dd876550ecdf91b0009c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164514 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/tdf160077_layoutInCell.docx b/sw/qa/extras/ooxmlexport/data/tdf160077_layoutInCell.docx new file mode 100644 index 000000000000..811fc47e184c Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf160077_layoutInCell.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index fcb2eea321c9..5e320bb6d743 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -354,6 +354,33 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMargin15, "tdf160049_anchorMargin15 getProperty<sal_Int16>(getShape(1), "HoriOrientRelation")); } +DECLARE_OOXMLEXPORT_TEST(testTdf160077_layoutInCell, "tdf160077_layoutInCell.docx") +{ + // given an in-table, slightly rotated image vertically aligned -1cm (above) the top page margin + // (which is actually forced to layoutInCell, so that becomes 1cm above the paragraph instead) + + xmlDocUniquePtr pDump = parseLayoutDump(); + const sal_Int32 nCellTop + = getXPath(pDump, "//row[1]/cell[1]/infos/bounds"_ostr, "top"_ostr).toInt32(); + const sal_Int32 nParaTop + = getXPath(pDump, "//row[1]/cell[1]/txt/infos/bounds"_ostr, "top"_ostr).toInt32(); + const sal_Int32 nImageTop + = getXPath(pDump, "//row[1]/cell[1]/txt/anchored/SwAnchoredDrawObject/bounds"_ostr, + "top"_ostr) + .toInt32(); + // The image is approximately half-way between cell top and the start of the text + // correct ImageTop: 3588, while incorrect value was 1117. Cell top is 3051, ParaTop is 4195 + const sal_Int32 nHalfway = nCellTop + (nParaTop - nCellTop) / 2; + CPPUNIT_ASSERT_DOUBLES_EQUAL(nHalfway, nImageTop, 50); // +/- 4.4% + + // The effect is implemented by forcing "Entire paragraph area"/FRAME/0 + // instead of "Page text area"/PAGE_PRINT_AREA/8 + CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::FRAME, + getProperty<sal_Int16>(getShape(1), "VertOrientRelation")); + // since layoutInCell had been turned off. If the implementation changes, check the layout. + CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), "IsFollowingTextFlow")); +} + 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 b7d5f101f417..6ee808355a60 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -1285,6 +1285,19 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) if (m_pImpl->m_nWrap == text::WrapTextMode_THROUGH && m_pImpl->m_nHoriRelation == text::RelOrientation::FRAME) { + if (m_pImpl->m_bLayoutInCell && m_pImpl->m_rDomainMapper.IsInTable() + && (m_pImpl->m_nVertRelation == text::RelOrientation::PAGE_FRAME + || m_pImpl->m_nVertRelation == text::RelOrientation::PAGE_PRINT_AREA)) + { + // Impossible to be page-oriented when layout in cell. + // Since we are turning LayoutInCell off (to simplify layout), + // we need to set the orientation to the paragraph, + // as MSO effectively does when it forces layoutInCell. + // Probably also needs to happen with TEXT_LINE, + // but MSO is really weird with vertical relation to "line" + m_pImpl->m_nVertRelation = text::RelOrientation::FRAME; + } + // text::RelOrientation::FRAME is OOXML's "column", which behaves as if // layout-in-cell would be always off. m_pImpl->m_bLayoutInCell = false;