summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <jluth@mail.com>2024-08-24 16:50:06 -0400
committerMiklos Vajna <vmiklos@collabora.com>2024-08-26 11:54:13 +0200
commitc8e272734a8fa26d93b057d1c9def8dc6c401143 (patch)
tree9a1cc17feef0d974c725fc51efbab23df559a453
parent1cf86074147e89da880d539055b1804ca135b679 (diff)
tdf#162612 mso import NOT-layoutInCell: effectively are wrap-through
The way Microsoft implements the layout of in-table-anchored shapes that are NOT marked as layoutInCell is to treat them all as wrap-through. So, lets explicitly mark them as they ought to be during import. tdf154863-img-move-crash.docx is a fine example of this, although the document itself is ugly and too complex for a unit test. make CppunitTest_sw_ooxmlexport21 CPPUNIT_TEST_NAME=testTdf162612 make CppunitTest_sw_ww8export4 CPPUNIT_TEST_NAME=testTdf162541 There is a SLIGHT danger here, as shown by testTdf162541. LO looks VERY different from Microsoft's VERY WEIRD LAYOUT, but will "correct" it with a round-trip. I'm not too concerned - LO is exporting the document the way it sees it. Change-Id: I14d8ea9dcef257a3239a9601b63c04cde780cb33 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172364 Reviewed-by: Justin Luth <jluth@mail.com> Tested-by: Jenkins
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf162612_notLayoutInCell_notWrapThrough_contourOpaque.docxbin0 -> 35416 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport21.cxx21
-rw-r--r--sw/qa/extras/ww8export/ww8export4.cxx7
-rw-r--r--sw/source/filter/ww8/ww8graf.cxx11
-rw-r--r--sw/source/writerfilter/dmapper/GraphicImport.cxx7
5 files changed, 46 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf162612_notLayoutInCell_notWrapThrough_contourOpaque.docx b/sw/qa/extras/ooxmlexport/data/tdf162612_notLayoutInCell_notWrapThrough_contourOpaque.docx
new file mode 100644
index 000000000000..dae6163b2af3
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf162612_notLayoutInCell_notWrapThrough_contourOpaque.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index f07c93a04e0e..32892540e734 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -14,6 +14,7 @@
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
+#include <com/sun/star/text/WrapTextMode.hpp>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
@@ -724,6 +725,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf162551, "tdf162551_notLayoutInCell_charLeft_from
CPPUNIT_ASSERT(getProperty<bool>(getShape(1), u"IsFollowingTextFlow"_ustr));
}
+DECLARE_OOXMLEXPORT_TEST(testTdf162612,
+ "tdf162612_notLayoutInCell_notWrapThrough_contourOpaque.docx")
+{
+ // given cell B2 with a centered, tight-wrapped image that is NOT layoutInCell
+ // (but Microsoft doesn't wrap any text around it)
+ xmlDocUniquePtr pDump = parseLayoutDump();
+ CPPUNIT_ASSERT_EQUAL(OUString("-anchor point-"),
+ getXPathContent(pDump, "//tab/row[2]/cell[2]/txt"_ostr));
+ sal_Int32 nParaHeight
+ = getXPath(pDump, "//tab/row[2]/cell[2]/txt/infos/bounds"_ostr, "height"_ostr).toInt32();
+ // text should not wrap as two lines(552) beside the shape. It is one line(276) behind the shape
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(276), nParaHeight);
+
+ // the image is over top of the text
+ CPPUNIT_ASSERT(getProperty<bool>(getShape(1), u"Opaque"_ustr));
+ // image should be wrapThrough, not PARALLEL (despite being wp:wrapTight wrapText="bothSides")
+ CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH,
+ getProperty<text::WrapTextMode>(getShape(1), u"Surround"_ustr));
+}
+
CPPUNIT_TEST_FIXTURE(Test, testTdf159207_footerFramePrBorder)
{
loadFromFile(u"tdf159207_footerFramePrBorder.docx"); // re-imports as editeng Frame/Shape
diff --git a/sw/qa/extras/ww8export/ww8export4.cxx b/sw/qa/extras/ww8export/ww8export4.cxx
index 007e7f70cac4..084eb178af6a 100644
--- a/sw/qa/extras/ww8export/ww8export4.cxx
+++ b/sw/qa/extras/ww8export/ww8export4.cxx
@@ -209,6 +209,13 @@ DECLARE_WW8EXPORT_TEST(testTdf162541, "tdf162541_notLayoutInCell_paraLeft.doc")
CPPUNIT_ASSERT(nShapeLeft < nParaLeft); // shape is located in column A, not column B
CPPUNIT_ASSERT_EQUAL(nTableLeft, nShapeLeft);
CPPUNIT_ASSERT(!getProperty<bool>(getShape(1), u"IsFollowingTextFlow"_ustr));
+
+ // tdf#162612
+ // Note that this round-trip will "fix" the weird splitting table around the image...
+
+ // image should be wrapThrough, not PARALLEL (despite being wrapTight on largest side)
+ CPPUNIT_ASSERT_EQUAL(text::WrapTextMode_THROUGH,
+ getProperty<text::WrapTextMode>(getShape(1), u"Surround"_ustr));
}
DECLARE_WW8EXPORT_TEST(testTdf162542, "tdf162542_notLayoutInCell_charLeft_wrapThrough.doc")
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 9724ee3709d3..9f7a69426c8f 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -2431,6 +2431,16 @@ RndStdIds SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec& rRecord, WW8_FS
bIsObjectLayoutInTableCell = true;
rFlySet.Put(SwFormatFollowTextFlow(true));
}
+
+ // Microsoft strangely ignores all wrapping for not-layoutInCell objects
+ const SfxPoolItem* pItem;
+ if (SfxItemState::SET == rFlySet.GetItemState(RES_SURROUND, false, &pItem))
+ {
+ const text::WrapTextMode eSurround
+ = static_cast<const SwFormatSurround*>(pItem)->GetSurround();
+ if (eSurround != text::WrapTextMode_THROUGH)
+ rFlySet.Put(SwFormatSurround(text::WrapTextMode_THROUGH));
+ }
}
// If the image is inline, then the relative orientation means nothing,
@@ -2859,6 +2869,7 @@ SwFrameFormat* SwWW8ImplReader::Read_GrafLayer( tools::Long nGrafAnchorCp )
aFSFA.nby = WW8_FSPA::RelPageBorder;
}
+ // this might also adjust previously set RES_SURROUND and RES_FOLLOW_TEXT_FLOW
RndStdIds eAnchor = ProcessEscherAlign(*pRecord, aFSFA, aFlySet);
// Should we, and is it possible to make this into a writer textbox
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx b/sw/source/writerfilter/dmapper/GraphicImport.cxx
index 396508332e51..90f717a5ac93 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx
@@ -871,6 +871,13 @@ void GraphicImport::lcl_attribute(Id nName, const Value& rValue)
{
m_pImpl->m_nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA;
}
+
+ // Microsoft strangely ignores all wrapping for not-layoutInCell objects
+ if (m_pImpl->m_nWrap != text::WrapTextMode_THROUGH
+ && m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
+ {
+ m_pImpl->m_nWrap = text::WrapTextMode_THROUGH;
+ }
}
// Is it a graphic image
bool bUseShape = true;