summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinaya Mandke <vinaya.mandke@synerzip.com>2013-12-30 16:22:30 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-06-03 16:43:39 +0200
commit7bbfdfdac302d766325bd3476f52eb35854d7c38 (patch)
tree08085568c2a60c8b608b79d2adf5bfd8a7677440
parent11f54c327592080e3d918283bd7804ef6d704613 (diff)
fdo#79547 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 (cherry picked from commit 9679e9c23216decb5f9f25f85b04cb3f25211111) Conflicts: writerfilter/source/dmapper/DomainMapper_Impl.cxx Change-Id: I966b3d268dd407aa05823e29fe1da4d097091265
-rw-r--r--sw/qa/extras/ooxmlexport/data/fdo69649.docxbin0 -> 35048 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx13
-rw-r--r--sw/qa/extras/ooxmlimport/data/fdo69649.docxbin0 -> 35048 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx17
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx87
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx4
-rw-r--r--writerfilter/source/dmapper/ModelEventListener.cxx10
7 files changed, 113 insertions, 18 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/fdo69649.docx b/sw/qa/extras/ooxmlexport/data/fdo69649.docx
new file mode 100644
index 000000000000..cb0f78999880
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/fdo69649.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index ef0fa568b4eb..ccb299d56fe5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -42,6 +42,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>
@@ -2066,6 +2067,18 @@ DECLARE_OOXMLEXPORT_TEST(testfdo79008, "fdo79008.docx")
return;
}
+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 000000000000..cb0f78999880
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/fdo69649.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 7f7078cb5e91..47c499ad3344 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -42,7 +42,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>
@@ -1677,6 +1677,21 @@ DECLARE_OOXMLIMPORT_TEST(testBnc875718, "bnc875718.docx")
CPPUNIT_ASSERT_EQUAL( OUString( "Text\n" ), text->getString());
}
+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 2e6538ad2296..89472c68f29c 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
@@ -152,6 +153,8 @@ DomainMapper_Impl::DomainMapper_Impl(
m_bIsFirstSection( true ),
m_bIsColumnBreakDeferred( false ),
m_bIsPageBreakDeferred( false ),
+ m_bStartTOC(false),
+ m_bTOCPageRef(false),
m_nSymboldata(-1),
m_pLastSectionContext( ),
m_pLastCharacterContext(),
@@ -1221,14 +1224,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;
@@ -2778,6 +2813,7 @@ void DomainMapper_Impl::handleToc
const OUString & sTOCServiceName)
{
OUString sValue;
+ m_bStartTOC = true;
bool bTableOfFigures = false;
bool bHyperlinks = false;
bool bFromOutline = false;
@@ -2974,6 +3010,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;
+ }
+ }
}
@@ -3040,6 +3095,11 @@ void DomainMapper_Impl::CloseFieldCommand()
default:
break;
}
+ if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
+ {
+ m_bTOCPageRef = true;
+ bCreateField = false;
+ }
if( bCreateField || bCreateEnhancedField )
{
@@ -3351,7 +3411,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;
@@ -3695,15 +3755,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
@@ -3740,6 +3807,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 3c95a4c15742..9957e8de2c46 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -330,6 +330,8 @@ private:
bool m_bIsFirstSection;
bool m_bIsColumnBreakDeferred;
bool m_bIsPageBreakDeferred;
+ bool m_bStartTOC;
+ bool m_bTOCPageRef;
LineNumberSettings m_aLineNumberSettings;
@@ -393,6 +395,8 @@ private:
/// If the current paragraph is inside a structured document element.
bool m_bSdt;
+ 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 8da32243252f..45077b4a6e74 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);