[Libreoffice-commits] core.git: sw/qa writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 12 03:56:31 UTC 2018


 sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport12.cxx                       |   39 ++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx                |   15 +++
 3 files changed, 54 insertions(+)

New commits:
commit 579c0749bef8c980507229439715e72060c1b077
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Tue Oct 9 14:03:37 2018 +0300
Commit:     Justin Luth <justin_luth at sil.org>
CommitDate: Fri Oct 12 05:56:01 2018 +0200

    tdf120224 writerfilter: consume excess bookmark from fields
    
    Although this follows a very different code path, copy the ww8
    import idea of "consuming" the bookmark of a BOOK_FIELD.
    
    This is particularly important for textcontrols, especially
    since LO keeps duplicating bookmarks as it adds another
    bookmark for the field name at each save.
    
    Existing unit tests that this matches are fdo53985.docx and
    tdf111964.docx. I expected more, but apparently most fields
    don't contain or represent any bookmarks.
    
    This patch is for import only. A followup patch stops
    the creation of duplicate bookmarks during export.
    
    Change-Id: I1e11980e52dc523393fd6d621191228d676e9a17
    Reviewed-on: https://gerrit.libreoffice.org/61615
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx b/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx
new file mode 100644
index 000000000000..c76bbd691c47
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf120224_textControlCrossRef.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 2b55c3f1ecfd..7c24fa3751fc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -723,6 +723,45 @@ DECLARE_OOXMLEXPORT_TEST(testObjectCrossReference, "object_cross_reference.odt")
     CPPUNIT_ASSERT_EQUAL(sal_uInt16(21), nIndex);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf120224_textControlCrossRef, "tdf120224_textControlCrossRef.docx")
+{
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
+                                                                  uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+    uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(),
+                                                                 uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
+    xRunEnum->nextElement(); //Text
+    uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"),
+                         getProperty<OUString>(xPropertySet, "TextPortionType"));
+    uno::Reference<container::XNamed> xBookmark(
+        getProperty<uno::Reference<beans::XPropertySet>>(xPropertySet, "Bookmark"), uno::UNO_QUERY);
+
+    // Critical test: does TextField's bookmark name match cross-reference?
+    const OUString& sTextFieldName(xBookmark->getName());
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xFieldsAccess(
+        xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+    CPPUNIT_ASSERT(xFields->hasMoreElements());
+    xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sTextFieldName, getProperty<OUString>(xPropertySet, "SourceName"));
+
+    uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(),
+                                                            uno::UNO_QUERY);
+    uno::Reference<container::XNameAccess> xBookmarksByName(xBookmarksSupplier->getBookmarks(),
+                                                            uno::UNO_QUERY);
+    // TextFields should not be turned into real bookmarks.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xBookmarksByIdx->getCount());
+
+    // The actual name isn't critical, but if it fails, it is worth asking why.
+    CPPUNIT_ASSERT_EQUAL(OUString("Text1"), sTextFieldName);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf117504_numberingIndent, "tdf117504_numberingIndent.docx")
 {
     OUString sName = getProperty<OUString>(getParagraph(1), "NumberingStyleName");
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 5c1251f4d1d9..ced0cda06778 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -5101,7 +5101,22 @@ void DomainMapper_Impl::SetBookmarkName( const OUString& rBookmarkName )
 {
     BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( m_sCurrentBkmkId );
     if( aBookmarkIter != m_aBookmarkMap.end() )
+    {
+        // fields are internal bookmarks: consume redundant "normal" bookmark
+        if ( IsOpenField() )
+        {
+            FFDataHandler::Pointer_t  pFFDataHandler(GetTopFieldContext()->getFFDataHandler());
+            if ( IsOpenFieldCommand() || (pFFDataHandler && pFFDataHandler->getName() == rBookmarkName) )
+            {
+                // HACK: At the END marker, StartOrEndBookmark will START
+                // a bookmark which will eventually be abandoned, not created.
+                m_aBookmarkMap.erase(aBookmarkIter);
+                return;
+            }
+        }
+
         aBookmarkIter->second.m_sBookmarkName = rBookmarkName;
+    }
     else
         m_sCurrentBkmkName = rBookmarkName;
 }


More information about the Libreoffice-commits mailing list