[Libreoffice-commits] core.git: cppcanvas/source drawinglayer/source

Bartosz Kosiorek gang65 at poczta.onet.pl
Mon Oct 16 14:14:07 UTC 2017


 cppcanvas/source/mtfrenderer/emfplus.cxx     |   62 +++++++++------------
 drawinglayer/source/tools/emfphelperdata.cxx |   79 +++++++++++++--------------
 2 files changed, 69 insertions(+), 72 deletions(-)

New commits:
commit f2410ad4d0f1e93c7f12ee51da9e1a1a90f0f5a4
Author: Bartosz Kosiorek <gang65 at poczta.onet.pl>
Date:   Sun Oct 15 18:13:29 2017 +0200

    tdf#31814 Resolve TODO from EMF+ DrawImage and DrawImagePoints
    
    Change-Id: I1b128aa467286b5ae5e0d3cc298ee59f3e6ec12d
    Reviewed-on: https://gerrit.libreoffice.org/43408
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Patrick Jaap <patrick.jaap at tu-dresden.de>
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx
index acc0b3f58573..47e1b1d48d3f 100644
--- a/cppcanvas/source/mtfrenderer/emfplus.cxx
+++ b/cppcanvas/source/mtfrenderer/emfplus.cxx
@@ -1181,10 +1181,10 @@ namespace cppcanvas
                             SAL_INFO("cppcanvas.emf", "EMF+ " << (type == EmfPlusRecordTypeDrawImagePoints ? "DrawImagePoints" : "DrawImage") << "attributes index: " << attrIndex << "source unit: " << sourceUnit);
                             SAL_INFO("cppcanvas.emf", "EMF+\tTODO: use image attributes");
 
-                            if (sourceUnit == 2 && aObjects [flags & 0xff]) { // we handle only GraphicsUnit.Pixel now
+                            // For DrawImage and DrawImagePoints, source unit of measurement type must be 1 pixel
+                            if (sourceUnit == UnitTypePixel && aObjects [flags & 0xff]) {
                                 EMFPImage& image = *static_cast<EMFPImage *>( aObjects [flags & 0xff].get());
                                 float sx, sy, sw, sh;
-                                sal_Int32 aCount;
 
                                 ReadRectangle (rMF, sx, sy, sw, sh);
                                 ::tools::Rectangle aSource(Point(sx, sy), Size(sw, sh));
@@ -1193,12 +1193,13 @@ namespace cppcanvas
 
                                 ::basegfx::B2DPoint aDstPoint;
                                 ::basegfx::B2DSize aDstSize;
-                                bool bValid = false;
 
                                 if (type == EmfPlusRecordTypeDrawImagePoints) {
+                                    sal_Int32 aCount;
                                     rMF.ReadInt32( aCount );
 
-                                    if( aCount == 3) { // TODO: now that we now that this value is count we should support it better
+                                    // Number of points used by DrawImagePoints. Exactly 3 points must be specified.
+                                    if( aCount == 3 ) {
                                         float x1, y1, x2, y2, x3, y3;
 
                                         ReadPoint (rMF, x1, y1, flags);
@@ -1210,8 +1211,9 @@ namespace cppcanvas
 
                                         aDstPoint = Map (x1, y1);
                                         aDstSize = MapSize(x2 - x1, y3 - y1);
-
-                                        bValid = true;
+                                    } else {
+                                        SAL_WARN("cppcanvas.emf", "EMF+ DrawImagePoints Wrong EMF+ file. Expected 3 points, received: "<< aCount);
+                                        break;
                                     }
                                 } else if (type == EmfPlusRecordTypeDrawImage) {
                                     float dx, dy, dw, dh;
@@ -1222,39 +1224,33 @@ namespace cppcanvas
 
                                     aDstPoint = Map (dx, dy);
                                     aDstSize = MapSize(dw, dh);
-
-                                    bValid = true;
                                 }
 
-                                if (bValid) {
-                                    BitmapEx aBmp( image.graphic.GetBitmapEx () );
-                                    aBmp.Crop( aSource );
-
-                                    Size aSize( aBmp.GetSizePixel() );
-                                    SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height());
-                                    if( aSize.Width() > 0 && aSize.Height() > 0 ) {
-                                        std::shared_ptr<Action> pBmpAction (
-                                            internal::BitmapActionFactory::createBitmapAction (
-                                                aBmp,
-                                                rState.mapModeTransform * aDstPoint,
-                                                rState.mapModeTransform * aDstSize,
-                                                rCanvas,
-                                                rState));
-
-                                        if( pBmpAction ) {
-                                            maActions.emplace_back( pBmpAction,
-                                                                            rFactoryParms.mrCurrActionIndex );
-
-                                            rFactoryParms.mrCurrActionIndex += pBmpAction->getActionCount()-1;
-                                        }
-                                    } else {
-                                        SAL_INFO("cppcanvas.emf", "EMF+ warning: empty bitmap");
+                                BitmapEx aBmp( image.graphic.GetBitmapEx () );
+                                aBmp.Crop( aSource );
+
+                                Size aSize( aBmp.GetSizePixel() );
+                                SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height());
+                                if( aSize.Width() > 0 && aSize.Height() > 0 ) {
+                                    std::shared_ptr<Action> pBmpAction (
+                                        internal::BitmapActionFactory::createBitmapAction (
+                                            aBmp,
+                                            rState.mapModeTransform * aDstPoint,
+                                            rState.mapModeTransform * aDstSize,
+                                            rCanvas,
+                                            rState));
+
+                                    if( pBmpAction ) {
+                                        maActions.emplace_back( pBmpAction,
+                                                                        rFactoryParms.mrCurrActionIndex );
+
+                                        rFactoryParms.mrCurrActionIndex += pBmpAction->getActionCount()-1;
                                     }
                                 } else {
-                                    SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) TODO (fixme)");
+                                    SAL_WARN("cppcanvas.emf", "EMF+ warning: empty bitmap");
                                 }
                             } else {
-                                SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) TODO (fixme) - possibly unsupported source units for crop rectangle");
+                                SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) Wrong EMF+ file. Only Unit Type Pixel is support by EMF+ standard in DrawImage(Points)");
                             }
                             break;
                         }
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index c39083336046..d769ea9a0b9d 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -89,6 +89,13 @@ namespace emfplushelper
         return "";
     }
 
+    typedef enum
+    {
+      ImageDataTypeUnknown = 0x00000000,
+      ImageDataTypeBitmap = 0x00000001,
+      ImageDataTypeMetafile = 0x00000002
+    } ImageDataType;
+
     EMFPObject::~EMFPObject()
     {
     }
@@ -1061,26 +1068,25 @@ namespace emfplushelper
                         SAL_INFO("cppcanvas.emf", "EMF+ " << (type == EmfPlusRecordTypeDrawImagePoints ? "DrawImagePoints" : "DrawImage") << "attributes index: " << attrIndex << "source unit: " << sourceUnit);
                         SAL_INFO("cppcanvas.emf", "EMF+\tTODO: use image attributes");
 
-                        if (sourceUnit == 2 && maEMFPObjects[flags & 0xff].get())
+                        // For DrawImage and DrawImagePoints, source unit of measurement type must be 1 pixel
+                        if (sourceUnit == UnitTypePixel && maEMFPObjects[flags & 0xff].get())
                         {
-                            // we handle only GraphicsUnit.Pixel now
                             EMFPImage& image = *static_cast<EMFPImage *>(maEMFPObjects[flags & 0xff].get());
                             float sx, sy, sw, sh;
-                            sal_Int32 aCount;
                             ReadRectangle(rMS, sx, sy, sw, sh);
                             ::tools::Rectangle aSource(Point(sx, sy), Size(sw, sh));
                             SAL_INFO("cppcanvas.emf", "EMF+ " << (type == EmfPlusRecordTypeDrawImagePoints ? "DrawImagePoints" : "DrawImage") << " source rectangle: " << sx << "," << sy << " " << sw << "x" << sh);
                             ::basegfx::B2DPoint aDstPoint;
                             ::basegfx::B2DSize aDstSize;
-                            bool bValid = false;
 
                             if (type == EmfPlusRecordTypeDrawImagePoints)
                             {
+                                sal_Int32 aCount;
                                 rMS.ReadInt32(aCount);
 
-                                if (aCount == 3)
+                                // Number of points used by DrawImagePoints. Exactly 3 points must be specified.
+                                if(aCount == 3)
                                 {
-                                    // TODO: now that we now that this value is count we should support it better
                                     float x1, y1, x2, y2, x3, y3;
 
                                     ReadPoint(rMS, x1, y1, flags);
@@ -1092,8 +1098,11 @@ namespace emfplushelper
 
                                     aDstPoint = Map(x1, y1);
                                     aDstSize = MapSize(x2 - x1, y3 - y1);
-
-                                    bValid = true;
+                                }
+                                else
+                                {
+                                    SAL_WARN("cppcanvas.emf", "EMF+ DrawImagePoints Wrong EMF+ file. Expected 3 points, received: "<< aCount);
+                                    break;
                                 }
                             }
                             else if (type == EmfPlusRecordTypeDrawImage)
@@ -1103,50 +1112,42 @@ namespace emfplushelper
                                 SAL_INFO("cppcanvas.emf", "EMF+ destination rectangle: " << dx << "," << dy << " " << dw << "x" << dh);
                                 aDstPoint = Map(dx, dy);
                                 aDstSize = MapSize(dw, dh);
-                                bValid = true;
                             }
 
-                            if (bValid)
+                            // create correct transform matrix
+                            basegfx::B2DHomMatrix aTransformMatrix = basegfx::utils::createScaleTranslateB2DHomMatrix(
+                                aDstSize.getX(),
+                                aDstSize.getY(),
+                                aDstPoint.getX(),
+                                aDstPoint.getY());
+
+                            if (image.type == ImageDataTypeBitmap)
                             {
-                                // create correct transform matrix
-                                basegfx::B2DHomMatrix aTransformMatrix = basegfx::utils::createScaleTranslateB2DHomMatrix(
-                                    aDstSize.getX(),
-                                    aDstSize.getY(),
-                                    aDstPoint.getX(),
-                                    aDstPoint.getY());
-
-                                if (image.type == 1) // Bitmap
+                                BitmapEx aBmp(image.graphic.GetBitmapEx());
+                                aBmp.Crop(aSource);
+                                Size aSize(aBmp.GetSizePixel());
+                                SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height());
+                                if (aSize.Width() > 0 && aSize.Height() > 0)
                                 {
-                                    BitmapEx aBmp(image.graphic.GetBitmapEx());
-                                    aBmp.Crop(aSource);
-                                    Size aSize(aBmp.GetSizePixel());
-                                    SAL_INFO("cppcanvas.emf", "EMF+ bitmap size: " << aSize.Width() << "x" << aSize.Height());
-                                    if (aSize.Width() > 0 && aSize.Height() > 0)
-                                    {
-                                        mrTargetHolders.Current().append(
-                                            new drawinglayer::primitive2d::BitmapPrimitive2D(aBmp,aTransformMatrix));
-                                    }
-                                    else
-                                    {
-                                        SAL_INFO("cppcanvas.emf", "EMF+ warning: empty bitmap");
-                                    }
+                                    mrTargetHolders.Current().append(
+                                        new drawinglayer::primitive2d::BitmapPrimitive2D(aBmp, aTransformMatrix));
                                 }
-                                else if (image.type == 2) // Metafile
+                                else
                                 {
-                                    GDIMetaFile aGDI(image.graphic.GetGDIMetaFile());
-                                    aGDI.Clip(aSource);
-                                    mrTargetHolders.Current().append(
-                                            new drawinglayer::primitive2d::MetafilePrimitive2D(aTransformMatrix,aGDI));
+                                    SAL_INFO("cppcanvas.emf", "EMF+ warning: empty bitmap");
                                 }
                             }
-                            else
+                            else if (image.type == ImageDataTypeMetafile)
                             {
-                                SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) TODO (fixme)");
+                                GDIMetaFile aGDI(image.graphic.GetGDIMetaFile());
+                                aGDI.Clip(aSource);
+                                mrTargetHolders.Current().append(
+                                        new drawinglayer::primitive2d::MetafilePrimitive2D(aTransformMatrix, aGDI));
                             }
                         }
                         else
                         {
-                            SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) TODO (fixme) - possibly unsupported source units for crop rectangle");
+                            SAL_WARN("cppcanvas.emf", "EMF+ DrawImage(Points) Wrong EMF+ file. Only Unit Type Pixel is support by EMF+ standard in DrawImage(Points)");
                         }
                         break;
                     }


More information about the Libreoffice-commits mailing list