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 5841441ed9c0b78286706145b01ddd3f8111455c Author: Szymon KÅos <szymon.k...@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 <c...@libreoffice.org> Reviewed-by: Szymon KÅos <szymon.k...@collabora.com> Tested-by: Szymon KÅos <szymon.k...@collabora.com> (cherry picked from commit a470d16208a78ae6893d199b3b6bc77a8559b06a) Reviewed-on: https://gerrit.libreoffice.org/37460 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 e298c322f690..3d30b96b03f0 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -119,6 +119,7 @@ public: void testDOCXAutoTextEmpty(); void testDOCXAutoTextMultiple(); void testDOTMAutoText(); + void testDOCXAutoTextGallery(); void testTdf67238(); void testFdo75110(); void testFdo75898(); @@ -239,6 +240,7 @@ public: CPPUNIT_TEST(testDOCXAutoTextEmpty); CPPUNIT_TEST(testDOCXAutoTextMultiple); CPPUNIT_TEST(testDOTMAutoText); + CPPUNIT_TEST(testDOCXAutoTextGallery); CPPUNIT_TEST(testTdf67238); CPPUNIT_TEST(testFdo75110); CPPUNIT_TEST(testFdo75898); @@ -798,6 +800,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 8939e4922b02..6646f87e7edc 100644 --- a/sw/source/filter/docx/swdocxreader.cxx +++ b/sw/source/filter/docx/swdocxreader.cxx @@ -39,6 +39,8 @@ #include <unotxdoc.hxx> #include <unotools/streamwrap.hxx> +#define AUTOTEXT_GALLERY "autoTxt" + using namespace css; extern "C" SAL_DLLPUBLIC_EXPORT Reader* SAL_CALL ImportDOCX() @@ -104,6 +106,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 ) ) { @@ -119,6 +122,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 @@ -154,32 +161,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 003983b6e54c..2fe1705bde61 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 5ae6f3f2b14f..47ae4e654438 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1537,9 +1537,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 7bd388025305..6823e741619d 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -560,7 +560,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 bb1917307ff1..b79f290cfc9d 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"/>
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits