LCOV - code coverage report
Current view: top level - vcl/source/filter/wmf - enhwmf.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 591 763 77.5 %
Date: 2014-11-03 Functions: 20 23 87.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "winmtf.hxx"
      21             : #include <osl/endian.h>
      22             : #include <basegfx/matrix/b2dhommatrix.hxx>
      23             : #include <boost/bind.hpp>
      24             : #include <vcl/dibtools.hxx>
      25             : #include <boost/scoped_array.hpp>
      26             : 
      27             : using namespace std;
      28             : 
      29             : // GDI-Array
      30             : 
      31             : #define EMR_HEADER                      1
      32             : #define EMR_POLYBEZIER                  2
      33             : #define EMR_POLYGON                     3
      34             : #define EMR_POLYLINE                    4
      35             : #define EMR_POLYBEZIERTO                5
      36             : #define EMR_POLYLINETO                  6
      37             : #define EMR_POLYPOLYLINE                7
      38             : #define EMR_POLYPOLYGON                 8
      39             : #define EMR_SETWINDOWEXTEX              9
      40             : #define EMR_SETWINDOWORGEX              10
      41             : #define EMR_SETVIEWPORTEXTEX            11
      42             : #define EMR_SETVIEWPORTORGEX            12
      43             : #define EMR_SETBRUSHORGEX               13
      44             : #define EMR_EOF                         14
      45             : #define EMR_SETPIXELV                   15
      46             : #define EMR_SETMAPPERFLAGS              16
      47             : #define EMR_SETMAPMODE                  17
      48             : #define EMR_SETBKMODE                   18
      49             : #define EMR_SETPOLYFILLMODE             19
      50             : #define EMR_SETROP2                     20
      51             : #define EMR_SETSTRETCHBLTMODE           21
      52             : #define EMR_SETTEXTALIGN                22
      53             : #define EMR_SETCOLORADJUSTMENT          23
      54             : #define EMR_SETTEXTCOLOR                24
      55             : #define EMR_SETBKCOLOR                  25
      56             : #define EMR_OFFSETCLIPRGN               26
      57             : #define EMR_MOVETOEX                    27
      58             : #define EMR_SETMETARGN                  28
      59             : #define EMR_EXCLUDECLIPRECT             29
      60             : #define EMR_INTERSECTCLIPRECT           30
      61             : #define EMR_SCALEVIEWPORTEXTEX          31
      62             : #define EMR_SCALEWINDOWEXTEX            32
      63             : #define EMR_SAVEDC                      33
      64             : #define EMR_RESTOREDC                   34
      65             : #define EMR_SETWORLDTRANSFORM           35
      66             : #define EMR_MODIFYWORLDTRANSFORM        36
      67             : #define EMR_SELECTOBJECT                37
      68             : #define EMR_CREATEPEN                   38
      69             : #define EMR_CREATEBRUSHINDIRECT         39
      70             : #define EMR_DELETEOBJECT                40
      71             : #define EMR_ANGLEARC                    41
      72             : #define EMR_ELLIPSE                     42
      73             : #define EMR_RECTANGLE                   43
      74             : #define EMR_ROUNDRECT                   44
      75             : #define EMR_ARC                         45
      76             : #define EMR_CHORD                       46
      77             : #define EMR_PIE                         47
      78             : #define EMR_SELECTPALETTE               48
      79             : #define EMR_CREATEPALETTE               49
      80             : #define EMR_SETPALETTEENTRIES           50
      81             : #define EMR_RESIZEPALETTE               51
      82             : #define EMR_REALIZEPALETTE              52
      83             : #define EMR_EXTFLOODFILL                53
      84             : #define EMR_LINETO                      54
      85             : #define EMR_ARCTO                       55
      86             : #define EMR_POLYDRAW                    56
      87             : #define EMR_SETARCDIRECTION             57
      88             : #define EMR_SETMITERLIMIT               58
      89             : #define EMR_BEGINPATH                   59
      90             : #define EMR_ENDPATH                     60
      91             : #define EMR_CLOSEFIGURE                 61
      92             : #define EMR_FILLPATH                    62
      93             : #define EMR_STROKEANDFILLPATH           63
      94             : #define EMR_STROKEPATH                  64
      95             : #define EMR_FLATTENPATH                 65
      96             : #define EMR_WIDENPATH                   66
      97             : #define EMR_SELECTCLIPPATH              67
      98             : #define EMR_ABORTPATH                   68
      99             : 
     100             : #define EMR_GDICOMMENT                  70
     101             : #define EMR_FILLRGN                     71
     102             : #define EMR_FRAMERGN                    72
     103             : #define EMR_INVERTRGN                   73
     104             : #define EMR_PAINTRGN                    74
     105             : #define EMR_EXTSELECTCLIPRGN            75
     106             : #define EMR_BITBLT                      76
     107             : #define EMR_STRETCHBLT                  77
     108             : #define EMR_MASKBLT                     78
     109             : #define EMR_PLGBLT                      79
     110             : #define EMR_SETDIBITSTODEVICE           80
     111             : #define EMR_STRETCHDIBITS               81
     112             : #define EMR_EXTCREATEFONTINDIRECTW      82
     113             : #define EMR_EXTTEXTOUTA                 83
     114             : #define EMR_EXTTEXTOUTW                 84
     115             : #define EMR_POLYBEZIER16                85
     116             : #define EMR_POLYGON16                   86
     117             : #define EMR_POLYLINE16                  87
     118             : #define EMR_POLYBEZIERTO16              88
     119             : #define EMR_POLYLINETO16                89
     120             : #define EMR_POLYPOLYLINE16              90
     121             : #define EMR_POLYPOLYGON16               91
     122             : #define EMR_POLYDRAW16                  92
     123             : #define EMR_CREATEMONOBRUSH             93
     124             : #define EMR_CREATEDIBPATTERNBRUSHPT     94
     125             : #define EMR_EXTCREATEPEN                95
     126             : #define EMR_POLYTEXTOUTA                96
     127             : #define EMR_POLYTEXTOUTW                97
     128             : 
     129             : // WINDOWS VERSION >= 0x400
     130             : #define EMR_SETICMMODE                  98
     131             : #define EMR_CREATECOLORSPACE            99
     132             : #define EMR_SETCOLORSPACE              100
     133             : #define EMR_DELETECOLORSPACE           101
     134             : #define EMR_GLSRECORD                  102
     135             : #define EMR_GLSBOUNDEDRECORD           103
     136             : #define EMR_PIXELFORMAT                104
     137             : 
     138             : // WINDOWS VERSION >= 0x500
     139             : #define EMR_DRAWESCAPE                 105
     140             : #define EMR_EXTESCAPE                  106
     141             : #define EMR_STARTDOC                   107
     142             : #define EMR_SMALLTEXTOUT               108
     143             : #define EMR_FORCEUFIMAPPING            109
     144             : #define EMR_NAMEDESCAPE                110
     145             : #define EMR_COLORCORRECTPALETTE        111
     146             : #define EMR_SETICMPROFILEA             112
     147             : #define EMR_SETICMPROFILEW             113
     148             : #define EMR_ALPHABLEND                 114
     149             : #define EMR_ALPHADIBBLEND              115
     150             : #define EMR_TRANSPARENTBLT             116
     151             : #define EMR_TRANSPARENTDIB             117
     152             : #define EMR_GRADIENTFILL               118
     153             : #define EMR_SETLINKEDUFIS              119
     154             : #define EMR_SETTEXTJUSTIFICATION       120
     155             : 
     156             : namespace
     157             : {
     158             : 
     159             : const char *
     160           0 : record_type_name(sal_uInt32 nRecType)
     161             : {
     162             : #ifndef SAL_LOG_INFO
     163             :     (void) nRecType;
     164           0 :     return "";
     165             : #else
     166             :     switch( nRecType )
     167             :     {
     168             :     case EMR_HEADER: return "HEADER";
     169             :     case EMR_POLYBEZIER: return "POLYBEZIER";
     170             :     case EMR_POLYGON: return "POLYGON";
     171             :     case EMR_POLYLINE: return "POLYLINE";
     172             :     case EMR_POLYBEZIERTO: return "POLYBEZIERTO";
     173             :     case EMR_POLYLINETO: return "POLYLINETO";
     174             :     case EMR_POLYPOLYLINE: return "POLYPOLYLINE";
     175             :     case EMR_POLYPOLYGON: return "POLYPOLYGON";
     176             :     case EMR_SETWINDOWEXTEX: return "SETWINDOWEXTEX";
     177             :     case EMR_SETWINDOWORGEX: return "SETWINDOWORGEX";
     178             :     case EMR_SETVIEWPORTEXTEX: return "SETVIEWPORTEXTEX";
     179             :     case EMR_SETVIEWPORTORGEX: return "SETVIEWPORTORGEX";
     180             :     case EMR_SETBRUSHORGEX: return "SETBRUSHORGEX";
     181             :     case EMR_EOF: return "EOF";
     182             :     case EMR_SETPIXELV: return "SETPIXELV";
     183             :     case EMR_SETMAPPERFLAGS: return "SETMAPPERFLAGS";
     184             :     case EMR_SETMAPMODE: return "SETMAPMODE";
     185             :     case EMR_SETBKMODE: return "SETBKMODE";
     186             :     case EMR_SETPOLYFILLMODE: return "SETPOLYFILLMODE";
     187             :     case EMR_SETROP2: return "SETROP2";
     188             :     case EMR_SETSTRETCHBLTMODE: return "SETSTRETCHBLTMODE";
     189             :     case EMR_SETTEXTALIGN: return "SETTEXTALIGN";
     190             :     case EMR_SETCOLORADJUSTMENT: return "SETCOLORADJUSTMENT";
     191             :     case EMR_SETTEXTCOLOR: return "SETTEXTCOLOR";
     192             :     case EMR_SETBKCOLOR: return "SETBKCOLOR";
     193             :     case EMR_OFFSETCLIPRGN: return "OFFSETCLIPRGN";
     194             :     case EMR_MOVETOEX: return "MOVETOEX";
     195             :     case EMR_SETMETARGN: return "SETMETARGN";
     196             :     case EMR_EXCLUDECLIPRECT: return "EXCLUDECLIPRECT";
     197             :     case EMR_INTERSECTCLIPRECT: return "INTERSECTCLIPRECT";
     198             :     case EMR_SCALEVIEWPORTEXTEX: return "SCALEVIEWPORTEXTEX";
     199             :     case EMR_SCALEWINDOWEXTEX: return "SCALEWINDOWEXTEX";
     200             :     case EMR_SAVEDC: return "SAVEDC";
     201             :     case EMR_RESTOREDC: return "RESTOREDC";
     202             :     case EMR_SETWORLDTRANSFORM: return "SETWORLDTRANSFORM";
     203             :     case EMR_MODIFYWORLDTRANSFORM: return "MODIFYWORLDTRANSFORM";
     204             :     case EMR_SELECTOBJECT: return "SELECTOBJECT";
     205             :     case EMR_CREATEPEN: return "CREATEPEN";
     206             :     case EMR_CREATEBRUSHINDIRECT: return "CREATEBRUSHINDIRECT";
     207             :     case EMR_DELETEOBJECT: return "DELETEOBJECT";
     208             :     case EMR_ANGLEARC: return "ANGLEARC";
     209             :     case EMR_ELLIPSE: return "ELLIPSE";
     210             :     case EMR_RECTANGLE: return "RECTANGLE";
     211             :     case EMR_ROUNDRECT: return "ROUNDRECT";
     212             :     case EMR_ARC: return "ARC";
     213             :     case EMR_CHORD: return "CHORD";
     214             :     case EMR_PIE: return "PIE";
     215             :     case EMR_SELECTPALETTE: return "SELECTPALETTE";
     216             :     case EMR_CREATEPALETTE: return "CREATEPALETTE";
     217             :     case EMR_SETPALETTEENTRIES: return "SETPALETTEENTRIES";
     218             :     case EMR_RESIZEPALETTE: return "RESIZEPALETTE";
     219             :     case EMR_REALIZEPALETTE: return "REALIZEPALETTE";
     220             :     case EMR_EXTFLOODFILL: return "EXTFLOODFILL";
     221             :     case EMR_LINETO: return "LINETO";
     222             :     case EMR_ARCTO: return "ARCTO";
     223             :     case EMR_POLYDRAW: return "POLYDRAW";
     224             :     case EMR_SETARCDIRECTION: return "SETARCDIRECTION";
     225             :     case EMR_SETMITERLIMIT: return "SETMITERLIMIT";
     226             :     case EMR_BEGINPATH: return "BEGINPATH";
     227             :     case EMR_ENDPATH: return "ENDPATH";
     228             :     case EMR_CLOSEFIGURE: return "CLOSEFIGURE";
     229             :     case EMR_FILLPATH: return "FILLPATH";
     230             :     case EMR_STROKEANDFILLPATH: return "STROKEANDFILLPATH";
     231             :     case EMR_STROKEPATH: return "STROKEPATH";
     232             :     case EMR_FLATTENPATH: return "FLATTENPATH";
     233             :     case EMR_WIDENPATH: return "WIDENPATH";
     234             :     case EMR_SELECTCLIPPATH: return "SELECTCLIPPATH";
     235             :     case EMR_ABORTPATH: return "ABORTPATH";
     236             :     case EMR_GDICOMMENT: return "GDICOMMENT";
     237             :     case EMR_FILLRGN: return "FILLRGN";
     238             :     case EMR_FRAMERGN: return "FRAMERGN";
     239             :     case EMR_INVERTRGN: return "INVERTRGN";
     240             :     case EMR_PAINTRGN: return "PAINTRGN";
     241             :     case EMR_EXTSELECTCLIPRGN: return "EXTSELECTCLIPRGN";
     242             :     case EMR_BITBLT: return "BITBLT";
     243             :     case EMR_STRETCHBLT: return "STRETCHBLT";
     244             :     case EMR_MASKBLT: return "MASKBLT";
     245             :     case EMR_PLGBLT: return "PLGBLT";
     246             :     case EMR_SETDIBITSTODEVICE: return "SETDIBITSTODEVICE";
     247             :     case EMR_STRETCHDIBITS: return "STRETCHDIBITS";
     248             :     case EMR_EXTCREATEFONTINDIRECTW: return "EXTCREATEFONTINDIRECTW";
     249             :     case EMR_EXTTEXTOUTA: return "EXTTEXTOUTA";
     250             :     case EMR_EXTTEXTOUTW: return "EXTTEXTOUTW";
     251             :     case EMR_POLYBEZIER16: return "POLYBEZIER16";
     252             :     case EMR_POLYGON16: return "POLYGON16";
     253             :     case EMR_POLYLINE16: return "POLYLINE16";
     254             :     case EMR_POLYBEZIERTO16: return "POLYBEZIERTO16";
     255             :     case EMR_POLYLINETO16: return "POLYLINETO16";
     256             :     case EMR_POLYPOLYLINE16: return "POLYPOLYLINE16";
     257             :     case EMR_POLYPOLYGON16: return "POLYPOLYGON16";
     258             :     case EMR_POLYDRAW16: return "POLYDRAW16";
     259             :     case EMR_CREATEMONOBRUSH: return "CREATEMONOBRUSH";
     260             :     case EMR_CREATEDIBPATTERNBRUSHPT: return "CREATEDIBPATTERNBRUSHPT";
     261             :     case EMR_EXTCREATEPEN: return "EXTCREATEPEN";
     262             :     case EMR_POLYTEXTOUTA: return "POLYTEXTOUTA";
     263             :     case EMR_POLYTEXTOUTW: return "POLYTEXTOUTW";
     264             :     case EMR_SETICMMODE: return "SETICMMODE";
     265             :     case EMR_CREATECOLORSPACE: return "CREATECOLORSPACE";
     266             :     case EMR_SETCOLORSPACE: return "SETCOLORSPACE";
     267             :     case EMR_DELETECOLORSPACE: return "DELETECOLORSPACE";
     268             :     case EMR_GLSRECORD: return "GLSRECORD";
     269             :     case EMR_GLSBOUNDEDRECORD: return "GLSBOUNDEDRECORD";
     270             :     case EMR_PIXELFORMAT: return "PIXELFORMAT";
     271             :     case EMR_DRAWESCAPE: return "DRAWESCAPE";
     272             :     case EMR_EXTESCAPE: return "EXTESCAPE";
     273             :     case EMR_STARTDOC: return "STARTDOC";
     274             :     case EMR_SMALLTEXTOUT: return "SMALLTEXTOUT";
     275             :     case EMR_FORCEUFIMAPPING: return "FORCEUFIMAPPING";
     276             :     case EMR_NAMEDESCAPE: return "NAMEDESCAPE";
     277             :     case EMR_COLORCORRECTPALETTE: return "COLORCORRECTPALETTE";
     278             :     case EMR_SETICMPROFILEA: return "SETICMPROFILEA";
     279             :     case EMR_SETICMPROFILEW: return "SETICMPROFILEW";
     280             :     case EMR_ALPHABLEND: return "ALPHABLEND";
     281             :     case EMR_ALPHADIBBLEND: return "ALPHADIBBLEND";
     282             :     case EMR_TRANSPARENTBLT: return "TRANSPARENTBLT";
     283             :     case EMR_TRANSPARENTDIB: return "TRANSPARENTDIB";
     284             :     case EMR_GRADIENTFILL: return "GRADIENTFILL";
     285             :     case EMR_SETLINKEDUFIS: return "SETLINKEDUFIS";
     286             :     case EMR_SETTEXTJUSTIFICATION: return "SETTEXTJUSTIFICATION";
     287             :     default:
     288             :         // Yes, return a pointer to a static buffer. This is a very
     289             :         // local debugging output function, so no big deal.
     290             :         static char buffer[11];
     291             :         sprintf(buffer, "0x%08" SAL_PRIxUINT32, nRecType);
     292             :         return buffer;
     293             :     }
     294             : #endif
     295             : }
     296             : 
     297             : #ifdef OSL_BIGENDIAN
     298             : // little endian <-> big endian switch
     299             : static float GetSwapFloat(SvStream& rStream)
     300             : {
     301             :     float fTmp;
     302             :     sal_Int8* pPtr = (sal_Int8*)&fTmp;
     303             :     rStream.ReadSChar(pPtr[3]);
     304             :     rStream.ReadSChar(pPtr[2]);
     305             :     rStream.ReadSChar(pPtr[1]);
     306             :     rStream.ReadSChar(pPtr[0]);
     307             :     return fTmp;
     308             : }
     309             : #endif
     310             : 
     311             : struct BLENDFUNCTION
     312             : {
     313             :     unsigned char aBlendOperation;
     314             :     unsigned char aBlendFlags;
     315             :     unsigned char aSrcConstantAlpha;
     316             :     unsigned char aAlphaFormat;
     317             : 
     318             :     friend SvStream& operator>>(SvStream& rInStream, BLENDFUNCTION& rBlendFun);
     319             : };
     320             : 
     321          10 : SvStream& operator>>(SvStream& rInStream, BLENDFUNCTION& rBlendFun)
     322             : {
     323          10 :     rInStream.ReadUChar(rBlendFun.aBlendOperation);
     324          10 :     rInStream.ReadUChar(rBlendFun.aBlendFlags);
     325          10 :     rInStream.ReadUChar(rBlendFun.aSrcConstantAlpha);
     326          10 :     rInStream.ReadUChar(rBlendFun.aAlphaFormat);
     327          10 :     return rInStream;
     328             : }
     329             : 
     330        2476 : SvStream& operator>>(SvStream& rInStream, XForm& rXForm)
     331             : {
     332             :     if (sizeof(float) != 4)
     333             :     {
     334             :         OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
     335             :         rXForm = XForm();
     336             :     }
     337             :     else
     338             :     {
     339             : #ifdef OSL_BIGENDIAN
     340             :     rXForm.eM11 = GetSwapFloat(rInStream);
     341             :     rXForm.eM12 = GetSwapFloat(rInStream);
     342             :     rXForm.eM21 = GetSwapFloat(rInStream);
     343             :     rXForm.eM22 = GetSwapFloat(rInStream);
     344             :     rXForm.eDx = GetSwapFloat(rInStream);
     345             :     rXForm.eDy = GetSwapFloat(rInStream);
     346             : #else
     347        2476 :     rInStream.ReadFloat(rXForm.eM11);
     348        2476 :     rInStream.ReadFloat(rXForm.eM12);
     349        2476 :     rInStream.ReadFloat(rXForm.eM21);
     350        2476 :     rInStream.ReadFloat(rXForm.eM22);
     351        2476 :     rInStream.ReadFloat(rXForm.eDx);
     352        2476 :     rInStream.ReadFloat(rXForm.eDy);
     353             : #endif
     354             :     }
     355        2476 :     return rInStream;
     356             : }
     357             : 
     358         154 : static bool ImplReadRegion( tools::PolyPolygon& rPolyPoly, SvStream& rStream, sal_uInt32 nLen )
     359             : {
     360         154 :     if (nLen == 0)
     361           0 :         return false;
     362             : 
     363             :     sal_uInt32 nHdSize, nType, nCount, nRgnSize, i;
     364         154 :     rStream.ReadUInt32(nHdSize);
     365         154 :     rStream.ReadUInt32(nType);
     366         154 :     rStream.ReadUInt32(nCount);
     367         154 :     rStream.ReadUInt32(nRgnSize);
     368             : 
     369         154 :     if (   nCount > 0
     370         154 :         && nType == RDH_RECTANGLES
     371         154 :         && nLen >= ((nCount << 4) + (nHdSize - 16)))
     372             :     {
     373             :         sal_Int32 nx1, ny1, nx2, ny2;
     374             : 
     375         308 :         for (i = 0; i < nCount; i++)
     376             :         {
     377         154 :             rStream.ReadInt32(nx1);
     378         154 :             rStream.ReadInt32(ny1);
     379         154 :             rStream.ReadInt32(nx2);
     380         154 :             rStream.ReadInt32(ny2);
     381             : 
     382         154 :             Rectangle aRectangle(Point(nx1, ny1), Point(nx2, ny2));
     383             : 
     384         154 :             Polygon aPolygon(aRectangle);
     385         308 :             tools::PolyPolygon aPolyPolyOr1(aPolygon);
     386         308 :             tools::PolyPolygon aPolyPolyOr2(rPolyPoly);
     387         154 :             rPolyPoly.GetUnion(aPolyPolyOr1, aPolyPolyOr2);
     388         154 :             rPolyPoly = aPolyPolyOr2;
     389         154 :         }
     390         154 :         return true;
     391             :     }
     392           0 :     return false;
     393             : }
     394             : 
     395             : } // anonymous namespace
     396             : 
     397         223 : EnhWMFReader::EnhWMFReader(SvStream& rStream,GDIMetaFile& rGDIMetaFile,FilterConfigItem* pConfigItem)
     398         223 :     : WinMtf(new WinMtfOutput(rGDIMetaFile), rStream , pConfigItem)
     399             :     , bRecordPath(false)
     400             :     , nRecordCount(0)
     401         446 :     , bEMFPlus(false)
     402         223 : {}
     403             : 
     404         223 : EnhWMFReader::~EnhWMFReader()
     405         223 : {}
     406             : 
     407         908 : void EnhWMFReader::ReadEMFPlusComment(sal_uInt32 length, bool& bHaveDC)
     408             : {
     409         908 :     if (!bEMFPlus) {
     410         124 :         pOut->PassEMFPlusHeaderInfo();
     411             : 
     412             : #if OSL_DEBUG_LEVEL > 1
     413             :         // debug code - write the stream to debug file /tmp/emf-stream.emf
     414             :         int pos = pWMF->Tell();
     415             :         pWMF->Seek(0);
     416             :         SvFileStream file( OUString( "/tmp/emf-stream.emf" ), STREAM_WRITE | STREAM_TRUNC );
     417             : 
     418             :         pWMF->WriteStream(file);
     419             :         file.Flush();
     420             :         file.Close();
     421             : 
     422             :         pWMF->Seek( pos );
     423             : #endif
     424             : 
     425             :     }
     426         908 :     bEMFPlus = true;
     427             : 
     428         908 :     sal_Size pos = pWMF->Tell();
     429         908 :     void *buffer = malloc( length );
     430         908 :     pOut->PassEMFPlus( buffer, pWMF->Read( buffer, length ) );
     431         908 :     free( buffer );
     432         908 :     pWMF->Seek( pos );
     433             : 
     434         908 :     bHaveDC = false;
     435             : 
     436             :     OSL_ASSERT(length >= 4);
     437             :     // reduce by 32bit length itself, skip in SeekRel if
     438             :     // impossibly unavailable
     439         908 :     sal_uInt32 nRemainder = length >= 4 ? length-4 : length;
     440             : 
     441         908 :     const size_t nRequiredHeaderSize = 12;
     442        7106 :     while (nRemainder >= nRequiredHeaderSize)
     443             :     {
     444        5290 :         sal_uInt16 type(0), flags(0);
     445        5290 :         sal_uInt32 size(0), dataSize(0);
     446             : 
     447        5290 :         pWMF->ReadUInt16( type ).ReadUInt16( flags ).ReadUInt32( size ).ReadUInt32( dataSize );
     448        5290 :         nRemainder -= nRequiredHeaderSize;
     449             : 
     450             :         SAL_INFO ("vcl.emf", "\t\tEMF+ record type: " << std::hex << type << std::dec);
     451             : 
     452             :         // GetDC
     453        5290 :         if( type == 16388 ) {
     454         372 :             bHaveDC = true;
     455             :             SAL_INFO ("vcl.emf", "\t\tEMF+ lock DC (device context)");
     456             :         }
     457             : 
     458             :         // Get the length of the remaining data of this record based
     459             :         // on the alleged size
     460        5290 :         sal_uInt32 nRemainingRecordData = size >= nRequiredHeaderSize ?
     461        5290 :             size-nRequiredHeaderSize : 0;
     462             :         // clip to available size
     463        5290 :         nRemainingRecordData = std::min(nRemainingRecordData, nRemainder);
     464        5290 :         pWMF->SeekRel(nRemainingRecordData);
     465        5290 :         nRemainder -= nRemainingRecordData;
     466             :     }
     467         908 :     pWMF->SeekRel(nRemainder);
     468         908 : }
     469             : 
     470             : /**
     471             :  * Reads polygons from the stream.
     472             :  * The \<class T> parameter is for the type of the points (sal_uInt32 or sal_uInt16).
     473             :  * The \<class Drawer> parameter is a boost binding for the method that will draw the polygon.
     474             :  * skipFirst: if the first point read is the 0th point or the 1st point in the array.
     475             :  * */
     476             : template <class T, class Drawer>
     477        1034 : void EnhWMFReader::ReadAndDrawPolygon(Drawer drawer, const bool skipFirst)
     478             : {
     479        1034 :     sal_uInt32 nPoints(0), nStartIndex(0);
     480        1034 :     pWMF->SeekRel( 16 );
     481        1034 :     pWMF->ReadUInt32( nPoints );
     482        1034 :     if (skipFirst)
     483             :     {
     484         108 :         nPoints ++;
     485         108 :         nStartIndex ++;
     486             :     }
     487             : 
     488        1034 :     Polygon aPolygon = ReadPolygon<T>(nStartIndex, nPoints);
     489        1034 :     drawer(pOut, aPolygon, skipFirst, bRecordPath);
     490        1034 : }
     491             : 
     492             : /**
     493             :  * Reads polygons from the stream.
     494             :  * The \<class T> parameter is for the type of the points
     495             :  * nStartIndex: which is the starting index in the polygon of the first point read
     496             :  * nPoints: number of points
     497             :  * pWMF: the stream containings the polygons
     498             :  * */
     499             : template <class T>
     500        1052 : Polygon EnhWMFReader::ReadPolygon(sal_uInt32 nStartIndex, sal_uInt32 nPoints)
     501             : {
     502        1052 :     bool bRecordOk = nPoints <= SAL_MAX_UINT16;
     503             :     SAL_WARN_IF(!bRecordOk, "vcl.filter", "polygon record has more polygons than we can handle");
     504        1052 :     if (!bRecordOk)
     505           2 :         return Polygon();
     506             : 
     507        1050 :     Polygon aPolygon(nPoints);
     508        8594 :     for (sal_uInt16 i = nStartIndex ; i < nPoints && pWMF->good(); i++ )
     509             :     {
     510             :         T nX, nY;
     511        7544 :         *pWMF >> nX >> nY;
     512        7544 :         if (!pWMF->good())
     513           0 :             break;
     514        7544 :         aPolygon[ i ] = Point( nX, nY );
     515             :     }
     516             : 
     517        1050 :     return aPolygon;
     518             : }
     519             : 
     520             : /**
     521             :  * Reads a polyline from the WMF file and draws it
     522             :  * The \<class T> parameter refers to the type of the points. (e.g. sal_uInt16 or sal_uInt32)
     523             :  * */
     524             : template <class T>
     525          18 : void EnhWMFReader::ReadAndDrawPolyLine()
     526             : {
     527             :     sal_uInt32  nPoints;
     528          18 :     sal_Int32   i, nPoly(0), nGesPoints(0);
     529          18 :     pWMF->SeekRel( 0x10 );
     530             :     // Number of Polygons:
     531          18 :     pWMF->ReadInt32( nPoly ).ReadInt32( nGesPoints );
     532             : 
     533             :     // taking the amount of points of each polygon, retrieving the total number of points
     534          36 :     if ( pWMF->good() &&
     535             :          ( static_cast< sal_uInt32 >(nPoly) < SAL_MAX_UINT32 / sizeof(sal_uInt16) ) &&
     536          18 :          ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() )
     537             :        )
     538             :     {
     539          18 :         boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
     540          36 :         for ( i = 0; i < nPoly && pWMF->good(); i++ )
     541             :         {
     542          18 :             pWMF->ReadUInt32( nPoints );
     543          18 :             pnPoints[ i ] = (sal_uInt16)nPoints;
     544             :         }
     545             :         // Get polygon points:
     546          36 :         for ( i = 0; ( i < nPoly ) && pWMF->good(); i++ )
     547             :         {
     548          18 :             Polygon aPolygon = ReadPolygon<T>(0, pnPoints[i]);
     549          18 :             pOut->DrawPolyLine( aPolygon, false, bRecordPath );
     550          18 :         }
     551             :     }
     552          18 : }
     553             : 
     554             : // these are referenced from inside the templates
     555             : 
     556       18618 : SvStream& operator>>(SvStream& rStream, sal_Int16 &n)
     557             : {
     558       18618 :     return rStream.ReadInt16(n);
     559             : }
     560             : 
     561        5012 : SvStream& operator>>(SvStream& rStream, sal_Int32 &n)
     562             : {
     563        5012 :     return rStream.ReadInt32(n);
     564             : }
     565             : 
     566             : /**
     567             :  * Reads a poly polygon from the WMF file and draws it.
     568             :  * The \<class T> parameter refers to the type of the points. (e.g. sal_uInt16 or sal_uInt32)
     569             :  * */
     570             : template <class T>
     571          75 : void EnhWMFReader::ReadAndDrawPolyPolygon()
     572             : {
     573          75 :     sal_uInt32 nPoly(0), nGesPoints(0), nReadPoints(0);
     574          75 :     pWMF->SeekRel( 0x10 );
     575             :     // Number of polygons
     576          75 :     pWMF->ReadUInt32( nPoly ).ReadUInt32( nGesPoints );
     577         150 :     if ( pWMF->good() &&
     578             :         ( nGesPoints < SAL_MAX_UINT32 / sizeof(Point) ) && //check against numeric overflowing
     579             :         ( nPoly < SAL_MAX_UINT32 / sizeof(sal_uInt16) ) &&
     580          75 :         ( (  nPoly * sizeof( sal_uInt16 ) ) <= ( nEndPos - pWMF->Tell() ) ))
     581             :     {
     582             :         // Get number of points in each polygon
     583          75 :         boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
     584         214 :         for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
     585             :         {
     586         139 :             sal_uInt32 nPoints(0);
     587         139 :             pWMF->ReadUInt32( nPoints );
     588         139 :             pnPoints[ i ] = (sal_uInt16)nPoints;
     589             :         }
     590          75 :         if ( pWMF->good() && ( nGesPoints * (sizeof(T)+sizeof(T)) ) <= ( nEndPos - pWMF->Tell() ) )
     591             :         {
     592             :             // Get polygon points
     593          75 :             tools::PolyPolygon aPolyPoly(nPoly, nPoly);
     594         214 :             for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
     595             :             {
     596         139 :                 const sal_uInt16 nPointCount(pnPoints[i]);
     597         139 :                 boost::scoped_array<Point> pPtAry(new Point[nPointCount]);
     598        4410 :                 for (sal_uInt16 j = 0; j < nPointCount && pWMF->good(); ++j)
     599             :                 {
     600        4271 :                     T nX(0), nY(0);
     601        4271 :                     *pWMF >> nX >> nY;
     602        4271 :                     pPtAry[ j ] = Point( nX, nY );
     603        4271 :                     ++nReadPoints;
     604             :                 }
     605             : 
     606         139 :                 aPolyPoly.Insert(Polygon(nPointCount, pPtAry.get()));
     607             :             }
     608             : 
     609          75 :             pOut->DrawPolyPolygon( aPolyPoly, bRecordPath );
     610             :         }
     611             : 
     612          75 :         OSL_ENSURE(nReadPoints == nGesPoints, "The number Points processed from EMR_POLYPOLYGON is unequal imported number (!)");
     613             : 
     614             :     }
     615          75 : }
     616             : 
     617         223 : bool EnhWMFReader::ReadEnhWMF()
     618             : {
     619         223 :     sal_uInt32  nStretchBltMode = 0;
     620         223 :     sal_uInt32  nRecType(0), nRecSize(0), nNextPos(0),
     621         223 :                 nW(0), nH(0), nColor(0), nIndex(0),
     622         223 :                 nDat32(0), nNom1(0), nDen1(0), nNom2(0), nDen2(0);
     623         223 :     sal_Int32   nX32(0), nY32(0), nx32(0), ny32(0);
     624             : 
     625         223 :     bool    bFlag(false), bStatus = ReadHeader();
     626         223 :     bool    bHaveDC = false;
     627             : 
     628         223 :     static bool bEnableEMFPlus = ( getenv( "EMF_PLUS_DISABLE" ) == NULL );
     629             : 
     630       45943 :     while( bStatus && nRecordCount-- && pWMF->good())
     631             :     {
     632       45505 :         pWMF->ReadUInt32( nRecType ).ReadUInt32( nRecSize );
     633             : 
     634       45505 :         if ( !pWMF->good() || ( nRecSize < 8 ) || ( nRecSize & 3 ) )     // Parameters are always divisible by 4
     635             :         {
     636           6 :             bStatus = false;
     637           6 :             break;
     638             :         }
     639             : 
     640       45499 :         nNextPos = pWMF->Tell() + ( nRecSize - 8 );
     641             : 
     642       45499 :         if ( !pWMF->good() || nNextPos > nEndPos )
     643             :         {
     644           2 :             bStatus = false;
     645           2 :             break;
     646             :         }
     647             : 
     648       90994 :         if(  !aBmpSaveList.empty()
     649        2378 :           && ( nRecType != EMR_STRETCHBLT )
     650       47851 :           && ( nRecType != EMR_STRETCHDIBITS )
     651             :           ) {
     652        2338 :             pOut->ResolveBitmapActions( aBmpSaveList );
     653             :         }
     654             : 
     655       45497 :         bFlag = false;
     656             : 
     657             :         SAL_INFO ("vcl.emf", "0x" << std::hex << (nNextPos - nRecSize) <<  "-0x" << nNextPos << " " << record_type_name(nRecType) << " size: " <<  nRecSize << std::dec);
     658             : 
     659       45497 :         if( bEnableEMFPlus && nRecType == EMR_GDICOMMENT ) {
     660             :             sal_uInt32 length;
     661             : 
     662        1020 :             pWMF->ReadUInt32( length );
     663             : 
     664             :             SAL_INFO("vcl.emf", "\tGDI comment, length: " << length);
     665             : 
     666        1020 :             if( pWMF->good() && length >= 4 ) {
     667             :                 sal_uInt32 id;
     668             : 
     669        1020 :                 pWMF->ReadUInt32( id );
     670             : 
     671             :                 SAL_INFO ("vcl.emf", "\t\tbegin " << (char)(id & 0xff) << (char)((id & 0xff00) >> 8) << (char)((id & 0xff0000) >> 16) << (char)((id & 0xff000000) >> 24) << " id: 0x" << std::hex << id << std::dec);
     672             : 
     673             :                 // EMF+ comment (FIXME: BE?)
     674        1020 :                 if( id == 0x2B464D45 && nRecSize >= 12 )
     675         908 :                     ReadEMFPlusComment( length, bHaveDC );
     676             :                 // GDIC comment, doesn't do anything useful yet
     677         112 :                 else if( id == 0x43494447 && nRecSize >= 12 ) {
     678             :                     // TODO: ReadGDIComment()
     679             :                 } else {
     680             :                     SAL_INFO ("vcl.emf", "\t\tunknown id: 0x" << std::hex << id << std::dec);
     681             :                 }
     682        1020 :             }
     683             :         }
     684       44477 :         else if( !bEMFPlus || bHaveDC || nRecType == EMR_EOF )
     685             :         {
     686       41705 :             switch( nRecType )
     687             :             {
     688             :                 case EMR_POLYBEZIERTO :
     689           0 :                     ReadAndDrawPolygon<sal_Int32>(boost::bind(&WinMtfOutput::DrawPolyBezier, _1, _2, _3, _4), true);
     690           0 :                 break;
     691             :                 case EMR_POLYBEZIER :
     692           0 :                     ReadAndDrawPolygon<sal_Int32>(boost::bind(&WinMtfOutput::DrawPolyBezier, _1, _2, _3, _4), false);
     693           0 :                 break;
     694             : 
     695             :                 case EMR_POLYGON :
     696         156 :                     ReadAndDrawPolygon<sal_Int32>(boost::bind(&WinMtfOutput::DrawPolygon, _1, _2, _3, _4), false);
     697         156 :                 break;
     698             : 
     699             :                 case EMR_POLYLINETO :
     700          26 :                     ReadAndDrawPolygon<sal_Int32>(boost::bind(&WinMtfOutput::DrawPolyLine, _1, _2, _3, _4), true);
     701          26 :                 break;
     702             :                 case EMR_POLYLINE :
     703         620 :                     ReadAndDrawPolygon<sal_Int32>(boost::bind(&WinMtfOutput::DrawPolyLine, _1, _2, _3, _4), false);
     704         620 :                 break;
     705             : 
     706             :                 case EMR_POLYPOLYLINE :
     707           0 :                     ReadAndDrawPolyLine<sal_Int32>();
     708           0 :                 break;
     709             : 
     710             :                 case EMR_POLYPOLYGON :
     711           0 :                     ReadAndDrawPolyPolygon<sal_Int32>();
     712           0 :                 break;
     713             : 
     714             :                 case EMR_SETWINDOWEXTEX :
     715             :                 {                                                       // #75383#
     716         279 :                     pWMF->ReadUInt32( nW ).ReadUInt32( nH );
     717         279 :                     pOut->SetWinExt( Size( nW, nH ), true);
     718             :                 }
     719         279 :                 break;
     720             : 
     721             :                 case EMR_SETWINDOWORGEX :
     722             :                 {
     723         353 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
     724         353 :                     pOut->SetWinOrg( Point( nX32, nY32 ), true);
     725             :                 }
     726         353 :                 break;
     727             : 
     728             :                 case EMR_SCALEWINDOWEXTEX :
     729             :                 {
     730           0 :                     pWMF->ReadUInt32( nNom1 ).ReadUInt32( nDen1 ).ReadUInt32( nNom2 ).ReadUInt32( nDen2 );
     731           0 :                     pOut->ScaleWinExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 );
     732             :                 }
     733           0 :                 break;
     734             : 
     735             :                 case EMR_SETVIEWPORTORGEX :
     736             :                 {
     737         201 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
     738         201 :                     pOut->SetDevOrg( Point( nX32, nY32 ) );
     739             :                 }
     740         201 :                 break;
     741             : 
     742             :                 case EMR_SCALEVIEWPORTEXTEX :
     743             :                 {
     744           6 :                     pWMF->ReadUInt32( nNom1 ).ReadUInt32( nDen1 ).ReadUInt32( nNom2 ).ReadUInt32( nDen2 );
     745           6 :                     pOut->ScaleDevExt( (double)nNom1 / nDen1, (double)nNom2 / nDen2 );
     746             :                 }
     747           6 :                 break;
     748             : 
     749             :                 case EMR_SETVIEWPORTEXTEX :
     750             :                 {
     751         119 :                     pWMF->ReadUInt32( nW ).ReadUInt32( nH );
     752         119 :                     pOut->SetDevExt( Size( nW, nH ) );
     753             :                 }
     754         119 :                 break;
     755             : 
     756             :                 case EMR_EOF :
     757         215 :                     nRecordCount = 0;           // #76846#
     758         215 :                 break;
     759             : 
     760             :                 case EMR_SETPIXELV :
     761             :                 {
     762         108 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
     763         108 :                     pOut->DrawPixel( Point( nX32, nY32 ), ReadColor() );
     764             :                 }
     765         108 :                 break;
     766             : 
     767             :                 case EMR_SETMAPMODE :
     768             :                 {
     769             :                     sal_uInt32 nMapMode;
     770         131 :                     pWMF->ReadUInt32( nMapMode );
     771         131 :                     pOut->SetMapMode( nMapMode );
     772             :                 }
     773         131 :                 break;
     774             : 
     775             :                 case EMR_SETBKMODE :
     776             :                 {
     777         609 :                     pWMF->ReadUInt32( nDat32 );
     778         609 :                     pOut->SetBkMode( static_cast<BkMode>(nDat32) );
     779             :                 }
     780         609 :                 break;
     781             : 
     782             :                 case EMR_SETPOLYFILLMODE :
     783         195 :                 break;
     784             : 
     785             :                 case EMR_SETROP2 :
     786             :                 {
     787        1340 :                     pWMF->ReadUInt32( nDat32 );
     788        1340 :                     pOut->SetRasterOp( nDat32 );
     789             :                 }
     790        1340 :                 break;
     791             : 
     792             :                 case EMR_SETSTRETCHBLTMODE :
     793             :                 {
     794           0 :                     pWMF->ReadUInt32( nStretchBltMode );
     795             :                 }
     796           0 :                 break;
     797             : 
     798             :                 case EMR_SETTEXTALIGN :
     799             :                 {
     800         540 :                     pWMF->ReadUInt32( nDat32 );
     801         540 :                     pOut->SetTextAlign( nDat32 );
     802             :                 }
     803         540 :                 break;
     804             : 
     805             :                 case EMR_SETTEXTCOLOR :
     806             :                 {
     807        1642 :                     pOut->SetTextColor( ReadColor() );
     808             :                 }
     809        1642 :                 break;
     810             : 
     811             :                 case EMR_SETBKCOLOR :
     812             :                 {
     813        1138 :                     pOut->SetBkColor( ReadColor() );
     814             :                 }
     815        1138 :                 break;
     816             : 
     817             :                 case EMR_OFFSETCLIPRGN :
     818             :                 {
     819           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
     820           0 :                     pOut->MoveClipRegion( Size( nX32, nY32 ) );
     821             :                 }
     822           0 :                 break;
     823             : 
     824             :                 case EMR_MOVETOEX :
     825             :                 {
     826        1616 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
     827        1616 :                     pOut->MoveTo( Point( nX32, nY32 ), bRecordPath );
     828             :                 }
     829        1616 :                 break;
     830             : 
     831             :                 case EMR_INTERSECTCLIPRECT :
     832             :                 {
     833         618 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 );
     834         618 :                     pOut->IntersectClipRect( ReadRectangle( nX32, nY32, nx32, ny32 ) );
     835             :                 }
     836         618 :                 break;
     837             : 
     838             :                 case EMR_SAVEDC :
     839             :                 {
     840        1362 :                     pOut->Push();
     841             :                 }
     842        1362 :                 break;
     843             : 
     844             :                 case EMR_RESTOREDC :
     845             :                 {
     846        1276 :                     pOut->Pop();
     847             :                 }
     848        1276 :                 break;
     849             : 
     850             :                 case EMR_SETWORLDTRANSFORM :
     851             :                 {
     852          26 :                     XForm aTempXForm;
     853          26 :                     *pWMF >> aTempXForm;
     854          26 :                     pOut->SetWorldTransform( aTempXForm );
     855             :                 }
     856          26 :                 break;
     857             : 
     858             :                 case EMR_MODIFYWORLDTRANSFORM :
     859             :                 {
     860             :                     sal_uInt32  nMode;
     861         128 :                     XForm   aTempXForm;
     862         128 :                     *pWMF >> aTempXForm;
     863         128 :                     pWMF->ReadUInt32( nMode );
     864         128 :                     pOut->ModifyWorldTransform( aTempXForm, nMode );
     865             :                 }
     866         128 :                 break;
     867             : 
     868             :                 case EMR_SELECTOBJECT :
     869             :                 {
     870       14946 :                     pWMF->ReadUInt32( nIndex );
     871       14946 :                     pOut->SelectObject( nIndex );
     872             :                 }
     873       14946 :                 break;
     874             : 
     875             :                 case EMR_CREATEPEN :
     876             :                 {
     877        1174 :                     pWMF->ReadUInt32( nIndex );
     878        1174 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
     879             :                     {
     880             : 
     881        1174 :                         LineInfo    aLineInfo;
     882             :                         sal_uInt32      nStyle;
     883        1174 :                         Size        aSize;
     884             :                         // #fdo39428 Remove SvStream operator>>(long&)
     885        1174 :                         sal_Int32 nTmpW(0), nTmpH(0);
     886             : 
     887        1174 :                         pWMF->ReadUInt32( nStyle ).ReadInt32( nTmpW ).ReadInt32( nTmpH );
     888        1174 :                         aSize.Width() = nTmpW;
     889        1174 :                         aSize.Height() = nTmpH;
     890             : 
     891        1174 :                         if ( aSize.Width() )
     892          48 :                             aLineInfo.SetWidth( aSize.Width() );
     893             : 
     894        1174 :                         bool bTransparent = false;
     895        1174 :                         switch( nStyle & 0xFF )
     896             :                         {
     897             :                             case PS_DASHDOTDOT :
     898           0 :                                 aLineInfo.SetStyle( LINE_DASH );
     899           0 :                                 aLineInfo.SetDashCount( 1 );
     900           0 :                                 aLineInfo.SetDotCount( 2 );
     901           0 :                                 aLineInfo.SetDashLen( 150 );
     902           0 :                                 aLineInfo.SetDotLen( 30 );
     903           0 :                                 aLineInfo.SetDistance( 50 );
     904           0 :                             break;
     905             :                             case PS_DASHDOT :
     906           0 :                                 aLineInfo.SetStyle( LINE_DASH );
     907           0 :                                 aLineInfo.SetDashCount( 1 );
     908           0 :                                 aLineInfo.SetDotCount( 1 );
     909           0 :                                 aLineInfo.SetDashLen( 150 );
     910           0 :                                 aLineInfo.SetDotLen( 30 );
     911           0 :                                 aLineInfo.SetDistance( 90 );
     912           0 :                             break;
     913             :                             case PS_DOT :
     914           0 :                                 aLineInfo.SetStyle( LINE_DASH );
     915           0 :                                 aLineInfo.SetDashCount( 0 );
     916           0 :                                 aLineInfo.SetDotCount( 1 );
     917           0 :                                 aLineInfo.SetDotLen( 30 );
     918           0 :                                 aLineInfo.SetDistance( 50 );
     919           0 :                             break;
     920             :                             case PS_DASH :
     921           0 :                                 aLineInfo.SetStyle( LINE_DASH );
     922           0 :                                 aLineInfo.SetDashCount( 1 );
     923           0 :                                 aLineInfo.SetDotCount( 0 );
     924           0 :                                 aLineInfo.SetDashLen( 225 );
     925           0 :                                 aLineInfo.SetDistance( 100 );
     926           0 :                             break;
     927             :                             case PS_NULL :
     928         374 :                                 bTransparent = true;
     929         374 :                                 aLineInfo.SetStyle( LINE_NONE );
     930         374 :                             break;
     931             :                             case PS_INSIDEFRAME :
     932             :                             case PS_SOLID :
     933             :                             default :
     934         800 :                                 aLineInfo.SetStyle( LINE_SOLID );
     935             :                         }
     936        1174 :                         switch( nStyle & 0xF00 )
     937             :                         {
     938             :                             case PS_ENDCAP_ROUND :
     939        1174 :                                 aLineInfo.SetLineCap( com::sun::star::drawing::LineCap_ROUND );
     940        1174 :                             break;
     941             :                             case PS_ENDCAP_SQUARE :
     942           0 :                                 aLineInfo.SetLineCap( com::sun::star::drawing::LineCap_SQUARE );
     943           0 :                             break;
     944             :                             case PS_ENDCAP_FLAT :
     945             :                             default :
     946           0 :                                 aLineInfo.SetLineCap( com::sun::star::drawing::LineCap_BUTT );
     947             :                         }
     948        1174 :                         switch( nStyle & 0xF000 )
     949             :                         {
     950             :                             case PS_JOIN_ROUND :
     951        1174 :                                 aLineInfo.SetLineJoin ( basegfx::B2DLINEJOIN_ROUND );
     952        1174 :                             break;
     953             :                             case PS_JOIN_MITER :
     954           0 :                                 aLineInfo.SetLineJoin ( basegfx::B2DLINEJOIN_MITER );
     955           0 :                             break;
     956             :                             case PS_JOIN_BEVEL :
     957           0 :                                 aLineInfo.SetLineJoin ( basegfx::B2DLINEJOIN_BEVEL );
     958           0 :                             break;
     959             :                             default :
     960           0 :                                 aLineInfo.SetLineJoin ( basegfx::B2DLINEJOIN_NONE );
     961             :                         }
     962        1174 :                         pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( ReadColor(), aLineInfo, bTransparent ) );
     963             :                     }
     964             :                 }
     965        1174 :                 break;
     966             : 
     967             :                 case EMR_EXTCREATEPEN :
     968             :                 {
     969             :                     sal_Int32   elpHatch;
     970             :                     sal_uInt32  offBmi, cbBmi, offBits, cbBits, nStyle, nWidth, nBrushStyle, elpNumEntries;
     971          49 :                     Color       aColorRef;
     972             : 
     973          49 :                     pWMF->ReadUInt32( nIndex );
     974          49 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
     975             :                     {
     976          49 :                         pWMF->ReadUInt32( offBmi ).ReadUInt32( cbBmi ).ReadUInt32( offBits ).ReadUInt32( cbBits ). ReadUInt32( nStyle ).ReadUInt32( nWidth ).ReadUInt32( nBrushStyle );
     977          49 :                          aColorRef = ReadColor();
     978          49 :                          pWMF->ReadInt32( elpHatch ).ReadUInt32( elpNumEntries );
     979             : 
     980          49 :                         LineInfo    aLineInfo;
     981          49 :                         if ( nWidth )
     982          38 :                             aLineInfo.SetWidth( nWidth );
     983             : 
     984          49 :                         bool bTransparent = false;
     985          49 :                         sal_uInt16 nDashCount = 0;
     986          49 :                         sal_uInt16 nDotCount = 0;
     987             : 
     988          49 :                         switch( nStyle & PS_STYLE_MASK )
     989             :                         {
     990             :                             case PS_DASHDOTDOT :
     991           0 :                                 nDotCount++;
     992             :                             case PS_DASHDOT :
     993           0 :                                 nDashCount++;
     994             :                             case PS_DOT :
     995           0 :                                 nDotCount++;
     996           0 :                             break;
     997             :                             case PS_DASH :
     998           0 :                                 nDashCount++;
     999           0 :                             break;
    1000             :                             case PS_NULL :
    1001          11 :                                 bTransparent = true;
    1002          11 :                                 aLineInfo.SetStyle( LINE_NONE );
    1003          11 :                             break;
    1004             : 
    1005             :                             case PS_INSIDEFRAME :
    1006             :                             case PS_SOLID :
    1007             :                             default :
    1008          38 :                                 aLineInfo.SetStyle( LINE_SOLID );
    1009             :                         }
    1010          49 :                         if ( nDashCount | nDotCount )
    1011             :                         {
    1012           0 :                             aLineInfo.SetStyle( LINE_DASH );
    1013           0 :                             aLineInfo.SetDashCount( nDashCount );
    1014           0 :                             aLineInfo.SetDotCount( nDotCount );
    1015             :                         }
    1016          49 :                         pOut->CreateObject( nIndex, GDI_PEN, new WinMtfLineStyle( aColorRef, aLineInfo, bTransparent ) );
    1017             :                     }
    1018             :                 }
    1019          49 :                 break;
    1020             : 
    1021             :                 case EMR_CREATEBRUSHINDIRECT :
    1022             :                 {
    1023             :                     sal_uInt32  nStyle;
    1024        1187 :                     pWMF->ReadUInt32( nIndex );
    1025        1187 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
    1026             :                     {
    1027        1187 :                         pWMF->ReadUInt32( nStyle );
    1028        1187 :                         pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ) );
    1029             :                     }
    1030             :                 }
    1031        1187 :                 break;
    1032             : 
    1033             :                 case EMR_DELETEOBJECT :
    1034             :                 {
    1035        2894 :                     pWMF->ReadUInt32( nIndex );
    1036        2894 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
    1037        2894 :                         pOut->DeleteObject( nIndex );
    1038             :                 }
    1039        2894 :                 break;
    1040             : 
    1041             :                 case EMR_ELLIPSE :
    1042             :                 {
    1043           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 );
    1044           0 :                     pOut->DrawEllipse( ReadRectangle( nX32, nY32, nx32, ny32 ) );
    1045             :                 }
    1046           0 :                 break;
    1047             : 
    1048             :                 case EMR_RECTANGLE :
    1049             :                 {
    1050         246 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 );
    1051         246 :                     pOut->DrawRect( ReadRectangle( nX32, nY32, nx32, ny32 ) );
    1052             :                 }
    1053         246 :                 break;
    1054             : 
    1055             :                 case EMR_ROUNDRECT :
    1056             :                 {
    1057           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nW ).ReadUInt32( nH );
    1058           0 :                     Size aSize( Size( nW, nH ) );
    1059           0 :                     pOut->DrawRoundRect( ReadRectangle( nX32, nY32, nx32, ny32 ), aSize );
    1060             :                 }
    1061           0 :                 break;
    1062             : 
    1063             :                 case EMR_ARC :
    1064             :                 {
    1065             :                     sal_uInt32 nStartX, nStartY, nEndX, nEndY;
    1066           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY ).ReadUInt32( nEndX ).ReadUInt32( nEndY );
    1067           0 :                     pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) );
    1068             :                 }
    1069           0 :                 break;
    1070             : 
    1071             :                 case EMR_CHORD :
    1072             :                 {
    1073             :                     sal_uInt32 nStartX, nStartY, nEndX, nEndY;
    1074           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY ).ReadUInt32( nEndX ).ReadUInt32( nEndY );
    1075           0 :                     pOut->DrawChord( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ) );
    1076             :                 }
    1077           0 :                 break;
    1078             : 
    1079             :                 case EMR_PIE :
    1080             :                 {
    1081             :                     sal_uInt32 nStartX, nStartY, nEndX, nEndY;
    1082           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY ).ReadUInt32( nEndX ).ReadUInt32( nEndY );
    1083           0 :                     const Rectangle aRect( ReadRectangle( nX32, nY32, nx32, ny32 ));
    1084             : 
    1085             :                     // #i73608# OutputDevice deviates from WMF
    1086             :                     // semantics. start==end means full ellipse here.
    1087           0 :                     if( nStartX == nEndX && nStartY == nEndY )
    1088           0 :                         pOut->DrawEllipse( aRect );
    1089             :                     else
    1090           0 :                         pOut->DrawPie( aRect, Point( nStartX, nStartY ), Point( nEndX, nEndY ) );
    1091             :                 }
    1092           0 :                 break;
    1093             : 
    1094             :                 case EMR_LINETO :
    1095             :                 {
    1096        1500 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 );
    1097        1500 :                     pOut->LineTo( Point( nX32, nY32 ), bRecordPath );
    1098             :                 }
    1099        1500 :                 break;
    1100             : 
    1101             :                 case EMR_ARCTO :
    1102             :                 {
    1103             :                     sal_uInt32 nStartX, nStartY, nEndX, nEndY;
    1104           0 :                     pWMF->ReadInt32( nX32 ).ReadInt32( nY32 ).ReadInt32( nx32 ).ReadInt32( ny32 ).ReadUInt32( nStartX ).ReadUInt32( nStartY ).ReadUInt32( nEndX ).ReadUInt32( nEndY );
    1105           0 :                     pOut->DrawArc( ReadRectangle( nX32, nY32, nx32, ny32 ), Point( nStartX, nStartY ), Point( nEndX, nEndY ), true );
    1106             :                 }
    1107           0 :                 break;
    1108             : 
    1109             :                 case EMR_BEGINPATH :
    1110             :                 {
    1111          82 :                     pOut->ClearPath();
    1112          82 :                     bRecordPath = true;
    1113             :                 }
    1114          82 :                 break;
    1115             : 
    1116             :                 case EMR_ABORTPATH :
    1117           0 :                     pOut->ClearPath();
    1118             :                 case EMR_ENDPATH :
    1119          82 :                     bRecordPath = false;
    1120          82 :                 break;
    1121             : 
    1122             :                 case EMR_CLOSEFIGURE :
    1123          60 :                     pOut->ClosePath();
    1124          60 :                 break;
    1125             : 
    1126             :                 case EMR_FILLPATH :
    1127          26 :                     pOut->StrokeAndFillPath( false, true );
    1128          26 :                 break;
    1129             : 
    1130             :                 case EMR_STROKEANDFILLPATH :
    1131           2 :                     pOut->StrokeAndFillPath( true, true );
    1132           2 :                 break;
    1133             : 
    1134             :                 case EMR_STROKEPATH :
    1135          20 :                     pOut->StrokeAndFillPath( true, false );
    1136          20 :                 break;
    1137             : 
    1138             :                 case EMR_SELECTCLIPPATH :
    1139             :                 {
    1140             :                     sal_Int32 nClippingMode;
    1141          34 :                     pWMF->ReadInt32(nClippingMode);
    1142          34 :                     pOut->SetClipPath(pOut->GetPathObj(), nClippingMode, true);
    1143             :                 }
    1144          34 :                 break;
    1145             : 
    1146             :                 case EMR_EXTSELECTCLIPRGN :
    1147             :                 {
    1148             :                     sal_Int32 nClippingMode, cbRgnData;
    1149         254 :                     pWMF->ReadInt32(cbRgnData);
    1150         254 :                     pWMF->ReadInt32(nClippingMode);
    1151             : 
    1152         254 :                     tools::PolyPolygon aPolyPoly;
    1153         254 :                     if (cbRgnData)
    1154         154 :                         ImplReadRegion(aPolyPoly, *pWMF, nRecSize);
    1155         254 :                     pOut->SetClipPath(aPolyPoly, nClippingMode, false);
    1156             :                 }
    1157         254 :                 break;
    1158             : 
    1159             :                 case EMR_ALPHABLEND:
    1160             :                 {
    1161          10 :                     sal_Int32 xDest(0), yDest(0), cxDest(0), cyDest(0);
    1162             : 
    1163             :                     BLENDFUNCTION aFunc;
    1164          10 :                     sal_Int32 xSrc(0), ySrc(0), cxSrc(0), cySrc(0);
    1165          10 :                     XForm xformSrc;
    1166          10 :                     sal_uInt32 BkColorSrc(0), iUsageSrc(0), offBmiSrc(0);
    1167          10 :                     sal_uInt32 cbBmiSrc(0), offBitsSrc(0), cbBitsSrc(0);
    1168             : 
    1169          10 :                     sal_uInt32   nStart = pWMF->Tell() - 8;
    1170          10 :                     pWMF->SeekRel( 0x10 );
    1171             : 
    1172          10 :                     pWMF->ReadInt32( xDest ).ReadInt32( yDest ).ReadInt32( cxDest ).ReadInt32( cyDest );
    1173          10 :                     *pWMF >> aFunc;
    1174          10 :                     pWMF->ReadInt32( xSrc ).ReadInt32( ySrc );
    1175          10 :                     *pWMF >> xformSrc;
    1176          10 :                     pWMF->ReadUInt32( BkColorSrc ).ReadUInt32( iUsageSrc ).ReadUInt32( offBmiSrc ).ReadUInt32( cbBmiSrc )
    1177          10 :                                .ReadUInt32( offBitsSrc ).ReadUInt32( cbBitsSrc ).ReadInt32( cxSrc ).ReadInt32( cySrc ) ;
    1178             : 
    1179          10 :                     sal_uInt32  dwRop = SRCAND|SRCINVERT;
    1180             : 
    1181          10 :                     Bitmap      aBitmap;
    1182          10 :                     Rectangle   aRect( Point( xDest, yDest ), Size( cxDest+1, cyDest+1 ) );
    1183             : 
    1184          10 :                     if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) )
    1185           0 :                         bStatus = false;
    1186             :                     else
    1187             :                     {
    1188          10 :                         sal_uInt32 nSize = cbBmiSrc + cbBitsSrc + 14;
    1189          10 :                         if ( nSize <= ( nEndPos - nStartPos ) )
    1190             :                         {
    1191          10 :                             char* pBuf = new char[ nSize ];
    1192          10 :                             SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE );
    1193          10 :                             aTmp.ObjectOwnsMemory( true );
    1194          10 :                             aTmp.WriteUChar( 'B' )
    1195          10 :                                 .WriteUChar( 'M' )
    1196          10 :                                 .WriteUInt32( cbBitsSrc )
    1197          20 :                                 .WriteUInt16( 0 )
    1198          10 :                                 .WriteUInt16( 0 )
    1199          20 :                                 .WriteUInt32( cbBmiSrc + 14 );
    1200          10 :                             pWMF->Seek( nStart + offBmiSrc );
    1201          10 :                             pWMF->Read( pBuf + 14, cbBmiSrc );
    1202          10 :                             pWMF->Seek( nStart + offBitsSrc );
    1203          10 :                             pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc );
    1204          10 :                             aTmp.Seek( 0 );
    1205          10 :                             ReadDIB(aBitmap, aTmp, true);
    1206             : 
    1207             :                             // test if it is sensible to crop
    1208          50 :                             if ( ( cxSrc > 0 ) && ( cySrc > 0 ) &&
    1209          40 :                                 ( xSrc >= 0 ) && ( ySrc >= 0 ) &&
    1210          80 :                                     ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) &&
    1211          30 :                                         ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) )
    1212             :                             {
    1213          10 :                                 Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
    1214          10 :                                 aBitmap.Crop( aCropRect );
    1215             :                             }
    1216          10 :                             aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
    1217             :                         }
    1218          10 :                     }
    1219             :                 }
    1220          10 :                 break;
    1221             : 
    1222             :                 case EMR_BITBLT :   // PASSTHROUGH INTENDED
    1223             :                 case EMR_STRETCHBLT :
    1224             :                 {
    1225             :                     sal_Int32   xDest, yDest, cxDest, cyDest, xSrc, ySrc, cxSrc, cySrc;
    1226             :                     sal_uInt32  dwRop, iUsageSrc, offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc;
    1227        2312 :                     XForm   xformSrc;
    1228             : 
    1229        2312 :                     sal_uInt32  nStart = pWMF->Tell() - 8;
    1230             : 
    1231        2312 :                     pWMF->SeekRel( 0x10 );
    1232        2312 :                     pWMF->ReadInt32( xDest ).ReadInt32( yDest ).ReadInt32( cxDest ).ReadInt32( cyDest ).ReadUInt32( dwRop ).ReadInt32( xSrc ).ReadInt32( ySrc )
    1233        2312 :                             >> xformSrc;
    1234        2312 :                     pWMF->ReadUInt32( nColor ).ReadUInt32( iUsageSrc ).ReadUInt32( offBmiSrc ).ReadUInt32( cbBmiSrc )
    1235        2312 :                                .ReadUInt32( offBitsSrc ).ReadUInt32( cbBitsSrc );
    1236             : 
    1237        2312 :                     if ( nRecType == EMR_STRETCHBLT )
    1238          60 :                         pWMF->ReadInt32( cxSrc ).ReadInt32( cySrc );
    1239             :                     else
    1240        2252 :                         cxSrc = cySrc = 0;
    1241             : 
    1242        2312 :                     Bitmap      aBitmap;
    1243        2312 :                     Rectangle   aRect( Point( xDest, yDest ), Size( cxDest, cyDest ) );
    1244             : 
    1245        2312 :                     cxDest = abs( (int)cxDest );        // sj: i37894, size can be negative
    1246        2312 :                     cyDest = abs( (int)cyDest );        // and also 122889
    1247             : 
    1248        2312 :                     if ( (cbBitsSrc > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc) )
    1249           0 :                         bStatus = false;
    1250             :                     else
    1251             :                     {
    1252        2312 :                         sal_uInt32 nSize = cbBmiSrc + cbBitsSrc + 14;
    1253        2312 :                         if ( nSize <= ( nEndPos - nStartPos ) )
    1254             :                         {
    1255        2312 :                             char* pBuf = new char[ nSize ];
    1256        2312 :                             SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE );
    1257        2312 :                             aTmp.ObjectOwnsMemory( true );
    1258        2312 :                             aTmp.WriteUChar( 'B' )
    1259        2312 :                                 .WriteUChar( 'M' )
    1260        2312 :                                 .WriteUInt32( cbBitsSrc )
    1261        4624 :                                 .WriteUInt16( 0 )
    1262        2312 :                                 .WriteUInt16( 0 )
    1263        4624 :                                 .WriteUInt32( cbBmiSrc + 14 );
    1264        2312 :                             pWMF->Seek( nStart + offBmiSrc );
    1265        2312 :                             pWMF->Read( pBuf + 14, cbBmiSrc );
    1266        2312 :                             pWMF->Seek( nStart + offBitsSrc );
    1267        2312 :                             pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc );
    1268        2312 :                             aTmp.Seek( 0 );
    1269        2312 :                             ReadDIB(aBitmap, aTmp, true);
    1270             : 
    1271             :                             // test if it is sensible to crop
    1272        9248 :                             if ( ( cxSrc > 0 ) && ( cySrc > 0 ) &&
    1273           0 :                                 ( xSrc >= 0 ) && ( ySrc >= 0 ) &&
    1274        6936 :                                     ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) &&
    1275        2312 :                                         ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) )
    1276             :                             {
    1277           0 :                                 Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
    1278           0 :                                 aBitmap.Crop( aCropRect );
    1279             :                             }
    1280        2312 :                             aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
    1281             :                         }
    1282        2312 :                     }
    1283             :                 }
    1284        2312 :                 break;
    1285             : 
    1286             :                 case EMR_STRETCHDIBITS :
    1287             :                 {
    1288             :                     sal_Int32   xDest, yDest, xSrc, ySrc, cxSrc, cySrc, cxDest, cyDest;
    1289             :                     sal_uInt32  offBmiSrc, cbBmiSrc, offBitsSrc, cbBitsSrc, iUsageSrc, dwRop;
    1290          56 :                     sal_uInt32  nStart = pWMF->Tell() - 8;
    1291             : 
    1292          56 :                     pWMF->SeekRel( 0x10 );
    1293          56 :                     pWMF->ReadInt32( xDest )
    1294          56 :                          .ReadInt32( yDest )
    1295          56 :                          .ReadInt32( xSrc )
    1296          56 :                          .ReadInt32( ySrc )
    1297          56 :                          .ReadInt32( cxSrc )
    1298          56 :                          .ReadInt32( cySrc )
    1299          56 :                          .ReadUInt32( offBmiSrc )
    1300          56 :                          .ReadUInt32( cbBmiSrc )
    1301          56 :                          .ReadUInt32( offBitsSrc )
    1302          56 :                          .ReadUInt32( cbBitsSrc )
    1303          56 :                          .ReadUInt32( iUsageSrc )
    1304          56 :                          .ReadUInt32( dwRop )
    1305          56 :                          .ReadInt32( cxDest )
    1306          56 :                          .ReadInt32( cyDest );
    1307             : 
    1308          56 :                     Bitmap      aBitmap;
    1309          56 :                     Rectangle   aRect( Point( xDest, yDest ), Size( cxDest, cyDest ) );
    1310             : 
    1311          56 :                     cxDest = abs( (int)cxDest );        // sj: i37894, size can be negative
    1312          56 :                     cyDest = abs( (int)cyDest );        // and also 122889
    1313             : 
    1314          56 :                     if (  ((SAL_MAX_UINT32 - 14)             < cbBitsSrc)
    1315          56 :                        || ((SAL_MAX_UINT32 - 14) - cbBitsSrc < cbBmiSrc )
    1316             :                        )
    1317             :                     {
    1318           0 :                         bStatus = false;
    1319             :                     }
    1320             :                     else
    1321             :                     {
    1322          56 :                         sal_uInt32 nSize = cbBmiSrc + cbBitsSrc + 14;
    1323          56 :                         if ( nSize <= ( nEndPos - nStartPos ) )
    1324             :                         {
    1325          56 :                             char* pBuf = new char[ nSize ];
    1326          56 :                             SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE );
    1327          56 :                             aTmp.ObjectOwnsMemory( true );
    1328          56 :                             aTmp.WriteUChar( 'B' )
    1329          56 :                                .WriteUChar( 'M' )
    1330          56 :                                .WriteUInt32( cbBitsSrc )
    1331         112 :                                .WriteUInt16( 0 )
    1332          56 :                                .WriteUInt16( 0 )
    1333         112 :                                .WriteUInt32( cbBmiSrc + 14 );
    1334          56 :                             pWMF->Seek( nStart + offBmiSrc );
    1335          56 :                             pWMF->Read( pBuf + 14, cbBmiSrc );
    1336          56 :                             pWMF->Seek( nStart + offBitsSrc );
    1337          56 :                             pWMF->Read( pBuf + 14 + cbBmiSrc, cbBitsSrc );
    1338          56 :                             aTmp.Seek( 0 );
    1339          56 :                             ReadDIB(aBitmap, aTmp, true);
    1340             : 
    1341             :                             // test if it is sensible to crop
    1342         280 :                             if ( ( cxSrc > 0 ) && ( cySrc > 0 ) &&
    1343         224 :                                 ( xSrc >= 0 ) && ( ySrc >= 0 ) &&
    1344         448 :                                     ( xSrc + cxSrc <= aBitmap.GetSizePixel().Width() ) &&
    1345         168 :                                         ( ySrc + cySrc <= aBitmap.GetSizePixel().Height() ) )
    1346             :                             {
    1347          56 :                                 Rectangle aCropRect( Point( xSrc, ySrc ), Size( cxSrc, cySrc ) );
    1348          56 :                                 aBitmap.Crop( aCropRect );
    1349             :                             }
    1350          56 :                         aBmpSaveList.push_back( new BSaveStruct( aBitmap, aRect, dwRop, pOut->GetFillStyle () ) );
    1351             :                         }
    1352          56 :                     }
    1353             :                 }
    1354          56 :                 break;
    1355             : 
    1356             :                 case EMR_EXTCREATEFONTINDIRECTW :
    1357             :                 {
    1358         756 :                     pWMF->ReadUInt32( nIndex );
    1359         756 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
    1360             :                     {
    1361         756 :                         LOGFONTW aLogFont;
    1362         756 :                         pWMF->ReadInt32( aLogFont.lfHeight )
    1363         756 :                              .ReadInt32( aLogFont.lfWidth )
    1364         756 :                              .ReadInt32( aLogFont.lfEscapement )
    1365         756 :                              .ReadInt32( aLogFont.lfOrientation )
    1366         756 :                              .ReadInt32( aLogFont.lfWeight )
    1367         756 :                              .ReadUChar( aLogFont.lfItalic )
    1368         756 :                              .ReadUChar( aLogFont.lfUnderline )
    1369         756 :                              .ReadUChar( aLogFont.lfStrikeOut )
    1370         756 :                              .ReadUChar( aLogFont.lfCharSet )
    1371         756 :                              .ReadUChar( aLogFont.lfOutPrecision )
    1372         756 :                              .ReadUChar( aLogFont.lfClipPrecision )
    1373         756 :                              .ReadUChar( aLogFont.lfQuality )
    1374         756 :                              .ReadUChar( aLogFont.lfPitchAndFamily );
    1375             : 
    1376             :                         sal_Unicode lfFaceName[ LF_FACESIZE ];
    1377             : 
    1378       24948 :                         for ( int i = 0; i < LF_FACESIZE; i++ )
    1379             :                         {
    1380             :                             sal_uInt16 nChar;
    1381       24192 :                             pWMF->ReadUInt16( nChar );
    1382       24192 :                             lfFaceName[ i ] = nChar;
    1383             :                         }
    1384         756 :                         aLogFont.alfFaceName = OUString( lfFaceName );
    1385             : 
    1386             :                         // #i123216# Not used in the test case of #121382# (always identity in XForm), also
    1387             :                         // no hints in ms docu if FontSize should be scaled with WT. Using with the example
    1388             :                         // from #i123216# creates errors, so removing.
    1389             : 
    1390             :                         // // #i121382# Need to apply WorldTransform to FontHeight/Width; this should be completely
    1391             :                         // // changed to basegfx::B2DHomMatrix instead of 'struct XForm', but not now due to time
    1392             :                         // // constraints and dangers
    1393             :                         // const XForm& rXF = pOut->GetWorldTransform();
    1394             :                         // const basegfx::B2DHomMatrix aWT(rXF.eM11, rXF.eM21, rXF.eDx, rXF.eM12, rXF.eM22, rXF.eDy);
    1395             :                         // const basegfx::B2DVector aTransVec(aWT * basegfx::B2DVector(aLogFont.lfWidth, aLogFont.lfHeight));
    1396             :                         // aLogFont.lfWidth = aTransVec.getX();
    1397             :                         // aLogFont.lfHeight = aTransVec.getY();
    1398             : 
    1399         756 :                         pOut->CreateObject( nIndex, GDI_FONT, new WinMtfFontStyle( aLogFont ) );
    1400             :                     }
    1401             :                 }
    1402         756 :                 break;
    1403             : 
    1404             :                 case EMR_EXTTEXTOUTA :
    1405           0 :                     bFlag = true;
    1406             :                 case EMR_EXTTEXTOUTW :
    1407             :                 {
    1408             :                     sal_Int32   nLeft, nTop, nRight, nBottom, ptlReferenceX, ptlReferenceY, nGfxMode, nXScale, nYScale;
    1409             :                     sal_uInt32  nCurPos, nOffString, nOptions, offDx;
    1410             :                     sal_Int32   nLen;
    1411        2772 :                     long* pDX = NULL;
    1412             : 
    1413        2772 :                     nCurPos = pWMF->Tell() - 8;
    1414             : 
    1415        2772 :                     pWMF->ReadInt32( nLeft ).ReadInt32( nTop ).ReadInt32( nRight ).ReadInt32( nBottom ).ReadInt32( nGfxMode ).ReadInt32( nXScale ).ReadInt32( nYScale )
    1416        2772 :                        .ReadInt32( ptlReferenceX ).ReadInt32( ptlReferenceY ).ReadInt32( nLen ).ReadUInt32( nOffString ).ReadUInt32( nOptions );
    1417             : 
    1418        2772 :                     pWMF->SeekRel( 0x10 );
    1419        2772 :                     pWMF->ReadUInt32( offDx );
    1420             : 
    1421        2772 :                     ComplexTextLayoutMode nTextLayoutMode = TEXT_LAYOUT_DEFAULT;
    1422        2772 :                     if ( nOptions & ETO_RTLREADING )
    1423           0 :                         nTextLayoutMode = TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT;
    1424        2772 :                     pOut->SetTextLayoutMode( nTextLayoutMode );
    1425             :                     DBG_ASSERT( ( nOptions & ( ETO_PDY | ETO_GLYPH_INDEX ) ) == 0, "SJ: ETO_PDY || ETO_GLYPH_INDEX in EMF" );
    1426             : 
    1427        2772 :                     Point aPos( ptlReferenceX, ptlReferenceY );
    1428        2772 :                     if ( nLen && nLen < static_cast<sal_Int32>( SAL_MAX_UINT32 / sizeof(sal_Int32) ) )
    1429             :                     {
    1430        2764 :                         if ( offDx && (( nCurPos + offDx + nLen * 4 ) <= nNextPos ) )
    1431             :                         {
    1432        2764 :                             pWMF->Seek( nCurPos + offDx );
    1433        2764 :                             if ( ( nLen * sizeof(sal_uInt32) ) <= ( nEndPos - pWMF->Tell() ) )
    1434             :                             {
    1435        2764 :                                 pDX = new long[ nLen ];
    1436             :                                 sal_Int32 i;
    1437             :                                 sal_Int32 val;
    1438       17624 :                                 for ( i = 0; i < nLen; i++ )
    1439             :                                 {
    1440       14860 :                                     pWMF->ReadInt32( val );
    1441       14860 :                                     pDX[ i ] = val;
    1442             :                                 }
    1443             :                             }
    1444             :                         }
    1445        2764 :                         pWMF->Seek( nCurPos + nOffString );
    1446        2764 :                         OUString aText;
    1447        2764 :                         if ( bFlag )
    1448             :                         {
    1449           0 :                             if ( nLen <= static_cast<sal_Int32>( nEndPos - pWMF->Tell() ) )
    1450             :                             {
    1451           0 :                                 boost::scoped_array<sal_Char> pBuf(new sal_Char[ nLen ]);
    1452           0 :                                 pWMF->Read( pBuf.get(), nLen );
    1453           0 :                                 aText = OUString( pBuf.get(), (sal_uInt16)nLen, pOut->GetCharSet() );
    1454           0 :                                 pBuf.reset();
    1455             : 
    1456           0 :                                 if ( aText.getLength() != nLen )
    1457             :                                 {
    1458             :                                     sal_uInt16 i, j;
    1459           0 :                                     long* pOldDx = pDX;
    1460           0 :                                     pDX = new long[ aText.getLength() ];
    1461           0 :                                     for ( i = 0, j = 0; i < aText.getLength(); i++ )
    1462             :                                     {
    1463           0 :                                         sal_Unicode cUniChar = aText[i];
    1464           0 :                                         OString aCharacter(&cUniChar, 1, pOut->GetCharSet());
    1465           0 :                                         pDX[ i ] = 0;
    1466           0 :                                         for (sal_Int32 k = 0; ( k < aCharacter.getLength() ) && ( j < nLen ) && ( i < aText.getLength() ); ++k)
    1467           0 :                                             pDX[ i ] += pOldDx[ j++ ];
    1468           0 :                                     }
    1469           0 :                                     delete[] pOldDx;
    1470           0 :                                 }
    1471             :                             }
    1472             :                         }
    1473             :                         else
    1474             :                         {
    1475        2764 :                             if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) )
    1476             :                             {
    1477        2764 :                                 boost::scoped_array<sal_Unicode> pBuf(new sal_Unicode[ nLen ]);
    1478        2764 :                                 pWMF->Read( pBuf.get(), nLen << 1 );
    1479             : #ifdef OSL_BIGENDIAN
    1480             :                                 sal_Char nTmp, *pTmp = (sal_Char*)( pBuf.get() + nLen );
    1481             :                                 while ( pTmp-- != (sal_Char*)pBuf.get() )
    1482             :                                 {
    1483             :                                     nTmp = *pTmp--;
    1484             :                                     pTmp[ 1 ] = *pTmp;
    1485             :                                     *pTmp = nTmp;
    1486             :                                 }
    1487             : #endif
    1488        2764 :                                 aText = OUString(pBuf.get(), nLen);
    1489             :                             }
    1490             :                         }
    1491        2764 :                         pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode );
    1492             :                     }
    1493        2772 :                     delete[] pDX;
    1494             :                 }
    1495        2772 :                 break;
    1496             : 
    1497             :                 case EMR_POLYBEZIERTO16 :
    1498          82 :                     ReadAndDrawPolygon<sal_Int16>(boost::bind(&WinMtfOutput::DrawPolyBezier, _1, _2, _3, _4), true);
    1499          82 :                     break;
    1500             :                 case EMR_POLYBEZIER16 :
    1501           0 :                     ReadAndDrawPolygon<sal_Int16>(boost::bind(&WinMtfOutput::DrawPolyBezier, _1, _2, _3, _4), false);
    1502           0 :                 break;
    1503             : 
    1504             :                 case EMR_POLYGON16 :
    1505         146 :                     ReadAndDrawPolygon<sal_Int16>(boost::bind(&WinMtfOutput::DrawPolygon, _1, _2, _3, _4), false);
    1506         146 :                 break;
    1507             : 
    1508             :                 case EMR_POLYLINETO16 :
    1509           0 :                     ReadAndDrawPolygon<sal_Int16>(boost::bind(&WinMtfOutput::DrawPolyLine, _1, _2, _3, _4), true);
    1510           0 :                     break;
    1511             :                 case EMR_POLYLINE16 :
    1512           4 :                     ReadAndDrawPolygon<sal_Int16>(boost::bind(&WinMtfOutput::DrawPolyLine, _1, _2, _3, _4), false);
    1513           4 :                 break;
    1514             : 
    1515             :                 case EMR_POLYPOLYLINE16 :
    1516          18 :                     ReadAndDrawPolyLine<sal_Int16>();
    1517          18 :                     break;
    1518             : 
    1519             :                 case EMR_POLYPOLYGON16 :
    1520          75 :                     ReadAndDrawPolyPolygon<sal_Int16>();
    1521          75 :                 break;
    1522             : 
    1523             :                 case EMR_FILLRGN :
    1524             :                 {
    1525             :                     sal_uInt32 nLen;
    1526           0 :                     tools::PolyPolygon aPolyPoly;
    1527           0 :                     pWMF->SeekRel( 0x10 );
    1528           0 :                     pWMF->ReadUInt32( nLen ).ReadUInt32( nIndex );
    1529             : 
    1530           0 :                     if ( ImplReadRegion( aPolyPoly, *pWMF, nRecSize ) )
    1531             :                     {
    1532           0 :                         pOut->Push();
    1533           0 :                         pOut->SelectObject( nIndex );
    1534           0 :                         pOut->DrawPolyPolygon( aPolyPoly, false );
    1535           0 :                         pOut->Pop();
    1536           0 :                     }
    1537             :                 }
    1538           0 :                 break;
    1539             : 
    1540             :                 case EMR_CREATEDIBPATTERNBRUSHPT :
    1541             :                 {
    1542           2 :                     sal_uInt32  nStart = pWMF->Tell() - 8;
    1543           2 :                     Bitmap aBitmap;
    1544             : 
    1545           2 :                     pWMF->ReadUInt32( nIndex );
    1546             : 
    1547           2 :                     if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
    1548             :                     {
    1549             :                         sal_uInt32 usage, offBmi, cbBmi, offBits, cbBits;
    1550             : 
    1551           2 :                         pWMF->ReadUInt32( usage );
    1552           2 :                         pWMF->ReadUInt32( offBmi );
    1553           2 :                         pWMF->ReadUInt32( cbBmi );
    1554           2 :                         pWMF->ReadUInt32( offBits );
    1555           2 :                         pWMF->ReadUInt32( cbBits );
    1556             : 
    1557           2 :                         if ( (cbBits > (SAL_MAX_UINT32 - 14)) || ((SAL_MAX_UINT32 - 14) - cbBits < cbBmi) )
    1558           0 :                            bStatus = false;
    1559           2 :                         else if ( offBmi )
    1560             :                         {
    1561           2 :                             sal_uInt32  nSize = cbBmi + cbBits + 14;
    1562           2 :                             if ( nSize <= ( nEndPos - nStartPos ) )
    1563             :                             {
    1564           2 :                                 char*   pBuf = new char[ nSize ];
    1565             : 
    1566           2 :                                 SvMemoryStream aTmp( pBuf, nSize, STREAM_READ | STREAM_WRITE );
    1567           2 :                                 aTmp.ObjectOwnsMemory( true );
    1568           2 :                                 aTmp.WriteUChar( 'B' )
    1569           2 :                                     .WriteUChar( 'M' )
    1570           2 :                                     .WriteUInt32( cbBits )
    1571           4 :                                     .WriteUInt16( 0 )
    1572           2 :                                     .WriteUInt16( 0 )
    1573           4 :                                     .WriteUInt32( cbBmi + 14 );
    1574           2 :                                 pWMF->Seek( nStart + offBmi );
    1575           2 :                                 pWMF->Read( pBuf + 14, cbBmi );
    1576           2 :                                 pWMF->Seek( nStart + offBits );
    1577           2 :                                 pWMF->Read( pBuf + 14 + cbBmi, cbBits );
    1578           2 :                                 aTmp.Seek( 0 );
    1579           2 :                                 ReadDIB(aBitmap, aTmp, true);
    1580             :                             }
    1581             :                         }
    1582             :                     }
    1583             : 
    1584           2 :                     pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( aBitmap ) );
    1585             :                 }
    1586           2 :                 break;
    1587             : 
    1588           0 :                 case EMR_MASKBLT :                  SAL_INFO("vcl.emf", "not implemented 'MaskBlt'");                   break;
    1589           0 :                 case EMR_PLGBLT :                   SAL_INFO("vcl.emf", "not implemented 'PlgBlt'");                    break;
    1590           0 :                 case EMR_SETDIBITSTODEVICE :        SAL_INFO("vcl.emf", "not implemented 'SetDIBitsToDevice'");         break;
    1591           0 :                 case EMR_FRAMERGN :                 SAL_INFO("vcl.emf", "not implemented 'FrameRgn'");                  break;
    1592           0 :                 case EMR_INVERTRGN :                SAL_INFO("vcl.emf", "not implemented 'InvertRgn'");                 break;
    1593           0 :                 case EMR_PAINTRGN :                 SAL_INFO("vcl.emf", "not implemented 'PaintRgn'");                  break;
    1594           0 :                 case EMR_FLATTENPATH :              SAL_INFO("vcl.emf", "not implemented 'FlattenPath'");               break;
    1595           0 :                 case EMR_WIDENPATH :                SAL_INFO("vcl.emf", "not implemented 'WidenPath'");                 break;
    1596           0 :                 case EMR_POLYDRAW :                 SAL_INFO("vcl.emf", "not implemented 'Polydraw'");                  break;
    1597           0 :                 case EMR_SETARCDIRECTION :          SAL_INFO("vcl.emf", "not implemented 'SetArcDirection'");           break;
    1598           0 :                 case EMR_SETPALETTEENTRIES :        SAL_INFO("vcl.emf", "not implemented 'SetPaletteEntries'");         break;
    1599           0 :                 case EMR_RESIZEPALETTE :            SAL_INFO("vcl.emf", "not implemented 'ResizePalette'");             break;
    1600           0 :                 case EMR_EXTFLOODFILL :             SAL_INFO("vcl.emf", "not implemented 'ExtFloodFill'");              break;
    1601           0 :                 case EMR_ANGLEARC :                 SAL_INFO("vcl.emf", "not implemented 'AngleArc'");                  break;
    1602           2 :                 case EMR_SETCOLORADJUSTMENT :       SAL_INFO("vcl.emf", "not implemented 'SetColorAdjustment'");        break;
    1603           0 :                 case EMR_POLYDRAW16 :               SAL_INFO("vcl.emf", "not implemented 'PolyDraw16'");                break;
    1604           0 :                 case EMR_POLYTEXTOUTA :             SAL_INFO("vcl.emf", "not implemented 'PolyTextOutA'");              break;
    1605           0 :                 case EMR_POLYTEXTOUTW :             SAL_INFO("vcl.emf", "not implemented 'PolyTextOutW'");              break;
    1606           0 :                 case EMR_CREATECOLORSPACE :         SAL_INFO("vcl.emf", "not implemented 'CreateColorSpace'");          break;
    1607           0 :                 case EMR_SETCOLORSPACE :            SAL_INFO("vcl.emf", "not implemented 'SetColorSpace'");             break;
    1608           0 :                 case EMR_DELETECOLORSPACE :         SAL_INFO("vcl.emf", "not implemented 'DeleteColorSpace'");          break;
    1609           0 :                 case EMR_GLSRECORD :                SAL_INFO("vcl.emf", "not implemented 'GlsRecord'");                 break;
    1610           0 :                 case EMR_GLSBOUNDEDRECORD :         SAL_INFO("vcl.emf", "not implemented 'GlsBoundRecord'");            break;
    1611           0 :                 case EMR_PIXELFORMAT :              SAL_INFO("vcl.emf", "not implemented 'PixelFormat'");               break;
    1612           0 :                 case EMR_DRAWESCAPE :               SAL_INFO("vcl.emf", "not implemented 'DrawEscape'");                break;
    1613           0 :                 case EMR_EXTESCAPE :                SAL_INFO("vcl.emf", "not implemented 'ExtEscape'");                 break;
    1614           0 :                 case EMR_STARTDOC :                 SAL_INFO("vcl.emf", "not implemented 'StartDoc'");                  break;
    1615           0 :                 case EMR_SMALLTEXTOUT :             SAL_INFO("vcl.emf", "not implemented 'SmallTextOut'");              break;
    1616           0 :                 case EMR_FORCEUFIMAPPING :          SAL_INFO("vcl.emf", "not implemented 'ForceUFIMapping'");           break;
    1617           0 :                 case EMR_NAMEDESCAPE :              SAL_INFO("vcl.emf", "not implemented 'NamedEscape'");               break;
    1618           0 :                 case EMR_COLORCORRECTPALETTE :      SAL_INFO("vcl.emf", "not implemented 'ColorCorrectPalette'");       break;
    1619           2 :                 case EMR_SETICMPROFILEA :           SAL_INFO("vcl.emf", "not implemented 'SetICMProfileA'");            break;
    1620           0 :                 case EMR_SETICMPROFILEW :           SAL_INFO("vcl.emf", "not implemented 'SetICMProfileW'");            break;
    1621           0 :                 case EMR_TRANSPARENTBLT :           SAL_INFO("vcl.emf", "not implemented 'TransparenBlt'");             break;
    1622           0 :                 case EMR_TRANSPARENTDIB :           SAL_INFO("vcl.emf", "not implemented 'TransparenDib'");             break;
    1623           0 :                 case EMR_GRADIENTFILL :             SAL_INFO("vcl.emf", "not implemented 'GradientFill'");              break;
    1624           0 :                 case EMR_SETLINKEDUFIS :            SAL_INFO("vcl.emf", "not implemented 'SetLinkedUFIS'");             break;
    1625             : 
    1626           0 :                 case EMR_SETMAPPERFLAGS :           SAL_INFO("vcl.emf", "not implemented 'SetMapperFlags'");            break;
    1627           0 :                 case EMR_SETICMMODE :               SAL_INFO("vcl.emf", "not implemented 'SetICMMode'");                break;
    1628           0 :                 case EMR_CREATEMONOBRUSH :          SAL_INFO("vcl.emf", "not implemented 'CreateMonoBrush'");           break;
    1629           2 :                 case EMR_SETBRUSHORGEX :            SAL_INFO("vcl.emf", "not implemented 'SetBrushOrgEx'");             break;
    1630         102 :                 case EMR_SETMETARGN :               SAL_INFO("vcl.emf", "not implemented 'SetMetArgn'");                break;
    1631          28 :                 case EMR_SETMITERLIMIT :            SAL_INFO("vcl.emf", "not implemented 'SetMiterLimit'");             break;
    1632           4 :                 case EMR_EXCLUDECLIPRECT :          SAL_INFO("vcl.emf", "not implemented 'ExcludeClipRect'");           break;
    1633           2 :                 case EMR_REALIZEPALETTE :           SAL_INFO("vcl.emf", "not implemented 'RealizePalette'");            break;
    1634          52 :                 case EMR_SELECTPALETTE :            SAL_INFO("vcl.emf", "not implemented 'SelectPalette'");             break;
    1635           2 :                 case EMR_CREATEPALETTE :            SAL_INFO("vcl.emf", "not implemented 'CreatePalette'");             break;
    1636           0 :                 case EMR_ALPHADIBBLEND :            SAL_INFO("vcl.emf", "not implemented 'AlphaDibBlend'");             break;
    1637           0 :                 case EMR_SETTEXTJUSTIFICATION :     SAL_INFO("vcl.emf", "not implemented 'SetTextJustification'");      break;
    1638             : 
    1639             :                 case EMR_GDICOMMENT :
    1640             :                 case EMR_HEADER :               // has already been read at ReadHeader()
    1641           0 :                 break;
    1642             : 
    1643          16 :                 default :                           SAL_INFO("vcl.emf", "Unknown Meta Action");                                     break;
    1644             :             }
    1645             :         }
    1646       45497 :         pWMF->Seek( nNextPos );
    1647             :     }
    1648         223 :     if( !aBmpSaveList.empty() )
    1649           0 :         pOut->ResolveBitmapActions( aBmpSaveList );
    1650             : 
    1651         223 :     if ( bStatus )
    1652         215 :         pWMF->Seek(nEndPos);
    1653             : 
    1654         223 :     return bStatus;
    1655             : };
    1656             : 
    1657         223 : bool EnhWMFReader::ReadHeader()
    1658             : {
    1659             :     sal_uInt32      nType, nSignature, nVersion;
    1660             :     sal_uInt32      nHeaderSize, nPalEntries;
    1661             : 
    1662             :     // Spare me the METAFILEHEADER here
    1663             :     // Reading the METAHEADER - EMR_HEADER ([MS-EMF] section 2.3.4.2 EMR_HEADER Record Types)
    1664         223 :     pWMF->ReadUInt32( nType ).ReadUInt32( nHeaderSize );
    1665         223 :     if (nType != 0x00000001)
    1666             :     {
    1667             :         // per [MS-EMF] 2.3.4.2 EMF Header Record Types, type MUST be 0x00000001
    1668             :         SAL_WARN("vcl.emf", "EMF header type is not set to 0x00000001 - possibly corrupted file?");
    1669           0 :         return false;
    1670             :     }
    1671             : 
    1672             :     // Start reading the EMR_HEADER Header object
    1673             : 
    1674             :     // bound size (RectL object, see [MS-WMF] section 2.2.2.19)
    1675         223 :     Rectangle rclBounds = ReadRectangle(); // rectangle in logical units
    1676             : 
    1677             :     // picture frame size (RectL object)
    1678         223 :     Rectangle rclFrame = ReadRectangle(); // rectangle in device units 1/100th mm
    1679             : 
    1680         223 :     pWMF->ReadUInt32( nSignature );
    1681             : 
    1682             :     // nSignature MUST be the ASCII characters "FME", see [WS-EMF] 2.2.9 Header Object
    1683             :     // and 2.1.14 FormatSignature Enumeration
    1684         223 :     if (nSignature != 0x464d4520)
    1685             :     {
    1686             :         SAL_WARN("vcl.emf", "EMF\t\tSignature is not 0x464d4520 (\"FME\") - possibly corrupted file?");
    1687           0 :         return false;
    1688             :     }
    1689             : 
    1690         223 :     pWMF->ReadUInt32(nVersion);  // according to [WS-EMF] 2.2.9, this SHOULD be 0x0001000, however
    1691             :                                    // Microsoft note that not even Windows checks this...
    1692         223 :     if (nVersion != 0x00010000)
    1693             :     {
    1694             :         SAL_WARN("vcl.emf", "EMF\t\tThis really should be 0x00010000, though not absolutely essential...");
    1695             :     }
    1696             : 
    1697         223 :     pWMF->ReadUInt32(nEndPos); // size of metafile
    1698         223 :     nEndPos += nStartPos;
    1699             : 
    1700         223 :     sal_uInt32 nStrmPos = pWMF->Tell(); // checking if nEndPos is valid
    1701         223 :     pWMF->Seek(STREAM_SEEK_TO_END);
    1702         223 :     sal_uInt32 nActualFileSize = pWMF->Tell();
    1703             : 
    1704         223 :     if ( nActualFileSize < nEndPos )
    1705             :     {
    1706             :         SAL_WARN("vcl.emf", "EMF\t\tEMF Header object records number of bytes as " << nEndPos
    1707             :                             << ", however the file size is actually " << nActualFileSize
    1708             :                             << " bytes. Possible file corruption?");
    1709           2 :         nEndPos = nActualFileSize;
    1710             :     }
    1711         223 :     pWMF->Seek(nStrmPos);
    1712             : 
    1713         223 :     pWMF->ReadInt32(nRecordCount);
    1714             : 
    1715         223 :     if (nRecordCount == 0)
    1716             :     {
    1717             :         SAL_WARN("vcl.emf", "EMF\t\tEMF Header object shows record counter as 0! This shouldn't "
    1718             :                             "be possible... indicator of possible file corruption?");
    1719           0 :         return false;
    1720             :     }
    1721             : 
    1722             :     // the number of "handles", or graphics objects used in the metafile
    1723             : 
    1724             :     sal_uInt16 nHandlesCount;
    1725         223 :     pWMF->ReadUInt16(nHandlesCount);
    1726             : 
    1727             :     // the next 2 bytes are reserved, but according to [MS-EMF] section 2.2.9
    1728             :     // it MUST be 0x000 and MUST be ignored... the thing is, having such a specific
    1729             :     // value is actually pretty useful in checking if there is possible corruption
    1730             : 
    1731             :     sal_uInt16 nReserved;
    1732         223 :     pWMF->ReadUInt16(nReserved);
    1733             : 
    1734         223 :     if ( nReserved != 0x0000 )
    1735             :     {
    1736             :         SAL_WARN("vcl.emf", "EMF\t\tEMF Header object's reserved field is NOT 0x0000... possible "
    1737             :                             "corruption?");
    1738             :     }
    1739             : 
    1740             :     // The next 4 bytes specifies the number of characters in the metafile description.
    1741             :     // The 4 bytes after that specific the offset from this record that contains the
    1742             :     // metafile description... zero means no description string.
    1743             :     // For now, we ignore it.
    1744             : 
    1745         223 :     pWMF->SeekRel(0x8);
    1746             : 
    1747             :     sal_Int32 nPixX, nPixY, nMillX, nMillY;
    1748         223 :     pWMF->ReadUInt32(nPalEntries);
    1749         223 :     pWMF->ReadInt32(nPixX);
    1750         223 :     pWMF->ReadInt32(nPixY);
    1751         223 :     pWMF->ReadInt32(nMillX);
    1752         223 :     pWMF->ReadInt32(nMillY);
    1753             : 
    1754         223 :     pOut->SetrclFrame(rclFrame);
    1755         223 :     pOut->SetrclBounds(rclBounds);
    1756         223 :     pOut->SetRefPix(Size( nPixX, nPixY ) );
    1757         223 :     pOut->SetRefMill(Size( nMillX, nMillY ) );
    1758             : 
    1759         223 :     pWMF->Seek(nStartPos + nHeaderSize);
    1760         223 :     return true;
    1761             : }
    1762             : 
    1763         446 : Rectangle EnhWMFReader::ReadRectangle()
    1764             : {
    1765             :     sal_Int32 nLeft, nTop, nRight, nBottom;
    1766         446 :     pWMF->ReadInt32(nLeft);
    1767         446 :     pWMF->ReadInt32(nTop);
    1768         446 :     pWMF->ReadInt32(nRight);
    1769         446 :     pWMF->ReadInt32(nBottom);
    1770         446 :     return Rectangle(nLeft, nTop, nRight, nBottom);
    1771             : }
    1772             : 
    1773         864 : Rectangle EnhWMFReader::ReadRectangle( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 )
    1774             : {
    1775         864 :     Point aTL ( Point( x1, y1 ) );
    1776         864 :     Point aBR( Point( --x2, --y2 ) );
    1777         864 :     return Rectangle( aTL, aBR );
    1778        1233 : }
    1779             : 
    1780             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10