writerfilter: import section margins and writingMode
Previously, only page styles got these values. But if the section is continuous, then these properties should be transferred to the section itself. This patch relies on the commit for tdf#122456. It confirms that it is a good idea for the last section to ignore the "fake" section and keep the real section properties. Otherwise these margins would be lost on export. Change-Id: I45efb0d80fb9307a57ff560b2e1a26899155f827 Reviewed-on: https://gerrit.libreoffice.org/65975 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org>
This commit is contained in:
BIN
sw/qa/extras/ooxmlexport/data/endingSectionProps.docx
Normal file
BIN
sw/qa/extras/ooxmlexport/data/endingSectionProps.docx
Normal file
Binary file not shown.
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <com/sun/star/awt/Size.hpp>
|
||||
#include <com/sun/star/beans/XPropertySet.hpp>
|
||||
#include <com/sun/star/text/WritingMode2.hpp>
|
||||
#include <com/sun/star/text/XTextFrame.hpp>
|
||||
#include <com/sun/star/text/XTextFramesSupplier.hpp>
|
||||
|
||||
@@ -50,6 +51,21 @@ DECLARE_OOXMLEXPORT_TEST(testTdf121374_sectionHF2, "tdf121374_sectionHF2.doc")
|
||||
CPPUNIT_ASSERT( xHeaderText->getString().startsWith("virkamatka-anomus") );
|
||||
}
|
||||
|
||||
DECLARE_OOXMLEXPORT_TEST(testendingSectionProps, "endingSectionProps.docx")
|
||||
{
|
||||
uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY);
|
||||
uno::Reference<text::XTextRange> xHeaderText = getProperty< uno::Reference<text::XTextRange> >(xPageStyle, "HeaderText");
|
||||
CPPUNIT_ASSERT_EQUAL( OUString("General header"), xHeaderText->getString());
|
||||
|
||||
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
|
||||
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
|
||||
uno::Reference<beans::XPropertySet> xSect(xSections->getByIndex(0), uno::UNO_QUERY);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("# of paragraphs", 2, getParagraphs());
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Section is RightToLeft", text::WritingMode2::RL_TB, getProperty<sal_Int16>(xSect, "WritingMode"));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Section Left Margin", sal_Int32(2540), getProperty<sal_Int32>(xSect, "SectionLeftMargin"));
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -682,6 +682,38 @@ void SectionPropertyMap::DontBalanceTextColumns()
|
||||
}
|
||||
}
|
||||
|
||||
void SectionPropertyMap::ApplySectionProperties( uno::Reference< beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( xSection.is() )
|
||||
{
|
||||
// Margins only valid if page style is already determined.
|
||||
// Take some care not to create an automatic page style (with GetPageStyle) if it isn't already created.
|
||||
if ( !m_aFollowPageStyle.is() && !m_sFollowPageStyleName.isEmpty() )
|
||||
GetPageStyle( rDM_Impl.GetPageStyles(), rDM_Impl.GetTextFactory(), false );
|
||||
if ( m_aFollowPageStyle.is() )
|
||||
{
|
||||
sal_Int32 nPageMargin = 0;
|
||||
m_aFollowPageStyle->getPropertyValue( getPropertyName( PROP_LEFT_MARGIN ) ) >>= nPageMargin;
|
||||
xSection->setPropertyValue( "SectionLeftMargin", uno::makeAny(m_nLeftMargin - nPageMargin) );
|
||||
|
||||
nPageMargin = 0;
|
||||
m_aFollowPageStyle->getPropertyValue( getPropertyName( PROP_RIGHT_MARGIN ) ) >>= nPageMargin;
|
||||
xSection->setPropertyValue( "SectionRightMargin", uno::makeAny(m_nRightMargin - nPageMargin) );
|
||||
}
|
||||
|
||||
boost::optional< PropertyMap::Property > pProp = getProperty( PROP_WRITING_MODE );
|
||||
if ( pProp )
|
||||
xSection->setPropertyValue( "WritingMode", pProp->second );
|
||||
}
|
||||
}
|
||||
catch ( uno::Exception& )
|
||||
{
|
||||
DBG_UNHANDLED_EXCEPTION("writerfilter", "Exception in SectionPropertyMap::ApplySectionProperties");
|
||||
}
|
||||
}
|
||||
|
||||
void SectionPropertyMap::ApplyProtectionProperties( uno::Reference< beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl )
|
||||
{
|
||||
try
|
||||
@@ -1398,6 +1430,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
|
||||
try
|
||||
{
|
||||
InheritOrFinalizePageStyles( rDM_Impl );
|
||||
ApplySectionProperties( xSection, rDM_Impl ); //depends on InheritOrFinalizePageStyles
|
||||
OUString aName = m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName;
|
||||
uno::Reference< beans::XPropertySet > xRangeProperties( lcl_GetRangeProperties( m_bIsFirstSection, rDM_Impl, m_xStartingRange ) );
|
||||
if ( m_bIsFirstSection && !aName.isEmpty() && xRangeProperties.is() )
|
||||
|
@@ -262,6 +262,9 @@ private:
|
||||
|
||||
void DontBalanceTextColumns();
|
||||
|
||||
/// Apply section-specific properties: only valid to use after PageStyle has been determined by InheritOrFinalizePageStyles
|
||||
void ApplySectionProperties( css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl );
|
||||
|
||||
/// Check if document is protected. If so, ensure a section exists, and apply its protected value.
|
||||
void ApplyProtectionProperties( css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl );
|
||||
|
||||
|
Reference in New Issue
Block a user