summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2016-07-04 18:27:52 +0300
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-07-07 07:18:02 +0000
commit1127bed4d943036473dbbda6bcfae1ec0a23ed2e (patch)
treecc2354289ae18f739989f5ca5d745e2640a2ba2c /writerfilter
parent048f298d9c87ec46c2415a1d23b87b20a1035cab (diff)
tdf#95367 inherit page style if no new one imported
CopyLastHeaderFooter doesn't do much good if the previous section has blank stylenames. (usually because of continuous section breaks). Change-Id: Ida1e42ab0b650c7c43f06539b3cc058fe5c27919 Reviewed-on: https://gerrit.libreoffice.org/26911 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx122
-rw-r--r--writerfilter/source/dmapper/PropertyMap.hxx8
2 files changed, 95 insertions, 35 deletions
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index efc8343b09c6..f4b4a1579c34 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1090,6 +1090,68 @@ bool SectionPropertyMap::FloatingTableConversion(FloatingTableInfo& rInfo)
return false;
}
+void SectionPropertyMap::InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Impl )
+throw ( css::beans::UnknownPropertyException,
+ css::beans::PropertyVetoException,
+ css::lang::IllegalArgumentException,
+ css::lang::WrappedTargetException,
+ css::uno::RuntimeException, std::exception )
+{
+ // don't mess with even/odd headers.
+ // just replicate what was done before to avoid causing any regressions
+ if( rDM_Impl.GetSettingsTable()->GetEvenAndOddHeaders() )
+ {
+ if( m_nBreakType != static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_nextColumn) )
+ {
+ OUString aName = m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName;
+ if( !aName.isEmpty() )
+ {
+ HandleMarginsHeaderFooter( /*bFirstPage=*/false, rDM_Impl );
+ if( m_bTitlePage )
+ HandleMarginsHeaderFooter( /*bFirstPage=*/true, rDM_Impl );
+ uno::Reference<beans::XPropertySet> xPageStyle( rDM_Impl.GetPageStyles()->getByName(aName), uno::UNO_QUERY_THROW );
+ if( rDM_Impl.IsNewDoc() )
+ {
+ ApplyProperties_( xPageStyle );
+ if( m_bTitlePage && m_aFollowPageStyle.is() )
+ ApplyProperties_( m_aFollowPageStyle );
+ }
+ }
+ }
+ return;
+ }
+
+ const uno::Reference< container::XNameContainer >& xPageStyles = rDM_Impl.GetPageStyles();
+ const uno::Reference < lang::XMultiServiceFactory >& xTextFactory = rDM_Impl.GetTextFactory();
+
+ // if no new styles have been created for this section, inherit from the previous section,
+ // otherwise apply this section's settings to the new style.
+ SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext();
+ if( pLastContext && m_sFirstPageStyleName.isEmpty() )
+ m_sFirstPageStyleName = pLastContext->GetPageStyleName( /*bFirst=*/true );
+ else
+ {
+ HandleMarginsHeaderFooter( /*bFirst=*/true, rDM_Impl );
+ GetPageStyle( xPageStyles, xTextFactory, /*bFirst=*/true );
+ if( rDM_Impl.IsNewDoc() && m_aFirstPageStyle.is() )
+ ApplyProperties_( m_aFirstPageStyle );
+ }
+
+ if( pLastContext && m_sFollowPageStyleName.isEmpty() )
+ m_sFollowPageStyleName = pLastContext->GetPageStyleName();
+ else
+ {
+ HandleMarginsHeaderFooter( /*bFirst=*/false, rDM_Impl );
+ GetPageStyle( xPageStyles, xTextFactory, /*bFirst=*/false );
+ if( rDM_Impl.IsNewDoc() && m_aFollowPageStyle.is() )
+ ApplyProperties_( m_aFollowPageStyle );
+ }
+
+ GetPageStyle( xPageStyles, xTextFactory, /*bFirst=*/true );
+ // Chain m_aFollowPageStyle to be after m_aFirstPageStyle
+ m_aFirstPageStyle->setPropertyValue( "FollowStyle", uno::makeAny(m_sFollowPageStyleName) );
+}
+
void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
{
// Text area width is known at the end of a section: decide if tables should be converted or not.
@@ -1138,35 +1200,20 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
//todo: insert a section or access the already inserted section
uno::Reference< beans::XPropertySet > xSection =
rDM_Impl.appendTextSectionAfter( m_xStartingRange );
- if( m_nColumnCount > 0 && xSection.is())
+ if( m_nColumnCount > 0 && xSection.is() )
ApplyColumnProperties( xSection, rDM_Impl );
- uno::Reference<beans::XPropertySet> xRangeProperties(lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange));
- if (xRangeProperties.is())
+
+ try
{
+ InheritOrFinalizePageStyles( rDM_Impl );
OUString aName = m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName;
- if (!aName.isEmpty())
- {
- try
- {
- if( m_bIsFirstSection )
- xRangeProperties->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), uno::makeAny(aName));
-
- uno::Reference<beans::XPropertySet> xPageStyle (rDM_Impl.GetPageStyles()->getByName(aName), uno::UNO_QUERY_THROW);
- HandleMarginsHeaderFooter(false, rDM_Impl);
- if( m_bTitlePage )
- HandleMarginsHeaderFooter(true, rDM_Impl);
- if (rDM_Impl.IsNewDoc())
- {
- ApplyProperties_(xPageStyle);
- if( m_bTitlePage && m_aFollowPageStyle.is() )
- ApplyProperties_(m_aFollowPageStyle);
- }
- }
- catch( const uno::Exception& )
- {
- SAL_WARN("writerfilter", "failed to set PageDescName!");
- }
- }
+ uno::Reference<beans::XPropertySet> xRangeProperties( lcl_GetRangeProperties(m_bIsFirstSection, rDM_Impl, m_xStartingRange) );
+ if ( m_bIsFirstSection && !aName.isEmpty() && xRangeProperties.is() )
+ xRangeProperties->setPropertyValue( getPropertyName(PROP_PAGE_DESC_NAME), uno::makeAny(aName) );
+ }
+ catch( const uno::Exception& )
+ {
+ SAL_WARN("writerfilter", "failed to set PageDescName!");
}
}
// If the section is of type "New column" (0x01), then simply insert a column break.
@@ -1174,17 +1221,22 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
// seems to be handled like a page break by MSO.
else if(m_nBreakType == static_cast<sal_Int32>(NS_ooxml::LN_Value_ST_SectionMark_nextColumn) && m_nColumnCount > 0 )
{
- uno::Reference< beans::XPropertySet > xRangeProperties;
- if( m_xStartingRange.is() )
- {
- xRangeProperties.set( m_xStartingRange, uno::UNO_QUERY_THROW );
- }
- else
+ try
{
- //set the start value at the beginning of the document
- xRangeProperties.set( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
+ InheritOrFinalizePageStyles( rDM_Impl );
+ uno::Reference< beans::XPropertySet > xRangeProperties;
+ if( m_xStartingRange.is() )
+ {
+ xRangeProperties.set( m_xStartingRange, uno::UNO_QUERY_THROW );
+ }
+ else
+ {
+ //set the start value at the beginning of the document
+ xRangeProperties.set( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW );
+ }
+ xRangeProperties->setPropertyValue( getPropertyName(PROP_BREAK_TYPE), uno::makeAny(style::BreakType_COLUMN_BEFORE) );
}
- xRangeProperties->setPropertyValue(getPropertyName(PROP_BREAK_TYPE), uno::makeAny(style::BreakType_COLUMN_BEFORE));
+ catch( const uno::Exception& ) {}
}
else
{
diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index f6796a6ef589..917c3e64fd4a 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -286,6 +286,14 @@ public:
const css::uno::Reference<css::lang::XMultiServiceFactory>& xTextFactory,
bool bFirst);
+ OUString GetPageStyleName( bool bFirstPage = false ) { return bFirstPage ? m_sFirstPageStyleName : m_sFollowPageStyleName; }
+ void InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Impl )
+ throw ( css::beans::UnknownPropertyException,
+ css::beans::PropertyVetoException,
+ css::lang::IllegalArgumentException,
+ css::lang::WrappedTargetException,
+ css::uno::RuntimeException, std::exception);
+
void SetBorder(BorderPosition ePos, sal_Int32 nLineDistance, const css::table::BorderLine2& rBorderLine, bool bShadow);
void SetBorderParams( sal_Int32 nSet ) { m_nBorderParams = nSet; }