From 60c96b4c3e79910cd98af0b764430e889bdd5e51 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. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137033 Tested-by: Jenkins Reviewed-by: Michael Stahl (cherry picked from commit d7827f712ddd21a6c1e151f54dc6eba5c12690da) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137057 Reviewed-by: Thorsten Behrens (cherry picked from commit 7a8f2c7e3a16dae6bdc891fb969e673527e45615) Change-Id: Id62a7ff5fb85dbe42b7e1a27b0d8b36b74cf1100 --- 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 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 703de09ef7f7..fb5441da5254 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -255,6 +255,18 @@ DECLARE_ODFIMPORT_TEST(testPageStyleLayoutDefault, "hello.odt") CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL, getProperty(xPropertySet, "PageStyleLayout")); } +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")); + } +} + DECLARE_ODFIMPORT_TEST(testTdf64038, "space.odt") { // no space diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 3d55ed251f2b..fcb2fe20c0ba 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -3241,13 +3241,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