From d7827f712ddd21a6c1e151f54dc6eba5c12690da Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 13 Jul 2022 16:11:29 +0200 Subject: tdf#149978 sw: ODF import: fix nondeterministic automatic styles The problem is that in SwpHints::TryInsertHint() there is a check for IsInXMLImport() that is presumably an optimization to avoid the potentially expensive call to BuildPortions(). While LO would only produce 1 text:span referencing an automatic style around any given character content, this is not required by ODF, and so other producers may legitimately produce such nested text:span elements. Unfortunately the current SwpHints::Insert() isn't deterministic, the RES_TXTATR_AUTOFMT with same start/end will be compared by address in CompareSwpHtStart() (whereas RES_TXTATR_CHARFMT has a sort number for this), so the result is going to be a random order. Change-Id: Id62a7ff5fb85dbe42b7e1a27b0d8b36b74cf1100 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137033 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/qa/extras/odfimport/data/tdf149978.fodt | 53 ++++++++++++++++++++++++++++++ sw/qa/extras/odfimport/odfimport.cxx | 12 +++++++ sw/source/core/txtnode/thints.cxx | 9 +++-- 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 sw/qa/extras/odfimport/data/tdf149978.fodt (limited to 'sw') diff --git a/sw/qa/extras/odfimport/data/tdf149978.fodt b/sw/qa/extras/odfimport/data/tdf149978.fodt new file mode 100644 index 000000000000..5c4840c258fc --- /dev/null +++ b/sw/qa/extras/odfimport/data/tdf149978.fodt @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + foo bar baz + + + + diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index d0235dfbd88d..c46061a5f30c 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -371,6 +371,18 @@ CPPUNIT_TEST_FIXTURE(Test, testDateFormFormats) } } +CPPUNIT_TEST_FIXTURE(Test, testTdf149978) +{ + load(mpTestDocumentPath, "tdf149978.fodt"); + // on Linux the bug only reproduces if a document has been loaded previously + load(mpTestDocumentPath, "tdf149978.fodt"); + // this was nondeterministic so try 10 times + for (int i = 1; i <= 10; ++i) + { + CPPUNIT_ASSERT_EQUAL(COL_WHITE, getProperty(getRun(getParagraph(i), 2, "bar"), "CharBackColor")); + } +} + CPPUNIT_TEST_FIXTURE(Test, testTdf64038) { load(mpTestDocumentPath, "space.odt"); diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 939f483a8662..f14c7d5ea5ed 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -3296,13 +3296,12 @@ bool SwpHints::TryInsertHint( { // There may be more than one character style at the current position. // Take care of the sort number. - // Special case ruby portion: During import, the ruby attribute is set - // multiple times - // Special case hyperlink: During import, the ruby attribute is set - // multiple times // FME 2007-11-08 #i82989# in NOHINTADJUST mode, we want to insert // character attributes directly - if ( RES_TXTATR_CHARFMT == nWhich && !bNoHintAdjustMode ) + if (!bNoHintAdjustMode + && ( (RES_TXTATR_CHARFMT == nWhich) + // tdf#149978 also for import of automatic styles, could be produced by non-LO application + || (RES_TXTATR_AUTOFMT == nWhich && rNode.GetDoc().IsInXMLImport()))) { BuildPortions( rNode, *pHint, nMode ); } -- cgit