xmloff,svx,sw: ODF export: prevent spurious z-index="0"

Currently any object anchored in a Writer header / footer which isn't
actually used in the document isn't put on the SdrPage and thus doesn't
have a ZOrder; this results in a spurious z-index="0" attribute, where 0
is a perfectly valid value that is typically already used by a visible
shape and is thus duplicated, which is invalid.

Fix SvxShape::getPropertyValueImpl() and SwXFrame::getPropertyValue() to
check that it has a parent, and
XMLTextParagraphExport::addTextFrameAttributes() to properly check that
the property has a valid value.

There is one possible use case for producing a z-index for something
that isn't visible: when it's anchored in a delete tracked change, and
we want to preserve the order relative to other shapes in the document.

However, it turns out that in SdXMLShapeContext::AddShape() and
XMLTextFrameContext_Impl::Create() the z-index of anything anchored in a
delete redline is already explicitly ignored, so it's a non-issue.

Change-Id: I37e461ebcd3e4546c60f421054ee39c053919267
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197474
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 7ffd4f7a27b9b2bc55ac3ddb7333dbaf3d48109c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197622
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Michael Stahl
2026-01-20 11:36:37 +01:00
parent 85dbb4dc81
commit c455986626
3 changed files with 8 additions and 5 deletions
+4 -1
View File
@@ -2592,7 +2592,10 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertyMapEn
case OWN_ATTR_ZORDER:
{
rValue <<= static_cast<sal_Int32>(GetSdrObject()->GetOrdNum());
if (GetSdrObject()->getParentSdrObjListFromSdrObject())
{
rValue <<= static_cast<sal_Int32>(GetSdrObject()->GetOrdNum());
}
break;
}
+1 -1
View File
@@ -2153,7 +2153,7 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName)
const SdrObject* pObj = pFormat->FindRealSdrObject();
if( pObj == nullptr )
pObj = pFormat->FindSdrObject();
if( pObj )
if (pObj && pObj->getParentSdrObjListFromSdrObject())
{
aAny <<= static_cast<sal_Int32>(pObj->GetOrdNum());
}
+3 -3
View File
@@ -3103,10 +3103,10 @@ XMLShapeExportFlags XMLTextParagraphExport::addTextFrameAttributes(
OUString sZOrder( u"ZOrder"_ustr );
if( xPropSetInfo->hasPropertyByName( sZOrder ) )
{
sal_Int32 nZIndex = 0;
rPropSet->getPropertyValue( sZOrder ) >>= nZIndex;
if( -1 != nZIndex )
sal_Int32 nZIndex{-1};
if (rPropSet->getPropertyValue(sZOrder) >>= nZIndex)
{
assert(0 <= nZIndex);
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX,
OUString::number( nZIndex ) );
}