diff options
author | Justin Luth <justin_luth@sil.org> | 2021-06-25 14:49:13 +0200 |
---|---|---|
committer | Justin Luth <justin_luth@sil.org> | 2021-06-26 18:31:49 +0200 |
commit | f5394ceda7e714b87050d78a0319dc3cfab9ac99 (patch) | |
tree | 16031181a4245c6a5addb68050a2615181de281c /sw | |
parent | f877ded8654edc70e466e92de1f9c1dbe5d959de (diff) |
tdf#104239 doc import: chose m_pChosenWW8OutlineStyle carefully
Chapter numbering is a horrendous invention of LibreOffice.
It is not at all a part of MS Formats.
If there is anything that potentially can cause problems
by choosing one style to be the outline style,
invalidate it.
We won't totally ignore CN because it has some unique
properties in LO, and so it is worthwhile trying
to round-trip it (alwyas LFO 0?) or populate it
with the expected Heading styles if compatible.
(I tried looping through and re-setting the
matching styles with the "Outline" numrule first,
but lots of unit tests prove that doesn't work well.)
I couldn't believe the incredibly good effect this had on
my torture test example document. Hurray.
Then again, completely preventing CN at all also
passed all unit tests, so I added a preventative test earlier.
Change-Id: Iafa0d3606e558a3f17e49c3f1f6cebb7b25de962
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117920
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'sw')
-rwxr-xr-x | sw/qa/extras/ww8export/data/tdf104239_chapterNumberTortureTest.doc | bin | 0 -> 24064 bytes | |||
-rw-r--r-- | sw/qa/extras/ww8export/ww8export3.cxx | 28 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 22 |
3 files changed, 50 insertions, 0 deletions
diff --git a/sw/qa/extras/ww8export/data/tdf104239_chapterNumberTortureTest.doc b/sw/qa/extras/ww8export/data/tdf104239_chapterNumberTortureTest.doc Binary files differnew file mode 100755 index 000000000000..dc8f65e76d40 --- /dev/null +++ b/sw/qa/extras/ww8export/data/tdf104239_chapterNumberTortureTest.doc diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index b9a2a847c986..1ca05650da55 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -822,6 +822,34 @@ DECLARE_WW8EXPORT_TEST(testTdf106541_inheritChapterNumberingB, "tdf106541_inheri CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty<OUString>(xPara, "ListLabelString")); } +DECLARE_WW8EXPORT_TEST(testTdf104239_chapterNumberTortureTest, "tdf104239_chapterNumberTortureTest.doc") +{ + // There is no point in identifying what the wrong values where in this test, + //because EVERYTHING was wrong, and MANY different fixes are required to solve the problems. + uno::Reference<beans::XPropertySet> xPara(getParagraph(1, "No numId in style or paragraph"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(2, "Paragraph cancels numbering(0)"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(3, "First numbered line"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1st.i.a.1.I"), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(7, "inheritOnly: inherit outlineLvl and listLvl."), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2nd.ii"), getProperty<OUString>(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(xPara, "NumberingLevel")); // Level 2 + xPara.set(getParagraph(9, "outline with Body listLvl(9)."), uno::UNO_QUERY); + if (!mbExported) + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(10, "outline with Body listLvl(9) #2."), uno::UNO_QUERY); + if (!mbExported) + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(11, "direct formatting - Body listLvl(9)."), uno::UNO_QUERY); + //CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); + xPara.set(getParagraph(12, "direct numId, inherit listLvl."), uno::UNO_QUERY); + //CPPUNIT_ASSERT_EQUAL(OUString("2nd.ii.a.1.I"), getProperty<OUString>(xPara, "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(4), getProperty<sal_Int16>(xPara, "NumberingLevel")); // Level 5 + xPara.set(getParagraph(13, "Style numId0 cancels inherited numbering."), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara, "ListLabelString")); +} + DECLARE_WW8EXPORT_TEST(testTdf106541_inheritOutlineNumbering, "tdf106541_inheritOutlineNumbering.doc") { // The level and numbering are inherited from Level2. diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index d4c2ddc62cd6..0f5257417dfb 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -5916,6 +5916,7 @@ void SwWW8ImplReader::SetOutlineStyles() { sal_uInt16 nStyle = 0; std::map<const SwNumRule*, int> aWW8ListStyleCounts; + std::map<const SwNumRule*, bool> aPreventUseAsChapterNumbering; for (SwWW8StyInf& rSI : m_vColl) { // Copy inherited numbering info since LO drops inheritance after ChapterNumbering @@ -5925,7 +5926,18 @@ void SwWW8ImplReader::SetOutlineStyles() && m_vColl[rSI.m_nBase].HasWW8OutlineLevel()) { if (rSI.m_nLFOIndex == USHRT_MAX) + { rSI.m_nLFOIndex = m_vColl[rSI.m_nBase].m_nLFOIndex; + + // When ANYTHING is wrong or strange, prohibit eligibility for ChapterNumbering. + // A style never inherits numbering from Chapter Numbering. + if (rSI.m_nLFOIndex != USHRT_MAX) + { + const SwNumRule* pNumRule = m_vColl[rSI.m_nBase].m_pOutlineNumrule; + if (pNumRule) + aPreventUseAsChapterNumbering[pNumRule] = true; + } + } if (rSI.m_nListLevel == MAXLEVEL) rSI.m_nListLevel = m_vColl[rSI.m_nBase].m_nListLevel; if (rSI.mnWW8OutlineLevel == MAXLEVEL) @@ -5943,6 +5955,13 @@ void SwWW8ImplReader::SetOutlineStyles() if (bReRegister) RegisterNumFormatOnStyle(nStyle); + // When ANYTHING is wrong or strange, prohibit eligibility for ChapterNumbering. + if (rSI.IsWW8BuiltInHeadingStyle() && rSI.m_nListLevel != rSI.mnWW8OutlineLevel + && rSI.IsOutlineNumbered()) + { + aPreventUseAsChapterNumbering[rSI.m_pOutlineNumrule] = true; + } + ++nStyle; // increment before the first "continue"; if (!rSI.IsWW8BuiltInHeadingStyle() || !rSI.HasWW8OutlineLevel()) @@ -5955,6 +5974,9 @@ void SwWW8ImplReader::SetOutlineStyles() const SwNumRule* pWW8ListStyle = rSI.GetOutlineNumrule(); if (pWW8ListStyle != nullptr) { + if (aPreventUseAsChapterNumbering[pWW8ListStyle]) + continue; + std::map<const SwNumRule*, int>::iterator aCountIter = aWW8ListStyleCounts.find(pWW8ListStyle); if (aCountIter == aWW8ListStyleCounts.end()) |