summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2018-07-19 19:20:26 +0300
committerLászló Németh <nemeth@numbertext.org>2018-07-20 10:44:15 +0200
commiteab67995d7056682c250efa3c903b1fffd812700 (patch)
tree9b2278ce93c508a759a2a28edb9c65ed6de82221
parent9b8c8c70fa8116f606ce0ebacdaad04ed9402c9f (diff)
tdf#118521 DOCX import: style sets unset left/right/hanging margin
followup to commit 480ac84f2f5049fb4337b36f12fd6796e005761b which nicely paved the way by doing this for top/bottom. Change-Id: I61b4e298e8732391b4f0467b459d9c15298925fa Reviewed-on: https://gerrit.libreoffice.org/57742 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docxbin0 -> 11538 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport11.cxx17
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx59
3 files changed, 57 insertions, 19 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx b/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx
new file mode 100644
index 000000000000..66170ede470c
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf118521_marginsLR.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index bc9e3f7f3328..3246fe5eec4d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -464,6 +464,23 @@ DECLARE_OOXMLEXPORT_TEST(testMarginsFromStyle, "margins_from_style.docx")
CPPUNIT_ASSERT_EQUAL(sal_Int32(600), getProperty<sal_Int32>(getParagraph(3), "ParaBottomMargin"));
}
+DECLARE_OOXMLEXPORT_TEST(testTdf118521_marginsLR, "tdf118521_marginsLR.docx")
+{
+ // tdf#118521 paragraphs with direct formatting of only some of left, right, or first margins have
+ // lost the other unset margins coming from paragraph style, getting a bad margin from the default style instead
+
+ uno::Reference<beans::XPropertySet> xMyStyle(getStyles("ParagraphStyles")->getByName("MyStyle"), uno::UNO_QUERY);
+ // from paragraph style - this is what direct formatting should equal
+ sal_Int32 nMargin = getProperty<sal_Int32>(xMyStyle, "ParaLeftMargin");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nMargin);
+ // from direct formatting
+ CPPUNIT_ASSERT_EQUAL(nMargin, getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
+
+ nMargin = getProperty<sal_Int32>(xMyStyle, "ParaRightMargin");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1900), nMargin);
+ CPPUNIT_ASSERT_EQUAL(nMargin, getProperty<sal_Int32>(getParagraph(2), "ParaRightMargin"));
+}
+
DECLARE_OOXMLIMPORT_TEST(testTdf104797, "tdf104797.docx")
{
// check moveFrom and moveTo
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a1fde6baae1b..2939902f03ca 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1122,16 +1122,16 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
TagLogger::getInstance().attribute("isTextAppend", sal_uInt32(xTextAppend.is()));
#endif
+ const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
+ OSL_ENSURE( pEntry.get(), "no style sheet found" );
+ const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
//apply numbering to paragraph if it was set at the style, but only if the paragraph itself
//does not specify the numbering
- if( pParaContext && !pParaContext->isSet(PROP_NUMBERING_RULES) )
+ if ( pStyleSheetProperties && pParaContext && !pParaContext->isSet(PROP_NUMBERING_RULES) )
{
- const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
- OSL_ENSURE( pEntry.get(), "no style sheet found" );
- const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
sal_Int32 nListId = pEntry ? lcl_getListId(pEntry, GetStyleSheetTable()) : -1;
- if( pStyleSheetProperties && nListId >= 0 )
+ if ( nListId >= 0 )
{
pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny( ListDef::GetStyleName( nListId ) ), false);
@@ -1169,7 +1169,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
}
}
- if( pStyleSheetProperties && pStyleSheetProperties->GetListLevel() >= 0 )
+ if ( pStyleSheetProperties->GetListLevel() >= 0 )
pParaContext->Insert( PROP_NUMBERING_LEVEL, uno::makeAny(pStyleSheetProperties->GetListLevel()), false);
}
@@ -1418,28 +1418,49 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap )
// tdf#118521 set paragraph top or bottom margin based on the paragraph style
// if we already set the other margin with direct formatting
- if (pParaContext && m_xPreviousParagraph.is() &&
+ if (pStyleSheetProperties && pParaContext && m_xPreviousParagraph.is() &&
pParaContext->isSet(PROP_PARA_TOP_MARGIN) != pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN))
{
- const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() );
- OSL_ENSURE( pEntry.get(), "no style sheet found" );
- const StyleSheetPropertyMap* pStyleSheetProperties =
- dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
- if (pStyleSheetProperties) {
+ boost::optional<PropertyMap::Property> oProperty;
+ if (pParaContext->isSet(PROP_PARA_TOP_MARGIN))
+ {
+ if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_BOTTOM_MARGIN)) )
+ m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", oProperty->second);
+ }
+ else
+ {
+ if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_TOP_MARGIN)) )
+ m_xPreviousParagraph->setPropertyValue("ParaTopMargin", oProperty->second);
+ }
+ }
+
+ // Left, Right, and Hanging settings are also grouped. Ensure that all or none are set.
+ // m_xPreviousParagraph was set earlier, so really it still is the current paragraph...
+ if ( pStyleSheetProperties && pParaContext && m_xPreviousParagraph.is() )
+ {
+ const bool bLeftSet = pParaContext->isSet(PROP_PARA_LEFT_MARGIN);
+ const bool bRightSet = pParaContext->isSet(PROP_PARA_RIGHT_MARGIN);
+ const bool bFirstSet = pParaContext->isSet(PROP_PARA_FIRST_LINE_INDENT);
+ if ( !(bLeftSet == bRightSet && bRightSet == bFirstSet) )
+ {
boost::optional<PropertyMap::Property> oProperty;
- if (pParaContext->isSet(PROP_PARA_TOP_MARGIN))
+ if ( !bLeftSet )
{
- if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_BOTTOM_MARGIN)) )
- m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", oProperty->second);
+ if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_LEFT_MARGIN)) )
+ m_xPreviousParagraph->setPropertyValue("ParaLeftMargin", oProperty->second);
}
- else
+ if ( !bRightSet )
{
- if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_TOP_MARGIN)) )
- m_xPreviousParagraph->setPropertyValue("ParaTopMargin", oProperty->second);
+ if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_RIGHT_MARGIN)) )
+ m_xPreviousParagraph->setPropertyValue("ParaRightMargin", oProperty->second);
+ }
+ if ( !bFirstSet )
+ {
+ if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT)) )
+ m_xPreviousParagraph->setPropertyValue("ParaFirstLineIndent", oProperty->second);
}
}
}
-
}
if( !bKeepLastParagraphProperties )
rAppendContext.pLastParagraphProperties = pToBeSavedProperties;