include/xmloff/xmlimp.hxx                             |    2 
 sw/CppunitTest_sw_ooxmlexport26.mk                    |    3 
 sw/inc/doc.hxx                                        |    3 
 sw/qa/extras/ooxmlexport/data/tdf166850_24.2.7.2.fodt |  164 ++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx            |   10 -
 sw/qa/extras/ooxmlexport/ooxmlexport26.cxx            |   48 +++++
 sw/source/core/fields/reffld.cxx                      |   42 ++++
 sw/source/core/unocore/unofield.cxx                   |    3 
 sw/source/filter/basflt/shellio.cxx                   |    1 
 sw/source/filter/xml/xmlfmt.cxx                       |    8 
 sw/source/filter/xml/xmlimp.cxx                       |    1 
 sw/source/writerfilter/dmapper/StyleSheetTable.cxx    |   16 -
 sw/source/writerfilter/dmapper/StyleSheetTable.hxx    |    2 
 xmloff/qa/unit/uxmloff.cxx                            |    4 
 xmloff/source/core/xmlimp.cxx                         |   12 +
 15 files changed, 293 insertions(+), 26 deletions(-)

New commits:
commit 169050eab3700c3012c2b1583000a922442f153b
Author:     Michael Stahl <[email protected]>
AuthorDate: Thu Jun 5 16:45:50 2025 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Wed Jun 18 11:07:19 2025 +0200

    tdf#159549 tdf#166850 sw,xmloff: fix localised STYLEREF differently
    
    SwXTextField must for the "SourceName" property convert from ProgName to
    UIName on setting and reverse on getting, for consistency with the rest
    of the sw UNO services.
    
    This is annoyingly complicated because the "sPar1" of SwGetRefField is
    used for numerous other purposes, including a bookmark name.
    
    Revert writerfilter changes of commit 
80877c7dc467bf5ad6b28ec1b2662db36fcf7542
    but keep the test.
    
    With de_DE locale we now get "Überschrift 1 (user)" cloned style (same
    as the reverted fix), and exported to ODF as "Überschrift 1"; the ODT
    works when loaded both with the same and a different locale.
    
    Unfortuantely an ODT created by versions on the 24.2 branch >= 24.2.4,
    which used to work being loaded in the same locale but not in a
    different one, stops working when loaded in the same locale with this,
    so add an incredibly ugly flag to SwDoc because no SvXMLImport etc can
    be accessed from SwGetRefField.
    
    Move testTdf160402 to the new ooxmlexport26 because it also failed with
    de_DE locale.
    (regression from commit e45f187870362ed4448f4a9fb96883b8431887fb)
    
    Change-Id: I6b7862f142d602544165d8b5a254bf8af28e527b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186228
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit f5d48df7355ac7db3f3dd396eed1e7c57658ef7c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186626

diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 44a97ddb9c3f..11cd7c570737 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -553,6 +553,8 @@ public:
     static const sal_uInt16 LO_63x = 63 | LO_flag;
     static const sal_uInt16 LO_7x = 70 | LO_flag;
     static const sal_uInt16 LO_76 = 76 | LO_flag;
+    static const sal_uInt16 LO_242 = 80 | LO_flag;
+    static const sal_uInt16 LO_248 = 81 | LO_flag;
     static const sal_uInt16 LO_New = 100 | LO_flag;
     static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16;
 
diff --git a/sw/CppunitTest_sw_ooxmlexport26.mk 
b/sw/CppunitTest_sw_ooxmlexport26.mk
index 8b57467c2f61..2bb987dd2ce4 100644
--- a/sw/CppunitTest_sw_ooxmlexport26.mk
+++ b/sw/CppunitTest_sw_ooxmlexport26.mk
@@ -11,6 +11,9 @@
 
 $(eval $(call sw_ooxmlexport_test,26))
 
+# this test requires "de" translations and if missing tests will be skipped
+$(call gb_CppunitTest_get_target,sw_ooxmlexport26) : $(call 
gb_AllLangMoTarget_get_target,sw)
+
 $(call gb_CppunitTest_get_target,sw_ooxmlexport26) : export LO_TEST_LOCALE=de
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 3c26a31db62e..0c9a77bd3cac 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -319,6 +319,7 @@ private:
     bool mbInWriting : 1; //< TRUE: Document is in the process of being 
written.
     bool mbInMailMerge           : 1;    //< TRUE: Document is in the process 
of being written by mail merge.
     bool mbInXMLImport           : 1;    //< TRUE: During xml import, 
attribute portion building is not necessary.
+    bool mbInXMLImport242        : 1 = false; //< TRUE: During xml import, 
apply workaround for style-ref field
     bool mbInWriterfilterImport  : 1;    //< TRUE: writerfilter import 
(DOCX,RTF)
     bool mbUpdateTOX             : 1;    //< TRUE: After loading document, 
update TOX.
     bool mbInLoadAsynchron       : 1;    //< TRUE: Document is in the process 
of being loaded asynchronously.
@@ -989,6 +990,8 @@ public:
 
     bool IsInXMLImport() const { return mbInXMLImport; }
     void SetInXMLImport( bool bNew ) { mbInXMLImport = bNew; }
+    bool IsInXMLImport242() const { return mbInXMLImport242; }
+    void SetInXMLImport242(bool const bNew) { mbInXMLImport242 = bNew; }
     bool IsInWriterfilterImport() const { return mbInWriterfilterImport; }
     void SetInWriterfilterImport(bool const b) { mbInWriterfilterImport = b; }
 
diff --git a/sw/qa/extras/ooxmlexport/data/tdf166850_24.2.7.2.fodt 
b/sw/qa/extras/ooxmlexport/data/tdf166850_24.2.7.2.fodt
new file mode 100644
index 000000000000..a2308801c2db
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf166850_24.2.7.2.fodt
@@ -0,0 +1,164 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:op
 endocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><dc:date>2025-06-10T15:12:43.320595150</dc:date><meta:generator>LibreOffice/24.2.7.2$Linux_X86_64
 
LibreOffice_project/ee3885777aa7032db5a9b65deec9457448a91162</meta:generator></office:meta>
+ <office:font-face-decls>
+  <style:font-face style:name="Calibri" svg:font-family="Calibri" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Calibri Light" svg:font-family="'Calibri 
Light'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Calibri1" svg:font-family="Calibri" 
style:font-family-generic="system" style:font-pitch="variable"/>
+  <style:font-face style:name="F" svg:font-family="" 
style:font-family-generic="system" style:font-pitch="variable"/>
+  </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" loext:tab-stop-distance="0cm" 
style:writing-mode="lr-tb" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Calibri" fo:font-size="11pt" 
fo:language="de" fo:country="AT" style:letter-kerning="false" 
style:font-name-asian="Calibri1" style:font-size-asian="11pt" 
style:language-asian="en" style:country-asian="US" style:font-name-complex="F" 
style:font-size-complex="11pt" style:language-complex="ar" 
style:country-complex="SA"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" 
style:line-break="strict" style:tab-stop-distance="1.249cm" 
style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Calibri" fo:font-size="11pt" 
fo:language="de" fo:country="AT" style:letter-kerning="false" 
style:font-name-asian="Calibri1" style:font-size-asian="11pt" 
style:language-asian="en" style:country-asian="US" style:font-name-complex="F" 
style:font-size-complex="11pt" style:language-complex="ar" 
style:country-complex="SA" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" 
loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.353cm" 
style:contextual-spacing="false" fo:line-height="115%" fo:text-align="start" 
style:justify-single-word="false" fo:orphans="2" fo:widows="2" 
style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Heading_20_1" style:display-name="Heading 1" 
style:family="paragraph" style:parent-style-name="Standard" 
style:next-style-name="Standard" 
loext:linked-style-name="Überschrift_20_1_20_Zchn" 
style:default-outline-level="1" style:list-style-name="" style:class="text">
+   <style:paragraph-properties fo:margin-top="0.847cm" fo:margin-bottom="0cm" 
style:contextual-spacing="false" fo:keep-together="always" 
fo:keep-with-next="always"/>
+   <style:text-properties fo:color="#2e74b5" loext:opacity="100%" 
style:font-name="Calibri Light" fo:font-family="'Calibri Light'" 
style:font-family-generic="roman" style:font-pitch="variable" 
fo:font-size="14pt" fo:font-weight="bold" style:font-name-asian="F" 
style:font-family-generic-asian="system" style:font-pitch-asian="variable" 
style:font-size-asian="14pt" style:font-weight-asian="bold" 
style:font-name-complex="F" style:font-family-generic-complex="system" 
style:font-pitch-complex="variable" style:font-size-complex="14pt" 
style:font-weight-complex="bold">
+    <loext:char-complex-color loext:theme-type="accent1" 
loext:color-type="theme">
+     <loext:transformation loext:type="shade" loext:value="2509"/>
+    </loext:char-complex-color>
+   </style:text-properties>
+  </style:style>
+  <style:style style:name="Header" style:family="paragraph" 
style:parent-style-name="Standard" loext:linked-style-name="Kopfzeile_20_Zchn" 
style:class="extra">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" 
style:contextual-spacing="false" fo:line-height="100%">
+    <style:tab-stops>
+     <style:tab-stop style:position="8.001cm" style:type="center"/>
+     <style:tab-stop style:position="16.002cm" style:type="right"/>
+    </style:tab-stops>
+   </style:paragraph-properties>
+  </style:style>
+  <style:style style:name="ListLabel_20_1" style:display-name="ListLabel 1" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_2" style:display-name="ListLabel 2" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_3" style:display-name="ListLabel 3" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_4" style:display-name="ListLabel 4" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_5" style:display-name="ListLabel 5" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_6" style:display-name="ListLabel 6" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_7" style:display-name="ListLabel 7" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_8" style:display-name="ListLabel 8" 
style:family="text"/>
+  <style:style style:name="ListLabel_20_9" style:display-name="ListLabel 9" 
style:family="text"/>
+  <text:outline-style style:name="Outline">
+   <text:outline-level-style text:level="1" text:style-name="ListLabel_20_1" 
loext:num-list-format="%1%." style:num-suffix="." style:num-format="1">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-0.762cm" fo:margin-left="0.762cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="2" text:style-name="ListLabel_20_2" 
loext:num-list-format="%1%.%2%" style:num-format="1" text:display-levels="2">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-1.016cm" fo:margin-left="1.016cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="3" text:style-name="ListLabel_20_3" 
loext:num-list-format="%1%.%2%.%3%" style:num-format="1" 
text:display-levels="3">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-1.27cm" fo:margin-left="1.27cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="4" text:style-name="ListLabel_20_4" 
loext:num-list-format="%1%.%2%.%3%.%4%" style:num-format="1" 
text:display-levels="4">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-1.524cm" fo:margin-left="1.524cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="5" text:style-name="ListLabel_20_5" 
loext:num-list-format="%1%.%2%.%3%.%4%.%5%" style:num-format="1" 
text:display-levels="5">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-1.778cm" fo:margin-left="1.778cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="6" text:style-name="ListLabel_20_6" 
loext:num-list-format="%1%.%2%.%3%.%4%.%5%.%6%" style:num-format="1" 
text:display-levels="6">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-2.032cm" fo:margin-left="2.032cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="7" text:style-name="ListLabel_20_7" 
loext:num-list-format="%1%.%2%.%3%.%4%.%5%.%6%.%7%" style:num-format="1" 
text:display-levels="7">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-2.286cm" fo:margin-left="2.286cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="8" text:style-name="ListLabel_20_8" 
loext:num-list-format="%1%.%2%.%3%.%4%.%5%.%6%.%7%.%8%" style:num-format="1" 
text:display-levels="8">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-2.54cm" fo:margin-left="2.54cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="9" text:style-name="ListLabel_20_9" 
loext:num-list-format="%1%.%2%.%3%.%4%.%5%.%6%.%7%.%8%.%9%" 
style:num-format="1" text:display-levels="9">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
fo:text-indent="-2.794cm" fo:margin-left="2.794cm"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="10" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+  </text:outline-style>
+  <text:notes-configuration text:note-class="footnote" style:num-format="1" 
text:start-value="0" text:footnotes-position="page" 
text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" style:num-format="i" 
text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+  <style:default-page-layout>
+   <style:page-layout-properties style:layout-grid-standard-mode="true"/>
+  </style:default-page-layout>
+  </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P14" style:family="paragraph" 
style:parent-style-name="Heading_20_1">
+   <style:paragraph-properties fo:break-before="page"/>
+  </style:style>
+  <style:style style:name="P15" style:family="paragraph" 
style:parent-style-name="Heading_20_1" style:master-page-name="Converted2">
+   <style:paragraph-properties style:page-number="auto"/>
+  </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="1.249cm" fo:margin-bottom="1.249cm" fo:margin-left="2.499cm" 
fo:margin-right="2.499cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="41" 
style:layout-grid-base-height="0.635cm" style:layout-grid-ruby-height="0cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:layout-grid-base-width="0.423cm" style:layout-grid-snap-to="true" 
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:page-layout style:name="pm3">
+   <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="1.249cm" fo:margin-bottom="1.249cm" fo:margin-left="2.499cm" 
fo:margin-right="2.499cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="41" 
style:layout-grid-base-height="0.635cm" style:layout-grid-ruby-height="0cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:layout-grid-base-width="0.423cm" style:layout-grid-snap-to="true" 
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:header-footer-properties fo:min-height="0.252cm" 
fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.152cm" 
style:dynamic-spacing="true"/>
+   </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"/>
+  <style:master-page style:name="Converted2" style:page-layout-name="pm3" 
draw:style-name="dp1">
+   <style:header>
+    <text:p text:style-name="Header"><loext:style-ref 
text:reference-format="text" text:ref-name="Überschrift 1" 
loext:reference-from-bottom="true">Second heading</loext:style-ref></text:p>
+   </style:header>
+  </style:master-page>
+ </office:master-styles>
+ <office:body>
+  <office:text text:use-soft-page-breaks="true">
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" 
text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
+   </text:sequence-decls>
+   <text:h text:style-name="P15" text:outline-level="1"><text:bookmark-start 
text:name="_Toc160439093"/>First heading<text:bookmark-end 
text:name="_Toc160439093"/></text:h>
+   <text:h text:style-name="P14" text:outline-level="1"><text:bookmark-start 
text:name="_Toc160439094"/>Second heading<text:bookmark-end 
text:name="_Toc160439094"/></text:h>
+   <text:p text:style-name="Header"><loext:style-ref 
text:reference-format="text" text:ref-name="Überschrift 1" 
loext:reference-from-bottom="true">Second heading</loext:style-ref></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 95a755c3bb29..1e7e8ce727dc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -739,16 +739,6 @@ DECLARE_OOXMLEXPORT_TEST(testTdf153082_comma, 
"custom-styles-TOC-comma.docx")
     CPPUNIT_ASSERT(tocContent.indexOf("Pellentesque habitant morbi tristique 
senectus et netus et malesuada fames ac turpis egestas.") != -1);
 }
 
-DECLARE_OOXMLEXPORT_TEST(testTdf160402, "StyleRef-DE.docx")
-{
-    xmlDocUniquePtr pLayout = parseLayoutDump();
-    assertXPath(pLayout, 
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 
"expand", u"Heading 1");
-    assertXPath(pLayout, 
"/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 
"expand", u"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.");
-    assertXPath(pLayout, 
"/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 
"expand", u"Cras faucibus condimentum odio. Sed ac ligula. Aliquam at eros.");
-    assertXPath(pLayout, 
"/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 
"expand", u"Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.");
-    assertXPath(pLayout, 
"/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", 
"expand", u"Aenean nec lorem. In porttitor. Donec laoreet nonummy augue.");
-}
-
 DECLARE_OOXMLEXPORT_TEST(testTdf142407, "tdf142407.docx")
 {
     uno::Reference<container::XNameAccess> xPageStyles = 
getStyles(u"PageStyles"_ustr);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx
index 2346da8dc504..f40100534939 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport26.cxx
@@ -9,6 +9,10 @@
 
 #include <swmodeltestbase.hxx>
 
+#include <config_folders.h>
+#include <osl/process.h>
+#include <osl/file.hxx>
+
 #include <IDocumentLayoutAccess.hxx>
 #include <wrtsh.hxx>
 
@@ -23,6 +27,21 @@ public:
     }
 };
 
+DECLARE_OOXMLEXPORT_TEST(testTdf160402, "StyleRef-DE.docx")
+{
+    xmlDocUniquePtr pLayout = parseLayoutDump();
+    assertXPath(pLayout, 
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Heading 1");
+    assertXPath(pLayout, 
"/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Nunc viverra imperdiet enim. Fusce est. Vivamus a 
tellus.");
+    assertXPath(pLayout, 
"/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Cras faucibus condimentum odio. Sed ac ligula. 
Aliquam at eros.");
+    assertXPath(pLayout, 
"/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Nunc viverra imperdiet enim. Fusce est. Vivamus a 
tellus.");
+    assertXPath(pLayout, 
"/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Aenean nec lorem. In porttitor. Donec laoreet 
nonummy augue.");
+}
+
 //test requires German user interface otherwise it will not detect the issue
 CPPUNIT_TEST_FIXTURE(Test, testTdf166850)
 {
@@ -35,6 +54,35 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf166850)
                 "expand", u"Heading 1");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf166850_ODT)
+{
+    // test ODT import from version 24.2 where this worked
+    // but only in the same locale that was used to import from DOCX, not in
+    // a different one
+    OUString instdir;
+    osl_getEnvironment(u"INSTDIR"_ustr.pData, &instdir.pData);
+    OUString url;
+    CPPUNIT_ASSERT_EQUAL(::osl::FileBase::E_None,
+                         ::osl::FileBase::getFileURLFromSystemPath(instdir, 
url));
+    url += "/" LIBO_SHARE_RESOURCE_FOLDER "/de/LC_MESSAGES/sw.mo";
+    ::osl::DirectoryItem item;
+    if (::osl::DirectoryItem::get(url, item) == ::osl::FileBase::E_NOENT)
+    {
+        return;
+    }
+    createSwDoc("tdf166850_24.2.7.2.fodt");
+    SwDoc* pDoc = getSwDoc();
+    SwViewShell* pViewShell = 
pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
+    pViewShell->UpdateFields();
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, 
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"First heading");
+    assertXPath(pXmlDoc, 
"/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Second heading");
+    assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"Second heading");
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 20dccd31999e..c7392d889f52 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -962,6 +962,17 @@ bool SwGetRefField::QueryValue( uno::Any& rAny, sal_uInt16 
nWhichId ) const
                 break;
             }
         }
+        else if (REF_STYLE == m_nSubType)
+        {
+            ProgName name;
+            SwStyleNameMapper::FillProgName(UIName{sTmp}, name, 
SwGetPoolIdFromName::TxtColl);
+            if (name == sTmp)
+            {
+                SwStyleNameMapper::FillProgName(UIName{sTmp}, name, 
SwGetPoolIdFromName::ChrFmt);
+            }
+            sTmp = name.toString();
+
+        }
         rAny <<= sTmp;
     }
     break;
@@ -1025,7 +1036,13 @@ bool SwGetRefField::PutValue( const uno::Any& rAny, 
sal_uInt16 nWhichId )
             case ReferenceFieldSource::BOOKMARK       : m_nSubType = 
REF_BOOKMARK   ; break;
             case ReferenceFieldSource::FOOTNOTE       : m_nSubType = 
REF_FOOTNOTE   ; break;
             case ReferenceFieldSource::ENDNOTE        : m_nSubType = 
REF_ENDNOTE    ; break;
-            case ReferenceFieldSource::STYLE          : m_nSubType = REF_STYLE 
     ; break;
+            case ReferenceFieldSource::STYLE          :
+                if (REF_STYLE != m_nSubType)
+                {
+                    m_nSubType = REF_STYLE;
+                    ConvertProgrammaticToUIName();
+                }
+                break;
             }
         }
         break;
@@ -1070,6 +1087,29 @@ bool SwGetRefField::PutValue( const uno::Any& rAny, 
sal_uInt16 nWhichId )
 
 void SwGetRefField::ConvertProgrammaticToUIName()
 {
+    if (GetTyp() && REF_STYLE == m_nSubType)
+    {
+        // this is super ugly, but there isn't a sensible way to check in 
xmloff
+        SwDoc & rDoc{static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc()};
+        if (rDoc.IsInXMLImport242())
+        {
+            SAL_INFO("sw.xml", "Potentially accepting erroneously produced 
UIName for style-ref field");
+            return;
+        }
+        ProgName const par1{GetPar1()};
+        UIName name;
+        SwStyleNameMapper::FillUIName(par1, name, 
SwGetPoolIdFromName::TxtColl);
+        if (name.toString() == par1.toString())
+        {
+            SwStyleNameMapper::FillUIName(par1, name, 
SwGetPoolIdFromName::ChrFmt);
+        }
+        if (name.toString() != par1.toString())
+        {
+            SetPar1(name.toString());
+        }
+        return;
+    }
+
     if(!(GetTyp() && REF_SEQUENCEFLD == m_nSubType))
         return;
 
diff --git a/sw/source/core/unocore/unofield.cxx 
b/sw/source/core/unocore/unofield.cxx
index 9fc8a02c6d96..746d21b1509f 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -1513,6 +1513,9 @@ void SAL_CALL SwXTextField::attach(
             case SwServiceType::FieldTypeGetReference:
             {
                 SwFieldType* pFieldType = 
pDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef);
+                // tdf#159549 tdf#166850: if nUSHORT2 is 
ReferenceFieldSource::STYLE,
+                // sPar1 needs to be converted from ProgName to UIName - this
+                // is done when setting the FIELD_PROP_USHORT2 below
                 xField.reset(new 
SwGetRefField(static_cast<SwGetRefFieldType*>(pFieldType),
                             SwMarkName(m_pImpl->m_pProps->sPar1),
                             m_pImpl->m_pProps->sPar4,
diff --git a/sw/source/filter/basflt/shellio.cxx 
b/sw/source/filter/basflt/shellio.cxx
index 38440d48eea3..c3d66e8269c8 100644
--- a/sw/source/filter/basflt/shellio.cxx
+++ b/sw/source/filter/basflt/shellio.cxx
@@ -346,6 +346,7 @@ ErrCodeMsg SwReader::Read( const Reader& rOptions )
 
     mxDoc->SetInReading( false );
     mxDoc->SetInXMLImport( false );
+    mxDoc->SetInXMLImport242(false);
     mxDoc->SetInWriterfilterImport(false);
 
     if (!mbSkipInvalidateNumRules)
diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx
index d5b06c6ac502..f4944a282209 100644
--- a/sw/source/filter/xml/xmlfmt.cxx
+++ b/sw/source/filter/xml/xmlfmt.cxx
@@ -995,6 +995,14 @@ void 
SwXMLMasterStylesContext_Impl::endFastElement(sal_Int32 )
 SvXMLImportContext *SwXMLImport::CreateStylesContext(
         bool bAuto )
 {
+    // tdf#166850 this only worked in 24.2.4..24.2.7 and broke in 24.8.0
+    // anyway but must *not* be applied to fixed 25.2.x or later
+    if (isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_248)
+        && !isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, 
SvXMLImport::LO_242))
+    {
+        getDoc()->SetInXMLImport242(true);
+    }
+
     SvXMLStylesContext *pContext = new SwXMLStylesContext_Impl( *this, bAuto );
     if( bAuto )
         SetAutoStyles( pContext );
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index d879abe2f03b..7e6820e3cf66 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -668,6 +668,7 @@ void SwXMLImport::endDocument()
         assert(pDoc->IsInXMLImport());
         pDoc->SetInReading(false);
         pDoc->SetInXMLImport(false);
+        pDoc->SetInXMLImport242(false);
     }
 
     SwDrawModel* pDrawModel = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel();
diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx 
b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
index 6e3259aacc8f..099ae839e7ef 100644
--- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
+++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
@@ -1103,22 +1103,19 @@ OUString StyleSheetTable::CloneTOCStyle(FontTablePtr 
const& rFontTable, StyleShe
     // the old converted name is what is applied to paragraphs
     m_pImpl->m_ClonedTOCStylesMap.emplace(pStyle->m_sConvertedStyleName, 
pClone->m_sConvertedStyleName);
     std::vector<StyleSheetEntryPtr> const styles{ pClone };
-    std::vector<OUString> aRetStyleNames = ApplyStyleSheetsImpl(rFontTable, 
styles);
-    pClone->m_sConvertedStyleName = aRetStyleNames[0];
+    ApplyStyleSheetsImpl(rFontTable, styles);
     return pClone->m_sConvertedStyleName;
 }
 
 void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
 {
-    ApplyStyleSheetsImpl(rFontTable, m_pImpl->m_aStyleSheetEntries);
+    return ApplyStyleSheetsImpl(rFontTable, m_pImpl->m_aStyleSheetEntries);
 }
 
-std::vector<OUString> StyleSheetTable::ApplyStyleSheetsImpl(const 
FontTablePtr& rFontTable, std::vector<StyleSheetEntryPtr> const& rEntries)
+void StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries)
 {
-    std::vector<OUString> aStyleUINames(rEntries.size());
-    std::vector<OUString>::iterator aStyleUINamesIt = aStyleUINames.begin();
     if (!m_pImpl->m_xTextDocument)
-        return aStyleUINames;
+        return;
     try
     {
         rtl::Reference< SwXStyleFamilies > xStyleFamilies = 
m_pImpl->m_xTextDocument->getSwStyleFamilies();
@@ -1134,7 +1131,6 @@ std::vector<OUString> 
StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr&
             std::vector<beans::PropertyValue> aTableStylesVec;
             for (auto& pEntry : rEntries)
             {
-                *aStyleUINamesIt = pEntry->m_sStyleName;
                 if( pEntry->m_nStyleTypeCode == STYLE_TYPE_UNKNOWN && 
!pEntry->m_sStyleName.isEmpty() )
                     pEntry->m_nStyleTypeCode = STYLE_TYPE_PARA; // unspecified 
style types are considered paragraph styles
 
@@ -1418,7 +1414,7 @@ std::vector<OUString> 
StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr&
                             aMissingParent.emplace_back( sParentStyle, xStyle 
);
 
                         xStyles->insertStyleByName( sConvertedStyleName, 
static_cast<SwXStyle*>(xStyle.get()) );
-                        *aStyleUINamesIt = 
static_cast<SwXStyle*>(xStyle.get())->GetStyleUIName().toString();
+
                         if (!m_pImpl->m_bIsNewDoc && bParaStyle)
                         {
                             // Remember the inserted style, which may or may 
not be referred during
@@ -1447,7 +1443,6 @@ std::vector<OUString> 
StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr&
                     pEntry->m_pProperties->InsertProps( 
m_pImpl->m_pDefaultCharProps, /*bOverwrite=*/false );
                     pEntry->m_pProperties->InsertProps( 
m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false );
                 }
-                ++aStyleUINamesIt;
             }
 
             // Update the styles that were created before their parents or 
next-styles
@@ -1497,7 +1492,6 @@ std::vector<OUString> 
StyleSheetTable::ApplyStyleSheetsImpl(const FontTablePtr&
     {
         DBG_UNHANDLED_EXCEPTION("writerfilter", "Styles could not be imported 
completely");
     }
-    return aStyleUINames;
 }
 
 
diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.hxx 
b/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
index 3715e1ef6ef7..eaf84387b512 100644
--- a/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
+++ b/sw/source/writerfilter/dmapper/StyleSheetTable.hxx
@@ -128,7 +128,7 @@ private:
 
     void applyDefaults(bool bParaProperties);
 
-    std::vector<OUString> ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries);
+    void ApplyStyleSheetsImpl(const FontTablePtr& rFontTable, 
std::vector<StyleSheetEntryPtr> const& rEntries);
 };
 
 
diff --git a/xmloff/qa/unit/uxmloff.cxx b/xmloff/qa/unit/uxmloff.cxx
index 7fb1004bf612..cf888baa93fd 100644
--- a/xmloff/qa/unit/uxmloff.cxx
+++ b/xmloff/qa/unit/uxmloff.cxx
@@ -199,7 +199,9 @@ void Test::testMetaGenerator()
         { "LibreOffice_powered_by_CIBDev/6.4.0.0.0$Linux_X86_64 
LibreOffice_project/e29e100174c133d27e953934311d68602c4515b7", ";6.4.0.0.0", 
SvXMLImport::LO_63x },
         { "LibreOfficeDev/7.0.6.0.0$Linux_X86_64 
LibreOffice_project/dfc40e2292c6e19e285c10ed8c8044d9454107d0", ";7.0.6.0.0", 
SvXMLImport::LO_7x },
         { "CIB_OfficeDev/6.4.0.19$Linux_X86_64 
LibreOffice_project/2e04f804b5f82770435f250873f07b3384d95504", ";6.4.0.19", 
SvXMLImport::LO_63x },
-        { "LibreOfficeDev/24.2.0.0.alpha0$Linux_X86_64 
LibreOffice_project/b81e7b6f3c71fb3ade1cb665444ac730dac0a9a9", ";24.2.0.0.", 
SvXMLImport::LO_New },
+        { "LibreOfficeDev/24.2.0.0.alpha0$Linux_X86_64 
LibreOffice_project/b81e7b6f3c71fb3ade1cb665444ac730dac0a9a9", ";24.2.0.0.", 
SvXMLImport::LO_242 },
+        { "LibreOfficeDev/24.8.6.2$Linux_X86_64 
LibreOffice_project/dc6216c3d2b4ec3bcdba950f1e6ee1d013adb2d6", ";24.8.6.2", 
SvXMLImport::LO_248 },
+        { "LibreOfficeDev/25.8.0.0.alpha0$Linux_X86_64 
LibreOffice_project/308705574842e0c36f7385f73fc47da9a4542367", ";25.8.0.0.", 
SvXMLImport::LO_New }
     };
 
     for (auto const[pGenerator, pBuildId, nResult] : tests)
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index a487b992a142..134259fdb0f5 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -234,8 +234,16 @@ public:
                     {
                         OUString const nMajor(loVersion.subView(0, firstDot));
                         auto const year(nMajor.toInt32());
-                        //auto const 
month(loVersion.copy(firstDot+1).toInt32());
-                        if (0 < year)
+                        auto const 
month(o3tl::toInt32(loVersion.subView(firstDot+1)));
+                        if (24 == year && month == 2)
+                        {
+                            mnGeneratorVersion = SvXMLImport::LO_242;
+                        }
+                        else if (24 == year && month == 8)
+                        {
+                            mnGeneratorVersion = SvXMLImport::LO_248;
+                        }
+                        else if (0 < year)
                         {
                             mnGeneratorVersion = SvXMLImport::LO_New;
                         }

Reply via email to