forked from mathog/libUEMF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuemf_print.c
More file actions
2704 lines (2488 loc) · 103 KB
/
uemf_print.c
File metadata and controls
2704 lines (2488 loc) · 103 KB
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
/**
@file uemf_print.c
@brief Functions for printing EMF records
*/
/*
File: uemf_print.c
Version: 0.0.22
Date: 12-MAY-2020
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
Copyright: 2020 David Mathog and California Institute of Technology (Caltech)
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h> /* for offsetof() macro */
#include <string.h>
#include "uemf.h"
#include "upmf_print.h"
#include "uemf_safe.h"
//! \cond
#define UNUSED(x) (void)(x)
/* This bit of code is used all over the place, so reduce it to a DEFINITION */
#define IF_MEM_UNSAFE_PRINT_AND_RETURN(A,B,C) if(IS_MEM_UNSAFE(A,B,C)){printf(" record corruption HERE\n"); return; }
/* one needed prototype */
void U_swap4(void *ul, unsigned int count);
//! \endcond
/**
\brief calculate a CRC32 value for record
\returns CRC32 value calculated for record
\param record pointer to the first byte
\param Size number of bytes in the record
Code based on example crc32b here:
http://www.hackersdelight.org/hdcodetxt/crc.c.txt
*/
uint32_t lu_crc32(const char *record, uint32_t Size){
const unsigned char *message = (const unsigned char *)record;
uint32_t i, j;
uint32_t crc, mask;
crc = 0xFFFFFFFF;
for(i=0;i<Size;i++){ // over all bytes
crc = crc ^ *message++;
for (j = 0; j < 8; j++) { // over all bits
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
}
return ~crc;
}
/**
\brief Print some number of hex bytes
\param buf pointer to the first byte
\param num number of bytes
*/
void hexbytes_print(uint8_t *buf,unsigned int num){
for(; num; num--,buf++){
printf("%2.2X",*buf);
}
}
/* **********************************************************************************************
These functions print standard objects used in the EMR records.
The low level ones do not append EOL.
*********************************************************************************************** */
/**
\brief Print a U_COLORREF object.
\param color U_COLORREF object
*/
void colorref_print(
U_COLORREF color
){
printf("{%u,%u,%u} ",color.Red,color.Green,color.Blue);
}
/**
\brief Print a U_RGBQUAD object.
\param color U_RGBQUAD object
*/
void rgbquad_print(
U_RGBQUAD color
){
printf("{%u,%u,%u,%u} ",color.Blue,color.Green,color.Red,color.Reserved);
}
/**
\brief Print rect and rectl objects from Upper Left and Lower Right corner points.
\param rect U_RECTL object
*/
void rectl_print(
U_RECTL rect
){
printf("{%d,%d,%d,%d} ",rect.left,rect.top,rect.right,rect.bottom);
}
/**
\brief Print a U_SIZEL object.
\param sz U_SizeL object
*/
void sizel_print(
U_SIZEL sz
){
printf("{%d,%d} ",sz.cx ,sz.cy);
}
/**
\brief Print a U_POINTL object
\param pt U_POINTL object
*/
void pointl_print(
U_POINTL pt
){
printf("{%d,%d} ",pt.x ,pt.y);
}
/**
\brief Print a pointer to a U_POINT16 object
\param pt pointer to a U_POINT16 object
Warning - WMF data may contain unaligned U_POINT16, do not call
this routine with a pointer to such data!
*/
void point16_print(
U_POINT16 pt
){
printf("{%d,%d} ",pt.x ,pt.y);
}
/**
\brief Print a U_LCS_GAMMA object
\param lg U_LCS_GAMMA object
*/
void lcs_gamma_print(
U_LCS_GAMMA lg
){
uint8_t tmp;
tmp = lg.ignoreHi; printf("ignoreHi:%u ",tmp);
tmp = lg.intPart ; printf("intPart :%u ",tmp);
tmp = lg.fracPart; printf("fracPart:%u ",tmp);
tmp = lg.ignoreLo; printf("ignoreLo:%u ",tmp);
}
/**
\brief Print a U_LCS_GAMMARGB object
\param lgr U_LCS_GAMMARGB object
*/
void lcs_gammargb_print(
U_LCS_GAMMARGB lgr
){
printf("lcsGammaRed:"); lcs_gamma_print(lgr.lcsGammaRed );
printf("lcsGammaGreen:"); lcs_gamma_print(lgr.lcsGammaGreen);
printf("lcsGammaBlue:"); lcs_gamma_print(lgr.lcsGammaBlue );
}
/**
\brief Print a U_TRIVERTEX object.
\param tv U_TRIVERTEX object.
*/
void trivertex_print(
U_TRIVERTEX tv
){
printf("{{%d,%d},{%u,%u,%u,%u}} ",tv.x,tv.y,tv.Red,tv.Green,tv.Blue,tv.Alpha);
}
/**
\brief Print a U_GRADIENT3 object.
\param g3 U_GRADIENT3 object.
*/
void gradient3_print(
U_GRADIENT3 g3
){
printf("{%u,%u,%u} ",g3.Vertex1,g3.Vertex2,g3.Vertex3);
}
/**
\brief Print a U_GRADIENT4 object.
\param g4 U_GRADIENT4 object.
*/
void gradient4_print(
U_GRADIENT4 g4
){
printf("{%u,%u} ",g4.UpperLeft,g4.LowerRight);
}
/**
\brief Print a U_LOGBRUSH object.
\param lb U_LOGBRUSH object.
*/
void logbrush_print(
U_LOGBRUSH lb
){
printf("lbStyle:0x%8.8X ", lb.lbStyle);
printf("lbColor:"); colorref_print(lb.lbColor);
printf("lbHatch:0x%8.8X ", lb.lbHatch);
}
/**
\brief Print a U_XFORM object.
\param xform U_XFORM object
*/
void xform_print(
U_XFORM xform
){
printf("{%f,%f.%f,%f,%f,%f} ",xform.eM11,xform.eM12,xform.eM21,xform.eM22,xform.eDx,xform.eDy);
}
/**
\brief Print a U_CIEXYZ object
\param ciexyz U_CIEXYZ object
*/
void ciexyz_print(
U_CIEXYZ ciexyz
){
printf("{%d,%d.%d} ",ciexyz.ciexyzX,ciexyz.ciexyzY,ciexyz.ciexyzZ);
}
/**
\brief Print a U_CIEXYZTRIPLE object
\param cie3 U_CIEXYZTRIPLE object
*/
void ciexyztriple_print(
U_CIEXYZTRIPLE cie3
){
printf("{Red:"); ciexyz_print(cie3.ciexyzRed );
printf(", Green:"); ciexyz_print(cie3.ciexyzGreen);
printf(", Blue:"); ciexyz_print(cie3.ciexyzBlue );
printf("} ");
}
/**
\brief Print a U_LOGCOLORSPACEA object.
\param lcsa U_LOGCOLORSPACEA object
*/
void logcolorspacea_print(
U_LOGCOLORSPACEA lcsa
){
printf("lcsSignature:%u ",lcsa.lcsSignature);
printf("lcsVersion:%u ", lcsa.lcsVersion );
printf("lcsSize:%u ", lcsa.lcsSize );
printf("lcsCSType:%d ", lcsa.lcsCSType );
printf("lcsIntent:%d ", lcsa.lcsIntent );
printf("lcsEndpoints:"); ciexyztriple_print(lcsa.lcsEndpoints);
printf("lcsGammaRGB: "); lcs_gammargb_print(lcsa.lcsGammaRGB );
printf("filename:%s ", lcsa.lcsFilename );
}
/**
\brief Print a U_LOGCOLORSPACEW object.
\param lcsa U_LOGCOLORSPACEW object
*/
void logcolorspacew_print(
U_LOGCOLORSPACEW lcsa
){
char *string;
printf("lcsSignature:%d ",lcsa.lcsSignature);
printf("lcsVersion:%d ", lcsa.lcsVersion );
printf("lcsSize:%d ", lcsa.lcsSize );
printf("lcsCSType:%d ", lcsa.lcsCSType );
printf("lcsIntent:%d ", lcsa.lcsIntent );
printf("lcsEndpoints:"); ciexyztriple_print(lcsa.lcsEndpoints);
printf("lcsGammaRGB: "); lcs_gammargb_print(lcsa.lcsGammaRGB );
string = U_Utf16leToUtf8(lcsa.lcsFilename, U_MAX_PATH, NULL);
printf("filename:%s ", string );
free(string);
}
/**
\brief Print a U_PANOSE object.
\param panose U_PANOSE object
*/
void panose_print(
U_PANOSE panose
){
printf("bFamilyType:%u ", panose.bFamilyType );
printf("bSerifStyle:%u ", panose.bSerifStyle );
printf("bWeight:%u ", panose.bWeight );
printf("bProportion:%u ", panose.bProportion );
printf("bContrast:%u ", panose.bContrast );
printf("bStrokeVariation:%u ",panose.bStrokeVariation);
printf("bArmStyle:%u ", panose.bArmStyle );
printf("bLetterform:%u ", panose.bLetterform );
printf("bMidline:%u ", panose.bMidline );
printf("bXHeight:%u ", panose.bXHeight );
}
/**
\brief Print a U_LOGFONT object.
\param lf U_LOGFONT object
*/
void logfont_print(
U_LOGFONT lf
){
char *string;
printf("lfHeight:%d ", lf.lfHeight );
printf("lfWidth:%d ", lf.lfWidth );
printf("lfEscapement:%d ", lf.lfEscapement );
printf("lfOrientation:%d ", lf.lfOrientation );
printf("lfWeight:%d ", lf.lfWeight );
printf("lfItalic:0x%2.2X ", lf.lfItalic );
printf("lfUnderline:0x%2.2X ", lf.lfUnderline );
printf("lfStrikeOut:0x%2.2X ", lf.lfStrikeOut );
printf("lfCharSet:0x%2.2X ", lf.lfCharSet );
printf("lfOutPrecision:0x%2.2X ", lf.lfOutPrecision );
printf("lfClipPrecision:0x%2.2X ", lf.lfClipPrecision );
printf("lfQuality:0x%2.2X ", lf.lfQuality );
printf("lfPitchAndFamily:0x%2.2X ", lf.lfPitchAndFamily);
string = U_Utf16leToUtf8(lf.lfFaceName, U_LF_FACESIZE, NULL);
printf("lfFaceName:%s ", string );
free(string);
}
/**
\brief Print a U_LOGFONT_PANOSE object.
\return U_LOGFONT_PANOSE object
*/
void logfont_panose_print(
U_LOGFONT_PANOSE lfp
){
char *string;
printf("elfLogFont:"); logfont_print(lfp.elfLogFont);
string = U_Utf16leToUtf8(lfp.elfFullName, U_LF_FULLFACESIZE, NULL);
printf("elfFullName:%s ", string );
free(string);
string = U_Utf16leToUtf8(lfp.elfStyle, U_LF_FACESIZE, NULL);
printf("elfStyle:%s ", string );
free(string);
printf("elfVersion:%u " ,lfp.elfVersion );
printf("elfStyleSize:%u " ,lfp.elfStyleSize);
printf("elfMatch:%u " ,lfp.elfMatch );
printf("elfReserved:%u " ,lfp.elfReserved );
printf("elfVendorId:"); hexbytes_print((uint8_t *)lfp.elfVendorId,U_ELF_VENDOR_SIZE); printf(" ");
printf("elfCulture:%u " ,lfp.elfCulture );
printf("elfPanose:"); panose_print(lfp.elfPanose);
}
/**
\brief Print a pointer to U_BITMAPINFOHEADER object.
This may be called indirectly from WMF _print routines, where problems could occur
if the data was passed as the struct or a pointer to the struct, as the struct may not
be aligned in memory.
\returns Actual number of color table entries.
\param Bmih pointer to a U_BITMAPINFOHEADER object
*/
int bitmapinfoheader_print(
const char *Bmih
){
uint32_t utmp4;
int32_t tmp4;
int16_t tmp2;
int Colors, BitCount, Width, Height, RealColors;
/* DIB from a WMF may not be properly aligned on a 4 byte boundary, will be aligned on a 2 byte boundary */
memcpy(&utmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biSize), 4); printf("biSize:%u " ,utmp4 );
memcpy(&tmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biWidth), 4); printf("biWidth:%d " ,tmp4 );
Width = tmp4;
memcpy(&tmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biHeight), 4); printf("biHeight:%d " ,tmp4 );
Height = tmp4;
memcpy(&tmp2, Bmih + offsetof(U_BITMAPINFOHEADER,biPlanes), 2); printf("biPlanes:%u " ,tmp2 );
memcpy(&tmp2, Bmih + offsetof(U_BITMAPINFOHEADER,biBitCount), 2); printf("biBitCount:%u " ,tmp2 );
BitCount = tmp2;
memcpy(&utmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biCompression), 4); printf("biCompression:%u " ,utmp4 );
memcpy(&utmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biSizeImage), 4); printf("biSizeImage:%u " ,utmp4 );
memcpy(&tmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biXPelsPerMeter), 4); printf("biXPelsPerMeter:%d " ,tmp4 );
memcpy(&tmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biYPelsPerMeter), 4); printf("biYPelsPerMeter:%d " ,tmp4 );
memcpy(&utmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biClrUsed), 4); printf("biClrUsed:%u " ,utmp4 );
Colors = utmp4;
memcpy(&utmp4, Bmih + offsetof(U_BITMAPINFOHEADER,biClrImportant), 4); printf("biClrImportant:%u " ,utmp4 );
RealColors = get_real_color_icount(Colors, BitCount, Width, Height);
printf("ColorEntries:%d ",RealColors);
return(RealColors);
}
/**
\brief Print a Pointer to a U_BITMAPINFO object.
\param Bmi Pointer to a U_BITMAPINFO object
\param blimit Pointer to the first byte after after this record
This may be called from WMF _print routines, where problems could occur
if the data was passed as the struct or a pointer to the struct, as the struct may not
be aligned in memory.
*/
void bitmapinfo_print(
const char *Bmi,
const char *blimit
){
int i,k;
int ClrUsed;
U_RGBQUAD BmiColor;
printf("BmiHeader: ");
IF_MEM_UNSAFE_PRINT_AND_RETURN(Bmi, offsetof(U_BITMAPINFO,bmiHeader) + sizeof(U_BITMAPINFOHEADER), blimit);
ClrUsed = bitmapinfoheader_print(Bmi + offsetof(U_BITMAPINFO,bmiHeader));
if(ClrUsed){
k= offsetof(U_BITMAPINFO,bmiColors);
IF_MEM_UNSAFE_PRINT_AND_RETURN(Bmi, offsetof(U_BITMAPINFO,bmiColors) + ClrUsed*sizeof(U_RGBQUAD), blimit);
for(i=0; i<ClrUsed; i++, k+= sizeof(U_RGBQUAD)){
memcpy(&BmiColor, Bmi+k, sizeof(U_RGBQUAD));
printf("%d:",i); rgbquad_print(BmiColor);
}
}
}
/**
\brief Print a U_BLEND object.
\param blend a U_BLEND object
*/
void blend_print(
U_BLEND blend
){
printf("Operation:%u " ,blend.Operation);
printf("Flags:%u " ,blend.Flags );
printf("Global:%u " ,blend.Global );
printf("Op:%u " ,blend.Op );
}
/**
\brief Print a pointer to a U_EXTLOGPEN object.
\param elp PU_EXTLOGPEN object
*/
void extlogpen_print(
PU_EXTLOGPEN elp
){
unsigned int i;
U_STYLEENTRY *elpStyleEntry;
printf("elpPenStyle:0x%8.8X " ,elp->elpPenStyle );
printf("elpWidth:%u " ,elp->elpWidth );
printf("elpBrushStyle:0x%8.8X " ,elp->elpBrushStyle);
printf("elpColor"); colorref_print(elp->elpColor);
printf("elpHatch:%d " ,elp->elpHatch );
printf("elpNumEntries:%u " ,elp->elpNumEntries);
if(elp->elpNumEntries){
printf("elpStyleEntry:");
elpStyleEntry = (uint32_t *) elp->elpStyleEntry;
for(i=0;i<elp->elpNumEntries;i++){
printf("%d:%u ",i,elpStyleEntry[i]);
}
}
}
/**
\brief Print a U_LOGPEN object.
\param lp U_LOGPEN object
*/
void logpen_print(
U_LOGPEN lp
){
printf("lopnStyle:0x%8.8X " ,lp.lopnStyle );
printf("lopnWidth:"); pointl_print( lp.lopnWidth );
printf("lopnColor:"); colorref_print(lp.lopnColor );
}
/**
\brief Print a U_LOGPLTNTRY object.
\param lpny Ignore U_LOGPLTNTRY object.
*/
void logpltntry_print(
U_LOGPLTNTRY lpny
){
printf("peReserved:%u " ,lpny.peReserved );
printf("peRed:%u " ,lpny.peRed );
printf("peGreen:%u " ,lpny.peGreen );
printf("peBlue:%u " ,lpny.peBlue );
}
/**
\brief Print a pointer to a U_LOGPALETTE object.
\param lp Pointer to a U_LOGPALETTE object.
*/
void logpalette_print(
PU_LOGPALETTE lp
){
int i;
PU_LOGPLTNTRY palPalEntry;
printf("palVersion:%u ", lp->palVersion );
printf("palNumEntries:%u ", lp->palNumEntries );
if(lp->palNumEntries){
palPalEntry = (PU_LOGPLTNTRY) &(lp->palPalEntry);
for(i=0;i<lp->palNumEntries;i++){
printf("%d:",i); logpltntry_print(palPalEntry[i]);
}
}
}
/**
\brief Print a U_RGNDATAHEADER object.
\param rdh U_RGNDATAHEADER object
*/
void rgndataheader_print(
U_RGNDATAHEADER rdh
){
printf("dwSize:%u ", rdh.dwSize );
printf("iType:%u ", rdh.iType );
printf("nCount:%u ", rdh.nCount );
printf("nRgnSize:%u ", rdh.nRgnSize );
printf("rclBounds:"); rectl_print(rdh.rclBounds );
}
/**
\brief Print a pointer to a U_RGNDATA object.
\param rd pointer to a U_RGNDATA object.
\param limit pointer that sets upper limit for data examination
*/
void rgndata_print(
PU_RGNDATA rd,
const char *blimit
){
unsigned int i;
PU_RECTL rects;
IF_MEM_UNSAFE_PRINT_AND_RETURN(rd, sizeof(U_RGNDATAHEADER), blimit);
printf("rdh: "); rgndataheader_print(rd->rdh ); printf(" rects: ");
if(rd->rdh.nCount){
rects = (PU_RECTL) &(rd->Buffer);
IF_MEM_UNSAFE_PRINT_AND_RETURN(rects, rd->rdh.nCount * sizeof(U_RECTL), blimit);
for(i=0;i<rd->rdh.nCount;i++){
printf("%d:",i); rectl_print(rects[i]);
}
}
}
/**
\brief Print a U_COLORADJUSTMENT object.
\param ca U_COLORADJUSTMENT object.
*/
void coloradjustment_print(
U_COLORADJUSTMENT ca
){
printf("caSize:%u " ,ca.caSize );
printf("caFlags:0x%4.4X " ,ca.caFlags );
printf("caIlluminantIndex:%u " ,ca.caIlluminantIndex);
printf("caRedGamma:%u " ,ca.caRedGamma );
printf("caGreenGamma:%u " ,ca.caGreenGamma );
printf("caBlueGamma:%u " ,ca.caBlueGamma );
printf("caReferenceBlack:%u " ,ca.caReferenceBlack );
printf("caReferenceWhite:%u " ,ca.caReferenceWhite );
printf("caContrast:%d " ,ca.caContrast );
printf("caBrightness:%d " ,ca.caBrightness );
printf("caColorfulness:%d " ,ca.caColorfulness );
printf("caRedGreenTint:%d " ,ca.caRedGreenTint );
}
/**
\brief Print a U_PIXELFORMATDESCRIPTOR object.
\param pfd U_PIXELFORMATDESCRIPTOR object
*/
void pixelformatdescriptor_print(
U_PIXELFORMATDESCRIPTOR pfd
){
printf("nSize:%u " ,pfd.nSize );
printf("nVersion:%u " ,pfd.nVersion );
printf("dwFlags:0x%8.8X " ,pfd.dwFlags );
printf("iPixelType:%u " ,pfd.iPixelType );
printf("cColorBits:%u " ,pfd.cColorBits );
printf("cRedBits:%u " ,pfd.cRedBits );
printf("cRedShift:%u " ,pfd.cRedShift );
printf("cGreenBits:%u " ,pfd.cGreenBits );
printf("cGreenShift:%u " ,pfd.cGreenShift );
printf("cBlueBits:%u " ,pfd.cBlueBits );
printf("cBlueShift:%u " ,pfd.cBlueShift );
printf("cAlphaBits:%u " ,pfd.cAlphaBits );
printf("cAlphaShift:%u " ,pfd.cAlphaShift );
printf("cAccumBits:%u " ,pfd.cAccumBits );
printf("cAccumRedBits:%u " ,pfd.cAccumRedBits );
printf("cAccumGreenBits:%u " ,pfd.cAccumGreenBits );
printf("cAccumBlueBits:%u " ,pfd.cAccumBlueBits );
printf("cAccumAlphaBits:%u " ,pfd.cAccumAlphaBits );
printf("cDepthBits:%u " ,pfd.cDepthBits );
printf("cStencilBits:%u " ,pfd.cStencilBits );
printf("cAuxBuffers:%u " ,pfd.cAuxBuffers );
printf("iLayerType:%u " ,pfd.iLayerType );
printf("bReserved:%u " ,pfd.bReserved );
printf("dwLayerMask:%u " ,pfd.dwLayerMask );
printf("dwVisibleMask:%u " ,pfd.dwVisibleMask );
printf("dwDamageMask:%u " ,pfd.dwDamageMask );
}
/**
\brief Print a Pointer to a U_EMRTEXT record
\param emt Pointer to a U_EMRTEXT record
\param record Pointer to the start of the record which contains this U_ERMTEXT
\param blimit Pointer to the first byte after after this record
\param type 0 for 8 bit character, anything else for 16
*/
void emrtext_print(
const char *emt,
const char *record,
const char *blimit,
int type
){
unsigned int i,off;
char *string;
PU_EMRTEXT pemt = (PU_EMRTEXT) emt;
// constant part
printf("ptlReference:"); pointl_print(pemt->ptlReference);
printf("nChars:%u " ,pemt->nChars );
printf("offString:%u " ,pemt->offString );
if(pemt->offString){
if(!type){
IF_MEM_UNSAFE_PRINT_AND_RETURN(record, pemt->offString + pemt->nChars*sizeof(char), blimit);
printf("string8:<%s> ",record + pemt->offString);
}
else {
IF_MEM_UNSAFE_PRINT_AND_RETURN(record, pemt->offString + pemt->nChars*2*sizeof(char), blimit);
string = U_Utf16leToUtf8((uint16_t *)(record + pemt->offString), pemt->nChars, NULL);
printf("string16:<%s> ",string);
free(string);
}
}
printf("fOptions:0x%8.8X " ,pemt->fOptions );
off = sizeof(U_EMRTEXT);
if(!(pemt->fOptions & U_ETO_NO_RECT)){
printf("rcl"); rectl_print( *((U_RECTL *)(emt+off)) );
off += sizeof(U_RECTL);
}
printf("offDx:%u " , *((U_OFFDX *)(emt+off)) ); off = *(U_OFFDX *)(emt+off);
printf("Dx:");
for(i=0; i<pemt->nChars; i++, off+=sizeof(uint32_t)){
printf("%d:", *((uint32_t *)(record+off)) );
}
}
// hide these from Doxygen
//! @cond
/* **********************************************************************************************
These functions contain shared code used by various U_EMR*_print functions. These should NEVER be called
by end user code and to further that end prototypes are NOT provided and they are hidden from Doxygen.
These are (mostly) ordered by U_EMR_* index number.
The exceptions:
void core3_print(const char *name, const char *label, const char *contents)
void core7_print(const char *name, const char *field1, const char *field2, const char *contents)
void core8_print(const char *name, const char *contents, int type)
*********************************************************************************************** */
// Functions with the same form starting with U_EMRPOLYBEZIER_print
void core1_print(const char *name, const char *contents){
unsigned int i;
UNUSED(name);
PU_EMRPOLYLINETO pEmr = (PU_EMRPOLYLINETO) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRPOLYBEZIER)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" cptl: %d\n",pEmr->cptl );
printf(" Points: ");
IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->aptl, pEmr->cptl*sizeof(U_POINTL), blimit);
for(i=0;i<pEmr->cptl; i++){
printf("[%d]:",i); pointl_print(pEmr->aptl[i]);
}
printf("\n");
}
// Functions with the same form starting with U_EMRPOLYPOLYLINE_print
void core2_print(const char *name, const char *contents){
unsigned int i;
UNUSED(name);
PU_EMRPOLYPOLYGON pEmr = (PU_EMRPOLYPOLYGON) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRPOLYPOLYGON)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" nPolys: %d\n",pEmr->nPolys );
printf(" cptl: %d\n",pEmr->cptl );
printf(" Counts: ");
IF_MEM_UNSAFE_PRINT_AND_RETURN(pEmr->aPolyCounts, pEmr->nPolys*sizeof(U_POLYCOUNTS), blimit);
for(i=0;i<pEmr->nPolys; i++){
printf(" [%d]:%d ",i,pEmr->aPolyCounts[i] );
}
printf("\n");
PU_POINTL paptl = (PU_POINTL)((char *)pEmr->aPolyCounts + sizeof(uint32_t)* pEmr->nPolys);
printf(" Points: ");
IF_MEM_UNSAFE_PRINT_AND_RETURN(paptl, pEmr->cptl*sizeof(U_POINTL), blimit);
for(i=0;i<pEmr->cptl; i++){
printf(" [%d]:",i); pointl_print(paptl[i]);
}
printf("\n");
}
// Functions with the same form starting with U_EMRSETMAPMODE_print
void core3_print(const char *name, const char *label, const char *contents){
UNUSED(name);
/* access violation is impossible for these because there are no counts or offsets */
PU_EMRSETMAPMODE pEmr = (PU_EMRSETMAPMODE)(contents);
if(pEmr->emr.nSize < sizeof(U_EMRSETMAPMODE)){
printf(" record corruption HERE\n");
return;
}
if(!strcmp(label,"crColor:")){
printf(" %-15s ",label); colorref_print(*(U_COLORREF *)&(pEmr->iMode)); printf("\n");
}
else if(!strcmp(label,"iMode:")){
printf(" %-15s 0x%8.8X\n",label,pEmr->iMode );
}
else {
printf(" %-15s %d\n",label,pEmr->iMode );
}
}
// Functions taking a single U_RECT or U_RECTL, starting with U_EMRELLIPSE_print, also U_EMRFILLPATH_print,
void core4_print(const char *name, const char *contents){
UNUSED(name);
PU_EMRELLIPSE pEmr = (PU_EMRELLIPSE)( contents);
if(pEmr->emr.nSize < sizeof(U_EMRELLIPSE)){
printf(" record corruption HERE\n");
return;
}
printf(" rclBox: "); rectl_print(pEmr->rclBox); printf("\n");
}
// Functions with the same form starting with U_EMRPOLYBEZIER16_print
void core6_print(const char *name, const char *contents){
UNUSED(name);
unsigned int i;
PU_EMRPOLYBEZIER16 pEmr = (PU_EMRPOLYBEZIER16) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRPOLYBEZIER16)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" cpts: %d\n",pEmr->cpts );
printf(" Points: ");
PU_POINT16 papts = (PU_POINT16)(&(pEmr->apts));
IF_MEM_UNSAFE_PRINT_AND_RETURN(papts, pEmr->cpts*sizeof(U_POINT16), blimit);
for(i=0; i<pEmr->cpts; i++){
printf(" [%d]:",i); point16_print(papts[i]);
}
printf("\n");
}
// Records with the same form starting with U_EMRSETWINDOWEXTEX_print
// CAREFUL, in the _set equivalents all functions with two uint32_t values are mapped here, and member names differ, consequently
// print routines must supply the names of the two arguments. These cannot be null. If the second one is
// empty the values are printed as a pair {x,y}, otherwise each is printed with its own label on a separate line.
void core7_print(const char *name, const char *field1, const char *field2, const char *contents){
UNUSED(name);
PU_EMRGENERICPAIR pEmr = (PU_EMRGENERICPAIR) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRGENERICPAIR)){
printf(" record corruption HERE\n");
return;
}
if(*field2){
printf(" %-15s %d\n",field1,pEmr->pair.x);
printf(" %-15s %d\n",field2,pEmr->pair.y);
}
else {
printf(" %-15s {%d,%d}\n",field1,pEmr->pair.x,pEmr->pair.y);
}
}
// For U_EMREXTTEXTOUTA and U_EMREXTTEXTOUTW, type=0 for the first one
void core8_print(const char *name, const char *contents, int type){
UNUSED(name);
PU_EMREXTTEXTOUTA pEmr = (PU_EMREXTTEXTOUTA) (contents);
const char *blimit = contents + pEmr->emr.nSize;
printf(" iGraphicsMode: %u\n",pEmr->iGraphicsMode );
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" exScale: %f\n",pEmr->exScale );
printf(" eyScale: %f\n",pEmr->eyScale );
printf(" emrtext: ");
emrtext_print(contents + sizeof(U_EMREXTTEXTOUTA) - sizeof(U_EMRTEXT),contents,blimit,type);
printf("\n");
}
// Functions that take a rect and a pair of points, starting with U_EMRARC_print
void core9_print(const char *name, const char *contents){
UNUSED(name);
PU_EMRARC pEmr = (PU_EMRARC) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRARC)){
printf(" record corruption HERE\n");
return;
}
printf(" rclBox: "); rectl_print(pEmr->rclBox); printf("\n");
printf(" ptlStart: "); pointl_print(pEmr->ptlStart); printf("\n");
printf(" ptlEnd: "); pointl_print(pEmr->ptlEnd); printf("\n");
}
// Functions with the same form starting with U_EMRPOLYPOLYLINE16_print
void core10_print(const char *name, const char *contents){
UNUSED(name);
unsigned int i;
PU_EMRPOLYPOLYLINE16 pEmr = (PU_EMRPOLYPOLYLINE16) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRPOLYPOLYLINE16)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" nPolys: %d\n",pEmr->nPolys );
printf(" cpts: %d\n",pEmr->cpts );
printf(" Counts: ");
IF_MEM_UNSAFE_PRINT_AND_RETURN(&(pEmr->aPolyCounts), pEmr->nPolys*sizeof(U_POLYCOUNTS), blimit);
for(i=0;i<pEmr->nPolys; i++){
printf(" [%d]:%d ",i,pEmr->aPolyCounts[i] );
}
printf("\n");
printf(" Points: ");
PU_POINT16 papts = (PU_POINT16)((char *)pEmr->aPolyCounts + pEmr->nPolys*sizeof(U_POLYCOUNTS) );
IF_MEM_UNSAFE_PRINT_AND_RETURN(papts, pEmr->cpts*sizeof(U_POINT16), blimit);
for(i=0; i<pEmr->cpts; i++){
printf(" [%d]:",i); point16_print(papts[i]);
}
printf("\n");
}
// Functions with the same form starting with U_EMRINVERTRGN_print and U_EMRPAINTRGN_print,
void core11_print(const char *name, const char *contents){
UNUSED(name);
PU_EMRINVERTRGN pEmr = (PU_EMRINVERTRGN) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRINVERTRGN)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print(pEmr->rclBounds); printf("\n");
printf(" cbRgnData: %d\n",pEmr->cbRgnData);
printf(" RegionData:");
const char *minptr = MAKE_MIN_PTR(((const char *) &pEmr->RgnData + pEmr->cbRgnData),blimit);
rgndata_print(pEmr->RgnData, minptr);
printf("\n");
}
// common code for U_EMRCREATEMONOBRUSH_print and U_EMRCREATEDIBPATTERNBRUSHPT_print,
void core12_print(const char *name, const char *contents){
UNUSED(name);
PU_EMRCREATEMONOBRUSH pEmr = (PU_EMRCREATEMONOBRUSH) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRCREATEMONOBRUSH)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" ihBrush: %u\n",pEmr->ihBrush );
printf(" iUsage : %u\n",pEmr->iUsage );
printf(" offBmi : %u\n",pEmr->offBmi );
printf(" cbBmi : %u\n",pEmr->cbBmi );
if(pEmr->cbBmi){
printf(" bitmap:");
bitmapinfo_print(contents + pEmr->offBmi, blimit);
printf("\n");
}
printf(" offBits: %u\n",pEmr->offBits );
printf(" cbBits : %u\n",pEmr->cbBits );
}
// common code for U_EMRALPHABLEND_print and U_EMRTRANSPARENTBLT_print,
void core13_print(const char *name, const char *contents){
UNUSED(name);
PU_EMRALPHABLEND pEmr = (PU_EMRALPHABLEND) (contents);
if(pEmr->emr.nSize < sizeof(U_EMRALPHABLEND)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n");
printf(" Dest: "); pointl_print(pEmr->Dest); printf("\n");
printf(" cDest: "); pointl_print(pEmr->cDest); printf("\n");
printf(" Blend: "); blend_print(pEmr->Blend); printf("\n");
printf(" Src: "); pointl_print(pEmr->Src); printf("\n");
printf(" xformSrc: "); xform_print( pEmr->xformSrc); printf("\n");
printf(" crBkColorSrc: "); colorref_print( pEmr->crBkColorSrc); printf("\n");
printf(" iUsageSrc: %u\n",pEmr->iUsageSrc );
printf(" offBmiSrc: %u\n",pEmr->offBmiSrc );
printf(" cbBmiSrc: %u\n",pEmr->cbBmiSrc );
if(pEmr->cbBmiSrc){
printf(" bitmap:");
bitmapinfo_print(contents + pEmr->offBmiSrc, blimit);
printf("\n");
}
printf(" offBitsSrc: %u\n",pEmr->offBitsSrc );
printf(" cbBitsSrc: %u\n",pEmr->cbBitsSrc );
}
//! @endcond
/* **********************************************************************************************
These are the core EMR functions, each creates a particular type of record.
All return these records via a char* pointer, which is NULL if the call failed.
They are listed in order by the corresponding U_EMR_* index number.
*********************************************************************************************** */
/**
\brief Print a pointer to a U_EMR_whatever record which has not been implemented.
\param name name of this type of record
\param contents pointer to a buffer holding all EMR records
*/
void U_EMRNOTIMPLEMENTED_print(const char *name, const char *contents){
UNUSED(name);
UNUSED(contents);
printf(" Not Implemented!\n");
}
// U_EMRHEADER 1
/**
\brief Print a pointer to a U_EMR_HEADER record.
\param contents pointer to a buffer holding all EMR records
*/
void U_EMRHEADER_print(const char *contents){
char *string;
int p1len;
PU_EMRHEADER pEmr = (PU_EMRHEADER)(contents);
if(pEmr->emr.nSize < sizeof(U_EMRHEADER)){
printf(" record corruption HERE\n");
return;
}
const char *blimit = contents + pEmr->emr.nSize;
printf(" rclBounds: "); rectl_print( pEmr->rclBounds); printf("\n");
printf(" rclFrame: "); rectl_print( pEmr->rclFrame); printf("\n");
printf(" dSignature: 0x%8.8X\n", pEmr->dSignature );
printf(" nVersion: 0x%8.8X\n", pEmr->nVersion );
printf(" nBytes: %d\n", pEmr->nBytes );
printf(" nRecords: %d\n", pEmr->nRecords );
printf(" nHandles: %d\n", pEmr->nHandles );
printf(" sReserved: %d\n", pEmr->sReserved );
printf(" nDescription: %d\n", pEmr->nDescription );
printf(" offDescription: %d\n", pEmr->offDescription);
if(pEmr->offDescription){
IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->offDescription + pEmr->nDescription*2*sizeof(char), blimit);
string = U_Utf16leToUtf8((uint16_t *)((char *) pEmr + pEmr->offDescription), pEmr->nDescription, NULL);
printf(" Desc. A: %s\n",string);
free(string);
p1len = 2 + 2*wchar16len((uint16_t *)((char *) pEmr + pEmr->offDescription));
string = U_Utf16leToUtf8((uint16_t *)((char *) pEmr + pEmr->offDescription + p1len), pEmr->nDescription, NULL);
printf(" Desc. B: %s\n",string);
free(string);
}
printf(" nPalEntries: %d\n", pEmr->nPalEntries );
printf(" szlDevice: {%d,%d} \n", pEmr->szlDevice.cx,pEmr->szlDevice.cy);
printf(" szlMillimeters: {%d,%d} \n", pEmr->szlMillimeters.cx,pEmr->szlMillimeters.cy);
if((pEmr->nDescription && (pEmr->offDescription >= 100)) ||
(!pEmr->offDescription && pEmr->emr.nSize >= 100)
){
printf(" cbPixelFormat: %d\n", pEmr->cbPixelFormat );
printf(" offPixelFormat: %d\n", pEmr->offPixelFormat);
if(pEmr->cbPixelFormat){
printf(" PFD:");
IF_MEM_UNSAFE_PRINT_AND_RETURN(contents, pEmr->offPixelFormat + sizeof(U_PIXELFORMATDESCRIPTOR), blimit);
pixelformatdescriptor_print( *(PU_PIXELFORMATDESCRIPTOR) (contents + pEmr->offPixelFormat));
printf("\n");
}
printf(" bOpenGL: %d\n",pEmr->bOpenGL );
if((pEmr->nDescription && (pEmr->offDescription >= 108)) ||
(pEmr->cbPixelFormat && (pEmr->offPixelFormat >=108)) ||
(!pEmr->offDescription && !pEmr->cbPixelFormat && pEmr->emr.nSize >= 108)
){
printf(" szlMicrometers: {%d,%d} \n", pEmr->szlMicrometers.cx,pEmr->szlMicrometers.cy);
}
}
}
// U_EMRPOLYBEZIER 2
/**
\brief Print a pointer to a U_EMR_POLYBEZIER record.
\param contents pointer to a buffer holding all EMR records
*/
void U_EMRPOLYBEZIER_print(const char *contents){
core1_print("U_EMRPOLYBEZIER", contents);
}
// U_EMRPOLYGON 3
/**
\brief Print a pointer to a U_EMR_POLYGON record.
\param contents pointer to a buffer holding all EMR records
*/
void U_EMRPOLYGON_print(const char *contents){
core1_print("U_EMRPOLYGON", contents);
}