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

sushil_shinde sushil.shinde at synerzip.com
Fri Mar 7 01:19:30 PST 2014


 sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                 |   13 +++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx        |   38 ++++++++++++++-
 writerfilter/source/dmapper/DomainMapper_Impl.hxx        |    3 -
 4 files changed, 51 insertions(+), 3 deletions(-)

New commits:
commit c6b99eedda03461202f9bf012a422dfd81da72ec
Author: sushil_shinde <sushil.shinde at synerzip.com>
Date:   Fri Feb 28 15:33:10 2014 +0530

    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 at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx b/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx
new file mode 100644
index 0000000..698142e
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/Unsupportedtextfields.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index c51b58a..f9fda5f 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 0d08a38..7d63908 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 6c7cac5..2b54bb8 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;


More information about the Libreoffice-commits mailing list