diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-10-12 23:49:04 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-10-14 08:04:39 +0000 |
commit | e95b9fd796e3a52afbb52bc142019115653c6099 (patch) | |
tree | 51d17f723c2353450a822b247bc769667021798c | |
parent | bdc5aab39be149b2fc7d37520414ae251341bc14 (diff) |
tdf#94804 sw: allow duplicate heading cross reference bookmarks
... in ODF import, so that reference fields do not break that reference
numbering cross reference bookmarks that were corrupted by commit
679faffc68bb854af0f55d0f218698e2f372f00b.
This used to work by accident before commit
9d0c51daea67104349cac26de9839afa8baeb099 fixed it to actually check for
duplicates properly.
(cherry picked from commit 7c3c3006deaaaf1bb3f2f4eeeaf11da3bcebe53c)
Change-Id: I5ed58eda7f3f2ce470a778852f6dda7a14356860
Reviewed-on: https://gerrit.libreoffice.org/19339
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/inc/IDocumentMarkAccess.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/odfexport/data/CrossRefHeadingBookmark.fodt | 120 | ||||
-rw-r--r-- | sw/qa/extras/odfexport/odfexport.cxx | 30 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unobkm.cxx | 9 |
6 files changed, 164 insertions, 5 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index e7500feafe31..0bd2add3aabe 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -77,7 +77,7 @@ class IDocumentMarkAccess */ virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM, const OUString& rProposedName, - MarkType eMark) =0; + MarkType eMark, bool = false) = 0; virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM, const OUString& rName, diff --git a/sw/qa/extras/odfexport/data/CrossRefHeadingBookmark.fodt b/sw/qa/extras/odfexport/data/CrossRefHeadingBookmark.fodt new file mode 100644 index 000000000000..64d6205372d5 --- /dev/null +++ b/sw/qa/extras/odfexport/data/CrossRefHeadingBookmark.fodt @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:meta><meta:initial-creator>ms </meta:initial-creator><meta:creation-date>2015-08-24T21:49:45.305718699</meta:creation-date><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="0" meta:word-count="0" meta:character-count="0" meta:non-whitespace-character-count="0"/><meta:generator>LibreOfficeDev/4.3.7.2$Linux_X86_64 LibreOffice_project/8a35821d8636a03b8bf4e15b48f59794652c68ba</meta:generator></office:meta> + <office:font-face-decls> + <style:font-face style:name="Lohit Devanagari1" svg:font-family="'Lohit Devanagari'"/> + <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/> + <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/> + <style:font-face style:name="Lohit Devanagari" svg:font-family="'Lohit Devanagari'" style:font-family-generic="system" style:font-pitch="variable"/> + <style:font-face style:name="Source Han Sans CN Regular" svg:font-family="'Source Han Sans CN Regular'" 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" 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" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="de" fo:country="DE" style:letter-kerning="true" style:font-name-asian="Source Han Sans CN Regular" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN"/> + </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.251cm" style:writing-mode="page"/> + <style:text-properties style:use-window-font-color="true" style:font-name="Liberation Serif" fo:font-size="12pt" fo:language="de" fo:country="DE" style:letter-kerning="true" style:font-name-asian="Source Han Sans CN Regular" style:font-size-asian="10.5pt" style:language-asian="zh" style:country-asian="CN" style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2"/> + </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"/> + + <text:list-style style:name="WW8Num2"> + <text:list-level-style-number text:level="1" style:num-prefix="daj o úroveň viac" 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" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="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" text:list-tab-stop-position="1cm" fo:text-indent="-1cm" fo:margin-left="1cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="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" text:list-tab-stop-position="2.6cm" fo:text-indent="-1.6cm" fo:margin-left="2.6cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="4" style:num-suffix=")" style:num-format="a" style:num-letter-sync="true"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="1.801cm" fo:text-indent="-0.55cm" fo:margin-left="1.801cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="5" style:num-suffix=")" style:num-format="a" style:num-letter-sync="true"> + <style:list-level-properties text:list-level-position-and-space-mode="label-alignment"> + <style:list-level-label-alignment text:label-followed-by="listtab" text:list-tab-stop-position="3.18cm" fo:text-indent="-0.64cm" fo:margin-left="3.18cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="6" style:num-suffix=" " 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" text:list-tab-stop-position="4.445cm" fo:text-indent="-0.635cm" fo:margin-left="4.445cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="7" style:num-suffix=" " 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" text:list-tab-stop-position="5.08cm" fo:text-indent="-0.635cm" fo:margin-left="5.08cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="8" style:num-suffix=" " 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" text:list-tab-stop-position="5.715cm" fo:text-indent="-0.635cm" fo:margin-left="5.715cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="9" style:num-suffix=" " 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" text:list-tab-stop-position="6.35cm" fo:text-indent="-0.635cm" fo:margin-left="6.35cm"/> + </style:list-level-properties> + </text:list-level-style-number> + <text:list-level-style-number text:level="10" 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" text:list-tab-stop-position="6.985cm" fo:text-indent="-0.635cm" fo:margin-left="6.985cm"/> + </style:list-level-properties> + </text:list-level-style-number> + </text:list-style> + + </office:styles> + <office:automatic-styles> + <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="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="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:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="WW8Num2"> + <style:text-properties officeooo:rsid="0014f4d6" officeooo:paragraph-rsid="0014f4d6"/> + </style:style> + <style:style style:name="P3" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="WW8Num2"> + <style:text-properties officeooo:rsid="0014f4d6" officeooo:paragraph-rsid="00150749"/> + </style:style> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text> + <text:list xml:id="list1703205442746379122" text:style-name="WW8Num2"> + <text:list-item> + <text:list> + <text:list-item> + <text:p text:style-name="P2"><text:bookmark-start text:name="__RefHeading__8284_1826734303"/><text:bookmark-start text:name="__RefHeading__1673_25705824"/>text<text:bookmark-end text:name="__RefHeading__8284_1826734303"/><text:bookmark-end text:name="__RefHeading__1673_25705824"/></text:p> + </text:list-item> + <text:list-item> + <text:p text:style-name="P3">cross-reference to <text:bookmark-ref text:reference-format="number" text:ref-name="__RefHeading__1673_25705824">1.1</text:bookmark-ref> <text:span text:style-name="T1">(Numbered paragraph - Number) and </text:span><text:span text:style-name="T1"><text:bookmark-ref text:reference-format="number-no-superior" text:ref-name="__RefHeading__1673_25705824">1.1</text:bookmark-ref></text:span><text:span text:style-name="T1">(Numbered paragraph - no context)</text:span></text:p> + </text:list-item> + </text:list> + </text:list-item> + </text:list> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 22083c7292bd..ace9e355317f 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/RelOrientation.hpp> #include <com/sun/star/text/XDocumentIndex.hpp> +#include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/graphic/XGraphic.hpp> @@ -212,6 +213,35 @@ DECLARE_ODFEXPORT_TEST(testTextframeGradient, "textframe-gradient.odt") CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style); } +DECLARE_ODFEXPORT_TEST(testDuplicateCrossRefHeadingBookmark, "CrossRefHeadingBookmark.fodt") +{ + // the file contains invalid duplicate heading cross reference bookmarks + // but we have to round trip them, tdf#94804 + + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarks( + xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference<text::XTextContent> xBookmark1( + xBookmarks->getByName("__RefHeading__8284_1826734303"), uno::UNO_QUERY); + CPPUNIT_ASSERT(xBookmark1.is()); + uno::Reference<text::XTextContent> xBookmark2( + xBookmarks->getByName("__RefHeading__1673_25705824"), uno::UNO_QUERY); + CPPUNIT_ASSERT(xBookmark2.is()); + + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh(); + + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + uno::Any aField1 = xFields->nextElement(); + uno::Reference<text::XTextField> xField1(aField1, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1.1"), xField1->getPresentation(false)); + uno::Any aField2 = xFields->nextElement(); + uno::Reference<text::XTextField> xField2(aField2, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1.1"), xField2->getPresentation(false)); +} + DECLARE_ODFEXPORT_TEST(testFdo60769, "fdo60769.odt") { // Test multi-paragraph comment range feature. diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index ce0ff19b1b3f..ae6342e989e4 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -354,7 +354,8 @@ namespace sw { namespace mark ::sw::mark::IMark* MarkManager::makeMark(const SwPaM& rPaM, const OUString& rName, - const IDocumentMarkAccess::MarkType eType) + const IDocumentMarkAccess::MarkType eType, + bool const isHorribleHackIgnoreDuplicates) { #if 0 { @@ -377,7 +378,8 @@ namespace sw { namespace mark " - more than USHRT_MAX marks are not supported correctly"); // There should only be one CrossRefBookmark per Textnode per Type if ((eType == CROSSREF_NUMITEM_BOOKMARK || eType == CROSSREF_HEADING_BOOKMARK) - && (lcl_FindMarkAtPos(m_vBookmarks, *rPaM.Start(), eType) != m_vBookmarks.end())) + && (lcl_FindMarkAtPos(m_vBookmarks, *rPaM.Start(), eType) != m_vBookmarks.end()) + && !isHorribleHackIgnoreDuplicates) { // this can happen via UNO API SAL_WARN("sw.core", "MarkManager::makeMark(..)" " - refusing to create duplicate CrossRefBookmark"); diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 52fea0a07d91..74e37c1ee92d 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -35,7 +35,7 @@ namespace sw { public: MarkManager(/*[in/out]*/ SwDoc& rDoc); // IDocumentMarkAccess - virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM, const OUString& rName, IDocumentMarkAccess::MarkType eMark) SAL_OVERRIDE; + virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM, const OUString& rName, IDocumentMarkAccess::MarkType eMark, bool = false) SAL_OVERRIDE; virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM, const OUString& rName, diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index 2f252f99d1a3..65d2168ce04b 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -225,6 +225,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) SwUnoInternalPaM aPam(*m_pImpl->m_pDoc); ::sw::XTextRangeToSwPaM(aPam, xTextRange); UnoActionContext aCont(m_pImpl->m_pDoc); + bool isHorribleHackIgnoreDuplicates(false); if (m_pImpl->m_sMarkName.isEmpty()) { m_pImpl->m_sMarkName = "Bookmark"; @@ -239,10 +240,16 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( aPam ) ) { eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK; + // tdf#94804 LO 4.2-5.0 create invalid duplicates that must be preserved + // note: do not check meta:generator, may be preserved by other versions + if (m_pImpl->m_pDoc->IsInXMLImport()) + { + isHorribleHackIgnoreDuplicates = true; + } } m_pImpl->registerInMark(*this, m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark( - aPam, m_pImpl->m_sMarkName, eType)); + aPam, m_pImpl->m_sMarkName, eType, isHorribleHackIgnoreDuplicates)); // #i81002# // Check, if bookmark has been created. // E.g., the creation of a cross-reference bookmark is suppress, |