[Libreoffice-commits] core.git: sw/source writerfilter/inc writerfilter/source
Szymon Kłos
szymon.klos at collabora.com
Mon May 1 17:11:34 UTC 2017
sw/source/filter/docx/swdocxreader.cxx | 25 ++++-------------
writerfilter/inc/dmapper/resourcemodel.hxx | 6 ++++
writerfilter/source/dmapper/DomainMapper.cxx | 11 +++++++
writerfilter/source/dmapper/DomainMapper.hxx | 2 +
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 5 +++
writerfilter/source/dmapper/DomainMapper_Impl.hxx | 10 ++++++
writerfilter/source/dmapper/LoggedResources.cxx | 26 ++++++++++++++++++
writerfilter/source/dmapper/LoggedResources.hxx | 4 ++
writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 12 ++++++++
writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 2 +
writerfilter/source/ooxml/model.xml | 5 ++-
11 files changed, 88 insertions(+), 20 deletions(-)
New commits:
commit 0d50845c4299a1b9564d65464fbf3997d598d6d1
Author: Szymon Kłos <szymon.klos at collabora.com>
Date: Fri Apr 28 21:00:23 2017 +0200
AutoText: Reading multiple entries
+ each entry is placed in a separate section
+ extended model and dmapper to react on docPart mark
Change-Id: I7e5213a09ae7352d1d09369bd0a209b6d4e18e82
Reviewed-on: https://gerrit.libreoffice.org/37107
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
diff --git a/sw/source/filter/docx/swdocxreader.cxx b/sw/source/filter/docx/swdocxreader.cxx
index 419d0bc142fb..7a3cc9425bd5 100644
--- a/sw/source/filter/docx/swdocxreader.cxx
+++ b/sw/source/filter/docx/swdocxreader.cxx
@@ -87,16 +87,8 @@ bool SwDOCXReader::ReadGlossaries( SwTextBlocks& rBlocks, bool /* bSaveRelFiles
aDescriptor[1].Name = "ReadGlossaries";
aDescriptor[1].Value <<= true;
- try
- {
- xFilter->filter( aDescriptor );
- }
- catch( uno::Exception const& e )
- {
- SAL_WARN("sw.docx", "SwDOCXReader::ReadGlossaries(): exception: " << e.Message);
- }
-
- return MakeEntries( static_cast<SwDocShell*>( &xDocSh )->GetDoc(), rBlocks );
+ if( xFilter->filter( aDescriptor ) )
+ return MakeEntries( static_cast<SwDocShell*>( &xDocSh )->GetDoc(), rBlocks );
}
return false;
@@ -110,7 +102,7 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks )
bool bRet = false;
SwNodeIndex aDocEnd( pD->GetNodes().GetEndOfContent() );
- SwNodeIndex aStart( *aDocEnd.GetNode().StartOfSectionNode() );
+ SwNodeIndex aStart( *aDocEnd.GetNode().StartOfSectionNode(), 1 );
if( aStart < aDocEnd && ( aDocEnd.GetIndex() - aStart.GetIndex() > 2 ) )
{
@@ -144,6 +136,7 @@ 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();
// TODO: correct entry name
@@ -174,15 +167,9 @@ bool SwDOCXReader::MakeEntries( SwDoc *pD, SwTextBlocks &rBlocks )
rBlocks.PutDoc();
}
- if( aStart.GetNodes().Count() <= aStart.GetNode().GetIndex() )
- aStart = aStart.GetNode().EndOfSectionIndex() + 1;
- else
- break;
-
+ aStart = aStart.GetNode().EndOfSectionIndex() + 1;
++nGlosEntry;
-
- } while( aStart < aDocEnd );
-
+ } while( aStart < aDocEnd && aStart.GetNode().IsStartNode() );
bRet = true;
}
diff --git a/writerfilter/inc/dmapper/resourcemodel.hxx b/writerfilter/inc/dmapper/resourcemodel.hxx
index ca3e022c4ce5..6c09ee7ee417 100644
--- a/writerfilter/inc/dmapper/resourcemodel.hxx
+++ b/writerfilter/inc/dmapper/resourcemodel.hxx
@@ -292,6 +292,12 @@ public:
*/
virtual void info(const std::string & info) = 0;
+ /// Receives start mark for glossary document entry.
+ virtual void startGlossaryEntry() = 0;
+
+ /// Receives end mark for glossary document entry.
+ virtual void endGlossaryEntry() = 0;
+
protected:
~Stream() {}
};
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 151f33774d38..1784c612c0bd 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3427,6 +3427,17 @@ void DomainMapper::lcl_info(const std::string & /*info_*/)
{
}
+void DomainMapper::lcl_startGlossaryEntry()
+{
+ uno::Reference< text::XTextRange > xTextRange = GetCurrentTextRange();
+ m_pImpl->setGlossaryEntryStart(xTextRange);
+}
+
+void DomainMapper::lcl_endGlossaryEntry()
+{
+ m_pImpl->appendGlossaryEntry();
+}
+
void DomainMapper::handleUnderlineType(const Id nId, const ::std::shared_ptr<PropertyMap>& rContext)
{
sal_Int16 nUnderline = awt::FontUnderline::NONE;
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx
index 4f05118b1190..7a346884d642 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -146,6 +146,8 @@ private:
virtual void lcl_substream(Id name,
::writerfilter::Reference<Stream>::Pointer_t ref) override;
virtual void lcl_info(const std::string & info) override;
+ virtual void lcl_startGlossaryEntry() override;
+ virtual void lcl_endGlossaryEntry() override;
// Properties
virtual void lcl_attribute(Id Name, Value & val) override;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a11b10c78844..bbcdc2c58445 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1559,6 +1559,11 @@ uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
return xRet;
}
+uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendGlossaryEntry()
+{
+ return appendTextSectionAfter(m_xGlossaryEntryStart);
+}
+
void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType)
{
m_aHeaderFooterStack.push(HeaderFooterContext(m_bTextInserted));
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index de7c95dda550..0b033a3a8618 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -463,6 +463,8 @@ private:
std::map<sal_Int32, css::uno::Any> deferredCharacterProperties;
SmartTagHandler m_aSmartTagHandler;
+ css::uno::Reference<css::text::XTextRange> m_xGlossaryEntryStart;
+
public:
css::uno::Reference<css::text::XTextRange> m_xInsertTextRange;
private:
@@ -556,6 +558,14 @@ public:
void appendStarMath( const Value& v );
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();
+ /// Remember where entry was started
+ void setGlossaryEntryStart( css::uno::Reference<css::text::XTextRange>& xStart )
+ {
+ m_xGlossaryEntryStart = xStart;
+ }
+
// push the new properties onto the stack and make it the 'current' property map
void PushProperties(ContextType eId);
void PushStyleProperties(const PropertyMapPtr& pStyleProperties);
diff --git a/writerfilter/source/dmapper/LoggedResources.cxx b/writerfilter/source/dmapper/LoggedResources.cxx
index 55ade5a41138..33744b9765e7 100644
--- a/writerfilter/source/dmapper/LoggedResources.cxx
+++ b/writerfilter/source/dmapper/LoggedResources.cxx
@@ -301,6 +301,32 @@ void LoggedStream::info(const std::string & _info)
#endif
}
+void LoggedStream::startGlossaryEntry()
+{
+#ifdef DEBUG_WRITERFILTER
+ mHelper.startElement("startGlossaryEntry");
+#endif
+
+ lcl_startGlossaryEntry();
+
+#ifdef DEBUG_WRITERFILTER
+ LoggedResourcesHelper::endElement("startGlossaryEntry");
+#endif
+}
+
+void LoggedStream::endGlossaryEntry()
+{
+#ifdef DEBUG_WRITERFILTER
+ mHelper.startElement("endGlossaryEntry");
+#endif
+
+ lcl_endGlossaryEntry();
+
+#ifdef DEBUG_WRITERFILTER
+ LoggedResourcesHelper::endElement("endGlossaryEntry");
+#endif
+}
+
// class LoggedProperties
LoggedProperties::LoggedProperties(
#ifdef DEBUG_WRITERFILTER
diff --git a/writerfilter/source/dmapper/LoggedResources.hxx b/writerfilter/source/dmapper/LoggedResources.hxx
index 0c466448a85b..c5d59a68a9ec 100644
--- a/writerfilter/source/dmapper/LoggedResources.hxx
+++ b/writerfilter/source/dmapper/LoggedResources.hxx
@@ -69,6 +69,8 @@ public:
void table(Id name, writerfilter::Reference<Table>::Pointer_t ref) override;
void substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref) override;
void info(const std::string & info) override;
+ void startGlossaryEntry() override;
+ void endGlossaryEntry() override;
protected:
virtual void lcl_startSectionGroup() = 0;
@@ -89,6 +91,8 @@ protected:
virtual void lcl_table(Id name, writerfilter::Reference<Table>::Pointer_t ref) = 0;
virtual void lcl_substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref) = 0;
virtual void lcl_info(const std::string & info) = 0;
+ virtual void lcl_startGlossaryEntry() { }
+ virtual void lcl_endGlossaryEntry() { }
#ifdef DEBUG_WRITERFILTER
LoggedResourcesHelper mHelper;
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index bc3140662aad..3310314d1436 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -641,6 +641,18 @@ void OOXMLFastContextHandler::positivePercentage(const OUString& rText)
mpStream->positivePercentage(rText);
}
+void OOXMLFastContextHandler::startGlossaryEntry()
+{
+ if (isForwardEvents())
+ mpStream->startGlossaryEntry();
+}
+
+void OOXMLFastContextHandler::endGlossaryEntry()
+{
+ if (isForwardEvents())
+ mpStream->endGlossaryEntry();
+}
+
void OOXMLFastContextHandler::propagateCharacterProperties()
{
mpParserState->setCharacterProperties(getPropertySet());
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index f1786c6f0471..40d44c158c95 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -163,6 +163,8 @@ public:
void alignH(const OUString & sText);
void alignV(const OUString & sText);
void positivePercentage(const OUString& rText);
+ void startGlossaryEntry();
+ void endGlossaryEntry();
void startTxbxContent();
void endTxbxContent();
void propagateCharacterProperties();
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index f241efc7c291..f943618a35bd 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -19058,7 +19058,10 @@
<resource name="CT_Document" resource="Stream"/>
<resource name="CT_GlossaryDocument" resource="Stream"/>
<resource name="CT_DocParts" resource="Stream"/>
- <resource name="CT_DocPart" resource="Stream"/>
+ <resource name="CT_DocPart" resource="Stream">
+ <action name="start" action="startGlossaryEntry"/>
+ <action name="end" action="endGlossaryEntry"/>
+ </resource>
<resource name="document" resource="Stream"/>
<resource name="glossaryDocument" resource="Stream"/>
<resource name="CT_TxbxContent" resource="Stream">
More information about the Libreoffice-commits
mailing list