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

Szymon Kłos szymon.klos at collabora.com
Wed May 10 09:17:45 UTC 2017


 sw/qa/extras/uiwriter/data/autotext-gallery.dotx  |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                |   18 +++++++
 sw/source/filter/docx/swdocxreader.cxx            |   54 +++++++++++++---------
 writerfilter/source/dmapper/DomainMapper.cxx      |   29 ++++++++++-
 writerfilter/source/dmapper/DomainMapper.hxx      |    1 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    4 -
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    2 
 writerfilter/source/ooxml/model.xml               |   10 ++--
 8 files changed, 85 insertions(+), 33 deletions(-)

New commits:
commit a470d16208a78ae6893d199b3b6bc77a8559b06a
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Tue May 9 11:56:35 2017 +0200

    AutoText: add only real AutoText entries
    
    * add only autoTxT gallery type
    * new test with other types of entries
    
    Change-Id: Ibf7751c73dcf3b6ebd69eec5f4931dbeaaf098c8
    Reviewed-on: https://gerrit.libreoffice.org/37425
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Tested-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/sw/qa/extras/uiwriter/data/autotext-gallery.dotx b/sw/qa/extras/uiwriter/data/autotext-gallery.dotx
new file mode 100644
index 000000000000..827ec60c29f4
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/autotext-gallery.dotx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 57e41ebf5765..0d40ae1829a1 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -124,6 +124,7 @@ public:
     void testDOCXAutoTextEmpty();
     void testDOCXAutoTextMultiple();
     void testDOTMAutoText();
+    void testDOCXAutoTextGallery();
     void testTdf67238();
     void testFdo75110();
     void testFdo75898();
@@ -255,6 +256,7 @@ public:
     CPPUNIT_TEST(testDOCXAutoTextEmpty);
     CPPUNIT_TEST(testDOCXAutoTextMultiple);
     CPPUNIT_TEST(testDOTMAutoText);
+    CPPUNIT_TEST(testDOCXAutoTextGallery);
     CPPUNIT_TEST(testTdf67238);
     CPPUNIT_TEST(testFdo75110);
     CPPUNIT_TEST(testFdo75898);
@@ -825,6 +827,22 @@ void SwUiWriterTest::testDOTMAutoText()
     CPPUNIT_ASSERT_EQUAL(OUString("paragraph"), rNode.GetTextNode()->GetText());
 }
 
+void SwUiWriterTest::testDOCXAutoTextGallery()
+{
+    // this file contains one AutoText entry and other
+    // entries which are not AutoText (have different "gallery" value)
+    std::unique_ptr<SwTextBlocks> pGlossary = readDOCXAutotext("autotext-gallery.dotx");
+
+    SwDoc* pDoc = pGlossary->GetDoc();
+    CPPUNIT_ASSERT(pDoc != nullptr);
+
+    // check entries count
+    CPPUNIT_ASSERT_EQUAL((sal_uInt16)1, pGlossary->GetCount());
+
+    // check entry name (if not contains gallery type)
+    CPPUNIT_ASSERT_EQUAL(OUString("Multiple"), pGlossary->GetLongName(0));
+}
+
 void SwUiWriterTest::testFdo74981()
 {
     // create a document with an input field
diff --git a/sw/source/filter/docx/swdocxreader.cxx b/sw/source/filter/docx/swdocxreader.cxx
index b72253c0b57a..501b0e567a18 100644
--- a/sw/source/filter/docx/swdocxreader.cxx
+++ b/sw/source/filter/docx/swdocxreader.cxx
@@ -38,6 +38,8 @@
 #include <unotxdoc.hxx>
 #include <unotools/streamwrap.hxx>
 
+#define AUTOTEXT_GALLERY "autoTxt"
+
 using namespace css;
 
 extern "C" SAL_DLLPUBLIC_EXPORT Reader* SAL_CALL ImportDOCX()
@@ -103,6 +105,7 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks )
 
     SwNodeIndex aDocEnd( pD->GetNodes().GetEndOfContent() );
     SwNodeIndex aStart( *aDocEnd.GetNode().StartOfSectionNode(), 1 );
+    bool bIsAutoText = false;
 
     if( aStart < aDocEnd && ( aDocEnd.GetIndex() - aStart.GetIndex() > 2 ) )
     {
@@ -118,6 +121,10 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks )
                 SwNodeIndex& rIdx = aPam.GetPoint()->nNode;
                 ++rIdx;
                 aLNm = aPam.GetNode().GetTextNode()->GetText();
+
+                // is AutoText?
+                bIsAutoText = aLNm.startsWith(AUTOTEXT_GALLERY);
+                aLNm = aLNm.copy(strlen(AUTOTEXT_GALLERY) + 1);
             }
 
             // Do not copy name
@@ -153,32 +160,35 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks )
             }
             aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
 
-            // Now we have the right selection for one entry
-            rBlocks.ClearDoc();
+            if( bIsAutoText )
+            {
+                // Now we have the right selection for one entry
+                rBlocks.ClearDoc();
 
-            OUString sShortcut = aLNm;
+                OUString sShortcut = aLNm;
 
-            // Need to check make sure the shortcut is not already being used
-            sal_Int32 nStart = 0;
-            sal_uInt16 nCurPos = rBlocks.GetIndex( sShortcut );
-            sal_Int32 nLen = sShortcut.getLength();
+                // Need to check make sure the shortcut is not already being used
+                sal_Int32 nStart = 0;
+                sal_uInt16 nCurPos = rBlocks.GetIndex( sShortcut );
+                sal_Int32 nLen = sShortcut.getLength();
 
-            while( (sal_uInt16)-1 != nCurPos )
-            {
-                sShortcut = sShortcut.copy( 0, nLen );
-                // add an Number to it
-                sShortcut += OUString::number( ++nStart );
-                nCurPos = rBlocks.GetIndex( sShortcut );
-            }
+                while( (sal_uInt16)-1 != nCurPos )
+                {
+                    sShortcut = sShortcut.copy( 0, nLen );
+                    // add an Number to it
+                    sShortcut += OUString::number( ++nStart );
+                    nCurPos = rBlocks.GetIndex( sShortcut );
+                }
 
-            if( rBlocks.BeginPutDoc( sShortcut, sShortcut ) )
-            {
-                SwDoc* pGlDoc = rBlocks.GetDoc();
-                SwNodeIndex aIdx( pGlDoc->GetNodes().GetEndOfContent(), -1 );
-                pCNd = aIdx.GetNode().GetContentNode();
-                SwPosition aPos( aIdx, SwIndex( pCNd, ( pCNd ) ? pCNd->Len() : 0 ) );
-                pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true );
-                rBlocks.PutDoc();
+                if( rBlocks.BeginPutDoc( sShortcut, sShortcut ) )
+                {
+                    SwDoc* pGlDoc = rBlocks.GetDoc();
+                    SwNodeIndex aIdx( pGlDoc->GetNodes().GetEndOfContent(), -1 );
+                    pCNd = aIdx.GetNode().GetContentNode();
+                    SwPosition aPos( aIdx, SwIndex( pCNd, ( pCNd ) ? pCNd->Len() : 0 ) );
+                    pD->getIDocumentContentOperations().CopyRange( aPam, aPos, /*bCopyAll=*/false, /*bCheckPos=*/true );
+                    rBlocks.PutDoc();
+                }
             }
 
             aStart = aStart.GetNode().EndOfSectionIndex() + 1;
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 62544ca858f1..2f3df2fa01fc 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1082,9 +1082,18 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
             break;
         case NS_ooxml::LN_CT_DocPartName_val:
         {
-            // Add glossary entry name as a first paragraph in section
-            PropertyMapPtr pContext = m_pImpl->GetTopContext();
-            m_pImpl->appendTextPortion(sStringValue, pContext);
+            m_sGlossaryEntryName = sStringValue;
+            break;
+        }
+        case NS_ooxml::LN_CT_DocPartGallery_val:
+        {
+            OUString sGlossaryEntryGallery = sStringValue;
+            if(m_pImpl->GetTopContext().get())
+            {
+                OUString sName = sGlossaryEntryGallery + ":" + m_sGlossaryEntryName;
+                // Add glossary entry name as a first paragraph in section
+                m_pImpl->appendTextPortion(sName, m_pImpl->GetTopContext());
+            }
             break;
         }
         default:
@@ -2767,6 +2776,20 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
             pProperties->resolve(*this);
     }
     break;
+    case NS_ooxml::LN_CT_DocPartPr_category:
+    {
+        writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
+        if (pProperties.get() != nullptr)
+            pProperties->resolve(*this);
+    }
+    break;
+    case NS_ooxml::LN_CT_DocPartCategory_gallery:
+    {
+        writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
+        if (pProperties.get() != nullptr)
+            pProperties->resolve(*this);
+    }
+    break;
     default:
         {
 #ifdef DEBUG_WRITERFILTER
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx
index 7a346884d642..f509efef8870 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -166,6 +166,7 @@ private:
     bool mbIsSplitPara;
     std::unique_ptr< GraphicZOrderHelper > zOrderHelper;
     std::unique_ptr<GraphicNamingHelper> m_pGraphicNamingHelper;
+    OUString m_sGlossaryEntryName;
 };
 
 } // namespace dmapper
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 41788537021c..2427209c3326 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1560,9 +1560,9 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
     return xRet;
 }
 
-uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendGlossaryEntry()
+void DomainMapper_Impl::appendGlossaryEntry()
 {
-    return appendTextSectionAfter(m_xGlossaryEntryStart);
+    appendTextSectionAfter(m_xGlossaryEntryStart);
 }
 
 void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 6198dec06cf3..b43d310db917 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -559,7 +559,7 @@ public:
     css::uno::Reference<css::beans::XPropertySet> appendTextSectionAfter(css::uno::Reference<css::text::XTextRange>& xBefore);
 
     /// AutoText import: each entry is placed in the separate section
-    css::uno::Reference<css::beans::XPropertySet> appendGlossaryEntry();
+    void appendGlossaryEntry();
     /// Remember where entry was started
     void setGlossaryEntryStart( css::uno::Reference<css::text::XTextRange>& xStart )
     {
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index a39f0537fa76..ae89c4ba5c54 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -19006,9 +19006,8 @@
       <attribute name="val" tokenid="ooxml:CT_DocPartType_val" action="setValue"/>
       <action name="start" action="setDefaultStringValue"/>
     </resource>
-    <resource name="CT_DocPartGallery" resource="Value">
-      <attribute name="val" tokenid="ooxml:CT_DocPartGallery_val" action="setValue"/>
-      <action name="start" action="setDefaultStringValue"/>
+    <resource name="CT_DocPartGallery" resource="Properties">
+        <attribute name="val" tokenid="ooxml:CT_DocPartGallery_val"/>
     </resource>
     <resource name="CT_DocPartName" resource="Properties">
       <attribute name="val" tokenid="ooxml:CT_DocPartName_val"/>
@@ -19065,9 +19064,10 @@
     <resource name="CT_DocPartPr" resource="Properties">
         <action name="start" action="startSectionGroup"/>
         <element name="name" tokenid="ooxml:CT_DocPartPr_name"/>
+        <element name="category" tokenid="ooxml:CT_DocPartPr_category"/>
     </resource>
-    <resource name="CT_DocPartName" resource="Properties">
-        <attribute name="val" tokenid="ooxml:CT_DocPartName_val"/>
+    <resource name="CT_DocPartCategory" resource="Properties">
+        <element name="gallery" tokenid="ooxml:CT_DocPartCategory_gallery"/>
     </resource>
     <resource name="document" resource="Stream"/>
     <resource name="glossaryDocument" resource="Stream"/>


More information about the Libreoffice-commits mailing list