drawinglayer/source/tools/emfphelperdata.cxx | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-)
New commits: commit b78b6fdfcb3f3a7e0e3248d788ae0593d37ac409 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Feb 28 09:45:55 2022 +0000 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Mar 3 06:13:03 2022 +0100 check if cast is to the right type LIBREOFFICE-311XVJ95 Change-Id: I159f516daafad3e4088677fe2c8c6f5423b3e264 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130670 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit b44bd9ef8e2efdb66558917200e1f179b9db1c58) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130768 Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx index 164237b043e3..cb1ee024c528 100644 --- a/drawinglayer/source/tools/emfphelperdata.cxx +++ b/drawinglayer/source/tools/emfphelperdata.cxx @@ -460,7 +460,7 @@ namespace emfplushelper } else // we use a brush { - const EMFPBrush* brush = static_cast<EMFPBrush*>(maEMFPObjects[brushIndexOrColor & 0xff].get()); + const EMFPBrush* brush = dynamic_cast<EMFPBrush*>(maEMFPObjects[brushIndexOrColor & 0xff].get()); if (brush) { color = brush->GetColor(); @@ -736,7 +736,7 @@ namespace emfplushelper } else // use Brush { - EMFPBrush* brush = static_cast<EMFPBrush*>( maEMFPObjects[brushIndexOrColor & 0xff].get() ); + EMFPBrush* brush = dynamic_cast<EMFPBrush*>(maEMFPObjects[brushIndexOrColor & 0xff].get()); SAL_INFO("drawinglayer.emf", "EMF+\t\t Fill polygon, brush slot: " << brushIndexOrColor << " (brush type: " << (brush ? brush->GetType() : -1) << ")"); // give up in case something wrong happened @@ -1263,7 +1263,11 @@ namespace emfplushelper rMS.ReadUInt32(brushIndexOrColor); SAL_INFO("drawinglayer.emf", "EMF+\t FillRegion slot: " << index); - EMFPPlusFillPolygon(static_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get())->regionPolyPolygon, flags & 0x8000, brushIndexOrColor); + EMFPRegion* region = dynamic_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get()); + if (region) + EMFPPlusFillPolygon(region->regionPolyPolygon, flags & 0x8000, brushIndexOrColor); + else + SAL_WARN("drawinglayer.emf", "EMF+\tEmfPlusRecordTypeFillRegion missing region"); } break; case EmfPlusRecordTypeDrawEllipse: @@ -1442,10 +1446,10 @@ namespace emfplushelper SAL_INFO("drawinglayer.emf", "EMF+\t TODO: use image attributes"); // Source unit of measurement type must be 1 pixel - if (sourceUnit == UnitTypePixel && maEMFPObjects[flags & 0xff]) + if (EMFPImage* image = sourceUnit == UnitTypePixel ? + dynamic_cast<EMFPImage*>(maEMFPObjects[flags & 0xff].get()) : + nullptr) { - EMFPImage& image - = *static_cast<EMFPImage*>(maEMFPObjects[flags & 0xff].get()); float sx, sy, sw, sh; ReadRectangle(rMS, sx, sy, sw, sh); @@ -1495,9 +1499,9 @@ namespace emfplushelper SAL_INFO("drawinglayer.emf", "EMF+\t Rectangle: " << dx << "," << dy << " " << dw << "x" << dh); Size aSize; - if (image.type == ImageDataTypeBitmap) + if (image->type == ImageDataTypeBitmap) { - aSize = image.graphic.GetBitmapEx().GetSizePixel(); + aSize = image->graphic.GetBitmapEx().GetSizePixel(); SAL_INFO("drawinglayer.emf", "EMF+\t Bitmap size: " << aSize.Width() << "x" << aSize.Height()); @@ -1542,9 +1546,9 @@ namespace emfplushelper /* Row 1, Column 1 */ aDstSize.getY(), /* Row 1, Column 2 */ aDstPoint.getY()); - if (image.type == ImageDataTypeBitmap) + if (image->type == ImageDataTypeBitmap) { - BitmapEx aBmp(image.graphic.GetBitmapEx()); + BitmapEx aBmp(image->graphic.GetBitmapEx()); aBmp.Crop(aSource); aSize = aBmp.GetSizePixel(); if (aSize.Width() > 0 && aSize.Height() > 0) @@ -1556,9 +1560,9 @@ namespace emfplushelper else SAL_WARN("drawinglayer.emf", "EMF+\t warning: empty bitmap"); } - else if (image.type == ImageDataTypeMetafile) + else if (image->type == ImageDataTypeMetafile) { - GDIMetaFile aGDI(image.graphic.GetGDIMetaFile()); + GDIMetaFile aGDI(image->graphic.GetGDIMetaFile()); aGDI.Clip(aSource); mrTargetHolders.Current().append( new drawinglayer::primitive2d::MetafilePrimitive2D(aTransformMatrix, @@ -1593,7 +1597,7 @@ namespace emfplushelper // get the stringFormat from the Object table ( this is OPTIONAL and may be nullptr ) const EMFPStringFormat *stringFormat = dynamic_cast<EMFPStringFormat*>(maEMFPObjects[formatId & 0xff].get()); // get the font from the flags - const EMFPFont *font = static_cast< EMFPFont* >( maEMFPObjects[flags & 0xff].get() ); + const EMFPFont *font = dynamic_cast<EMFPFont*>(maEMFPObjects[flags & 0xff].get()); if (!font) { break; @@ -2033,7 +2037,7 @@ namespace emfplushelper SAL_INFO("drawinglayer.emf", "EMF+\t SetClipPath combine mode: " << combineMode); SAL_INFO("drawinglayer.emf", "EMF+\t Path in slot: " << (flags & 0xff)); - EMFPPath *path = static_cast<EMFPPath*>(maEMFPObjects[flags & 0xff].get()); + EMFPPath *path = dynamic_cast<EMFPPath*>(maEMFPObjects[flags & 0xff].get()); if (!path) { SAL_WARN("drawinglayer.emf", "EMF+\t TODO Unable to find path in slot: " << (flags & 0xff)); @@ -2051,7 +2055,7 @@ namespace emfplushelper int combineMode = (flags >> 8) & 0xf; SAL_INFO("drawinglayer.emf", "EMF+\t Region in slot: " << (flags & 0xff)); SAL_INFO("drawinglayer.emf", "EMF+\t Combine mode: " << combineMode); - EMFPRegion *region = static_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get()); + EMFPRegion *region = dynamic_cast<EMFPRegion*>(maEMFPObjects[flags & 0xff].get()); if (!region) { SAL_WARN("drawinglayer.emf", "EMF+\t TODO Unable to find region in slot: " << (flags & 0xff)); @@ -2120,7 +2124,7 @@ namespace emfplushelper } // get the font from the flags - EMFPFont *font = static_cast< EMFPFont* >( maEMFPObjects[flags & 0xff].get() ); + EMFPFont *font = dynamic_cast<EMFPFont*>(maEMFPObjects[flags & 0xff].get()); if (!font) { break;