sw/source/core/fields/reffld.cxx |   26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

New commits:
commit c48ed74eb6d269fb921bbfa808cc08b5892d4caa
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jun 6 13:43:19 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jun 11 14:26:01 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 <michael.st...@allotropia.de>
    (cherry picked from commit 0d1c8e0427756414d3296b06a6f2c0e7b96ba250)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168554
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 85a18c78927f..98a4181ebe5e 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1438,6 +1438,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:
@@ -1530,21 +1536,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;
@@ -1553,21 +1559,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;
                 }
@@ -1599,7 +1605,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;
@@ -1607,7 +1613,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;
@@ -1615,14 +1621,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;
                 }

Reply via email to