diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-07-17 14:59:19 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-11-17 09:32:01 +0000 |
commit | 084d5986823e7bd7baaa68450c0a6b4772c84246 (patch) | |
tree | b54578c9911167523121f9e435a5f1d1de45498d | |
parent | a1a76a362ab8ad23e54791da2711b76907f1edad (diff) |
fdo#84645 RTF import: set DontBalanceTextColumns=true for the last section ...
... if it has multiple columns. See commit
d185204737031955c56a24356ed003d342548434 (DOCX import: set
DontBalanceTextColumns=true for the last section, 2014-07-17) for the
DOCX equivalent of this problem; this just adapts the RTF tokenizer to
dmapper.
(cherry picked from commit d185204737031955c56a24356ed003d342548434)
(cherry picked from commit f4bb73164a51ec83fe1d5975b1232d35f8a9e88a)
Change-Id: Ib30f9b386e204b8b2987832ab17ee0cc53b3f0bc
Reviewed-on: https://gerrit.libreoffice.org/12462
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rwxr-xr-x | sw/qa/extras/ooxmlimport/data/unbalanced-columns.docx | bin | 0 -> 12820 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 8 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/data/unbalanced-columns.rtf | 5 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 8 | ||||
-rw-r--r-- | writerfilter/inc/dmapper/DomainMapper.hxx | 1 | ||||
-rw-r--r-- | writerfilter/inc/resourcemodel/WW8ResourceModel.hxx | 3 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/ooxml/model.xml | 1 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 6 |
15 files changed, 59 insertions, 4 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/unbalanced-columns.docx b/sw/qa/extras/ooxmlimport/data/unbalanced-columns.docx Binary files differnew file mode 100755 index 000000000000..da6f93f760ae --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/unbalanced-columns.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 900a25ee478c..008200958116 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -2395,6 +2395,14 @@ DECLARE_OOXMLIMPORT_TEST(testBnc821804, "bnc821804.docx") CPPUNIT_ASSERT_EQUAL(false,getProperty<bool>(getRun(getParagraph(10), 3), "IsStart")); } +DECLARE_OOXMLIMPORT_TEST(testUnbalancedColumns, "unbalanced-columns.docx") +{ + uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTextSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); + // This was false, last section was balanced, but it's unbalanced in Word. + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextSections->getByIndex(2), "DontBalanceTextColumns")); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf b/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf new file mode 100644 index 000000000000..aa57e382dc33 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/unbalanced-columns.rtf @@ -0,0 +1,5 @@ +{\rtf1 +\cols2 +\pard\plain First paragraph.\par +Second paragraph.\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 1214051dc7aa..8a6c6daa4edf 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2009,6 +2009,14 @@ DECLARE_RTFIMPORT_TEST(testFdo82512, "fdo82512.rtf") CPPUNIT_ASSERT_EQUAL(style::BreakType_COLUMN_BEFORE, getProperty<style::BreakType>(getParagraph(2), "BreakType")); } +DECLARE_RTFIMPORT_TEST(testUnbalancedColumns, "unbalanced-columns.rtf") +{ + uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTextSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY); + // This was false, last section was balanced, but it's unbalanced in Word. + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextSections->getByIndex(0), "DontBalanceTextColumns")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/dmapper/DomainMapper.hxx b/writerfilter/inc/dmapper/DomainMapper.hxx index 9266f0834478..7143219a93fc 100644 --- a/writerfilter/inc/dmapper/DomainMapper.hxx +++ b/writerfilter/inc/dmapper/DomainMapper.hxx @@ -87,6 +87,7 @@ public: // Stream virtual void markLastParagraphInSection() SAL_OVERRIDE; + virtual void markLastSectionGroup() SAL_OVERRIDE; // BinaryObj virtual void data(const sal_uInt8* buf, size_t len, diff --git a/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx b/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx index 0d3634276e70..dd64b34473ca 100644 --- a/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx +++ b/writerfilter/inc/resourcemodel/WW8ResourceModel.hxx @@ -197,6 +197,9 @@ public: */ virtual void endSectionGroup() = 0; + /// The current section is the last one in this body text. + virtual void markLastSectionGroup( ) { }; + /** Receives start mark for group with the same paragraph properties. */ diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 7c8ac2073131..8bc332083a1d 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2576,6 +2576,11 @@ void DomainMapper::markLastParagraphInSection( ) m_pImpl->SetIsLastParagraphInSection( true ); } +void DomainMapper::markLastSectionGroup( ) +{ + m_pImpl->SetIsLastSectionGroup( true ); +} + void DomainMapper::lcl_startShape( uno::Reference< drawing::XShape > xShape ) { if (m_pImpl->GetTopContext()) diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 41d12af13f53..c3343f1eb799 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -188,6 +188,7 @@ DomainMapper_Impl::DomainMapper_Impl( m_bDummyParaAddedForTableInSection( false ), m_bTextFrameInserted(false), m_bIsLastParaInSection( false ), + m_bIsLastSectionGroup( false ), m_bIsInComments( false ), m_bParaSectpr( false ), m_bUsingEnhancedFields( false ), @@ -396,6 +397,11 @@ sal_Int32 DomainMapper_Impl::GetSymbolData() return m_nSymboldata; } +void DomainMapper_Impl::SetIsLastSectionGroup( bool bIsLast ) +{ + m_bIsLastSectionGroup = bIsLast; +} + void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast ) { m_bIsLastParaInSection = bIsLast; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index e60eab466fe9..f72c8666bb40 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -374,6 +374,7 @@ private: bool m_bDummyParaAddedForTableInSection; bool m_bTextFrameInserted; bool m_bIsLastParaInSection; + bool m_bIsLastSectionGroup; bool m_bIsInComments; /// If the current paragraph contains section property definitions. bool m_bParaSectpr; @@ -452,6 +453,8 @@ public: void RemoveLastParagraph( ); void SetIsLastParagraphInSection( bool bIsLast ); bool GetIsLastParagraphInSection(); + void SetIsLastSectionGroup( bool bIsLast ); + bool GetIsLastSectionGroup() { return m_bIsLastSectionGroup;} void SetIsFirstParagraphInSection( bool bIsFirst ); bool GetIsFirstParagraphInSection(); void SetIsDummyParaAddedForTableInSection( bool bIsAdded ); diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 2512a9d5b0ea..5014d63d6870 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -619,7 +619,7 @@ void SectionPropertyMap::SetBorderDistance( uno::Reference< beans::XPropertySet uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties( - uno::Reference< beans::XPropertySet > xColumnContainer ) + uno::Reference< beans::XPropertySet > xColumnContainer, bool bLast ) { uno::Reference< text::XTextColumns > xColumns; try @@ -671,6 +671,8 @@ uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties( rPropNameSupplier.GetName( PROP_SEPARATOR_LINE_IS_ON ), uno::makeAny( m_bSeparatorLineIsOn )); xColumnContainer->setPropertyValue( sTextColumns, uno::makeAny( xColumns ) ); + if (bLast) + xColumnContainer->setPropertyValue("DontBalanceTextColumns", uno::makeAny(true)); } catch( const uno::Exception& ) { @@ -980,7 +982,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) uno::Reference< beans::XPropertySet > xSection = rDM_Impl.appendTextSectionAfter( m_xStartingRange ); if( m_nColumnCount > 0 && xSection.is()) - ApplyColumnProperties( xSection ); + ApplyColumnProperties( xSection, rDM_Impl.GetIsLastSectionGroup() ); uno::Reference<beans::XPropertySet> xRangeProperties(lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange)); if (xRangeProperties.is()) { @@ -1036,7 +1038,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) } uno::Reference< text::XTextColumns > xColumns; if( m_nColumnCount > 0 ) - xColumns = ApplyColumnProperties( xFollowPageStyle ); + xColumns = ApplyColumnProperties( xFollowPageStyle, rDM_Impl.GetIsLastSectionGroup() ); //prepare text grid properties sal_Int32 nHeight = 1; @@ -1197,6 +1199,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) OSL_FAIL( "Exception in SectionPropertyMap::CloseSectionGroup"); } } + rDM_Impl.SetIsLastSectionGroup(false); rDM_Impl.SetIsFirstParagraphInSection(true); } diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index 58487d678bfb..63721b61a26f 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -221,7 +221,7 @@ class SectionPropertyMap : public PropertyMap void _ApplyProperties( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xStyle ); ::com::sun::star::uno::Reference< com::sun::star::text::XTextColumns > ApplyColumnProperties( - ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xFollowPageStyle ); + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xFollowPageStyle, bool bLast ); void CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl ); void CopyHeaderFooter( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPrevStyle, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xStyle ); diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 7fd973c5d5e8..51045742d19e 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -738,6 +738,11 @@ void OOXMLFastContextHandler::setLastParagraphInSection() mpStream->markLastParagraphInSection( ); } +void OOXMLFastContextHandler::setLastSectionGroup() +{ + mpStream->markLastSectionGroup( ); +} + void OOXMLFastContextHandler::newProperty (const Id & /*nId*/, OOXMLValue::Pointer_t /*pVal*/) { diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index a7d9bfa982ab..f56f5e9a6c3e 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -186,6 +186,7 @@ public: void startSectionGroup(); void setLastParagraphInSection(); + void setLastSectionGroup(); void endSectionGroup(); void startParagraphGroup(); void endParagraphGroup(); diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index b3f25afe6002..1e427b1a0fa5 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -25887,6 +25887,7 @@ --> <action name="end" action="endCharacterGroup"/> <action name="end" action="endParagraphGroup"/> + <action name="end" action="setLastSectionGroup"/> <action name="end" action="endSectionGroup"/> </resource> <resource xmlns:v="urn:schemas-microsoft-com:vml" name="CT_ShapeDefaults" resource="Properties" tag="shape"> diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 6c6e282f9845..b372d34065db 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -601,6 +601,12 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) writerfilter::Reference<Properties>::Pointer_t const pProperties( new RTFReferenceProperties(aAttributes, aSprms) ); + + if (bFinal && !m_pSuperstream) + // This is the end of the document, not just the end of e.g. a header. + // This makes sure that dmapper can set DontBalanceTextColumns=true for this section if necessary. + Mapper().markLastSectionGroup(); + // The trick is that we send properties of the previous section right now, which will be exactly what dmapper expects. Mapper().props(pProperties); Mapper().endParagraphGroup(); |