tdf#111895 writerfilter: avoid hiding shapes behind background

In MSO, page background is "in hell" zOrder, however
in LO, page background is at the same zOrder as the text,
so avoid hiding shapes behind the page background unless
doing so would hide text.

When importing gradients/pattern/hatch backgrounds are supported,
HasPageBackground will need to be expanded to include those as well.

Change-Id: I4496fd3f4c644ac9ac1854090658017078ce3e88
Reviewed-on: https://gerrit.libreoffice.org/41486
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
This commit is contained in:
Justin Luth
2017-08-23 19:02:12 -04:00
committed by Miklos Vajna
parent 4b8214414b
commit d21f67fa7f
6 changed files with 37 additions and 1 deletions

View File

@@ -229,6 +229,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf98700_keepWithNext, "tdf98700_keepWithNext.odt")
CPPUNIT_ASSERT_EQUAL_MESSAGE("Text Body style toggled off keep with next", false, getProperty<bool>(getParagraph(5), "ParaKeepTogether")); CPPUNIT_ASSERT_EQUAL_MESSAGE("Text Body style toggled off keep with next", false, getProperty<bool>(getParagraph(5), "ParaKeepTogether"));
} }
DECLARE_OOXMLEXPORT_TEST(testTdf111895_foregroundShape, "tdf111895_foregroundShape.docx")
{
uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light yellow background", sal_Int32(0xFFFF66), getProperty<sal_Int32>(xPageStyle, "BackColor"));
// despite a behindDoc==1, put shape in foreground since the page background would have hidden it otherwise.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in front of page background", true, getProperty<bool>(getShape(1), "Opaque"));
}
DECLARE_OOXMLEXPORT_TEST(testTdf111895_foregroundShape2, "tdf111895_foregroundShape2.docx")
{
uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Light yellow background", sal_Int32(0xFFFF66), getProperty<sal_Int32>(xPageStyle, "BackColor"));
// despite a page background, don't show behindDoc==1 shape in front since it would have hidden wrap_THROUGH text.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in front of page background", false, getProperty<bool>(getShape(1), "Opaque"));
}
// base class to supply a helper method for testHFLinkToPrev // base class to supply a helper method for testHFLinkToPrev
class testHFBase : public Test class testHFBase : public Test
{ {

View File

@@ -3775,6 +3775,11 @@ bool DomainMapper::IsStyleSheetImport() const
return m_pImpl->IsStyleSheetImport(); return m_pImpl->IsStyleSheetImport();
} }
bool DomainMapper::HasPageBackground() const
{
return (bool)m_pImpl->m_oBackgroundColor;
}
void DomainMapper::enableInteropGrabBag(const OUString& aName) void DomainMapper::enableInteropGrabBag(const OUString& aName)
{ {
m_pImpl->m_aInteropGrabBagName = aName; m_pImpl->m_aInteropGrabBagName = aName;

View File

@@ -110,6 +110,7 @@ public:
bool IsInHeaderFooter() const; bool IsInHeaderFooter() const;
bool IsInTable() const; bool IsInTable() const;
bool IsStyleSheetImport() const; bool IsStyleSheetImport() const;
bool HasPageBackground() const;
/** /**
@see DomainMapper_Impl::processDeferredCharacterProperties() @see DomainMapper_Impl::processDeferredCharacterProperties()
*/ */

View File

@@ -197,6 +197,7 @@ public:
text::WrapTextMode nWrap; text::WrapTextMode nWrap;
bool bLayoutInCell; bool bLayoutInCell;
bool bOpaque; bool bOpaque;
bool bBehindDoc;
bool bContour; bool bContour;
bool bContourOutside; bool bContourOutside;
WrapPolygon::Pointer_t mpWrapPolygon; WrapPolygon::Pointer_t mpWrapPolygon;
@@ -266,6 +267,7 @@ public:
,nWrap(text::WrapTextMode_NONE) ,nWrap(text::WrapTextMode_NONE)
,bLayoutInCell(false) ,bLayoutInCell(false)
,bOpaque( !rDMapper.IsInHeaderFooter() ) ,bOpaque( !rDMapper.IsInHeaderFooter() )
,bBehindDoc( false )
,bContour(false) ,bContour(false)
,bContourOutside(true) ,bContourOutside(true)
,nLeftMargin(319) ,nLeftMargin(319)
@@ -365,6 +367,10 @@ public:
GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper(); GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper();
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder))); xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), uno::makeAny(pZOrderHelper->findZOrder(zOrder)));
pZOrderHelper->addItem(xGraphicObjectProperties, zOrder); pZOrderHelper->addItem(xGraphicObjectProperties, zOrder);
// use opaque setting unless it would hide text that should be in front of the shape.
const bool bPutInForeground = bOpaque && !(bBehindDoc && nWrap == text::WrapTextMode_THROUGH);
xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny( bPutInForeground ) );
} }
} }
@@ -598,7 +604,15 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
break; break;
case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background
if( nIntValue > 0 ) if( nIntValue > 0 )
m_pImpl->bOpaque = false; {
m_pImpl->bBehindDoc = true;
// In MSO, page background is "in hell" zOrder, however
// in LO, page background is at the same zOrder as the text,
// so avoid hiding shapes behind the page background.
if( !m_pImpl->rDomainMapper.HasPageBackground() )
m_pImpl->bOpaque = false;
}
break; break;
case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored
break; break;