Kaydet (Commit) 38c0293d authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Andras Timar

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
679faffc.

This used to work by accident before commit
9d0c51da fixed it to actually check for
duplicates properly.

(cherry picked from commit 7c3c3006)

Change-Id: I5ed58eda7f3f2ce470a778852f6dda7a14356860
Reviewed-on: https://gerrit.libreoffice.org/19337Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
(cherry picked from commit c5f55acd)
üst 8d119cc1
......@@ -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,
......
......@@ -16,6 +16,7 @@
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/table/ShadowFormat.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
......@@ -372,6 +373,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.
......
......@@ -352,7 +352,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
{
......@@ -375,7 +376,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 == MarkType::CROSSREF_NUMITEM_BOOKMARK || eType == MarkType::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");
......
......@@ -36,7 +36,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,
......
......@@ -226,6 +226,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";
......@@ -240,10 +241,16 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( aPam ) )
{
eType = IDocumentMarkAccess::MarkType::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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment