diff options
author | sushil_shinde <sushil.shinde@synerzip.com> | 2014-02-28 15:33:10 +0530 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-03-07 03:19:07 -0600 |
commit | c6b99eedda03461202f9bf012a422dfd81da72ec (patch) | |
tree | 102e75062d9fc9b78f9378f369fb23c6254f282f | |
parent | af42ac01a4931714d5e362cee253e34b9b3689b1 (diff) |
fdo#75158 : Handled unsupported fields for docx file.
- Handled unsupported fields using fieldmark API.
- Added Unit Test.
Change-Id: I0c69458f330fa2e98821c392ea97410fe1b1e20e
Reviewed-on: https://gerrit.libreoffice.org/8391
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx | bin | 0 -> 15608 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 13 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 38 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 |
4 files changed, 51 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx b/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx Binary files differnew file mode 100644 index 000000000000..698142effe46 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index c51b58a340c4..f9fda5fb1eb3 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -2950,6 +2950,19 @@ DECLARE_OOXMLEXPORT_TEST(testTableCurruption, "tableCurrupt.docx") assertXPath(pXmlDoc, "/w:hdr/w:tbl[1]/w:tr[1]/w:tc[1]",1); } +DECLARE_OOXMLEXPORT_TEST(testGenericTextField, "Unsupportedtextfields.docx") +{ + // fdo#75158 : This test case is to verify the unsupported textfields are exported properly. + + xmlDocPtr pXmlDoc = parseExport(); + if (!pXmlDoc) + return; + xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:r[2]/w:instrText"); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)); + CPPUNIT_ASSERT(contents.match("PRINTDATE \\* MERGEFORMAT")); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 0d08a38296f6..7d63908ff666 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -151,6 +151,8 @@ DomainMapper_Impl::DomainMapper_Impl( m_bStartIndex(false), m_bStartBibliography(false), m_bTOCPageRef(false), + m_bStartGenericField(false), + m_bTextInserted(false), m_pLastSectionContext( ), m_pLastCharacterContext(), m_nCurrentTabStopIndex( 0 ), @@ -1146,7 +1148,7 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapP } else { - if (m_bStartTOC || m_bStartIndex || m_bStartBibliography) + if (m_bStartTOC || m_bStartIndex || m_bStartBibliography || m_bStartGenericField) { m_bStartedTOC = true; uno::Reference< text::XTextCursor > xTOCTextCursor; @@ -1154,9 +1156,10 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapP xTOCTextCursor->gotoEnd(false); if (xTOCTextCursor.is()) { - if (m_bStartIndex || m_bStartBibliography) + if (m_bStartIndex || m_bStartBibliography || m_bStartGenericField) xTOCTextCursor->goLeft(1, false); xTextRange = xTextAppend->insertTextPortion(rString, pValues, xTOCTextCursor); + m_bTextInserted = true; xTOCTextCursor->gotoRange(xTextRange->getEnd(), true); mxTOCTextCursor = xTOCTextCursor; } @@ -3587,6 +3590,28 @@ void DomainMapper_Impl::CloseFieldCommand() break; } } + else + { + /* Unsupported fields will be handled here for docx file. + * To handle unsupported fields used fieldmark API. + */ + static const OUString sAPI_unsupportedfield( "com.sun.star.text.Fieldmark"); + OUString aCode( pContext->GetCommand().trim() ); + xFieldInterface = m_xTextFactory->createInstance(sAPI_unsupportedfield); + const uno::Reference<text::XTextContent> xTextContent(xFieldInterface, uno::UNO_QUERY_THROW); + uno::Reference< text::XTextAppend > xTextAppend; + xTextAppend = m_aTextAppendStack.top().xTextAppend; + uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange()); + if (xTextContent.is()) + { + xTextAppend->insertTextContent(xCrsr,xTextContent, sal_True); + } + const uno::Reference<uno::XInterface> xContent(xTextContent); + uno::Reference< text::XFormField> xFormField(xContent, uno::UNO_QUERY); + xFormField->setFieldType(aCode); + m_bStartGenericField = true; + pContext->SetFormField( xFormField ); + } //set the text field if there is any pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) ); } @@ -3819,6 +3844,15 @@ void DomainMapper_Impl::PopFieldContext() xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName)); } } + else if(m_bStartGenericField) + { + m_bStartGenericField = false; + if(m_bTextInserted) + { + m_aTextAppendStack.pop(); + m_bTextInserted = false; + } + } } } } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 6c7cac57cdfc..2b54bb879bc2 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -322,7 +322,8 @@ private: bool m_bStartIndex; bool m_bStartBibliography; bool m_bTOCPageRef; - + bool m_bStartGenericField; + bool m_bTextInserted; LineNumberSettings m_aLineNumberSettings; BookmarkMap_t m_aBookmarkMap; |