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(-)

New commits:
commit 7a8f2c7e3a16dae6bdc891fb969e673527e45615
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Jul 13 16:11:29 2022 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Jul 14 23:04:18 2022 +0200

    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 <michael.st...@allotropia.de>
    (cherry picked from commit d7827f712ddd21a6c1e151f54dc6eba5c12690da)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137057
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

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 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns
 :config:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="ur
 n:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:xforms="http://www.w3.org/2002/xforms"; office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.text">
+    <office:font-face-decls>
+      <style:font-face style:font-family-generic="roman" 
style:font-pitch="variable" style:name="Times New Roman" 
svg:font-family="'Times New Roman'"/>
+      <style:font-face style:font-family-generic="system" 
style:font-pitch="variable" style:name="Lucida Sans Unicode" 
svg:font-family="'Lucida Sans Unicode'"/>
+      <style:font-face style:font-family-generic="system" 
style:font-pitch="variable" style:name="Tahoma" svg:font-family="Tahoma"/>
+    </office:font-face-decls>
+    <office:styles>
+      <style:default-style style:family="paragraph">
+        <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
style:line-break="strict" style:punctuation-wrap="hanging" 
style:tab-stop-distance="1.251cm" style:text-autospace="ideograph-alpha" 
style:writing-mode="page"/>
+        <style:text-properties fo:country="DE" fo:font-size="12pt" 
fo:hyphenate="false" fo:hyphenation-push-char-count="2" 
fo:hyphenation-remain-char-count="2" fo:language="de" 
style:country-asian="none" style:country-complex="none" style:font-name="Times 
New Roman" style:font-name-asian="Lucida Sans Unicode" 
style:font-name-complex="Tahoma" style:font-size-asian="12pt" 
style:font-size-complex="12pt" style:language-asian="zxx" 
style:language-complex="zxx" style:letter-kerning="true" 
style:use-window-font-color="true"/>
+      </style:default-style>
+    </office:styles>
+
+    <office:automatic-styles>
+      <style:style style:family="text" style:name="A25" 
style:parent-style-name="">
+        <style:text-properties fo:background-color="#d3d3d3"/>
+      </style:style>
+      <style:style style:family="text" style:name="A26" 
style:parent-style-name="">
+        <style:text-properties fo:background-color="inherit" 
fo:color="inherit"/>
+      </style:style>
+
+        <style:page-layout style:name="pm1">
+            <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:footnote-max-height="0cm" loext:margin-gutter="0cm">
+                <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+            </style:page-layout-properties>
+            <style:header-style/>
+            <style:footer-style/>
+        </style:page-layout>
+        <style:style style:name="dp1" style:family="drawing-page">
+            <style:drawing-page-properties draw:background-size="full"/>
+        </style:style>
+    </office:automatic-styles>
+    <office:master-styles>
+        <style:master-page style:name="Standard" style:page-layout-name="pm1" 
draw:style-name="dp1"/>
+    </office:master-styles>
+    <office:body>
+        <office:text>
+
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+           <text:p>foo <text:span text:style-name="A25"><text:span 
text:style-name="A26">bar</text:span></text:span> baz</text:p>
+
+        </office:text>
+    </office:body>
+</office:document>
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 9c177f981aa4..b6f242601f5f 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<Color>(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 c7418514d31e..a9fc7920fda2 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -3246,13 +3246,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 );
         }

Reply via email to