diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-06-13 01:32:03 +0500 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-06-13 22:36:25 +0200 |
commit | b3f503c5d88b2314fca9fc9124f918090c8c427b (patch) | |
tree | 7c3c64bb492093813465e147f64c3de6c285bf4f /sw | |
parent | 54e46d3425846ed8e5bf84b1bf06ff8cf3aa48ce (diff) |
tdf#161509: Output the same special style names and identifiers as Word
Take care to match the case of the names. Some tools rely on specific
case; so standardize on what Word outputs.
getXPath is modified to tell which XPath has failed (needed for the
unit test).
Change-Id: I3e71f5905b26d7e784d68ba11ff205eefedaaa2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168755
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
(cherry picked from commit e74c94c1a6ae47eb507eec610e231ebb6b02a8be)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168726
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/special_styles.docx | bin | 0 -> 18732 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport18.cxx | 4 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 191 | ||||
-rw-r--r-- | sw/source/filter/ww8/styles.cxx | 89 |
4 files changed, 238 insertions, 46 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/special_styles.docx b/sw/qa/extras/ooxmlexport/data/special_styles.docx Binary files differnew file mode 100644 index 000000000000..08ed5c029355 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/special_styles.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index df196a5496fc..58f833d85732 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -831,9 +831,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf153664) CPPUNIT_ASSERT(pXmlStyles); // Without the fix this was styleId='FigureIndex1' and name was "Figure Index 1" // This led to style settings being reset when ToF was updated in Word - // TOF's paragraph style should be exported as "Table of Figures" as that's the default Word style name + // TOF's paragraph style should be exported as "table of figures" as that's the default Word style name assertXPath(pXmlStyles, "/w:styles/w:style[12]"_ostr, "styleId"_ostr, u"TableofFigures"_ustr); - assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TableofFigures']/w:name"_ostr, "val"_ostr, u"Table of Figures"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TableofFigures']/w:name"_ostr, "val"_ostr, u"table of figures"_ustr); } DECLARE_OOXMLEXPORT_TEST(testTdf124472_hyperlink, "tdf124472.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index 18dfc8e758e1..a2636ef97e8a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -614,6 +614,197 @@ CPPUNIT_TEST_FIXTURE(Test, testEmptyObjectRange) loadAndSave("cloud.docx"); } +CPPUNIT_TEST_FIXTURE(Test, testTdf161509) +{ + loadAndReload("special_styles.docx"); + xmlDocUniquePtr pXmlStyles = parseExport(u"word/styles.xml"_ustr); + CPPUNIT_ASSERT(pXmlStyles); + + // Check the mapping of standard style names to their IDs + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Normal']/w:name"_ostr, "val"_ostr, + u"Normal"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading1']/w:name"_ostr, "val"_ostr, + u"heading 1"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading2']/w:name"_ostr, "val"_ostr, + u"heading 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading3']/w:name"_ostr, "val"_ostr, + u"heading 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading4']/w:name"_ostr, "val"_ostr, + u"heading 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading5']/w:name"_ostr, "val"_ostr, + u"heading 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading6']/w:name"_ostr, "val"_ostr, + u"heading 6"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading7']/w:name"_ostr, "val"_ostr, + u"heading 7"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading8']/w:name"_ostr, "val"_ostr, + u"heading 8"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Heading9']/w:name"_ostr, "val"_ostr, + u"heading 9"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index1']/w:name"_ostr, "val"_ostr, + u"index 1"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index2']/w:name"_ostr, "val"_ostr, + u"index 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index3']/w:name"_ostr, "val"_ostr, + u"index 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index4']/w:name"_ostr, "val"_ostr, + u"index 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index5']/w:name"_ostr, "val"_ostr, + u"index 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index6']/w:name"_ostr, "val"_ostr, + u"index 6"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index7']/w:name"_ostr, "val"_ostr, + u"index 7"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index8']/w:name"_ostr, "val"_ostr, + u"index 8"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Index9']/w:name"_ostr, "val"_ostr, + u"index 9"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC1']/w:name"_ostr, "val"_ostr, + u"toc 1"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC2']/w:name"_ostr, "val"_ostr, + u"toc 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC3']/w:name"_ostr, "val"_ostr, + u"toc 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC4']/w:name"_ostr, "val"_ostr, + u"toc 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC5']/w:name"_ostr, "val"_ostr, + u"toc 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC6']/w:name"_ostr, "val"_ostr, + u"toc 6"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC7']/w:name"_ostr, "val"_ostr, + u"toc 7"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC8']/w:name"_ostr, "val"_ostr, + u"toc 8"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOC9']/w:name"_ostr, "val"_ostr, + u"toc 9"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='NormalIndent']/w:name"_ostr, "val"_ostr, + u"Normal Indent"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='FootnoteText']/w:name"_ostr, "val"_ostr, + u"footnote text"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='CommentText']/w:name"_ostr, "val"_ostr, + u"annotation text"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Header']/w:name"_ostr, "val"_ostr, + u"header"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Footer']/w:name"_ostr, "val"_ostr, + u"footer"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='IndexHeading']/w:name"_ostr, "val"_ostr, + u"index heading"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Caption']/w:name"_ostr, "val"_ostr, + u"caption"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TableofFigures']/w:name"_ostr, + "val"_ostr, u"table of figures"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='EnvelopeAddress']/w:name"_ostr, + "val"_ostr, u"envelope address"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='EnvelopeReturn']/w:name"_ostr, + "val"_ostr, u"envelope return"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='FootnoteReference']/w:name"_ostr, + "val"_ostr, u"footnote reference"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='CommentReference']/w:name"_ostr, + "val"_ostr, u"annotation reference"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='LineNumber']/w:name"_ostr, "val"_ostr, + u"line number"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='PageNumber']/w:name"_ostr, "val"_ostr, + u"page number"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='EndnoteReference']/w:name"_ostr, + "val"_ostr, u"endnote reference"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='EndnoteText']/w:name"_ostr, "val"_ostr, + u"endnote text"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TableofAuthorities']/w:name"_ostr, + "val"_ostr, u"table of authorities"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='MacroText']/w:name"_ostr, "val"_ostr, + u"macro"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='TOCHeading']/w:name"_ostr, "val"_ostr, + u"TOC Heading"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='List']/w:name"_ostr, "val"_ostr, + u"List"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListBullet']/w:name"_ostr, "val"_ostr, + u"List Bullet"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListNumber']/w:name"_ostr, "val"_ostr, + u"List Number"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='List2']/w:name"_ostr, "val"_ostr, + u"List 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='List3']/w:name"_ostr, "val"_ostr, + u"List 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='List4']/w:name"_ostr, "val"_ostr, + u"List 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='List5']/w:name"_ostr, "val"_ostr, + u"List 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListBullet2']/w:name"_ostr, "val"_ostr, + u"List Bullet 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListBullet3']/w:name"_ostr, "val"_ostr, + u"List Bullet 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListBullet4']/w:name"_ostr, "val"_ostr, + u"List Bullet 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListBullet5']/w:name"_ostr, "val"_ostr, + u"List Bullet 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListNumber2']/w:name"_ostr, "val"_ostr, + u"List Number 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListNumber3']/w:name"_ostr, "val"_ostr, + u"List Number 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListNumber4']/w:name"_ostr, "val"_ostr, + u"List Number 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListNumber5']/w:name"_ostr, "val"_ostr, + u"List Number 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Title']/w:name"_ostr, "val"_ostr, + u"Title"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Closing']/w:name"_ostr, "val"_ostr, + u"Closing"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Signature']/w:name"_ostr, "val"_ostr, + u"Signature"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='DefaultParagraphFont']/w:name"_ostr, + "val"_ostr, u"Default Paragraph Font"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyText']/w:name"_ostr, "val"_ostr, + u"Body Text"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyTextIndent']/w:name"_ostr, + "val"_ostr, u"Body Text Indent"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListContinue']/w:name"_ostr, "val"_ostr, + u"List Continue"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListContinue2']/w:name"_ostr, "val"_ostr, + u"List Continue 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListContinue3']/w:name"_ostr, "val"_ostr, + u"List Continue 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListContinue4']/w:name"_ostr, "val"_ostr, + u"List Continue 4"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='ListContinue5']/w:name"_ostr, "val"_ostr, + u"List Continue 5"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='MessageHeader']/w:name"_ostr, "val"_ostr, + u"Message Header"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Subtitle']/w:name"_ostr, "val"_ostr, + u"Subtitle"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Salutation']/w:name"_ostr, "val"_ostr, + u"Salutation"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Date']/w:name"_ostr, "val"_ostr, + u"Date"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyTextFirstIndent']/w:name"_ostr, + "val"_ostr, u"Body Text First Indent"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyTextFirstIndent2']/w:name"_ostr, + "val"_ostr, u"Body Text First Indent 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='NoteHeading']/w:name"_ostr, "val"_ostr, + u"Note Heading"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyText2']/w:name"_ostr, "val"_ostr, + u"Body Text 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyText3']/w:name"_ostr, "val"_ostr, + u"Body Text 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyTextIndent2']/w:name"_ostr, + "val"_ostr, u"Body Text Indent 2"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BodyTextIndent3']/w:name"_ostr, + "val"_ostr, u"Body Text Indent 3"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='BlockText']/w:name"_ostr, "val"_ostr, + u"Block Text"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Hyperlink']/w:name"_ostr, "val"_ostr, + u"Hyperlink"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='FollowedHyperlink']/w:name"_ostr, + "val"_ostr, u"FollowedHyperlink"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Strong']/w:name"_ostr, "val"_ostr, + u"Strong"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Emphasis']/w:name"_ostr, "val"_ostr, + u"Emphasis"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='DocumentMap']/w:name"_ostr, "val"_ostr, + u"Document Map"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='PlainText']/w:name"_ostr, "val"_ostr, + u"Plain Text"_ustr); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/styles.cxx b/sw/source/filter/ww8/styles.cxx index 33d0ad3dec5f..dc8f7e33d321 100644 --- a/sw/source/filter/ww8/styles.cxx +++ b/sw/source/filter/ww8/styles.cxx @@ -27,54 +27,55 @@ namespace const char **GetStiNames() noexcept { // Matches enum ww::sti in sw/source/filter/inc/wwstyles.hxx + // tdf#161509: The case of the names must match Word-generated document's w:latentStyles static const char *stiName[] = { "Normal", // stiNormal - "Heading 1", // stiLev1 - "Heading 2", // stiLev2 - "Heading 3", // stiLev3 - "Heading 4", // stiLev4 - "Heading 5", // stiLev5 - "Heading 6", // stiLev6 - "Heading 7", // stiLev7 - "Heading 8", // stiLev8 - "Heading 9", // stiLev9 - "Index 1", // stiIndex1 - "Index 2", // stiIndex2 - "Index 3", // stiIndex3 - "Index 4", // stiIndex4 - "Index 5", // stiIndex5 - "Index 6", // stiIndex6 - "Index 7", // stiIndex7 - "Index 8", // stiIndex8 - "Index 9", // stiIndex9 - "TOC 1", // stiToc1 - "TOC 2", // stiToc2 - "TOC 3", // stiToc3 - "TOC 4", // stiToc4 - "TOC 5", // stiToc5 - "TOC 6", // stiToc6 - "TOC 7", // stiToc7 - "TOC 8", // stiToc8 - "TOC 9", // stiToc9 + "heading 1", // stiLev1 + "heading 2", // stiLev2 + "heading 3", // stiLev3 + "heading 4", // stiLev4 + "heading 5", // stiLev5 + "heading 6", // stiLev6 + "heading 7", // stiLev7 + "heading 8", // stiLev8 + "heading 9", // stiLev9 + "index 1", // stiIndex1 + "index 2", // stiIndex2 + "index 3", // stiIndex3 + "index 4", // stiIndex4 + "index 5", // stiIndex5 + "index 6", // stiIndex6 + "index 7", // stiIndex7 + "index 8", // stiIndex8 + "index 9", // stiIndex9 + "toc 1", // stiToc1 + "toc 2", // stiToc2 + "toc 3", // stiToc3 + "toc 4", // stiToc4 + "toc 5", // stiToc5 + "toc 6", // stiToc6 + "toc 7", // stiToc7 + "toc 8", // stiToc8 + "toc 9", // stiToc9 "Normal Indent", // stiNormIndent - "Footnote Text", // stiFootnoteText - "Annotation Text", // stiAtnText - "Header", // stiHeader - "Footer", // stiFooter - "Index Heading", // stiIndexHeading - "Caption", // stiCaption - "Table of Figures", // stiToCaption - "Envelope Address", // stiEnvAddr - "Envelope Return", // stiEnvRet - "Footnote Reference", // stiFootnoteRef - "Annotation Reference", // stiAtnRef - "Line Number", // stiLnn - "Page Number", // stiPgn - "Endnote Reference", // stiEdnRef - "Endnote Text", // stiEdnText - "Table of Authorities", // stiToa - "Macro Text", // stiMacro + "footnote text", // stiFootnoteText + "annotation text", // stiAtnText + "header", // stiHeader + "footer", // stiFooter + "index heading", // stiIndexHeading + "caption", // stiCaption + "table of figures", // stiToCaption + "envelope address", // stiEnvAddr + "envelope return", // stiEnvRet + "footnote reference", // stiFootnoteRef + "annotation reference", // stiAtnRef + "line number", // stiLnn + "page number", // stiPgn + "endnote reference", // stiEdnRef + "endnote text", // stiEdnText + "table of authorities", // stiToa + "macro", // stiMacro "TOC Heading", // stiToaHeading - tdf143726 "List", // stiList "List Bullet", // stiListBullet |