[PATCH 3/3] Futher refactoring in enhwmf.cxx

Marc-Andre Laverdiere marc-andre at atc.tcs.com
Tue Sep 20 00:24:43 PDT 2011


---
 svtools/source/filter/wmf/enhwmf.cxx |  100 +++++++++++-----------------------
 svtools/source/filter/wmf/winmtf.hxx |    2 +-
 2 files changed, 34 insertions(+), 68 deletions(-)

diff --git a/svtools/source/filter/wmf/enhwmf.cxx b/svtools/source/filter/wmf/enhwmf.cxx
index 9d80efb..b95fd8f 100644
--- a/svtools/source/filter/wmf/enhwmf.cxx
+++ b/svtools/source/filter/wmf/enhwmf.cxx
@@ -397,6 +397,36 @@ Polygon EnhWMFReader::ReadPolygon(sal_uInt16 nStartIndex, sal_uInt16 nPoints)
 
     return aPolygon;
 }
+template <class T>
+void EnhWMFReader::ReadAndDrawPolyLine()
+{
+    sal_uInt32  nPoints;
+    sal_Int32   i, nPoly(0), nGesPoints(0);
+    pWMF->SeekRel( 0x10 );
+    // Number of Polygons:
+    *pWMF >> nPoly >> nGesPoints;
+
+    // taking the amount of points of each polygon, retrieving the total number of points
+    if ( pWMF->good() &&
+         ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(sal_uInt16) ) &&
+         ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() )
+       )
+    {
+        sal_uInt16* pnPoints = new sal_uInt16[ nPoly ];
+        for ( i = 0; i < nPoly && pWMF->good(); i++ )
+        {
+            *pWMF >> nPoints;
+            pnPoints[ i ] = (sal_uInt16)nPoints;
+        }
+        // Get polygon points:
+        for ( i = 0; ( i < nPoly ) && pWMF->good(); i++ )
+        {
+            Polygon aPolygon = ReadPolygon<T>(0, pnPoints[i]);
+            pOut->DrawPolyLine( aPolygon, sal_False, bRecordPath );
+        }
+        delete[] pnPoints;
+    }
+}
 
 template <class T>
 void EnhWMFReader::ReadAndDrawPolyPolygon()
@@ -529,47 +559,11 @@ sal_Bool EnhWMFReader::ReadEnhWMF()
             break;
 
             case EMR_POLYPOLYLINE :
-            {
-                sal_Int32   i, nPoly(0);
-                pWMF->SeekRel( 0x10 );
-
-                // Number of Polygons:
-                *pWMF >> nPoly >> i;
-
-                // taking the amount of points of each polygon, retrieving the total number of points
-                if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(sal_uInt16) )
-                {
-                    if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() ) )
-                    {
-                        sal_uInt16* pnPoints = new sal_uInt16[ nPoly ];
-
-                        for ( i = 0; i < nPoly; i++ )
-                        {
-                            *pWMF >> nPoints;
-                            pnPoints[ i ] = (sal_uInt16)nPoints;
-                        }
-
-                        // Get polygon points:
-                        for ( i = 0; ( i < nPoly ) && !pWMF->IsEof(); i++ )
-                        {
-                            Polygon aPoly( pnPoints[ i ] );
-                            for( sal_uInt16 k = 0; k < pnPoints[ i ]; k++ )
-                            {
-                                *pWMF >> nX32 >> nY32;
-                                aPoly[ k ] = Point( nX32, nY32 );
-                            }
-                            pOut->DrawPolyLine( aPoly, sal_False, bRecordPath );
-                        }
-                        delete[] pnPoints;
-                    }
-                }
-            }
+                ReadAndDrawPolyLine<sal_uInt32>();
             break;
 
             case EMR_POLYPOLYGON :
-            {
                 ReadAndDrawPolyPolygon<sal_uInt32>();
-            }
             break;
 
             case EMR_SETWINDOWEXTEX :
@@ -1252,39 +1246,11 @@ sal_Bool EnhWMFReader::ReadEnhWMF()
             break;
 
             case EMR_POLYPOLYLINE16 :
-            {
-                sal_Int32   i, nPoly(0), nGesPoints(0);
-                pWMF->SeekRel( 0x10 );
-                // Number of Polygons:
-                *pWMF >> nPoly >> nGesPoints;
-
-                // taking the amount of points of each polygon, retrieving the total number of points
-                if ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(sal_uInt16) )
-                {
-                    if ( ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() ) )
-                    {
-                        sal_uInt16* pnPoints = new sal_uInt16[ nPoly ];
-                        for ( i = 0; i < nPoly; i++ )
-                        {
-                            *pWMF >> nPoints;
-                            pnPoints[ i ] = (sal_uInt16)nPoints;
-                        }
-                        // Get polygon points:
-                        for ( i = 0; ( i < nPoly ) && pWMF->good(); i++ )
-                        {
-                            Polygon aPolygon = ReadPolygon<sal_Int16>(0, pnPoints[i]);
-                            pOut->DrawPolyLine( aPolygon, sal_False, bRecordPath );
-                        }
-                        delete[] pnPoints;
-                    }
-                }
-            }
-            break;
+                ReadAndDrawPolyLine<sal_uInt16>();
+                break;
 
             case EMR_POLYPOLYGON16 :
-            {
                 ReadAndDrawPolyPolygon<sal_uInt16>();
-            }
             break;
 
             case EMR_FILLRGN :
diff --git a/svtools/source/filter/wmf/winmtf.hxx b/svtools/source/filter/wmf/winmtf.hxx
index 07ddb7e..0fa899d 100644
--- a/svtools/source/filter/wmf/winmtf.hxx
+++ b/svtools/source/filter/wmf/winmtf.hxx
@@ -843,8 +843,8 @@ public:
     void            ReadGDIComment();
 private:
     template <class T> void ReadAndDrawPolyPolygon();
+    template <class T> void ReadAndDrawPolyLine();
     template <class T> Polygon ReadPolygon(sal_uInt16 nStartIndex, sal_uInt16 nPoints);
-//    template <class T, void * O> void ReadAndDrawPolygon(const sal_uInt16 nPoints, const sal_Bool skipFirst);
     template <class T, class Drawer> void ReadAndDrawPolygon(Drawer drawer, const sal_Bool skipFirst);
 };
 
-- 
1.7.6


--------------040808010506090009050800
Content-Type: text/plain;
 name="0002-Refactoring-drawing-of-simple-polygons-in-enhwmf.cxx.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0002-Refactoring-drawing-of-simple-polygons-in-enhwmf.cxx.pa";
 filename*1="tch"



More information about the LibreOffice mailing list