sw/source/core/fields/reffld.cxx | 26 +++++++++++-------- sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 26 ++++++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-)
New commits: commit 0d1c8e0427756414d3296b06a6f2c0e7b96ba250 Author: Michael Stahl <[email protected]> AuthorDate: Thu Jun 6 13:43:19 2024 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jun 6 15:51:38 2024 +0200 sw: evaluate undocumented STYLEREF field heading switch forum-mso-de-86231.docx contains funny fields that use undocumented switch and style name: STYLEREF 2 \s StyleRef Word can evaluate both and find the paragraph with style "Heading 2". Change-Id: I4c577fc633a56ef37ca5556e6d60f425c4171a09 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168496 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 4c03b26960a9..6b7cd10cc4fb 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1436,6 +1436,12 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, pReference = pSelf; } + // undocumented Word feature: 1 = "Heading 1" etc. + OUString const styleName( + (rRefMark.getLength() == 1 && '1' <= rRefMark[0] && rRefMark[0] <= '9') + ? SwStyleNameMapper::GetProgName(RES_POOLCOLL_HEADLINE1 + rRefMark[0] - '1', rRefMark) + : rRefMark); + switch (elementType) { case Marginal: @@ -1528,21 +1534,21 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, pSearchThird.push_back(nodes[n]); } - pTextNd = SearchForStyleAnchor(pSelf, pInPage, rRefMark, pStt, pEnd); + pTextNd = SearchForStyleAnchor(pSelf, pInPage, styleName, pStt, pEnd); if (pTextNd) { break; } // 2. Search up from the top of the page - pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, rRefMark, pStt, pEnd); + pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, styleName, pStt, pEnd); if (pTextNd) { break; } // 3. Search down from the bottom of the page - pTextNd = SearchForStyleAnchor(pSelf, pSearchThird, rRefMark, pStt, pEnd); + pTextNd = SearchForStyleAnchor(pSelf, pSearchThird, styleName, pStt, pEnd); if (pTextNd) { break; @@ -1551,21 +1557,21 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, // Word has case insensitive styles. LO has case sensitive styles. If we didn't find // it yet, maybe we could with a case insensitive search. Let's do that - pTextNd = SearchForStyleAnchor(pSelf, pInPage, rRefMark, pStt, pEnd, + pTextNd = SearchForStyleAnchor(pSelf, pInPage, styleName, pStt, pEnd, false /* bCaseSensitive */); if (pTextNd) { break; } - pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, rRefMark, pStt, pEnd, + pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, styleName, pStt, pEnd, false /* bCaseSensitive */); if (pTextNd) { break; } - pTextNd = SearchForStyleAnchor(pSelf, pSearchThird, rRefMark, pStt, pEnd, + pTextNd = SearchForStyleAnchor(pSelf, pSearchThird, styleName, pStt, pEnd, false /* bCaseSensitive */); break; } @@ -1597,7 +1603,7 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, // 1. Search up until we hit the top of the document - pTextNd = SearchForStyleAnchor(pSelf, pSearchFirst, rRefMark, pStt, pEnd); + pTextNd = SearchForStyleAnchor(pSelf, pSearchFirst, styleName, pStt, pEnd); if (pTextNd) { break; @@ -1605,7 +1611,7 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, // 2. Search down until we hit the bottom of the document - pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, rRefMark, pStt, pEnd); + pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, styleName, pStt, pEnd); if (pTextNd) { break; @@ -1613,14 +1619,14 @@ SwTextNode* SwGetRefFieldType::FindAnchor(SwDoc* pDoc, const OUString& rRefMark, // Again, we need to remember that Word styles are not case sensitive - pTextNd = SearchForStyleAnchor(pSelf, pSearchFirst, rRefMark, pStt, pEnd, + pTextNd = SearchForStyleAnchor(pSelf, pSearchFirst, styleName, pStt, pEnd, false /* bCaseSensitive */); if (pTextNd) { break; } - pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, rRefMark, pStt, pEnd, + pTextNd = SearchForStyleAnchor(pSelf, pSearchSecond, styleName, pStt, pEnd, false /* bCaseSensitive */); break; } commit aac625cf1cc502de5d55c0b30afb962147ccf3e1 Author: Michael Stahl <[email protected]> AuthorDate: Thu Jun 6 13:28:51 2024 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jun 6 15:51:29 2024 +0200 writerfilter: import undocumented STYLEREF field heading switch forum-mso-de-86231.docx contains a funny field that uses undocumented switch: StyleRef Word can evaluate it and find the paragraph with style "Heading 2". Translate it to "2" in DomainMapper, which is also evaluated by Word. (regression from commit d4fdafa103bfea94a279d7069ddc50ba92f67d01) Change-Id: I587e6df1ea72642278d93723ed6692ff5011ed57 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168495 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 25f9e0630083..3442fac33a59 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -8040,11 +8040,29 @@ void DomainMapper_Impl::CloseFieldCommand() getPropertyName(PROP_REFERENCE_FIELD_SOURCE), uno::Any(sal_Int16(text::ReferenceFieldSource::STYLE))); - uno::Any aStyleDisplayName; - aStyleDisplayName <<= ConvertTOCStyleName(sFirstParam); + OUString styleName(sFirstParam); + if (styleName.isEmpty()) + { + for (auto const& rSwitch : vSwitches) + { + // undocumented Word feature: = "Heading 1" etc. + if (rSwitch.getLength() == 2 && rSwitch[0] == '\' + && '1' <= rSwitch[1] && rSwitch[1] <= '9') + { + styleName = OUString(rSwitch[1]); + break; + } + } + } - xFieldProperties->setPropertyValue( - getPropertyName(PROP_SOURCE_NAME), aStyleDisplayName); + if (!styleName.isEmpty()) + { + uno::Any aStyleDisplayName; + aStyleDisplayName <<= ConvertTOCStyleName(styleName); + + xFieldProperties->setPropertyValue( + getPropertyName(PROP_SOURCE_NAME), aStyleDisplayName); + } sal_uInt16 nFlags = 0; OUString sValue;
