sw/qa/extras/ooxmlexport/data/tdf113258.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 9 +++++++++ writerfilter/source/dmapper/DomainMapper.cxx | 22 ++++++++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 7 +++++++ writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 +++ 5 files changed, 41 insertions(+)
New commits: commit f737c9386a605cb7d8c9dbc210c557f98f6cdc19 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Mon Feb 12 22:04:55 2018 +0100 tdf#113258 DOCX import: fix beforeAutospacing for shape first paragraph Commit c761df1e42fd11acc5fc05b0baacd803c3788ca6 (tdf#84678 DOCX import: fix handling of textbox margins, 2016-10-25) uncovered a previously harder to notice problem that single-paragraph shapes have an incorrect upper paragraph margin for the first paragraph. Now that the shape margins are correct this problematic paragraph margin causes crop of the shape text. Fix the problem by adapting the DOCX import to the WW8 import's SwWW8ImplReader::AppendTextNode() (the "If this is the first paragraph in the document" part), where it seems the first paragraph is not only the literally first paragraph in the document, but also the first paragraph of shapes as well. Change-Id: I9d99b9cfabae2c9a7c33eefefb5a9f008669e93d Reviewed-on: https://gerrit.libreoffice.org/49617 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/sw/qa/extras/ooxmlexport/data/tdf113258.docx b/sw/qa/extras/ooxmlexport/data/tdf113258.docx new file mode 100644 index 000000000000..d60a2ee6413c Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf113258.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 5a6cfd48cf13..d3cc7275a92e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -220,6 +220,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf114703, "tdf114703.docx") comphelper::SequenceAsHashMap(xRules->getByIndex(0))["FirstLineIndent"].get<sal_Int32>()); } +DECLARE_OOXMLEXPORT_TEST(testTdf113258, "tdf113258.docx") +{ + uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY); + // This was 494, i.e. automatic spacing resulted in non-zero paragraph top + // margin for the first paragraph in a shape. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), + getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 080bfdc6fb14..d31ca615de86 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2114,7 +2114,27 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) StyleSheetTablePtr pStyleTable = m_pImpl->GetStyleSheetTable(); const OUString sConvertedStyleName = pStyleTable->ConvertStyleName( sStringValue, true ); if (m_pImpl->GetTopContext() && m_pImpl->GetTopContextType() != CONTEXT_SECTION) + { m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sConvertedStyleName )); + + if (m_pImpl->GetIsFirstParagraphInShape()) + { + // First paragraph in shape: see if we need to disable + // paragraph top margin from style. + StyleSheetEntryPtr pEntry + = m_pImpl->GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( + sConvertedStyleName); + if (pEntry) + { + boost::optional<PropertyMap::Property> pParaAutoBefore + = pEntry->pProperties->getProperty( + PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING); + if (pParaAutoBefore) + m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN, + uno::makeAny(static_cast<sal_Int32>(0))); + } + } + } } break; case NS_ooxml::LN_EG_RPrBase_rStyle: @@ -2978,6 +2998,8 @@ void DomainMapper::lcl_startShape(uno::Reference<drawing::XShape> const& xShape) // No context? Then this image should not appear directly inside the // document, just save it for later usage. m_pImpl->PushPendingShape(xShape); + + m_pImpl->SetIsFirstParagraphInShape(true); } void DomainMapper::lcl_endShape( ) diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 9060b3ce0dbd..bb15f12c824c 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -466,6 +466,10 @@ void DomainMapper_Impl::SetIsFirstParagraphInSection( bool bIsFirst ) m_bIsFirstParaInSection = bIsFirst; } +void DomainMapper_Impl::SetIsFirstParagraphInShape(bool bIsFirst) +{ + m_bIsFirstParaInShape = bIsFirst; +} void DomainMapper_Impl::SetIsDummyParaAddedForTableInSection( bool bIsAdded ) { @@ -1377,6 +1381,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap ) SetIsLastParagraphInSection(false); } + if (m_bIsFirstParaInShape) + m_bIsFirstParaInShape = false; + if (pParaContext) { // Reset the frame properties for the next paragraph diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 19f2d80dbf15..d7fb9b4e8c40 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -490,6 +490,7 @@ private: /// If the current paragraph has any runs. bool m_bParaChanged; bool m_bIsFirstParaInSection; + bool m_bIsFirstParaInShape = false; bool m_bDummyParaAddedForTableInSection; bool m_bTextFrameInserted; bool m_bIsPreviousParagraphFramed; @@ -580,6 +581,8 @@ public: bool GetIsLastSectionGroup() { return m_bIsLastSectionGroup;} void SetIsFirstParagraphInSection( bool bIsFirst ); bool GetIsFirstParagraphInSection() { return m_bIsFirstParaInSection;} + void SetIsFirstParagraphInShape(bool bIsFirst); + bool GetIsFirstParagraphInShape() { return m_bIsFirstParaInShape; } void SetIsDummyParaAddedForTableInSection( bool bIsAdded ); bool GetIsDummyParaAddedForTableInSection() { return m_bDummyParaAddedForTableInSection;} void SetIsTextFrameInserted( bool bIsInserted ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits