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