Kaydet (Commit) f737c938 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#113258 DOCX import: fix beforeAutospacing for shape first paragraph

Commit c761df1e (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/49617Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst b75609fa
......@@ -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: */
......@@ -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( )
......
......@@ -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
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment