Kaydet (Commit) 9679e9c2 authored tarafından Vinaya Mandke's avatar Vinaya Mandke Kaydeden (comit) Miklos Vajna

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
üst c619f874
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <unotools/ucbstreamhelper.hxx> #include <unotools/ucbstreamhelper.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <libxml/xpathInternals.h> #include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h> #include <libxml/parserInternals.h>
...@@ -2213,6 +2214,18 @@ DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedParagraphMark, "testTrackChange ...@@ -2213,6 +2214,18 @@ DECLARE_OOXMLEXPORT_TEST(testTrackChangesInsertedParagraphMark, "testTrackChange
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:ins"); 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 #endif
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include <com/sun/star/table/TableBorder2.hpp> #include <com/sun/star/table/TableBorder2.hpp>
#include <com/sun/star/text/SizeType.hpp> #include <com/sun/star/text/SizeType.hpp>
#include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/xml/dom/XDocument.hpp>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <unotools/fltrcfg.hxx> #include <unotools/fltrcfg.hxx>
...@@ -1670,6 +1670,21 @@ DECLARE_OOXMLIMPORT_TEST(testFdo65090, "fdo65090.docx") ...@@ -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()); 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 #endif
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/awt/XControlModel.hpp> #include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
#include <oox/mathml/import.hxx> #include <oox/mathml/import.hxx>
#ifdef DEBUG_DOMAINMAPPER #ifdef DEBUG_DOMAINMAPPER
...@@ -151,6 +152,8 @@ DomainMapper_Impl::DomainMapper_Impl( ...@@ -151,6 +152,8 @@ DomainMapper_Impl::DomainMapper_Impl(
m_bIsFirstSection( true ), m_bIsFirstSection( true ),
m_bIsColumnBreakDeferred( false ), m_bIsColumnBreakDeferred( false ),
m_bIsPageBreakDeferred( false ), m_bIsPageBreakDeferred( false ),
m_bStartTOC(false),
m_bTOCPageRef(false),
m_pLastSectionContext( ), m_pLastSectionContext( ),
m_pLastCharacterContext(), m_pLastCharacterContext(),
m_nCurrentTabStopIndex( 0 ), m_nCurrentTabStopIndex( 0 ),
...@@ -1183,14 +1186,46 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapP ...@@ -1183,14 +1186,46 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapP
{ {
try 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; uno::Reference< text::XTextRange > xTextRange;
if (m_aTextAppendStack.top().xInsertPosition.is()) 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); m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), false);
} }
else 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 ); CheckRedline( xTextRange );
m_bParaChanged = true; m_bParaChanged = true;
...@@ -2657,6 +2692,7 @@ void DomainMapper_Impl::handleToc ...@@ -2657,6 +2692,7 @@ void DomainMapper_Impl::handleToc
const OUString & sTOCServiceName) const OUString & sTOCServiceName)
{ {
OUString sValue; OUString sValue;
m_bStartTOC = true;
bool bTableOfFigures = false; bool bTableOfFigures = false;
bool bHyperlinks = false; bool bHyperlinks = false;
bool bFromOutline = false; bool bFromOutline = false;
...@@ -2853,6 +2889,25 @@ void DomainMapper_Impl::handleToc ...@@ -2853,6 +2889,25 @@ void DomainMapper_Impl::handleToc
} }
} }
pContext->SetTOC( xTOC ); 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() ...@@ -2916,6 +2971,11 @@ void DomainMapper_Impl::CloseFieldCommand()
default: default:
break; break;
} }
if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
{
m_bTOCPageRef = true;
bCreateField = false;
}
if( bCreateField || bCreateEnhancedField ) if( bCreateField || bCreateEnhancedField )
{ {
...@@ -3227,7 +3287,7 @@ void DomainMapper_Impl::CloseFieldCommand() ...@@ -3227,7 +3287,7 @@ void DomainMapper_Impl::CloseFieldCommand()
break; break;
case FIELD_PAGEREF: case FIELD_PAGEREF:
case FIELD_REF: case FIELD_REF:
if (xFieldProperties.is()) if (xFieldProperties.is() && !m_bStartTOC)
{ {
bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF; bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(), OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(),
...@@ -3554,15 +3614,22 @@ void DomainMapper_Impl::PopFieldContext() ...@@ -3554,15 +3614,22 @@ void DomainMapper_Impl::PopFieldContext()
uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY ); uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
if( xToInsert.is() ) if( xToInsert.is() )
{ {
xCrsr->gotoEnd( true ); m_bStartTOC = false;
xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW )); m_aTextAppendStack.pop();
if(xTOCMarkerCursor.is())
{
xTOCMarkerCursor->goLeft(1,sal_True);
xTOCMarkerCursor->setString(OUString());
xTOCMarkerCursor->goLeft(1,sal_True);
xTOCMarkerCursor->setString(OUString());
}
} }
else else
{ {
xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY); 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); xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
if( xToInsert.is() ) if( xToInsert.is() && !m_bStartTOC)
{ {
uno::Sequence<beans::PropertyValue> aValues; uno::Sequence<beans::PropertyValue> aValues;
// Character properties of the field show up here the // Character properties of the field show up here the
...@@ -3599,6 +3666,12 @@ void DomainMapper_Impl::PopFieldContext() ...@@ -3599,6 +3666,12 @@ void DomainMapper_Impl::PopFieldContext()
uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW ); uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno:: xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
makeAny(pContext->GetHyperlinkURL())); makeAny(pContext->GetHyperlinkURL()));
if (m_bStartTOC) {
OUString sDisplayName("Index Link");
xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName));
xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName));
}
} }
} }
} }
......
...@@ -329,6 +329,8 @@ private: ...@@ -329,6 +329,8 @@ private:
bool m_bIsFirstSection; bool m_bIsFirstSection;
bool m_bIsColumnBreakDeferred; bool m_bIsColumnBreakDeferred;
bool m_bIsPageBreakDeferred; bool m_bIsPageBreakDeferred;
bool m_bStartTOC;
bool m_bTOCPageRef;
LineNumberSettings m_aLineNumberSettings; LineNumberSettings m_aLineNumberSettings;
...@@ -392,6 +394,8 @@ private: ...@@ -392,6 +394,8 @@ private:
bool m_bSdt; bool m_bSdt;
bool m_bIsFirstRun; bool m_bIsFirstRun;
uno::Reference< text::XTextCursor > xTOCMarkerCursor;
//annotation import //annotation import
uno::Reference< beans::XPropertySet > m_xAnnotationField; uno::Reference< beans::XPropertySet > m_xAnnotationField;
AnnotationPosition m_aAnnotationPosition; AnnotationPosition m_aAnnotationPosition;
......
...@@ -58,20 +58,10 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) thro ...@@ -58,20 +58,10 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) thro
{ {
PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( rEvent.Source, uno::UNO_QUERY );
//remove listener //remove listener
uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener( uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY )->removeEventListener(
uno::Reference<document::XEventListener>(this)); 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. // If we have PAGEREF fields, update fields as well.
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY); uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY); uno::Reference<container::XEnumeration> xEnumeration(xTextFieldsSupplier->getTextFields()->createEnumeration(), uno::UNO_QUERY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment