filter/source/svg/svgexport.cxx | 295 +++++++++++++++++++--------------------- 1 file changed, 145 insertions(+), 150 deletions(-)
New commits: commit 5674350533a3576f40604df7c8247051cd35d52a Author: Noel Grandin <[email protected]> AuthorDate: Fri Nov 21 15:16:49 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Sat Nov 22 07:13:54 2025 +0100 flatten the code in SVGFilter::implExportShape a little Change-Id: I74d74326c61fe2a02910c0cfed39454e0dac5ae2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194328 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx index a326d473d90c..636064cdcd8c 100644 --- a/filter/source/svg/svgexport.cxx +++ b/filter/source/svg/svgexport.cxx @@ -2094,186 +2094,181 @@ bool SVGFilter::implExportShapes( const Reference< css::drawing::XShapes >& rxSh bool SVGFilter::implExportShape( const Reference< css::drawing::XShape >& rxShape, bool bMaster ) { Reference< XPropertySet > xShapePropSet( rxShape, UNO_QUERY ); - bool bRet = false; + if( !xShapePropSet.is() ) + return false; - if( xShapePropSet.is() ) + const OUString aShapeType( rxShape->getShapeType() ); + bool bHideObj = false; + + if( mbPresentation ) { - const OUString aShapeType( rxShape->getShapeType() ); - bool bHideObj = false; + xShapePropSet->getPropertyValue( u"IsEmptyPresentationObject"_ustr ) >>= bHideObj; + } - if( mbPresentation ) - { - xShapePropSet->getPropertyValue( u"IsEmptyPresentationObject"_ustr ) >>= bHideObj; - } + OUString aShapeClass = implGetClassFromShape( rxShape ); + if( bMaster ) + { + if( aShapeClass == "TitleText" || aShapeClass == "Outline" ) + bHideObj = true; + } - OUString aShapeClass = implGetClassFromShape( rxShape ); - if( bMaster ) - { - if( aShapeClass == "TitleText" || aShapeClass == "Outline" ) - bHideObj = true; - } + if( bHideObj ) + return false; - if( !bHideObj ) + if( aShapeType.lastIndexOf( "drawing.GroupShape" ) != -1 ) + { + Reference< css::drawing::XShapes > xShapes( rxShape, UNO_QUERY ); + + if( xShapes.is() ) { - if( aShapeType.lastIndexOf( "drawing.GroupShape" ) != -1 ) + mpSVGExport->AddAttribute(u"class"_ustr, u"Group"_ustr); + const OUString& rShapeId = implGetValidIDFromInterface( Reference<XInterface>(rxShape, UNO_QUERY) ); + if( !rShapeId.isEmpty() ) { - Reference< css::drawing::XShapes > xShapes( rxShape, UNO_QUERY ); - - if( xShapes.is() ) - { - mpSVGExport->AddAttribute(u"class"_ustr, u"Group"_ustr); - const OUString& rShapeId = implGetValidIDFromInterface( Reference<XInterface>(rxShape, UNO_QUERY) ); - if( !rShapeId.isEmpty() ) - { - mpSVGExport->AddAttribute(u"id"_ustr, rShapeId); - } - SvXMLElementExport aExp(*mpSVGExport, u"g"_ustr, true, true); - - bRet = implExportShapes( xShapes, bMaster ); - } + mpSVGExport->AddAttribute(u"id"_ustr, rShapeId); } + SvXMLElementExport aExp(*mpSVGExport, u"g"_ustr, true, true); - if( !bRet && mpObjects->contains( rxShape ) ) - { - css::awt::Rectangle aBoundRect; - const GDIMetaFile& rMtf = (*mpObjects)[ rxShape ].GetRepresentation(); + if (implExportShapes( xShapes, bMaster )) + return true; + } + } - xShapePropSet->getPropertyValue( u"BoundRect"_ustr ) >>= aBoundRect; + if( !mpObjects->contains( rxShape ) ) + return false; - const Point aTopLeft( aBoundRect.X, aBoundRect.Y ); - const Size aSize( aBoundRect.Width, aBoundRect.Height ); + css::awt::Rectangle aBoundRect; + const GDIMetaFile& rMtf = (*mpObjects)[ rxShape ].GetRepresentation(); - if( rMtf.GetActionSize() ) - { // for text field shapes we set up text-adjust attributes - // and set visibility to hidden - OUString aElementId; + xShapePropSet->getPropertyValue( u"BoundRect"_ustr ) >>= aBoundRect; - if( mbPresentation ) - { - bool bIsPageNumber = ( aShapeClass == "PageNumber" ); - bool bIsFooter = ( aShapeClass == "Footer" ); - bool bIsDateTime = ( aShapeClass == "DateTime" ); - bool bTextField = bIsPageNumber || bIsFooter || bIsDateTime; - if( bTextField ) - { - // to notify to the SVGActionWriter::ImplWriteActions method - // that we are dealing with a placeholder shape - aElementId = sPlaceholderTag; + const Point aTopLeft( aBoundRect.X, aBoundRect.Y ); + const Size aSize( aBoundRect.Width, aBoundRect.Height ); - mpSVGExport->AddAttribute(u"visibility"_ustr, u"hidden"_ustr); - } + if( rMtf.GetActionSize() == 0 ) + return true; - if( bTextField || ( aShapeClass == "TextShape" ) ) - { - sal_uInt16 nTextAdjust = sal_uInt16(ParagraphAdjust_LEFT); - OUString sTextAdjust; - xShapePropSet->getPropertyValue( u"ParaAdjust"_ustr ) >>= nTextAdjust; + // for text field shapes we set up text-adjust attributes + // and set visibility to hidden + OUString aElementId; - switch( static_cast<ParagraphAdjust>(nTextAdjust) ) - { - case ParagraphAdjust_LEFT: - sTextAdjust = "left"; - break; - case ParagraphAdjust_CENTER: - sTextAdjust = "center"; - break; - case ParagraphAdjust_RIGHT: - sTextAdjust = "right"; - break; - default: - break; - } - mpSVGExport->AddAttribute(NSPREFIX "text-adjust"_ustr, sTextAdjust); - } - } - mpSVGExport->AddAttribute(u"class"_ustr, aShapeClass); - SvXMLElementExport aExp(*mpSVGExport, u"g"_ustr, true, true); + if( mbPresentation ) + { + bool bIsPageNumber = ( aShapeClass == "PageNumber" ); + bool bIsFooter = ( aShapeClass == "Footer" ); + bool bIsDateTime = ( aShapeClass == "DateTime" ); + bool bTextField = bIsPageNumber || bIsFooter || bIsDateTime; + if( bTextField ) + { + // to notify to the SVGActionWriter::ImplWriteActions method + // that we are dealing with a placeholder shape + aElementId = sPlaceholderTag; - Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY ); + mpSVGExport->AddAttribute(u"visibility"_ustr, u"hidden"_ustr); + } - OUString aTitle; - xShapePropSet->getPropertyValue( u"Title"_ustr ) >>= aTitle; - if( !aTitle.isEmpty() ) - { - SvXMLElementExport aExp2(*mpSVGExport, u"title"_ustr, true, true); - xExtDocHandler->characters( aTitle ); - } + if( bTextField || ( aShapeClass == "TextShape" ) ) + { + sal_uInt16 nTextAdjust = sal_uInt16(ParagraphAdjust_LEFT); + OUString sTextAdjust; + xShapePropSet->getPropertyValue( u"ParaAdjust"_ustr ) >>= nTextAdjust; - OUString aDescription; - xShapePropSet->getPropertyValue( u"Description"_ustr ) >>= aDescription; - if( !aDescription.isEmpty() ) - { - SvXMLElementExport aExp2(*mpSVGExport, u"desc"_ustr, true, true); - xExtDocHandler->characters( aDescription ); - } + switch( static_cast<ParagraphAdjust>(nTextAdjust) ) + { + case ParagraphAdjust_LEFT: + sTextAdjust = "left"; + break; + case ParagraphAdjust_CENTER: + sTextAdjust = "center"; + break; + case ParagraphAdjust_RIGHT: + sTextAdjust = "right"; + break; + default: + break; + } + mpSVGExport->AddAttribute(NSPREFIX "text-adjust"_ustr, sTextAdjust); + } + } + mpSVGExport->AddAttribute(u"class"_ustr, aShapeClass); + SvXMLElementExport aExp(*mpSVGExport, u"g"_ustr, true, true); + Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY ); - const OUString& rShapeId = implGetValidIDFromInterface( Reference<XInterface>(rxShape, UNO_QUERY) ); - if( !rShapeId.isEmpty() ) - { - mpSVGExport->AddAttribute(u"id"_ustr, rShapeId); - } + OUString aTitle; + xShapePropSet->getPropertyValue( u"Title"_ustr ) >>= aTitle; + if( !aTitle.isEmpty() ) + { + SvXMLElementExport aExp2(*mpSVGExport, u"title"_ustr, true, true); + xExtDocHandler->characters( aTitle ); + } - const GDIMetaFile* pEmbeddedBitmapsMtf = nullptr; - if( mEmbeddedBitmapActionMap.contains( rxShape ) ) - { - pEmbeddedBitmapsMtf = &( mEmbeddedBitmapActionMap[ rxShape ].GetRepresentation() ); - } + OUString aDescription; + xShapePropSet->getPropertyValue( u"Description"_ustr ) >>= aDescription; + if( !aDescription.isEmpty() ) + { + SvXMLElementExport aExp2(*mpSVGExport, u"desc"_ustr, true, true); + xExtDocHandler->characters( aDescription ); + } - { - OUString aBookmark; - Reference<XPropertySetInfo> xShapePropSetInfo = xShapePropSet->getPropertySetInfo(); - if(xShapePropSetInfo->hasPropertyByName(u"Bookmark"_ustr)) - { - xShapePropSet->getPropertyValue( u"Bookmark"_ustr ) >>= aBookmark; - } + const OUString& rShapeId = implGetValidIDFromInterface( Reference<XInterface>(rxShape, UNO_QUERY) ); + if( !rShapeId.isEmpty() ) + { + mpSVGExport->AddAttribute(u"id"_ustr, rShapeId); + } - SvXMLElementExport aExp2(*mpSVGExport, u"g"_ustr, true, true); + const GDIMetaFile* pEmbeddedBitmapsMtf = nullptr; + if( mEmbeddedBitmapActionMap.contains( rxShape ) ) + { + pEmbeddedBitmapsMtf = &( mEmbeddedBitmapActionMap[ rxShape ].GetRepresentation() ); + } - // export the shape bounding box - { - mpSVGExport->AddAttribute( u"class"_ustr, u"BoundingBox"_ustr ); - mpSVGExport->AddAttribute( u"stroke"_ustr, u"none"_ustr ); - mpSVGExport->AddAttribute( u"fill"_ustr, u"none"_ustr ); - mpSVGExport->AddAttribute( u"x"_ustr, OUString::number( aBoundRect.X ) ); - mpSVGExport->AddAttribute( u"y"_ustr, OUString::number( aBoundRect.Y ) ); - mpSVGExport->AddAttribute( u"width"_ustr, OUString::number( aBoundRect.Width ) ); - mpSVGExport->AddAttribute( u"height"_ustr, OUString::number( aBoundRect.Height ) ); - SvXMLElementExport aBB(*mpSVGExport, u"rect"_ustr, true, true); - } + OUString aBookmark; + Reference<XPropertySetInfo> xShapePropSetInfo = xShapePropSet->getPropertySetInfo(); + if(xShapePropSetInfo->hasPropertyByName(u"Bookmark"_ustr)) + { + xShapePropSet->getPropertyValue( u"Bookmark"_ustr ) >>= aBookmark; + } - if( !aBookmark.isEmpty() ) - { - INetURLObject aINetURLObject(aBookmark); - if (!aINetURLObject.HasError() - && aINetURLObject.GetProtocol() != INetProtocol::Javascript) - { - mpSVGExport->AddAttribute(u"xlink:href"_ustr, aBookmark); - SvXMLElementExport alinkA(*mpSVGExport, u"a"_ustr, true, true); - mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, - 0xffffffff, - aElementId, - &rxShape, - pEmbeddedBitmapsMtf ); - } - } - else - { - mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, - 0xffffffff, - aElementId, - &rxShape, - pEmbeddedBitmapsMtf ); - } - } - } + SvXMLElementExport aExp2(*mpSVGExport, u"g"_ustr, true, true); - bRet = true; - } + // export the shape bounding box + { + mpSVGExport->AddAttribute( u"class"_ustr, u"BoundingBox"_ustr ); + mpSVGExport->AddAttribute( u"stroke"_ustr, u"none"_ustr ); + mpSVGExport->AddAttribute( u"fill"_ustr, u"none"_ustr ); + mpSVGExport->AddAttribute( u"x"_ustr, OUString::number( aBoundRect.X ) ); + mpSVGExport->AddAttribute( u"y"_ustr, OUString::number( aBoundRect.Y ) ); + mpSVGExport->AddAttribute( u"width"_ustr, OUString::number( aBoundRect.Width ) ); + mpSVGExport->AddAttribute( u"height"_ustr, OUString::number( aBoundRect.Height ) ); + SvXMLElementExport aBB(*mpSVGExport, u"rect"_ustr, true, true); + } + + if( !aBookmark.isEmpty() ) + { + INetURLObject aINetURLObject(aBookmark); + if (!aINetURLObject.HasError() + && aINetURLObject.GetProtocol() != INetProtocol::Javascript) + { + mpSVGExport->AddAttribute(u"xlink:href"_ustr, aBookmark); + SvXMLElementExport alinkA(*mpSVGExport, u"a"_ustr, true, true); + mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, + 0xffffffff, + aElementId, + &rxShape, + pEmbeddedBitmapsMtf ); } } + else + { + mpSVGWriter->WriteMetaFile( aTopLeft, aSize, rMtf, + 0xffffffff, + aElementId, + &rxShape, + pEmbeddedBitmapsMtf ); + } - return bRet; + return true; }
