mirrored from git://source.winehq.org/git/wine.git
/
enhmetafile.c
2816 lines (2485 loc) · 84.8 KB
/
enhmetafile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Enhanced metafile functions
* Copyright 1998 Douglas Ridgway
* 1999 Huw D M Davies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* NOTES:
*
* The enhanced format consists of the following elements:
*
* A header
* A table of handles to GDI objects
* An array of metafile records
* A private palette
*
*
* The standard format consists of a header and an array of metafile records.
*
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winnls.h"
#include "winerror.h"
#include "gdi_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
typedef struct
{
ENHMETAHEADER *emh;
BOOL on_disk; /* true if metafile is on disk */
} ENHMETAFILEOBJ;
static const struct emr_name {
DWORD type;
const char *name;
} emr_names[] = {
#define X(p) {p, #p}
X(EMR_HEADER),
X(EMR_POLYBEZIER),
X(EMR_POLYGON),
X(EMR_POLYLINE),
X(EMR_POLYBEZIERTO),
X(EMR_POLYLINETO),
X(EMR_POLYPOLYLINE),
X(EMR_POLYPOLYGON),
X(EMR_SETWINDOWEXTEX),
X(EMR_SETWINDOWORGEX),
X(EMR_SETVIEWPORTEXTEX),
X(EMR_SETVIEWPORTORGEX),
X(EMR_SETBRUSHORGEX),
X(EMR_EOF),
X(EMR_SETPIXELV),
X(EMR_SETMAPPERFLAGS),
X(EMR_SETMAPMODE),
X(EMR_SETBKMODE),
X(EMR_SETPOLYFILLMODE),
X(EMR_SETROP2),
X(EMR_SETSTRETCHBLTMODE),
X(EMR_SETTEXTALIGN),
X(EMR_SETCOLORADJUSTMENT),
X(EMR_SETTEXTCOLOR),
X(EMR_SETBKCOLOR),
X(EMR_OFFSETCLIPRGN),
X(EMR_MOVETOEX),
X(EMR_SETMETARGN),
X(EMR_EXCLUDECLIPRECT),
X(EMR_INTERSECTCLIPRECT),
X(EMR_SCALEVIEWPORTEXTEX),
X(EMR_SCALEWINDOWEXTEX),
X(EMR_SAVEDC),
X(EMR_RESTOREDC),
X(EMR_SETWORLDTRANSFORM),
X(EMR_MODIFYWORLDTRANSFORM),
X(EMR_SELECTOBJECT),
X(EMR_CREATEPEN),
X(EMR_CREATEBRUSHINDIRECT),
X(EMR_DELETEOBJECT),
X(EMR_ANGLEARC),
X(EMR_ELLIPSE),
X(EMR_RECTANGLE),
X(EMR_ROUNDRECT),
X(EMR_ARC),
X(EMR_CHORD),
X(EMR_PIE),
X(EMR_SELECTPALETTE),
X(EMR_CREATEPALETTE),
X(EMR_SETPALETTEENTRIES),
X(EMR_RESIZEPALETTE),
X(EMR_REALIZEPALETTE),
X(EMR_EXTFLOODFILL),
X(EMR_LINETO),
X(EMR_ARCTO),
X(EMR_POLYDRAW),
X(EMR_SETARCDIRECTION),
X(EMR_SETMITERLIMIT),
X(EMR_BEGINPATH),
X(EMR_ENDPATH),
X(EMR_CLOSEFIGURE),
X(EMR_FILLPATH),
X(EMR_STROKEANDFILLPATH),
X(EMR_STROKEPATH),
X(EMR_FLATTENPATH),
X(EMR_WIDENPATH),
X(EMR_SELECTCLIPPATH),
X(EMR_ABORTPATH),
X(EMR_GDICOMMENT),
X(EMR_FILLRGN),
X(EMR_FRAMERGN),
X(EMR_INVERTRGN),
X(EMR_PAINTRGN),
X(EMR_EXTSELECTCLIPRGN),
X(EMR_BITBLT),
X(EMR_STRETCHBLT),
X(EMR_MASKBLT),
X(EMR_PLGBLT),
X(EMR_SETDIBITSTODEVICE),
X(EMR_STRETCHDIBITS),
X(EMR_EXTCREATEFONTINDIRECTW),
X(EMR_EXTTEXTOUTA),
X(EMR_EXTTEXTOUTW),
X(EMR_POLYBEZIER16),
X(EMR_POLYGON16),
X(EMR_POLYLINE16),
X(EMR_POLYBEZIERTO16),
X(EMR_POLYLINETO16),
X(EMR_POLYPOLYLINE16),
X(EMR_POLYPOLYGON16),
X(EMR_POLYDRAW16),
X(EMR_CREATEMONOBRUSH),
X(EMR_CREATEDIBPATTERNBRUSHPT),
X(EMR_EXTCREATEPEN),
X(EMR_POLYTEXTOUTA),
X(EMR_POLYTEXTOUTW),
X(EMR_SETICMMODE),
X(EMR_CREATECOLORSPACE),
X(EMR_SETCOLORSPACE),
X(EMR_DELETECOLORSPACE),
X(EMR_GLSRECORD),
X(EMR_GLSBOUNDEDRECORD),
X(EMR_PIXELFORMAT),
X(EMR_DRAWESCAPE),
X(EMR_EXTESCAPE),
X(EMR_STARTDOC),
X(EMR_SMALLTEXTOUT),
X(EMR_FORCEUFIMAPPING),
X(EMR_NAMEDESCAPE),
X(EMR_COLORCORRECTPALETTE),
X(EMR_SETICMPROFILEA),
X(EMR_SETICMPROFILEW),
X(EMR_ALPHABLEND),
X(EMR_SETLAYOUT),
X(EMR_TRANSPARENTBLT),
X(EMR_RESERVED_117),
X(EMR_GRADIENTFILL),
X(EMR_SETLINKEDUFI),
X(EMR_SETTEXTJUSTIFICATION),
X(EMR_COLORMATCHTOTARGETW),
X(EMR_CREATECOLORSPACEW)
#undef X
};
/****************************************************************************
* get_emr_name
*/
static const char *get_emr_name(DWORD type)
{
unsigned int i;
for(i = 0; i < sizeof(emr_names) / sizeof(emr_names[0]); i++)
if(type == emr_names[i].type) return emr_names[i].name;
TRACE("Unknown record type %d\n", type);
return NULL;
}
/***********************************************************************
* is_dib_monochrome
*
* Returns whether a DIB can be converted to a monochrome DDB.
*
* A DIB can be converted if its color table contains only black and
* white. Black must be the first color in the color table.
*
* Note : If the first color in the color table is white followed by
* black, we can't convert it to a monochrome DDB with
* SetDIBits, because black and white would be inverted.
*/
static inline BOOL is_dib_monochrome( const BITMAPINFO* info )
{
if (info->bmiHeader.biBitCount != 1) return FALSE;
if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
{
const RGBTRIPLE *rgb = ((const BITMAPCOREINFO *) info)->bmciColors;
/* Check if the first color is black */
if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
{
rgb++;
/* Check if the second color is white */
return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
&& (rgb->rgbtBlue == 0xff));
}
else return FALSE;
}
else /* assume BITMAPINFOHEADER */
{
const RGBQUAD *rgb = info->bmiColors;
/* Check if the first color is black */
if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
(rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
{
rgb++;
/* Check if the second color is white */
return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
&& (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
}
else return FALSE;
}
}
/****************************************************************************
* EMF_Create_HENHMETAFILE
*/
HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk )
{
HENHMETAFILE hmf;
ENHMETAFILEOBJ *metaObj;
if (emh->iType != EMR_HEADER)
{
SetLastError(ERROR_INVALID_DATA);
return 0;
}
if (emh->dSignature != ENHMETA_SIGNATURE ||
(emh->nBytes & 3)) /* refuse to load unaligned EMF as Windows does */
{
WARN("Invalid emf header type 0x%08x sig 0x%08x.\n",
emh->iType, emh->dSignature);
return 0;
}
if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
metaObj->emh = emh;
metaObj->on_disk = on_disk;
if (!(hmf = alloc_gdi_handle( metaObj, OBJ_ENHMETAFILE, NULL )))
HeapFree( GetProcessHeap(), 0, metaObj );
return hmf;
}
/****************************************************************************
* EMF_Delete_HENHMETAFILE
*/
static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf )
{
ENHMETAFILEOBJ *metaObj = free_gdi_handle( hmf );
if(!metaObj) return FALSE;
if(metaObj->on_disk)
UnmapViewOfFile( metaObj->emh );
else
HeapFree( GetProcessHeap(), 0, metaObj->emh );
return HeapFree( GetProcessHeap(), 0, metaObj );
}
/******************************************************************
* EMF_GetEnhMetaHeader
*
* Returns ptr to ENHMETAHEADER associated with HENHMETAFILE
*/
static ENHMETAHEADER *EMF_GetEnhMetaHeader( HENHMETAFILE hmf )
{
ENHMETAHEADER *ret = NULL;
ENHMETAFILEOBJ *metaObj = GDI_GetObjPtr( hmf, OBJ_ENHMETAFILE );
TRACE("hmf %p -> enhmetaObj %p\n", hmf, metaObj);
if (metaObj)
{
ret = metaObj->emh;
GDI_ReleaseObj( hmf );
}
return ret;
}
/*****************************************************************************
* EMF_GetEnhMetaFile
*
*/
static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile )
{
ENHMETAHEADER *emh;
HANDLE hMapping;
HENHMETAFILE hemf;
hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
CloseHandle( hMapping );
if (!emh) return 0;
hemf = EMF_Create_HENHMETAFILE( emh, TRUE );
if (!hemf)
UnmapViewOfFile( emh );
return hemf;
}
/*****************************************************************************
* GetEnhMetaFileA (GDI32.@)
*
*
*/
HENHMETAFILE WINAPI GetEnhMetaFileA(
LPCSTR lpszMetaFile /* [in] filename of enhanced metafile */
)
{
HENHMETAFILE hmf;
HANDLE hFile;
hFile = CreateFileA(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
OPEN_EXISTING, 0, 0);
if (hFile == INVALID_HANDLE_VALUE) {
WARN("could not open %s\n", lpszMetaFile);
return 0;
}
hmf = EMF_GetEnhMetaFile( hFile );
CloseHandle( hFile );
return hmf;
}
/*****************************************************************************
* GetEnhMetaFileW (GDI32.@)
*/
HENHMETAFILE WINAPI GetEnhMetaFileW(
LPCWSTR lpszMetaFile) /* [in] filename of enhanced metafile */
{
HENHMETAFILE hmf;
HANDLE hFile;
hFile = CreateFileW(lpszMetaFile, GENERIC_READ, FILE_SHARE_READ, 0,
OPEN_EXISTING, 0, 0);
if (hFile == INVALID_HANDLE_VALUE) {
WARN("could not open %s\n", debugstr_w(lpszMetaFile));
return 0;
}
hmf = EMF_GetEnhMetaFile( hFile );
CloseHandle( hFile );
return hmf;
}
/*****************************************************************************
* GetEnhMetaFileHeader (GDI32.@)
*
* Retrieves the record containing the header for the specified
* enhanced-format metafile.
*
* RETURNS
* If buf is NULL, returns the size of buffer required.
* Otherwise, copy up to bufsize bytes of enhanced metafile header into
* buf.
*/
UINT WINAPI GetEnhMetaFileHeader(
HENHMETAFILE hmf, /* [in] enhanced metafile */
UINT bufsize, /* [in] size of buffer */
LPENHMETAHEADER buf /* [out] buffer */
)
{
LPENHMETAHEADER emh;
UINT size;
emh = EMF_GetEnhMetaHeader(hmf);
if(!emh) return FALSE;
size = emh->nSize;
if (!buf) return size;
size = min(size, bufsize);
memmove(buf, emh, size);
return size;
}
/*****************************************************************************
* GetEnhMetaFileDescriptionA (GDI32.@)
*
* See GetEnhMetaFileDescriptionW.
*/
UINT WINAPI GetEnhMetaFileDescriptionA(
HENHMETAFILE hmf, /* [in] enhanced metafile */
UINT size, /* [in] size of buf */
LPSTR buf /* [out] buffer to receive description */
)
{
LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
DWORD len;
WCHAR *descrW;
if(!emh) return FALSE;
if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
descrW = (WCHAR *) ((char *) emh + emh->offDescription);
len = WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, NULL, 0, NULL, NULL );
if (!buf || !size ) return len;
len = min( size, len );
WideCharToMultiByte( CP_ACP, 0, descrW, emh->nDescription, buf, len, NULL, NULL );
return len;
}
/*****************************************************************************
* GetEnhMetaFileDescriptionW (GDI32.@)
*
* Copies the description string of an enhanced metafile into a buffer
* _buf_.
*
* RETURNS
* If _buf_ is NULL, returns size of _buf_ required. Otherwise, returns
* number of characters copied.
*/
UINT WINAPI GetEnhMetaFileDescriptionW(
HENHMETAFILE hmf, /* [in] enhanced metafile */
UINT size, /* [in] size of buf */
LPWSTR buf /* [out] buffer to receive description */
)
{
LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
if(!emh) return FALSE;
if(emh->nDescription == 0 || emh->offDescription == 0) return 0;
if (!buf || !size ) return emh->nDescription;
memmove(buf, (char *) emh + emh->offDescription, min(size,emh->nDescription)*sizeof(WCHAR));
return min(size, emh->nDescription);
}
/****************************************************************************
* SetEnhMetaFileBits (GDI32.@)
*
* Creates an enhanced metafile by copying _bufsize_ bytes from _buf_.
*/
HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf)
{
ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize );
HENHMETAFILE hmf;
memmove(emh, buf, bufsize);
hmf = EMF_Create_HENHMETAFILE( emh, FALSE );
if (!hmf)
HeapFree( GetProcessHeap(), 0, emh );
return hmf;
}
/*****************************************************************************
* GetEnhMetaFileBits (GDI32.@)
*
*/
UINT WINAPI GetEnhMetaFileBits(
HENHMETAFILE hmf,
UINT bufsize,
LPBYTE buf
)
{
LPENHMETAHEADER emh = EMF_GetEnhMetaHeader( hmf );
UINT size;
if(!emh) return 0;
size = emh->nBytes;
if( buf == NULL ) return size;
size = min( size, bufsize );
memmove(buf, emh, size);
return size;
}
typedef struct EMF_dc_state
{
INT mode;
XFORM world_transform;
INT wndOrgX;
INT wndOrgY;
INT wndExtX;
INT wndExtY;
INT vportOrgX;
INT vportOrgY;
INT vportExtX;
INT vportExtY;
struct EMF_dc_state *next;
} EMF_dc_state;
typedef struct enum_emh_data
{
XFORM init_transform;
EMF_dc_state state;
INT save_level;
EMF_dc_state *saved_state;
} enum_emh_data;
#define ENUM_GET_PRIVATE_DATA(ht) \
((enum_emh_data*)(((unsigned char*)(ht))-sizeof (enum_emh_data)))
#define WIDTH(rect) ( (rect).right - (rect).left )
#define HEIGHT(rect) ( (rect).bottom - (rect).top )
#define IS_WIN9X() (GetVersion()&0x80000000)
static void EMF_Update_MF_Xform(HDC hdc, const enum_emh_data *info)
{
XFORM mapping_mode_trans, final_trans;
double scaleX, scaleY;
scaleX = (double)info->state.vportExtX / (double)info->state.wndExtX;
scaleY = (double)info->state.vportExtY / (double)info->state.wndExtY;
mapping_mode_trans.eM11 = scaleX;
mapping_mode_trans.eM12 = 0.0;
mapping_mode_trans.eM21 = 0.0;
mapping_mode_trans.eM22 = scaleY;
mapping_mode_trans.eDx = (double)info->state.vportOrgX - scaleX * (double)info->state.wndOrgX;
mapping_mode_trans.eDy = (double)info->state.vportOrgY - scaleY * (double)info->state.wndOrgY;
CombineTransform(&final_trans, &info->state.world_transform, &mapping_mode_trans);
CombineTransform(&final_trans, &final_trans, &info->init_transform);
if (!SetWorldTransform(hdc, &final_trans))
{
ERR("World transform failed!\n");
}
}
static void EMF_RestoreDC( enum_emh_data *info, INT level )
{
if (abs(level) > info->save_level || level == 0) return;
if (level < 0) level = info->save_level + level + 1;
while (info->save_level >= level)
{
EMF_dc_state *state = info->saved_state;
info->saved_state = state->next;
state->next = NULL;
if (--info->save_level < level)
info->state = *state;
HeapFree( GetProcessHeap(), 0, state );
}
}
static void EMF_SaveDC( enum_emh_data *info )
{
EMF_dc_state *state = HeapAlloc( GetProcessHeap(), 0, sizeof(*state));
if (state)
{
*state = info->state;
state->next = info->saved_state;
info->saved_state = state;
info->save_level++;
TRACE("save_level %d\n", info->save_level);
}
}
static void EMF_SetMapMode(HDC hdc, enum_emh_data *info)
{
INT horzSize = GetDeviceCaps( hdc, HORZSIZE );
INT vertSize = GetDeviceCaps( hdc, VERTSIZE );
INT horzRes = GetDeviceCaps( hdc, HORZRES );
INT vertRes = GetDeviceCaps( hdc, VERTRES );
TRACE("%d\n", info->state.mode);
switch(info->state.mode)
{
case MM_TEXT:
info->state.wndExtX = 1;
info->state.wndExtY = 1;
info->state.vportExtX = 1;
info->state.vportExtY = 1;
break;
case MM_LOMETRIC:
case MM_ISOTROPIC:
info->state.wndExtX = horzSize * 10;
info->state.wndExtY = vertSize * 10;
info->state.vportExtX = horzRes;
info->state.vportExtY = -vertRes;
break;
case MM_HIMETRIC:
info->state.wndExtX = horzSize * 100;
info->state.wndExtY = vertSize * 100;
info->state.vportExtX = horzRes;
info->state.vportExtY = -vertRes;
break;
case MM_LOENGLISH:
info->state.wndExtX = MulDiv(1000, horzSize, 254);
info->state.wndExtY = MulDiv(1000, vertSize, 254);
info->state.vportExtX = horzRes;
info->state.vportExtY = -vertRes;
break;
case MM_HIENGLISH:
info->state.wndExtX = MulDiv(10000, horzSize, 254);
info->state.wndExtY = MulDiv(10000, vertSize, 254);
info->state.vportExtX = horzRes;
info->state.vportExtY = -vertRes;
break;
case MM_TWIPS:
info->state.wndExtX = MulDiv(14400, horzSize, 254);
info->state.wndExtY = MulDiv(14400, vertSize, 254);
info->state.vportExtX = horzRes;
info->state.vportExtY = -vertRes;
break;
case MM_ANISOTROPIC:
break;
default:
return;
}
}
/***********************************************************************
* EMF_FixIsotropic
*
* Fix viewport extensions for isotropic mode.
*/
static void EMF_FixIsotropic(HDC hdc, enum_emh_data *info)
{
double xdim = fabs((double)info->state.vportExtX * GetDeviceCaps( hdc, HORZSIZE ) /
(GetDeviceCaps( hdc, HORZRES ) * info->state.wndExtX));
double ydim = fabs((double)info->state.vportExtY * GetDeviceCaps( hdc, VERTSIZE ) /
(GetDeviceCaps( hdc, VERTRES ) * info->state.wndExtY));
if (xdim > ydim)
{
INT mincx = (info->state.vportExtX >= 0) ? 1 : -1;
info->state.vportExtX = floor(info->state.vportExtX * ydim / xdim + 0.5);
if (!info->state.vportExtX) info->state.vportExtX = mincx;
}
else
{
INT mincy = (info->state.vportExtY >= 0) ? 1 : -1;
info->state.vportExtY = floor(info->state.vportExtY * xdim / ydim + 0.5);
if (!info->state.vportExtY) info->state.vportExtY = mincy;
}
}
/*****************************************************************************
* emr_produces_output
*
* Returns TRUE if the record type writes something to the dc. Used by
* PlayEnhMetaFileRecord to determine whether it needs to update the
* dc's xform when in win9x mode.
*
* FIXME: need to test which records should be here.
*/
static BOOL emr_produces_output(int type)
{
switch(type) {
case EMR_POLYBEZIER:
case EMR_POLYGON:
case EMR_POLYLINE:
case EMR_POLYBEZIERTO:
case EMR_POLYLINETO:
case EMR_POLYPOLYLINE:
case EMR_POLYPOLYGON:
case EMR_SETPIXELV:
case EMR_MOVETOEX:
case EMR_EXCLUDECLIPRECT:
case EMR_INTERSECTCLIPRECT:
case EMR_SELECTOBJECT:
case EMR_ANGLEARC:
case EMR_ELLIPSE:
case EMR_RECTANGLE:
case EMR_ROUNDRECT:
case EMR_ARC:
case EMR_CHORD:
case EMR_PIE:
case EMR_EXTFLOODFILL:
case EMR_LINETO:
case EMR_ARCTO:
case EMR_POLYDRAW:
case EMR_GDICOMMENT:
case EMR_FILLRGN:
case EMR_FRAMERGN:
case EMR_INVERTRGN:
case EMR_PAINTRGN:
case EMR_BITBLT:
case EMR_STRETCHBLT:
case EMR_MASKBLT:
case EMR_PLGBLT:
case EMR_SETDIBITSTODEVICE:
case EMR_STRETCHDIBITS:
case EMR_EXTTEXTOUTA:
case EMR_EXTTEXTOUTW:
case EMR_POLYBEZIER16:
case EMR_POLYGON16:
case EMR_POLYLINE16:
case EMR_POLYBEZIERTO16:
case EMR_POLYLINETO16:
case EMR_POLYPOLYLINE16:
case EMR_POLYPOLYGON16:
case EMR_POLYDRAW16:
case EMR_POLYTEXTOUTA:
case EMR_POLYTEXTOUTW:
case EMR_SMALLTEXTOUT:
case EMR_ALPHABLEND:
case EMR_TRANSPARENTBLT:
return TRUE;
default:
return FALSE;
}
}
/*****************************************************************************
* PlayEnhMetaFileRecord (GDI32.@)
*
* Render a single enhanced metafile record in the device context hdc.
*
* RETURNS
* TRUE (non zero) on success, FALSE on error.
* BUGS
* Many unimplemented records.
* No error handling on record play failures (ie checking return codes)
*
* NOTES
* WinNT actually updates the current world transform in this function
* whereas Win9x does not.
*/
BOOL WINAPI PlayEnhMetaFileRecord(
HDC hdc, /* [in] device context in which to render EMF record */
LPHANDLETABLE handletable, /* [in] array of handles to be used in rendering record */
const ENHMETARECORD *mr, /* [in] EMF record to render */
UINT handles /* [in] size of handle array */
)
{
int type;
RECT tmprc;
enum_emh_data *info = ENUM_GET_PRIVATE_DATA(handletable);
TRACE("hdc = %p, handletable = %p, record = %p, numHandles = %d\n",
hdc, handletable, mr, handles);
if (!mr) return FALSE;
type = mr->iType;
TRACE("record %s\n", get_emr_name(type));
switch(type)
{
case EMR_HEADER:
break;
case EMR_EOF:
break;
case EMR_GDICOMMENT:
{
const EMRGDICOMMENT *lpGdiComment = (const EMRGDICOMMENT *)mr;
/* In an enhanced metafile, there can be both public and private GDI comments */
GdiComment( hdc, lpGdiComment->cbData, lpGdiComment->Data );
break;
}
case EMR_SETMAPMODE:
{
const EMRSETMAPMODE *pSetMapMode = (const EMRSETMAPMODE *)mr;
if (info->state.mode == pSetMapMode->iMode &&
(info->state.mode == MM_ISOTROPIC || info->state.mode == MM_ANISOTROPIC))
break;
info->state.mode = pSetMapMode->iMode;
EMF_SetMapMode(hdc, info);
break;
}
case EMR_SETBKMODE:
{
const EMRSETBKMODE *pSetBkMode = (const EMRSETBKMODE *)mr;
SetBkMode(hdc, pSetBkMode->iMode);
break;
}
case EMR_SETBKCOLOR:
{
const EMRSETBKCOLOR *pSetBkColor = (const EMRSETBKCOLOR *)mr;
SetBkColor(hdc, pSetBkColor->crColor);
break;
}
case EMR_SETPOLYFILLMODE:
{
const EMRSETPOLYFILLMODE *pSetPolyFillMode = (const EMRSETPOLYFILLMODE *)mr;
SetPolyFillMode(hdc, pSetPolyFillMode->iMode);
break;
}
case EMR_SETROP2:
{
const EMRSETROP2 *pSetROP2 = (const EMRSETROP2 *)mr;
SetROP2(hdc, pSetROP2->iMode);
break;
}
case EMR_SETSTRETCHBLTMODE:
{
const EMRSETSTRETCHBLTMODE *pSetStretchBltMode = (const EMRSETSTRETCHBLTMODE *)mr;
SetStretchBltMode(hdc, pSetStretchBltMode->iMode);
break;
}
case EMR_SETTEXTALIGN:
{
const EMRSETTEXTALIGN *pSetTextAlign = (const EMRSETTEXTALIGN *)mr;
SetTextAlign(hdc, pSetTextAlign->iMode);
break;
}
case EMR_SETTEXTCOLOR:
{
const EMRSETTEXTCOLOR *pSetTextColor = (const EMRSETTEXTCOLOR *)mr;
SetTextColor(hdc, pSetTextColor->crColor);
break;
}
case EMR_SAVEDC:
{
if (SaveDC( hdc ))
EMF_SaveDC( info );
break;
}
case EMR_RESTOREDC:
{
const EMRRESTOREDC *pRestoreDC = (const EMRRESTOREDC *)mr;
TRACE("EMR_RESTORE: %d\n", pRestoreDC->iRelative);
if (RestoreDC( hdc, pRestoreDC->iRelative ))
EMF_RestoreDC( info, pRestoreDC->iRelative );
break;
}
case EMR_INTERSECTCLIPRECT:
{
const EMRINTERSECTCLIPRECT *pClipRect = (const EMRINTERSECTCLIPRECT *)mr;
TRACE("EMR_INTERSECTCLIPRECT: rect %d,%d - %d, %d\n",
pClipRect->rclClip.left, pClipRect->rclClip.top,
pClipRect->rclClip.right, pClipRect->rclClip.bottom);
IntersectClipRect(hdc, pClipRect->rclClip.left, pClipRect->rclClip.top,
pClipRect->rclClip.right, pClipRect->rclClip.bottom);
break;
}
case EMR_SELECTOBJECT:
{
const EMRSELECTOBJECT *pSelectObject = (const EMRSELECTOBJECT *)mr;
if( pSelectObject->ihObject & 0x80000000 ) {
/* High order bit is set - it's a stock object
* Strip the high bit to get the index.
* See MSDN article Q142319
*/
SelectObject( hdc, GetStockObject( pSelectObject->ihObject &
0x7fffffff ) );
} else {
/* High order bit wasn't set - not a stock object
*/
SelectObject( hdc,
(handletable->objectHandle)[pSelectObject->ihObject] );
}
break;
}
case EMR_DELETEOBJECT:
{
const EMRDELETEOBJECT *pDeleteObject = (const EMRDELETEOBJECT *)mr;
DeleteObject( (handletable->objectHandle)[pDeleteObject->ihObject]);
(handletable->objectHandle)[pDeleteObject->ihObject] = 0;
break;
}
case EMR_SETWINDOWORGEX:
{
const EMRSETWINDOWORGEX *pSetWindowOrgEx = (const EMRSETWINDOWORGEX *)mr;
info->state.wndOrgX = pSetWindowOrgEx->ptlOrigin.x;
info->state.wndOrgY = pSetWindowOrgEx->ptlOrigin.y;
TRACE("SetWindowOrgEx: %d,%d\n", info->state.wndOrgX, info->state.wndOrgY);
break;
}
case EMR_SETWINDOWEXTEX:
{
const EMRSETWINDOWEXTEX *pSetWindowExtEx = (const EMRSETWINDOWEXTEX *)mr;
if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
break;
info->state.wndExtX = pSetWindowExtEx->szlExtent.cx;
info->state.wndExtY = pSetWindowExtEx->szlExtent.cy;
if (info->state.mode == MM_ISOTROPIC)
EMF_FixIsotropic(hdc, info);
TRACE("SetWindowExtEx: %d,%d\n",info->state.wndExtX, info->state.wndExtY);
break;
}
case EMR_SETVIEWPORTORGEX:
{
const EMRSETVIEWPORTORGEX *pSetViewportOrgEx = (const EMRSETVIEWPORTORGEX *)mr;
info->state.vportOrgX = pSetViewportOrgEx->ptlOrigin.x;
info->state.vportOrgY = pSetViewportOrgEx->ptlOrigin.y;
TRACE("SetViewportOrgEx: %d,%d\n", info->state.vportOrgX, info->state.vportOrgY);
break;
}
case EMR_SETVIEWPORTEXTEX:
{
const EMRSETVIEWPORTEXTEX *pSetViewportExtEx = (const EMRSETVIEWPORTEXTEX *)mr;
if (info->state.mode != MM_ISOTROPIC && info->state.mode != MM_ANISOTROPIC)
break;
info->state.vportExtX = pSetViewportExtEx->szlExtent.cx;
info->state.vportExtY = pSetViewportExtEx->szlExtent.cy;
if (info->state.mode == MM_ISOTROPIC)
EMF_FixIsotropic(hdc, info);
TRACE("SetViewportExtEx: %d,%d\n", info->state.vportExtX, info->state.vportExtY);
break;
}
case EMR_CREATEPEN:
{
const EMRCREATEPEN *pCreatePen = (const EMRCREATEPEN *)mr;
(handletable->objectHandle)[pCreatePen->ihPen] =
CreatePenIndirect(&pCreatePen->lopn);
break;
}
case EMR_EXTCREATEPEN:
{
const EMREXTCREATEPEN *pPen = (const EMREXTCREATEPEN *)mr;
LOGBRUSH lb;
lb.lbStyle = pPen->elp.elpBrushStyle;
lb.lbColor = pPen->elp.elpColor;
lb.lbHatch = pPen->elp.elpHatch;
if(pPen->offBmi || pPen->offBits)
FIXME("EMR_EXTCREATEPEN: Need to copy brush bitmap\n");
(handletable->objectHandle)[pPen->ihPen] =
ExtCreatePen(pPen->elp.elpPenStyle, pPen->elp.elpWidth, &lb,
pPen->elp.elpNumEntries, pPen->elp.elpNumEntries ? pPen->elp.elpStyleEntry : NULL);
break;
}
case EMR_CREATEBRUSHINDIRECT:
{
const EMRCREATEBRUSHINDIRECT *pBrush = (const EMRCREATEBRUSHINDIRECT *)mr;
LOGBRUSH brush;
brush.lbStyle = pBrush->lb.lbStyle;
brush.lbColor = pBrush->lb.lbColor;
brush.lbHatch = pBrush->lb.lbHatch;
(handletable->objectHandle)[pBrush->ihBrush] = CreateBrushIndirect(&brush);
break;
}
case EMR_EXTCREATEFONTINDIRECTW:
{
const EMREXTCREATEFONTINDIRECTW *pFont = (const EMREXTCREATEFONTINDIRECTW *)mr;
(handletable->objectHandle)[pFont->ihFont] =
CreateFontIndirectW(&pFont->elfw.elfLogFont);
break;
}
case EMR_MOVETOEX:
{
const EMRMOVETOEX *pMoveToEx = (const EMRMOVETOEX *)mr;
MoveToEx(hdc, pMoveToEx->ptl.x, pMoveToEx->ptl.y, NULL);
break;
}
case EMR_LINETO:
{
const EMRLINETO *pLineTo = (const EMRLINETO *)mr;
LineTo(hdc, pLineTo->ptl.x, pLineTo->ptl.y);
break;
}
case EMR_RECTANGLE:
{
const EMRRECTANGLE *pRect = (const EMRRECTANGLE *)mr;
Rectangle(hdc, pRect->rclBox.left, pRect->rclBox.top,
pRect->rclBox.right, pRect->rclBox.bottom);
break;
}
case EMR_ELLIPSE:
{
const EMRELLIPSE *pEllipse = (const EMRELLIPSE *)mr;
Ellipse(hdc, pEllipse->rclBox.left, pEllipse->rclBox.top,
pEllipse->rclBox.right, pEllipse->rclBox.bottom);
break;
}
case EMR_POLYGON16:
{
const EMRPOLYGON16 *pPoly = (const EMRPOLYGON16 *)mr;
/* Shouldn't use Polygon16 since pPoly->cpts is DWORD */
POINT *pts = HeapAlloc( GetProcessHeap(), 0,
pPoly->cpts * sizeof(POINT) );
DWORD i;
for(i = 0; i < pPoly->cpts; i++)