diff options
Diffstat (limited to 'filter/source/msfilter/escherex.cxx')
-rw-r--r-- | filter/source/msfilter/escherex.cxx | 332 |
1 files changed, 166 insertions, 166 deletions
diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx index 31d382796f43..b5be935d9b95 100644 --- a/filter/source/msfilter/escherex.cxx +++ b/filter/source/msfilter/escherex.cxx @@ -19,6 +19,7 @@ #include "eschesdo.hxx" #include <o3tl/any.hxx> +#include <o3tl/string_view.hxx> #include <svx/svdxcgv.hxx> #include <svx/svdomedia.hxx> #include <svx/xflftrit.hxx> @@ -30,6 +31,7 @@ #include <svx/svdoole2.hxx> #include <svx/sdtfsitm.hxx> #include <editeng/outlobj.hxx> +#include <utility> #include <vcl/graph.hxx> #include <vcl/cvtgrf.hxx> #include <vcl/svapp.hxx> @@ -91,6 +93,8 @@ #include <sal/log.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/numeric/ftools.hxx> +#include <osl/diagnose.h> #include <algorithm> #include <memory> @@ -105,8 +109,8 @@ EscherExContainer::EscherExContainer( SvStream& rSt, const sal_uInt16 nRecType, } EscherExContainer::~EscherExContainer() { - sal_uInt32 nPos = rStrm.Tell(); - sal_uInt32 nSize= nPos - nContPos; + sal_uInt64 nPos = rStrm.Tell(); + sal_uInt32 nSize = nPos - nContPos; if ( nSize ) { rStrm.Seek( nContPos - 4 ); @@ -123,8 +127,8 @@ EscherExAtom::EscherExAtom( SvStream& rSt, const sal_uInt16 nRecType, const sal_ } EscherExAtom::~EscherExAtom() { - sal_uInt32 nPos = rStrm.Tell(); - sal_uInt32 nSize= nPos - nContPos; + sal_uInt64 nPos = rStrm.Tell(); + sal_uInt32 nSize = nPos - nContPos; if ( nSize ) { rStrm.Seek( nContPos - 4 ); @@ -205,14 +209,13 @@ void EscherPropertyContainer::AddOpt( void EscherPropertyContainer::AddOpt( sal_uInt16 nPropID, - const OUString& rString) + std::u16string_view rString) { std::vector<sal_uInt8> aBuf; - aBuf.reserve(rString.getLength() * 2 + 2); + aBuf.reserve(rString.size() * 2 + 2); - for(sal_Int32 i(0); i < rString.getLength(); i++) + for(const sal_Unicode nUnicode: rString) { - const sal_Unicode nUnicode(rString[i]); aBuf.push_back(static_cast<sal_uInt8>(nUnicode)); aBuf.push_back(static_cast<sal_uInt8>(nUnicode >> 8)); } @@ -289,14 +292,9 @@ bool EscherPropertyContainer::GetOpt( sal_uInt16 nPropId, EscherPropSortStruct& return false; } -EscherProperties EscherPropertyContainer::GetOpts() const +const EscherProperties & EscherPropertyContainer::GetOpts() const { - EscherProperties aVector; - - for ( size_t i = 0; i < pSortStruct.size(); ++i ) - aVector.push_back( pSortStruct[ i ] ); - - return aVector; + return pSortStruct; } extern "C" { @@ -409,7 +407,7 @@ void EscherPropertyContainer::CreateGradientProperties( nFillType = ESCHER_FillShadeScale; nAngle = (rGradient.Angle * 0x10000) / 10; nFillFocus = (sal::static_int_cast<int>(rGradient.Style) == - sal::static_int_cast<int>(GradientStyle::Linear)) ? 0 : 50; + sal::static_int_cast<int>(css::awt::GradientStyle_LINEAR)) ? 0 : 50; } break; case awt::GradientStyle_RADIAL : @@ -580,7 +578,7 @@ void EscherPropertyContainer::CreateFillProperties( { if ( rXShape.is() ) { - SdrObject* pObj = GetSdrObjectFromXShape( rXShape ); + SdrObject* pObj = SdrObject::getSdrObjectFromXShape(rXShape); if ( pObj ) { const SfxItemSet& aAttr( pObj->GetMergedItemSet() ); @@ -600,7 +598,7 @@ void EscherPropertyContainer::CreateFillProperties( uno::Any aAny; AddOpt( ESCHER_Prop_WrapText, ESCHER_WrapNone ); AddOpt( ESCHER_Prop_AnchorText, ESCHER_AnchorMiddle ); - const OUString aPropName( "FillStyle" ); + static constexpr OUString aPropName( u"FillStyle"_ustr ); if ( EscherPropertyValueHelper::GetPropertyValue( aAny, rXPropSet, aPropName ) ) @@ -932,16 +930,16 @@ bool EscherPropertyContainer::GetLineArrow( const bool bLineStart, if ( !bIsMapped && comphelper::string::getTokenCount(aArrowStartName, ' ') == 2 ) { sal_Int32 nIdx{ 0 }; - OUString aArrowName( aArrowStartName.getToken( 0, ' ', nIdx ) ); - if ( aArrowName == "msArrowEnd" ) + std::u16string_view aArrowName( o3tl::getToken(aArrowStartName, 0, ' ', nIdx ) ); + if ( aArrowName == u"msArrowEnd" ) reLineEnd = ESCHER_LineArrowEnd; - else if ( aArrowName == "msArrowOpenEnd" ) + else if ( aArrowName == u"msArrowOpenEnd" ) reLineEnd = ESCHER_LineArrowOpenEnd; - else if ( aArrowName == "msArrowStealthEnd" ) + else if ( aArrowName == u"msArrowStealthEnd" ) reLineEnd = ESCHER_LineArrowStealthEnd; - else if ( aArrowName == "msArrowDiamondEnd" ) + else if ( aArrowName == u"msArrowDiamondEnd" ) reLineEnd = ESCHER_LineArrowDiamondEnd; - else if ( aArrowName == "msArrowOvalEnd" ) + else if ( aArrowName == u"msArrowOvalEnd" ) reLineEnd = ESCHER_LineArrowOvalEnd; else nIdx = -1; @@ -949,8 +947,8 @@ bool EscherPropertyContainer::GetLineArrow( const bool bLineStart, // now we have the arrow, and try to determine the arrow size; if ( nIdx>0 ) { - OUString aArrowSize( aArrowStartName.getToken( 0, ' ', nIdx ) ); - sal_Int32 nArrowSize = aArrowSize.toInt32(); + std::u16string_view aArrowSize = o3tl::getToken(aArrowStartName, 0, ' ', nIdx ); + sal_Int32 nArrowSize = o3tl::toInt32(aArrowSize); rnArrowWidth = ( nArrowSize - 1 ) / 3; rnArrowLength = nArrowSize - ( rnArrowWidth * 3 ) - 1; } @@ -1337,15 +1335,14 @@ bool EscherPropertyContainer::CreateOLEGraphicProperties(const uno::Reference<dr if ( rXShape.is() ) { - SdrObject* pObject = GetSdrObjectFromXShape(rXShape); // SJ: leaving unoapi, because currently there is + SdrObject* pObject = SdrObject::getSdrObjectFromXShape(rXShape); // SJ: leaving unoapi, because currently there is if (auto pOle2Obj = dynamic_cast<const SdrOle2Obj*>(pObject)) // no access to the native graphic object { const Graphic* pGraphic = pOle2Obj->GetGraphic(); if (pGraphic) { - Graphic aGraphic(*pGraphic); - std::unique_ptr<GraphicObject> xGraphicObject(new GraphicObject(aGraphic)); - bRetValue = CreateGraphicProperties(rXShape, *xGraphicObject); + GraphicObject aGraphicObject(*pGraphic); + bRetValue = CreateGraphicProperties(rXShape, aGraphicObject); } } } @@ -1387,11 +1384,11 @@ bool EscherPropertyContainer::CreateMediaGraphicProperties(const uno::Reference< bool bRetValue = false; if ( rXShape.is() ) { - SdrObject* pSdrObject(GetSdrObjectFromXShape(rXShape)); // SJ: leaving unoapi, because currently there is + SdrObject* pSdrObject(SdrObject::getSdrObjectFromXShape(rXShape)); // SJ: leaving unoapi, because currently there is if (auto pSdrMediaObj = dynamic_cast<const SdrMediaObj*>(pSdrObject)) // no access to the native graphic object { - std::unique_ptr<GraphicObject> xGraphicObject(new GraphicObject(pSdrMediaObj->getSnapshot())); - bRetValue = CreateGraphicProperties(rXShape, *xGraphicObject); + GraphicObject aGraphicObject(pSdrMediaObj->getSnapshot()); + bRetValue = CreateGraphicProperties(rXShape, aGraphicObject); } } return bRetValue; @@ -1419,10 +1416,10 @@ void EscherPropertyContainer::CreateEmbeddedBitmapProperties( uno::Reference<graphic::XGraphic> xGraphic(rxBitmap, uno::UNO_QUERY); if (!xGraphic.is()) return; - const Graphic aGraphic(xGraphic); + Graphic aGraphic(xGraphic); if (aGraphic.IsNone()) return; - const GraphicObject aGraphicObject(aGraphic); + GraphicObject aGraphicObject(std::move(aGraphic)); if (aGraphicObject.GetType() == GraphicType::NONE) return; if (ImplCreateEmbeddedBmp(aGraphicObject)) @@ -1468,7 +1465,7 @@ void EscherPropertyContainer::CreateEmbeddedHatchProperties(const drawing::Hatch { const tools::Rectangle aRect(pShapeBoundRect ? *pShapeBoundRect : tools::Rectangle(Point(0,0), Size(28000, 21000))); Graphic aGraphic(lclDrawHatch(rHatch, rBackColor, bFillBackground, aRect)); - GraphicObject aGraphicObject(aGraphic); + GraphicObject aGraphicObject(std::move(aGraphic)); if (ImplCreateEmbeddedBmp(aGraphicObject)) AddOpt( ESCHER_Prop_fillType, ESCHER_FillTexture ); @@ -1635,7 +1632,9 @@ bool EscherPropertyContainer::CreateGraphicProperties(const uno::Reference<beans nFormat != GraphicFileFormat::TIF && nFormat != GraphicFileFormat::PCT && nFormat != GraphicFileFormat::WMF && - nFormat != GraphicFileFormat::EMF) ) + nFormat != GraphicFileFormat::WMZ && + nFormat != GraphicFileFormat::EMF && + nFormat != GraphicFileFormat::EMZ) ) { std::unique_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream( aTmp.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ )); @@ -1777,7 +1776,7 @@ bool EscherPropertyContainer::CreateGraphicProperties(const uno::Reference<beans { EscherGraphicProvider aProvider; SvMemoryStream aMemStrm; - GraphicObject aGraphicObject(aGraphic); + GraphicObject aGraphicObject(std::move(aGraphic)); if (aProvider.GetBlibID(aMemStrm, aGraphicObject, nullptr, pGraphicAttr.get(), bOOxmlExport)) { @@ -1911,14 +1910,20 @@ bool EscherPropertyContainer::CreatePolygonProperties( const sal_uInt16 nPolyCount(aPolyPolygon.Count()); sal_uInt32 nTotalPoints(0); - std::vector< sal_uInt8 > aVertices(4, 0); - std::vector< sal_uInt8 > aSegments(4, 0); - aVertices.push_back(static_cast<sal_uInt8>(0xf0)); - aVertices.push_back(static_cast<sal_uInt8>(0xff)); + std::vector< sal_uInt8 > aVertices + { + 0, 0, 0, 0, + static_cast<sal_uInt8>(0xf0), + static_cast<sal_uInt8>(0xff) + }; - aSegments.push_back(static_cast<sal_uInt8>(2)); - aSegments.push_back(static_cast<sal_uInt8>(0)); + std::vector< sal_uInt8 > aSegments + { + 0, 0, 0, 0, + static_cast<sal_uInt8>(2), + static_cast<sal_uInt8>(0) + }; for(sal_uInt16 j(0); j < nPolyCount; ++j) { @@ -1995,47 +2000,45 @@ bool EscherPropertyContainer::CreatePolygonProperties( } } - if(0 != nTotalPoints && aSegments.size() >= 6 && aVertices.size() >= 6) - { - // Little endian - aVertices[0] = static_cast<sal_uInt8>(nTotalPoints); - aVertices[1] = static_cast<sal_uInt8>(nTotalPoints >> 8); - aVertices[2] = static_cast<sal_uInt8>(nTotalPoints); - aVertices[3] = static_cast<sal_uInt8>(nTotalPoints >> 8); - - aSegments.push_back(static_cast<sal_uInt8>(0)); - aSegments.push_back(static_cast<sal_uInt8>(0x80)); - - const sal_uInt32 nSegmentBufSize(aSegments.size() - 6); - aSegments[0] = static_cast<sal_uInt8>(nSegmentBufSize >> 1); - aSegments[1] = static_cast<sal_uInt8>(nSegmentBufSize >> 9); - aSegments[2] = static_cast<sal_uInt8>(nSegmentBufSize >> 1); - aSegments[3] = static_cast<sal_uInt8>(nSegmentBufSize >> 9); - - AddOpt( - ESCHER_Prop_geoRight, - rGeoRect.Width); - AddOpt( - ESCHER_Prop_geoBottom, - rGeoRect.Height); - AddOpt( - ESCHER_Prop_shapePath, - ESCHER_ShapeComplex); - AddOpt( - ESCHER_Prop_pVertices, - true, - aVertices.size() - 6, - aVertices); - AddOpt( - ESCHER_Prop_pSegmentInfo, - true, - aSegments.size(), - aSegments); + if(0 == nTotalPoints || aSegments.size() < 6 || aVertices.size() < 6) + return false; - return true; - } + // Little endian + aVertices[0] = static_cast<sal_uInt8>(nTotalPoints); + aVertices[1] = static_cast<sal_uInt8>(nTotalPoints >> 8); + aVertices[2] = static_cast<sal_uInt8>(nTotalPoints); + aVertices[3] = static_cast<sal_uInt8>(nTotalPoints >> 8); - return false; + aSegments.push_back(static_cast<sal_uInt8>(0)); + aSegments.push_back(static_cast<sal_uInt8>(0x80)); + + const sal_uInt32 nSegmentBufSize(aSegments.size() - 6); + aSegments[0] = static_cast<sal_uInt8>(nSegmentBufSize >> 1); + aSegments[1] = static_cast<sal_uInt8>(nSegmentBufSize >> 9); + aSegments[2] = static_cast<sal_uInt8>(nSegmentBufSize >> 1); + aSegments[3] = static_cast<sal_uInt8>(nSegmentBufSize >> 9); + + AddOpt( + ESCHER_Prop_geoRight, + rGeoRect.Width); + AddOpt( + ESCHER_Prop_geoBottom, + rGeoRect.Height); + AddOpt( + ESCHER_Prop_shapePath, + ESCHER_ShapeComplex); + AddOpt( + ESCHER_Prop_pVertices, + true, + aVertices.size() - 6, + aVertices); + AddOpt( + ESCHER_Prop_pSegmentInfo, + true, + aSegments.size(), + aSegments); + + return true; } @@ -2127,7 +2130,6 @@ static void lcl_Rotate(Degree100 nAngle, Point center, Point& pt) break; default: return; - break; } sal_Int32 x0 =pt.X()-center.X(); sal_Int32 y0 =pt.Y()-center.Y(); @@ -2451,13 +2453,13 @@ static void ConvertEnhancedCustomShapeEquation( sal_Int32 i; for ( i = 0; i < nEquationSourceCount; i++ ) { - EnhancedCustomShape2d aCustoShape2d( + EnhancedCustomShape2d aCustomShape2d( const_cast< SdrObjCustomShape& >(rSdrObjCustomShape)); try { std::shared_ptr< EnhancedCustomShape::ExpressionNode > aExpressNode( EnhancedCustomShape::FunctionParser::parseFunction( - sEquationSource[ i ], aCustoShape2d)); + sEquationSource[ i ], aCustomShape2d)); drawing::EnhancedCustomShapeParameter aPara( aExpressNode->fillNode( rEquations, nullptr, 0 ) ); if ( aPara.Type != drawing::EnhancedCustomShapeParameterType::EQUATION ) { @@ -2516,7 +2518,7 @@ bool EscherPropertyContainer::IsDefaultObject( { switch(eShapeType) { - // if the custom shape is not default shape of ppt, return sal_Fasle; + // if the custom shape is not default shape of ppt, return false; case mso_sptTearDrop: return false; @@ -2537,17 +2539,17 @@ bool EscherPropertyContainer::IsDefaultObject( void EscherPropertyContainer::LookForPolarHandles( const MSO_SPT eShapeType, sal_Int32& nAdjustmentsWhichNeedsToBeConverted ) { const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eShapeType ); - if ( !(pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles) ) + if ( !pDefCustomShape || pDefCustomShape->pHandles.empty() ) return; - sal_Int32 k, nkCount = pDefCustomShape->nHandles; - const SvxMSDffHandle* pData = pDefCustomShape->pHandles; - for ( k = 0; k < nkCount; k++, pData++ ) + sal_Int32 k, nkCount = pDefCustomShape->pHandles.size(); + for (k = 0; k < nkCount; k++) { + const SvxMSDffHandle* pData = &pDefCustomShape->pHandles[k]; if ( pData->nFlags & SvxMSDffHandleFlags::POLAR ) { - if ( ( pData->nPositionY >= 0x256 ) || ( pData->nPositionY <= 0x107 ) ) - nAdjustmentsWhichNeedsToBeConverted |= ( 1 << k ); + if ( ( pData->nPositionY >= 0x256 ) || ( pData->nPositionY <= 0x107 ) ) + nAdjustmentsWhichNeedsToBeConverted |= ( 1 << k ); } } } @@ -2582,25 +2584,26 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT if ( !aXPropSet.is() ) return; - if(nullptr == dynamic_cast< SdrObjCustomShape* >(GetSdrObjectFromXShape(rXShape))) + SdrObjCustomShape* pSdrObjCustomShape = dynamic_cast< SdrObjCustomShape* >(SdrObject::getSdrObjectFromXShape(rXShape)); + if(!pSdrObjCustomShape) { return; } - SdrObjCustomShape& rSdrObjCustomShape(static_cast< SdrObjCustomShape& >(*GetSdrObjectFromXShape(rXShape))); + SdrObjCustomShape& rSdrObjCustomShape = *pSdrObjCustomShape; uno::Any aGeoPropSet = aXPropSet->getPropertyValue( "CustomShapeGeometry" ); uno::Sequence< beans::PropertyValue > aGeoPropSeq; if ( !(aGeoPropSet >>= aGeoPropSeq) ) return; - const OUString sViewBox ( "ViewBox" ); - const OUString sTextRotateAngle ( "TextRotateAngle" ); - const OUString sExtrusion ( "Extrusion" ); - const OUString sEquations ( "Equations" ); - const OUString sPath ( "Path" ); - const OUString sTextPath ( "TextPath" ); - const OUString sHandles ( "Handles" ); - const OUString sAdjustmentValues ( "AdjustmentValues" ); + static constexpr OUStringLiteral sViewBox ( u"ViewBox" ); + static constexpr OUStringLiteral sTextRotateAngle ( u"TextRotateAngle" ); + static constexpr OUString sExtrusion ( u"Extrusion"_ustr ); + static constexpr OUStringLiteral sEquations ( u"Equations" ); + static constexpr OUStringLiteral sPath ( u"Path" ); + static constexpr OUString sTextPath ( u"TextPath"_ustr ); + static constexpr OUStringLiteral sHandles ( u"Handles" ); + static constexpr OUStringLiteral sAdjustmentValues ( u"AdjustmentValues" ); bool bAdjustmentValuesProp = false; uno::Any aAdjustmentValuesProp; @@ -2847,8 +2850,9 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT drawing::Direction3D aExtrusionRotationCenter; if ( rrProp.Value >>= aExtrusionRotationCenter ) { - AddOpt( DFF_Prop_c3DRotationCenterX, static_cast<sal_Int32>( aExtrusionRotationCenter.DirectionX * 360.0 ) ); - AddOpt( DFF_Prop_c3DRotationCenterY, static_cast<sal_Int32>( aExtrusionRotationCenter.DirectionY * 360.0 ) ); + // tdf#145904 X- and Y-component is fraction, Z-component in EMU + AddOpt( DFF_Prop_c3DRotationCenterX, static_cast<sal_Int32>( aExtrusionRotationCenter.DirectionX * 65536.0 ) ); + AddOpt( DFF_Prop_c3DRotationCenterY, static_cast<sal_Int32>( aExtrusionRotationCenter.DirectionY * 65536.0 ) ); AddOpt( DFF_Prop_c3DRotationCenterZ, static_cast<sal_Int32>( aExtrusionRotationCenter.DirectionZ * 360.0 ) ); nFillHarshFlags &=~8; // don't use AutoRotationCenter; } @@ -2857,7 +2861,11 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT { double fExtrusionShininess = 0; if ( rrProp.Value >>= fExtrusionShininess ) - AddOpt( DFF_Prop_c3DShininess, static_cast<sal_Int32>( fExtrusionShininess * 655.36 ) ); + { + // ODF to MS Office conversion invers to msdffimp.cxx + fExtrusionShininess = std::round(fExtrusionShininess / 10.0); + AddOpt( DFF_Prop_c3DShininess, static_cast<sal_Int32>(fExtrusionShininess) ); + } } else if ( rrProp.Name == "Skew" ) { @@ -2874,7 +2882,7 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT { double fExtrusionSpecularity = 0; if ( rrProp.Value >>= fExtrusionSpecularity ) - AddOpt( DFF_Prop_c3DSpecularAmt, static_cast<sal_Int32>( fExtrusionSpecularity * 1333 ) ); + AddOpt( DFF_Prop_c3DSpecularAmt, static_cast<sal_Int32>( fExtrusionSpecularity * 655.36 ) ); } else if ( rrProp.Name == "ProjectionMode" ) { @@ -3444,10 +3452,10 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT AddOpt(DFF_Prop_gtextAlign,gTextAlign); } } - if((nTextPathFlags & 0x4000) != 0) // Is Font work + if((nTextPathFlags & 0x4000) != 0) // Is Fontwork { OutlinerParaObject* pOutlinerParaObject(rSdrObjCustomShape.GetOutlinerParaObject()); - if ( pOutlinerParaObject && pOutlinerParaObject->IsVertical() ) + if ( pOutlinerParaObject && pOutlinerParaObject->IsEffectivelyVertical() ) nTextPathFlags |= 0x2000; } @@ -3711,8 +3719,7 @@ MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawi // In case of VML export, try to handle the // ooxml- prefix in rShapeType. If that fails, // just do the same as the binary export. - OString aType = OUStringToOString(rShapeType, RTL_TEXTENCODING_UTF8); - eShapeType = msfilter::util::GETVMLShapeType(aType); + eShapeType = msfilter::util::GETVMLShapeType(rShapeType); if (eShapeType == mso_sptNil) eShapeType = EnhancedCustomShapeTypeNames::Get(rShapeType); } @@ -3747,23 +3754,23 @@ MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawi bool EscherPropertyContainer::CreateBlipPropertiesforOLEControl(const uno::Reference<beans::XPropertySet> & rXPropSet, const uno::Reference<drawing::XShape> & rXShape) { - SdrObject* pShape = GetSdrObjectFromXShape( rXShape ); - if ( pShape ) - { - const Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pShape)); - const GraphicObject aGraphicObject(aGraphic); + SdrObject* pShape = SdrObject::getSdrObjectFromXShape(rXShape); + if ( !pShape ) + return false; + + Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pShape)); + const GraphicObject aGraphicObject(std::move(aGraphic)); - if (!aGraphicObject.GetUniqueID().isEmpty()) + if (!aGraphicObject.GetUniqueID().isEmpty()) + { + if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect ) { - if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect ) + sal_uInt32 nBlibId = pGraphicProvider->GetBlibID(*pPicOutStrm, aGraphicObject); + if ( nBlibId ) { - sal_uInt32 nBlibId = pGraphicProvider->GetBlibID(*pPicOutStrm, aGraphicObject); - if ( nBlibId ) - { - AddOpt( ESCHER_Prop_pib, nBlibId, true ); - ImplCreateGraphicAttributes( rXPropSet, nBlibId, false ); - return true; - } + AddOpt( ESCHER_Prop_pib, nBlibId, true ); + ImplCreateGraphicAttributes( rXPropSet, nBlibId, false ); + return true; } } } @@ -3781,12 +3788,8 @@ EscherPersistTable::~EscherPersistTable() bool EscherPersistTable::PtIsID( sal_uInt32 nID ) { - for(auto const & pPtr : maPersistTable) { - if ( pPtr->mnID == nID ) { - return true; - } - } - return false; + return std::any_of(maPersistTable.begin(), maPersistTable.end(), + [&nID](const auto& rxEntry) { return rxEntry->mnID == nID; }); } void EscherPersistTable::PtInsert( sal_uInt32 nID, sal_uInt32 nOfs ) @@ -3891,11 +3894,11 @@ beans::PropertyState EscherPropertyValueHelper::GetPropertyState( EscherBlibEntry::EscherBlibEntry( sal_uInt32 nPictureOffset, const GraphicObject& rObject, const OString& rId, const GraphicAttr* pGraphicAttr ) : + maPrefMapMode ( rObject.GetPrefMapMode() ), + maPrefSize ( rObject.GetPrefSize() ), mnPictureOffset ( nPictureOffset ), mnRefCount ( 1 ), mnSizeExtra ( 0 ), - maPrefSize ( rObject.GetPrefSize() ), - maPrefMapMode ( rObject.GetPrefMapMode() ), mbIsEmpty ( true ) { mbIsNativeGraphicPossible = ( pGraphicAttr == nullptr ); @@ -4050,7 +4053,8 @@ void EscherGraphicProvider::WriteBlibStoreContainer( SvStream& rSt, SvStream* pM if ( pMergePicStreamBSE ) { - sal_uInt32 nBlipSize, nOldPos = pMergePicStreamBSE->Tell(); + sal_uInt32 nBlipSize; + sal_uInt64 nOldPos = pMergePicStreamBSE->Tell(); const sal_uInt32 nBuf = 0x40000; // 256KB buffer std::unique_ptr<sal_uInt8[]> pBuf(new sal_uInt8[ nBuf ]); @@ -4194,15 +4198,13 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, GraphicObjec SvMemoryStream aGIFStream; const char* const pString = "MSOFFICE9.0"; aGIFStream.WriteBytes(pString, strlen(pString)); - nErrCode = rFilter.ExportGraphic( aGraphic, OUString(), aGIFStream, + nErrCode = rFilter.ExportGraphic( aGraphic, u"", aGIFStream, rFilter.GetExportFormatNumberForShortName( u"GIF" ) ); SAL_WARN_IF( nErrCode != ERRCODE_NONE, "filter.ms", "ExportGraphic to GIF failed with " << nErrCode); if (nErrCode == ERRCODE_NONE) { - uno::Sequence<beans::PropertyValue> aFilterData( 1 ); - uno::Sequence<beans::PropertyValue> aAdditionalChunkSequence( 1 ); sal_uInt32 nGIFSreamLen = aGIFStream.Tell(); uno::Sequence<sal_Int8> aGIFSeq( nGIFSreamLen ); sal_Int8* pSeq = aGIFSeq.getArray(); @@ -4211,11 +4213,11 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, GraphicObjec beans::PropertyValue aChunkProp, aFilterProp; aChunkProp.Name = "msOG"; aChunkProp.Value <<= aGIFSeq; - aAdditionalChunkSequence[ 0 ] = aChunkProp; + uno::Sequence<beans::PropertyValue> aAdditionalChunkSequence{ aChunkProp }; aFilterProp.Name = "AdditionalChunks"; aFilterProp.Value <<= aAdditionalChunkSequence; - aFilterData[ 0 ] = aFilterProp; - nErrCode = rFilter.ExportGraphic( aGraphic, OUString(), aStream, + uno::Sequence<beans::PropertyValue> aFilterData{ aFilterProp }; + nErrCode = rFilter.ExportGraphic( aGraphic, u"", aStream, rFilter.GetExportFormatNumberForShortName( u"PNG" ), &aFilterData ); } } @@ -4339,7 +4341,7 @@ sal_uInt32 EscherGraphicProvider::GetBlibID( SvStream& rPicOutStrm, GraphicObjec } if ( nAtomSize ) { - sal_uInt32 nPos = rPicOutStrm.Tell(); + sal_uInt64 nPos = rPicOutStrm.Tell(); rPicOutStrm.Seek( nAtomSize - 4 ); rPicOutStrm.WriteUInt32( nPos - nAtomSize ); rPicOutStrm.Seek( nPos ); @@ -4369,8 +4371,8 @@ struct EscherShapeListEntry uno::Reference<drawing::XShape>aXShape; sal_uInt32 n_EscherId; - EscherShapeListEntry(const uno::Reference<drawing::XShape> & rShape, sal_uInt32 nId) - : aXShape(rShape) + EscherShapeListEntry(uno::Reference<drawing::XShape> xShape, sal_uInt32 nId) + : aXShape(std::move(xShape)) , n_EscherId(nId) {} }; @@ -4419,7 +4421,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) uno::Reference<beans::XPropertySet> aPropertySet( aXShape, uno::UNO_QUERY ); - if ((aType == OString( "drawing.PolyPolygon" )) || (aType == OString( "drawing.PolyLine" ))) + if ((aType == "drawing.PolyPolygon") || (aType == "drawing.PolyLine")) { if ( aPropertySet.is() ) { @@ -4458,8 +4460,8 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) } } } - else if ((aType == OString( "drawing.OpenBezier" )) || (aType == OString( "drawing.OpenFreeHand" )) || (aType == OString( "drawing.PolyLinePath" )) - || (aType == OString( "drawing.ClosedBezier" )) || ( aType == OString( "drawing.ClosedFreeHand" )) || (aType == OString( "drawing.PolyPolygonPath" )) ) + else if ((aType == "drawing.OpenBezier") || (aType == "drawing.OpenFreeHand") || (aType == "drawing.PolyLinePath") + || (aType == "drawing.ClosedBezier") || ( aType == "drawing.ClosedFreeHand") || (aType == "drawing.PolyPolygonPath") ) { uno::Reference<beans::XPropertySet> aPropertySet2( aXShape, uno::UNO_QUERY ); @@ -4518,7 +4520,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) if (aType == "drawing.Custom") { - if (auto pSdrObjCustomShape = dynamic_cast< SdrObjCustomShape* >(GetSdrObjectFromXShape(aXShape))) + if (auto pSdrObjCustomShape = dynamic_cast< SdrObjCustomShape* >(SdrObject::getSdrObjectFromXShape(aXShape))) { const SdrCustomShapeGeometryItem& rGeometryItem = pSdrObjCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ); @@ -4559,7 +4561,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) else if ( nGluePointType == drawing::EnhancedCustomShapeGluePointType::SEGMENTS ) { tools::PolyPolygon aPolyPoly; - SdrObjectUniquePtr pTemporaryConvertResultObject(pSdrObjCustomShape->DoConvertToPolyObj(true, true)); + rtl::Reference<SdrObject> pTemporaryConvertResultObject(pSdrObjCustomShape->DoConvertToPolyObj(true, true)); SdrPathObj* pSdrPathObj(dynamic_cast< SdrPathObj* >(pTemporaryConvertResultObject.get())); if(pSdrPathObj) @@ -4570,7 +4572,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) } // do *not* forget to delete the temporary used SdrObject - possible memory leak (!) - pTemporaryConvertResultObject.reset(); + pTemporaryConvertResultObject.clear(); pSdrPathObj = nullptr; if(0 != aPolyPoly.Count()) @@ -4623,7 +4625,7 @@ sal_uInt32 EscherConnectorListEntry::GetConnectorRule( bool bFirst ) aPoly.Rotate( aRect.TopLeft(), Degree10(static_cast<sal_Int16>( ( nAngle + 5 ) / 10 )) ); nRule = GetClosestPoint( aPoly, aRefPoint ); - if (aType == OString( "drawing.Ellipse" )) + if (aType == "drawing.Ellipse") nRule <<= 1; // In PPT an ellipse has 8 ways to connect } } @@ -4853,15 +4855,14 @@ protected: virtual void FlushData() override {} public: - SvNullStream() : SvStream() {} + SvNullStream() {} }; } -EscherEx::EscherEx(const std::shared_ptr<EscherExGlobal>& rxGlobal, SvStream* pOutStrm, bool bOOXML) - : mxGlobal(rxGlobal) +EscherEx::EscherEx(std::shared_ptr<EscherExGlobal> xGlobal, SvStream* pOutStrm, bool bOOXML) + : mxGlobal(std::move(xGlobal)) , mpOutStrm(pOutStrm) - , mbOwnsStrm(false) , mnCurrentDg(0) , mnCountOfs(0) , mnGroupLevel(0) @@ -4872,8 +4873,8 @@ EscherEx::EscherEx(const std::shared_ptr<EscherExGlobal>& rxGlobal, SvStream* pO { if (!mpOutStrm) { - mpOutStrm = new SvNullStream(); - mbOwnsStrm = true; + mxOwnStrm = std::make_unique<SvNullStream>(); + mpOutStrm = mxOwnStrm.get(); } mnStrmStartOfs = mpOutStrm->Tell(); mpImplEESdrWriter.reset( new ImplEESdrWriter( *this ) ); @@ -4881,8 +4882,6 @@ EscherEx::EscherEx(const std::shared_ptr<EscherExGlobal>& rxGlobal, SvStream* pO EscherEx::~EscherEx() { - if (mbOwnsStrm) - delete mpOutStrm; } void EscherEx::Flush( SvStream* pPicStreamMergeBSE /* = NULL */ ) @@ -4922,7 +4921,8 @@ void EscherEx::Flush( SvStream* pPicStreamMergeBSE /* = NULL */ ) void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes ) { - sal_uInt32 nSize, nType, nSource, nBufSize, nToCopy, nCurPos = mpOutStrm->Tell(); + sal_uInt32 nSize, nType, nSource, nBufSize, nToCopy; + sal_uInt64 nCurPos = mpOutStrm->Tell(); // adjust persist table for(auto const & pPtr : maPersistTable) { @@ -4937,7 +4937,7 @@ void EscherEx::InsertAtCurrentPos( sal_uInt32 nBytes ) while ( mpOutStrm->Tell() < nCurPos ) { mpOutStrm->ReadUInt32( nType ).ReadUInt32( nSize ); - sal_uInt32 nEndOfRecord = mpOutStrm->Tell() + nSize; + sal_uInt64 nEndOfRecord = mpOutStrm->Tell() + nSize; bool bContainer = (nType & 0x0F) == 0x0F; /* Expand the record, if the insertion position is inside, or if the position is at the end of a container (expands always), or at the @@ -5014,7 +5014,7 @@ bool EscherEx::SeekToPersistOffset( sal_uInt32 nKey ) void EscherEx::InsertAtPersistOffset( sal_uInt32 nKey, sal_uInt32 nValue ) { - sal_uInt32 nOldPos = mpOutStrm->Tell(); + sal_uInt64 nOldPos = mpOutStrm->Tell(); bool bRetValue = SeekToPersistOffset( nKey ); if ( bRetValue ) { @@ -5081,8 +5081,8 @@ void EscherEx::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance ) void EscherEx::CloseContainer() { - sal_uInt32 nSize, nPos = mpOutStrm->Tell(); - nSize = ( nPos - mOffsets.back() ) - 4; + sal_uInt64 nPos = mpOutStrm->Tell(); + sal_uInt32 nSize = ( nPos - mOffsets.back() ) - 4; mpOutStrm->Seek( mOffsets.back() ); mpOutStrm->WriteUInt32( nSize ); @@ -5125,7 +5125,7 @@ void EscherEx::BeginAtom() void EscherEx::EndAtom( sal_uInt16 nRecType, int nRecVersion, int nRecInstance ) { - sal_uInt32 nOldPos = mpOutStrm->Tell(); + sal_uInt64 nOldPos = mpOutStrm->Tell(); mpOutStrm->Seek( mnCountOfs ); sal_uInt32 nSize = nOldPos - mnCountOfs; mpOutStrm->WriteUInt16( ( nRecInstance << 4 ) | ( nRecVersion & 0xf ) ).WriteUInt16( nRecType ).WriteUInt32( nSize - 8 ); @@ -5217,7 +5217,7 @@ void EscherEx::SetGroupSnapRect( sal_uInt32 nGroupLevel, const tools::Rectangle& { if ( nGroupLevel ) { - sal_uInt32 nCurrentPos = mpOutStrm->Tell(); + sal_uInt64 nCurrentPos = mpOutStrm->Tell(); if ( DoSeek( ESCHER_Persist_Grouping_Snap | ( nGroupLevel - 1 ) ) ) { mpOutStrm ->WriteInt32( rRect.Left() ) // Bounding box for the grouped shapes to which they will be attached @@ -5233,7 +5233,7 @@ void EscherEx::SetGroupLogicRect( sal_uInt32 nGroupLevel, const tools::Rectangle { if ( nGroupLevel ) { - sal_uInt32 nCurrentPos = mpOutStrm->Tell(); + sal_uInt64 nCurrentPos = mpOutStrm->Tell(); if ( DoSeek( ESCHER_Persist_Grouping_Logic | ( nGroupLevel - 1 ) ) ) { mpOutStrm->WriteInt16( rRect.Top() ).WriteInt16( rRect.Left() ).WriteInt16( rRect.Right() ).WriteInt16( rRect.Bottom() ); |