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

Vinaya Mandke vinaya.mandke at synerzip.com
Fri Jan 3 00:38:24 PST 2014


 sw/qa/extras/ooxmlexport/data/fdo69649.docx        |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx           |   13 +++
 sw/qa/extras/ooxmlimport/data/fdo69649.docx        |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx           |   17 +++-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx  |   87 +++++++++++++++++++--
 writerfilter/source/dmapper/DomainMapper_Impl.hxx  |    4 
 writerfilter/source/dmapper/ModelEventListener.cxx |   10 --
 7 files changed, 113 insertions(+), 18 deletions(-)

New commits:
commit 9679e9c23216decb5f9f25f85b04cb3f25211111
Author: Vinaya Mandke <vinaya.mandke at synerzip.com>
Date:   Mon Dec 30 16:22:30 2013 +0530

    fdo#69649 Fix for pre-rendered Table Of Contents
    
    Added Import and Export Uts for the same
    
    Conflicts:
    	sw/qa/extras/ooxmlexport/ooxmlexport.cxx
    Reviewed on:
    	https://gerrit.libreoffice.org/7207
    
    Change-Id: I966b3d268dd407aa05823e29fe1da4d097091265

diff --git a/sw/qa/extras/ooxmlexport/data/fdo69649.docx b/sw/qa/extras/ooxmlexport/data/fdo69649.docx
new file mode 100644
index 0000000..cb0f789
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo69649.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 1e20734..fa90304 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -43,6 +43,7 @@
 #include <unotools/tempfile.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <rtl/strbuf.hxx>
+#include <com/sun/star/text/XDocumentIndex.hpp>
 
 #include <libxml/xpathInternals.h>
 #include <libxml/parserInternals.h>
@@ -2213,6 +2214,18 @@ DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedParagraphMark, "testTrackChange
     assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:ins");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testFdo69649, "fdo69649.docx")
+{
+    // The DOCX containing the Table of Contents was not exported with correct page nos
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    if (!pXmlDoc)
+        return;
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[21]/w:hyperlink/w:r[2]/w:t");
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
+    CPPUNIT_ASSERT(contents.match("15"));
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/ooxmlimport/data/fdo69649.docx b/sw/qa/extras/ooxmlimport/data/fdo69649.docx
new file mode 100644
index 0000000..cb0f789
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/fdo69649.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 7804340..b79b6fb 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -43,7 +43,7 @@
 #include <com/sun/star/table/TableBorder2.hpp>
 #include <com/sun/star/text/SizeType.hpp>
 #include <com/sun/star/xml/dom/XDocument.hpp>
-
+#include <com/sun/star/text/XDocumentIndex.hpp>
 #include <vcl/svapp.hxx>
 #include <unotools/fltrcfg.hxx>
 
@@ -1670,6 +1670,21 @@ DECLARE_OOXMLIMPORT_TEST(testFdo65090, "fdo65090.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testFdo69649, "fdo69649.docx")
+{
+    // The DOCX containing the Table of Contents was not imported with correct page nos
+    uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes( ), uno::UNO_QUERY);
+    uno::Reference<text::XDocumentIndex> xTOCIndex(xIndexes->getByIndex(0), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xTextRange(xTOCIndex->getAnchor(), uno::UNO_QUERY);
+    uno::Reference<text::XText> xText(xTextRange->getText( ), uno::UNO_QUERY);
+    uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor( ), uno::UNO_QUERY);
+    xTextCursor->gotoRange(xTextRange->getStart(),false);
+    xTextCursor->gotoRange(xTextRange->getEnd(),true);
+    OUString xTocString(xTextCursor->getString());
+    xTocString = xTocString.copy(256);
+    CPPUNIT_ASSERT(xTocString.startsWithIgnoreAsciiCase( "Heading 15.1:\t15" ) );
+}
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 55f7a8f..ded8cd9 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -56,6 +56,7 @@
 #include <com/sun/star/container/XIndexContainer.hpp>
 #include <com/sun/star/awt/XControlModel.hpp>
 #include <com/sun/star/drawing/XControlShape.hpp>
+#include <com/sun/star/text/ControlCharacter.hpp>
 #include <oox/mathml/import.hxx>
 
 #ifdef DEBUG_DOMAINMAPPER
@@ -151,6 +152,8 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_bIsFirstSection( true ),
         m_bIsColumnBreakDeferred( false ),
         m_bIsPageBreakDeferred( false ),
+        m_bStartTOC(false),
+        m_bTOCPageRef(false),
         m_pLastSectionContext( ),
         m_pLastCharacterContext(),
         m_nCurrentTabStopIndex( 0 ),
@@ -1183,14 +1186,46 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapP
     {
         try
         {
+            uno::Sequence< beans::PropertyValue > pValues = pPropertyMap->GetPropertyValues();
+            sal_Int32 len = pValues.getLength();
+
+            if (m_bStartTOC)
+                for( int i =0; i < len; ++i )
+                {
+                    if (pValues[i].Name == "CharHidden")
+                        pValues[i].Value = uno::makeAny(sal_False);
+                }
+
             uno::Reference< text::XTextRange > xTextRange;
             if (m_aTextAppendStack.top().xInsertPosition.is())
             {
-                xTextRange = xTextAppend->insertTextPortion(rString, pPropertyMap->GetPropertyValues(), m_aTextAppendStack.top().xInsertPosition);
+                xTextRange = xTextAppend->insertTextPortion(rString, pValues, m_aTextAppendStack.top().xInsertPosition);
                 m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), false);
             }
             else
-                xTextRange = xTextAppend->appendTextPortion(rString, pPropertyMap->GetPropertyValues());
+            {
+                if (m_bStartTOC)
+                {
+                    uno::Reference< text::XTextCursor > xTOCTextCursor;
+                    xTOCTextCursor = xTextAppend->getEnd()->getText( )->createTextCursor( );
+                    xTOCTextCursor->gotoEnd(false);
+                    if (xTOCTextCursor.is())
+                    {
+                        xTextRange = xTextAppend->insertTextPortion(rString, pValues, xTOCTextCursor);
+                        xTOCTextCursor->gotoRange(xTextRange->getEnd(), true);
+                    }
+                    else
+                    {
+                        xTextRange = xTextAppend->appendTextPortion(rString, pValues);
+                        xTOCTextCursor = xTextAppend->createTextCursor();
+                        xTOCTextCursor->gotoRange(xTextRange->getEnd(), false);
+                    }
+                    m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor));
+                }
+                else
+                    xTextRange = xTextAppend->appendTextPortion(rString, pValues);
+            }
+
             CheckRedline( xTextRange );
             m_bParaChanged = true;
 
@@ -2657,6 +2692,7 @@ void DomainMapper_Impl::handleToc
     const OUString & sTOCServiceName)
 {
     OUString sValue;
+    m_bStartTOC = true;
     bool bTableOfFigures = false;
     bool bHyperlinks = false;
     bool bFromOutline = false;
@@ -2853,6 +2889,25 @@ void DomainMapper_Impl::handleToc
         }
     }
     pContext->SetTOC( xTOC );
+
+
+    OUString sMarker("Y");
+    //insert index
+    uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
+    uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
+    if (xTextAppend.is())
+    {
+        uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor();
+
+        uno::Reference< text::XText > xText = xTextAppend->getText();
+        if(xCrsr.is() && xText.is())
+        {
+            xCrsr->gotoEnd(false);
+            xText->insertString(xCrsr, sMarker, sal_False);
+            xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, sal_False);
+            xTOCMarkerCursor = xCrsr;
+        }
+    }
 }
 
 
@@ -2916,6 +2971,11 @@ void DomainMapper_Impl::CloseFieldCommand()
                 default:
                     break;
                 }
+                if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
+                {
+                    m_bTOCPageRef = true;
+                    bCreateField = false;
+                }
 
                 if( bCreateField || bCreateEnhancedField )
                 {
@@ -3227,7 +3287,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                     break;
                     case FIELD_PAGEREF:
                     case FIELD_REF:
-                    if (xFieldProperties.is())
+                    if (xFieldProperties.is() && !m_bStartTOC)
                     {
                         bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
                         OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(),
@@ -3554,15 +3614,22 @@ void DomainMapper_Impl::PopFieldContext()
                 uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
                 if( xToInsert.is() )
                 {
-                    xCrsr->gotoEnd( true );
-                    xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
+                    m_bStartTOC = false;
+                    m_aTextAppendStack.pop();
+                    if(xTOCMarkerCursor.is())
+                    {
+                        xTOCMarkerCursor->goLeft(1,sal_True);
+                        xTOCMarkerCursor->setString(OUString());
+                        xTOCMarkerCursor->goLeft(1,sal_True);
+                        xTOCMarkerCursor->setString(OUString());
+                    }
                 }
                 else
                 {
                     xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY);
-                    if( !xToInsert.is() )
+                    if( !xToInsert.is() && !m_bStartTOC )
                         xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
-                    if( xToInsert.is() )
+                    if( xToInsert.is() && !m_bStartTOC)
                     {
                         uno::Sequence<beans::PropertyValue> aValues;
                         // Character properties of the field show up here the
@@ -3599,6 +3666,12 @@ void DomainMapper_Impl::PopFieldContext()
                             uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
                             xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
                                                               makeAny(pContext->GetHyperlinkURL()));
+
+                            if (m_bStartTOC) {
+                                OUString sDisplayName("Index Link");
+                                xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName));
+                                xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName));
+                            }
                         }
                     }
                 }
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 02dc2e4..c4c1d9d 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -329,6 +329,8 @@ private:
     bool                                                                            m_bIsFirstSection;
     bool                                                                            m_bIsColumnBreakDeferred;
     bool                                                                            m_bIsPageBreakDeferred;
+    bool                                                                            m_bStartTOC;
+    bool                                                                            m_bTOCPageRef;
 
     LineNumberSettings                                                              m_aLineNumberSettings;
 
@@ -392,6 +394,8 @@ private:
     bool                            m_bSdt;
     bool                            m_bIsFirstRun;
 
+    uno::Reference< text::XTextCursor > xTOCMarkerCursor;
+
     //annotation import
     uno::Reference< beans::XPropertySet >                                      m_xAnnotationField;
     AnnotationPosition                                                         m_aAnnotationPosition;
diff --git a/writerfilter/source/dmapper/ModelEventListener.cxx b/writerfilter/source/dmapper/ModelEventListener.cxx
index 8da3224..45077b4 100644
--- a/writerfilter/source/dmapper/ModelEventListener.cxx
+++ b/writerfilter/source/dmapper/ModelEventListener.cxx
@@ -58,20 +58,10 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) thro
         {
             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
 
-            uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( rEvent.Source, uno::UNO_QUERY );
             //remove listener
             uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
             uno::Reference<document::XEventListener>(this));
 
-            uno::Reference< container::XIndexAccess > xIndexes = xIndexesSupplier->getDocumentIndexes();
-
-            sal_Int32 nIndexes = xIndexes->getCount();
-            for( sal_Int32 nIndex = 0; nIndex < nIndexes; ++nIndex)
-            {
-                uno::Reference< text::XDocumentIndex> xIndex( xIndexes->getByIndex( nIndex ), uno::UNO_QUERY );
-                xIndex->update();
-            }
-
             // If we have PAGEREF fields, update fields as well.
             uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY);
             uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY);


More information about the Libreoffice-commits mailing list