-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupmf_print.c
3400 lines (3186 loc) · 126 KB
/
upmf_print.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
/**
@file upmf_print.c
@brief Functions for printing EMF records
*/
/*
File: upmf_print.c
Version: 0.0.8
Date: 26-JAN-2016
Author: David Mathog, Biology Division, Caltech
email: [email protected]
Copyright: 2016 David Mathog and California Institute of Technology (Caltech)
*/
/* compiler options:
-DNOBRUSH causes brush objects to be treated as pen objects. PowerPoint 2003 and 2010 define pen objects
as brush objects, and this is one way to see their structure even though they are misidentified.
This option should only be used for tiny test files, consisting of just line objects.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h> /* for offsetof() macro */
#include <string.h>
#include "upmf_print.h"
#include "uemf_print.h"
#include "uemf_safe.h"
//! \cond
#define UNUSED(x) (void)(x) //! Please ignore - Doxygen simply insisted on including this
/*
this function is not visible in the API. Print "data" for one of the many records that has none.
*/
int U_PMR_NODATAREC_print(const char *contents){
U_PMF_CMN_HDR Header;
int status = U_PMR_RESETCLIP_get(contents,&Header); /* One of many possibilities */
if(status)status = Header.Size;
return(status);
}
/*
this function is not visible in the API. Common routine used by many functions that draw points.
*/
void U_PMF_VARPOINTS_print(const char **contents, int Flags, uint32_t Elements, const char *blimit){
unsigned int i;
U_FLOAT Xpos, Ypos;
if( Flags & U_PPF_P){ printf(" + Points(Relative):"); }
else if(Flags & U_PPF_C){ printf(" + Points(Int16):"); }
else { printf(" + Points(Float):"); }
for(Xpos = Ypos = i = 0; i<Elements; i++){
printf(" %d:",i);
if( Flags & U_PPF_P){ (void) U_PMF_POINTR_print(contents, &Xpos, &Ypos, blimit); }
else if(Flags & U_PPF_C){ (void) U_PMF_POINT_print(contents, blimit); }
else { (void) U_PMF_POINTF_print(contents, blimit); }
}
#if 0
int residual;
uintptr_t holdptr = (uintptr_t) *contents;
residual = holdptr & 0x3;
if(residual){ *contents += (4-residual); }
printf("DEBUG U_PMF_VARPOINTS_print residual:%d *contents:%p\n",residual,*contents);fflush(stdout);
#endif
printf("\n");
}
/*
this function is not visible in the API. Common routine used by many functions that draw points.
*/
void U_PMF_VARPOINTF_S_print(U_PMF_POINTF *Points, uint32_t Elements){
unsigned int i;
printf(" + Points:");
for(i=0; i<Elements; i++, Points++){
printf(" %d:",i);
(void) U_PMF_POINTF_S_print(Points);
}
printf("\n");
}
/*
this function is not visible in the API. Common routine used by many functions that draw rectangles.
*/
int U_PMF_VARRECTF_S_print(U_PMF_RECTF *Rects, uint32_t Elements){
if(!Elements)return(0);
if(Elements == 1){ printf(" Rect(Float):"); }
else { printf(" Rects(Float):"); }
while(1){
U_PMF_RECTF_S_print(Rects++);
Elements--;
if(!Elements)break;
printf(" ");
}
return(1);
}
/*
this function is not visible in the API. Common routine used by many functions.
*/
int U_PMF_VARBRUSHID_print(int btype, uint32_t BrushID){
if(btype){
printf(" Color:");
(void) U_PMF_ARGB_print((char *)&(BrushID));
}
else {
printf(" BrushID:%u",BrushID);
}
return(1);
}
//! \endcond
/**
\brief Print any EMF+ record
\returns record length for a normal record, 0 for EMREOF or , -1 for a bad record
\param contents pointer to a buffer holding this EMF+ record
\param blimit one byte after this EMF+ record
\param recnum EMF number of this record in contents
\param off Offset from the beginning of the EMF+ file to the start of this record.
*/
int U_pmf_onerec_print(const char *contents, const char *blimit, int recnum, int off){
int status;
int rstatus;
static U_OBJ_ACCUM ObjCont={NULL,0,0,0,0}; /* for keeping track of object continuation. These may
be split across multiple EMF Comment records */
U_PMF_CMN_HDR Header;
const char *contemp = contents;
/* Check that COMMON header data in record can be touched without an access violation. If it cannot be
this is either a corrupt EMF or one engineered to cause a buffer overflow. Pointer math
could wrap so check both sides of the range.
*/
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CMN_HDR), blimit))return(-1);
if(!U_PMF_CMN_HDR_get(&contemp, &Header)){return(-1);}
int type = Header.Type & U_PMR_TYPE_MASK; /* strip the U_PMR_RECFLAG bit, leaving the indexable part */
if(type < U_PMR_MIN || type > U_PMR_MAX)return(-1); /* unknown EMF+ record type */
status = U_PMF_CMN_HDR_print(contents, Header, recnum, off); /* EMF+ part */
/* Buggy EMF+ can set the continue bit and then do something else. In that case, force out the pending
Object. Side effect - clears the pending object. */
if((type != U_PMR_OBJECT) && (ObjCont.used > 0)){
U_PMR_OBJECT_print(contents, blimit, &ObjCont, 1);
}
/* Check that the record size is OK, abort if not. */
if(Header.Size < sizeof(U_PMF_CMN_HDR) ||
IS_MEM_UNSAFE(contents, Header.Size, blimit))return(-1);
switch(type){
case (U_PMR_HEADER): rstatus = U_PMR_HEADER_print(contents); break;
case (U_PMR_ENDOFFILE): rstatus = U_PMR_ENDOFFILE_print(contents);
U_OA_release(&ObjCont); break;
case (U_PMR_COMMENT): rstatus = U_PMR_COMMENT_print(contents); break;
case (U_PMR_GETDC): rstatus = U_PMR_GETDC_print(contents); break;
case (U_PMR_MULTIFORMATSTART): rstatus = U_PMR_MULTIFORMATSTART_print(contents); break;
case (U_PMR_MULTIFORMATSECTION): rstatus = U_PMR_MULTIFORMATSECTION_print(contents); break;
case (U_PMR_MULTIFORMATEND): rstatus = U_PMR_MULTIFORMATEND_print(contents); break;
case (U_PMR_OBJECT): rstatus = U_PMR_OBJECT_print(contents,blimit,&ObjCont,0); break;
case (U_PMR_CLEAR): rstatus = U_PMR_CLEAR_print(contents); break;
case (U_PMR_FILLRECTS): rstatus = U_PMR_FILLRECTS_print(contents); break;
case (U_PMR_DRAWRECTS): rstatus = U_PMR_DRAWRECTS_print(contents); break;
case (U_PMR_FILLPOLYGON): rstatus = U_PMR_FILLPOLYGON_print(contents); break;
case (U_PMR_DRAWLINES): rstatus = U_PMR_DRAWLINES_print(contents); break;
case (U_PMR_FILLELLIPSE): rstatus = U_PMR_FILLELLIPSE_print(contents); break;
case (U_PMR_DRAWELLIPSE): rstatus = U_PMR_DRAWELLIPSE_print(contents); break;
case (U_PMR_FILLPIE): rstatus = U_PMR_FILLPIE_print(contents); break;
case (U_PMR_DRAWPIE): rstatus = U_PMR_DRAWPIE_print(contents); break;
case (U_PMR_DRAWARC): rstatus = U_PMR_DRAWARC_print(contents); break;
case (U_PMR_FILLREGION): rstatus = U_PMR_FILLREGION_print(contents); break;
case (U_PMR_FILLPATH): rstatus = U_PMR_FILLPATH_print(contents); break;
case (U_PMR_DRAWPATH): rstatus = U_PMR_DRAWPATH_print(contents); break;
case (U_PMR_FILLCLOSEDCURVE): rstatus = U_PMR_FILLCLOSEDCURVE_print(contents); break;
case (U_PMR_DRAWCLOSEDCURVE): rstatus = U_PMR_DRAWCLOSEDCURVE_print(contents); break;
case (U_PMR_DRAWCURVE): rstatus = U_PMR_DRAWCURVE_print(contents); break;
case (U_PMR_DRAWBEZIERS): rstatus = U_PMR_DRAWBEZIERS_print(contents); break;
case (U_PMR_DRAWIMAGE): rstatus = U_PMR_DRAWIMAGE_print(contents); break;
case (U_PMR_DRAWIMAGEPOINTS): rstatus = U_PMR_DRAWIMAGEPOINTS_print(contents); break;
case (U_PMR_DRAWSTRING): rstatus = U_PMR_DRAWSTRING_print(contents); break;
case (U_PMR_SETRENDERINGORIGIN): rstatus = U_PMR_SETRENDERINGORIGIN_print(contents); break;
case (U_PMR_SETANTIALIASMODE): rstatus = U_PMR_SETANTIALIASMODE_print(contents); break;
case (U_PMR_SETTEXTRENDERINGHINT): rstatus = U_PMR_SETTEXTRENDERINGHINT_print(contents); break;
case (U_PMR_SETTEXTCONTRAST): rstatus = U_PMR_SETTEXTCONTRAST_print(contents); break;
case (U_PMR_SETINTERPOLATIONMODE): rstatus = U_PMR_SETINTERPOLATIONMODE_print(contents); break;
case (U_PMR_SETPIXELOFFSETMODE): rstatus = U_PMR_SETPIXELOFFSETMODE_print(contents); break;
case (U_PMR_SETCOMPOSITINGMODE): rstatus = U_PMR_SETCOMPOSITINGMODE_print(contents); break;
case (U_PMR_SETCOMPOSITINGQUALITY): rstatus = U_PMR_SETCOMPOSITINGQUALITY_print(contents); break;
case (U_PMR_SAVE): rstatus = U_PMR_SAVE_print(contents); break;
case (U_PMR_RESTORE): rstatus = U_PMR_RESTORE_print(contents); break;
case (U_PMR_BEGINCONTAINER): rstatus = U_PMR_BEGINCONTAINER_print(contents); break;
case (U_PMR_BEGINCONTAINERNOPARAMS): rstatus = U_PMR_BEGINCONTAINERNOPARAMS_print(contents); break;
case (U_PMR_ENDCONTAINER): rstatus = U_PMR_ENDCONTAINER_print(contents); break;
case (U_PMR_SETWORLDTRANSFORM): rstatus = U_PMR_SETWORLDTRANSFORM_print(contents); break;
case (U_PMR_RESETWORLDTRANSFORM): rstatus = U_PMR_RESETWORLDTRANSFORM_print(contents); break;
case (U_PMR_MULTIPLYWORLDTRANSFORM): rstatus = U_PMR_MULTIPLYWORLDTRANSFORM_print(contents); break;
case (U_PMR_TRANSLATEWORLDTRANSFORM): rstatus = U_PMR_TRANSLATEWORLDTRANSFORM_print(contents); break;
case (U_PMR_SCALEWORLDTRANSFORM): rstatus = U_PMR_SCALEWORLDTRANSFORM_print(contents); break;
case (U_PMR_ROTATEWORLDTRANSFORM): rstatus = U_PMR_ROTATEWORLDTRANSFORM_print(contents); break;
case (U_PMR_SETPAGETRANSFORM): rstatus = U_PMR_SETPAGETRANSFORM_print(contents); break;
case (U_PMR_RESETCLIP): rstatus = U_PMR_RESETCLIP_print(contents); break;
case (U_PMR_SETCLIPRECT): rstatus = U_PMR_SETCLIPRECT_print(contents); break;
case (U_PMR_SETCLIPPATH): rstatus = U_PMR_SETCLIPPATH_print(contents); break;
case (U_PMR_SETCLIPREGION): rstatus = U_PMR_SETCLIPREGION_print(contents); break;
case (U_PMR_OFFSETCLIP): rstatus = U_PMR_OFFSETCLIP_print(contents); break;
case (U_PMR_DRAWDRIVERSTRING): rstatus = U_PMR_DRAWDRIVERSTRING_print(contents); break;
case (U_PMR_STROKEFILLPATH): rstatus = U_PMR_STROKEFILLPATH_print(contents); break;
case (U_PMR_SERIALIZABLEOBJECT): rstatus = U_PMR_SERIALIZABLEOBJECT_print(contents); break;
case (U_PMR_SETTSGRAPHICS): rstatus = U_PMR_SETTSGRAPHICS_print(contents); break;
case (U_PMR_SETTSCLIP): rstatus = U_PMR_SETTSCLIP_print(contents); break;
}
if(!rstatus)status=-1;
return(status);
}
/**
\brief Print data from a U_PMF_CMN_HDR object
\return number of bytes in record, 0 on error
\param contents pointer to a buffer holding this EMF+ record
\param Header Header of the record
\param precnum EMF+ record number in file.
\param off Offset in file to the start of this EMF+ record.
common structure present at the beginning of all(*) EMF+ records
*/
int U_PMF_CMN_HDR_print(const char *contents, U_PMF_CMN_HDR Header, int precnum, int off){
printf(" %-29srec+:%5d type:%X offset:%8d rsize:%8u dsize:%8u flags:%4.4X crc32:%8.8X\n",
U_pmr_names(Header.Type &U_PMR_TYPE_MASK),precnum, Header.Type,off,Header.Size,Header.DataSize,Header.Flags,
lu_crc32(contents,Header.Size));
return((int) Header.Size);
}
/**
\brief Print data from a an array of uint8_t values
\return 1
\param Start Text to lead array data
\param Array uint8_t array of data passed as char *
\param Elements Number of elements in Array
\param End Text to follow array data
*/
int U_PMF_UINT8_ARRAY_print(const char *Start, const uint8_t *Array, int Elements, char *End){
if(Start)printf("%s",Start);
for(; Elements--; Array++){ printf(" %u", *Array); }
if(End)printf("%s",End);
return(1);
}
/**
\brief Print value of an BrushType Enumeration
\returns record 1 on sucess, 0 on error
\param otype Value to print.
EMF+ manual 2.1.1.3, Microsoft name: BrushType Enumeration
*/
int U_PMF_BRUSHTYPEENUMERATION_print(int otype){
int status=1;
switch(otype){
case U_BT_SolidColor: printf("SolidColor"); break;
case U_BT_HatchFill: printf("HatchFill"); break;
case U_BT_TextureFill: printf("TextureFill"); break;
case U_BT_PathGradient: printf("PathGradient"); break;
case U_BT_LinearGradient: printf("LinearGradient"); break;
default: status=0; printf("INVALID(%d)",otype); break;
}
return(status);
}
/**
\brief Print value of an BrushType Enumeration
\returns record 1 on sucess, 0 on error
\param otype Value to print.
EMF+ manual 2.1.1.4, Microsoft name: BrushType Enumeration
*/
int U_PMF_COMBINEMODEENUMERATION_print(int otype){
int status=1;
switch(otype){
case U_CM_Replace: printf("Replace" ); break;
case U_CM_Intersect: printf("Intersect" ); break;
case U_CM_Union: printf("Union" ); break;
case U_CM_XOR: printf("XOR" ); break;
case U_CM_Exclude: printf("Exclude" ); break;
case U_CM_Complement: printf("Complement"); break;
default: status=0; printf("INVALID(%d)",otype); break;
}
return(status);
}
/**
\brief Print value of a HatchStyle Enumeration
\returns record 1 on sucess, 0 on error
\param hstype Value to print.
EMF+ manual 2.1.1.13, Microsoft name: HatchStyle Enumeration
*/
int U_PMF_HATCHSTYLEENUMERATION_print(int hstype){
int status=1;
switch(hstype){
case U_HSP_Horizontal: printf("Horizontal"); break;
case U_HSP_Vertical: printf("Vertical"); break;
case U_HSP_ForwardDiagonal: printf("ForwardDiagonal"); break;
case U_HSP_BackwardDiagonal: printf("BackwardDiagonal"); break;
case U_HSP_LargeGrid: printf("LargeGrid"); break;
case U_HSP_DiagonalCross: printf("DiagonalCross"); break;
case U_HSP_05Percent: printf("05Percent"); break;
case U_HSP_10Percent: printf("10Percent"); break;
case U_HSP_20Percent: printf("20Percent"); break;
case U_HSP_25Percent: printf("25Percent"); break;
case U_HSP_30Percent: printf("30Percent"); break;
case U_HSP_40Percent: printf("40Percent"); break;
case U_HSP_50Percent: printf("50Percent"); break;
case U_HSP_60Percent: printf("60Percent"); break;
case U_HSP_70Percent: printf("70Percent"); break;
case U_HSP_75Percent: printf("75Percent"); break;
case U_HSP_80Percent: printf("80Percent"); break;
case U_HSP_90Percent: printf("90Percent"); break;
case U_HSP_LightDownwardDiagonal: printf("LightDownwardDiagonal"); break;
case U_HSP_LightUpwardDiagonal: printf("LightUpwardDiagonal"); break;
case U_HSP_DarkDownwardDiagonal: printf("DarkDownwardDiagonal"); break;
case U_HSP_DarkUpwardDiagonal: printf("DarkUpwardDiagonal"); break;
case U_HSP_WideDownwardDiagonal: printf("WideDownwardDiagonal"); break;
case U_HSP_WideUpwardDiagonal: printf("WideUpwardDiagonal"); break;
case U_HSP_LightVertical: printf("LightVertical"); break;
case U_HSP_LightHorizontal: printf("LightHorizontal"); break;
case U_HSP_NarrowVertical: printf("NarrowVertical"); break;
case U_HSP_NarrowHorizontal: printf("NarrowHorizontal"); break;
case U_HSP_DarkVertical: printf("DarkVertical"); break;
case U_HSP_DarkHorizontal: printf("DarkHorizontal"); break;
case U_HSP_DashedDownwardDiagonal: printf("DashedDownwardDiagonal"); break;
case U_HSP_DashedUpwardDiagonal: printf("DashedUpwardDiagonal"); break;
case U_HSP_DashedHorizontal: printf("DashedHorizontal"); break;
case U_HSP_DashedVertical: printf("DashedVertical"); break;
case U_HSP_SmallConfetti: printf("SmallConfetti"); break;
case U_HSP_LargeConfetti: printf("LargeConfetti"); break;
case U_HSP_ZigZag: printf("ZigZag"); break;
case U_HSP_Wave: printf("Wave"); break;
case U_HSP_DiagonalBrick: printf("DiagonalBrick"); break;
case U_HSP_HorizontalBrick: printf("HorizontalBrick"); break;
case U_HSP_Weave: printf("Weave"); break;
case U_HSP_Plaid: printf("Plaid"); break;
case U_HSP_Divot: printf("Divot"); break;
case U_HSP_DottedGrid: printf("DottedGrid"); break;
case U_HSP_DottedDiamond: printf("DottedDiamond"); break;
case U_HSP_Shingle: printf("Shingle"); break;
case U_HSP_Trellis: printf("Trellis"); break;
case U_HSP_Sphere: printf("Sphere"); break;
case U_HSP_SmallGrid: printf("SmallGrid"); break;
case U_HSP_SmallCheckerBoard: printf("SmallCheckerBoard"); break;
case U_HSP_LargeCheckerBoard: printf("LargeCheckerBoard"); break;
case U_HSP_OutlinedDiamond: printf("OutlinedDiamond"); break;
case U_HSP_SolidDiamond: printf("SolidDiamond"); break;
default: status=0; printf("INVALID(%d)",hstype); break;
}
return(status);
}
/**
\brief Print value of an ObjectType Enumeration
\returns record 1 on sucess, 0 on error
\param otype Value to print.
EMF+ manual 2.1.1.22, Microsoft name: ObjectType Enumeration
*/
int U_PMF_OBJECTTYPEENUMERATION_print(int otype){
int status=1;
switch(otype){
case U_OT_Invalid: printf("Invalid"); break;
case U_OT_Brush: printf("Brush"); break;
case U_OT_Pen: printf("Pen"); break;
case U_OT_Path: printf("Path"); break;
case U_OT_Region: printf("Region"); break;
case U_OT_Image: printf("Image"); break;
case U_OT_Font: printf("Font"); break;
case U_OT_StringFormat: printf("StringFormat"); break;
case U_OT_ImageAttributes: printf("ImageAttributes"); break;
case U_OT_CustomLineCap: printf("CustomLineCap"); break;
default:
status=0; printf("INVALID(%d)",otype); break;
}
return(status);
}
/**
\brief Print value of a U_PMF_PATHPOINTTYPE_ENUM object
\return 1
\param Type Value to print
EMF+ manual 2.1.1.23, Microsoft name: PathPointType Enumeration
*/
int U_PMF_PATHPOINTTYPE_ENUM_print(int Type){
switch(Type & U_PPT_MASK){
case U_PPT_Start : printf("Start"); break;
case U_PPT_Line : printf("Line"); break;
case U_PPT_Bezier: printf("Bezier"); break;
default: printf("INVALID(%d)",Type); break;
}
return(1);
}
/**
\brief Print data from a PixelFormat Enumeration value
\return 1 always
\param pfe A PixelFormat Enumeration value
EMF+ manual 2.1.1.25, Microsoft name: PixelFormat Enumeration (U_PF_*)
*/
int U_PMF_PX_FMT_ENUM_print(int pfe){
uint8_t idx;
printf(" + PxFmtEnum: ");
printf(" 32Bit:%c", (pfe & 1<< 9 ? 'Y' : 'N'));
printf(" 16Bit:%c", (pfe & 1<<10 ? 'Y' : 'N'));
printf(" PreAlpha:%c", (pfe & 1<<11 ? 'Y' : 'N'));
printf(" Alpha:%c", (pfe & 1<<12 ? 'Y' : 'N'));
printf(" GDI:%c", (pfe & 1<<13 ? 'Y' : 'N'));
printf(" LUT:%c", (pfe & 1<<14 ? 'Y' : 'N'));
printf(" BitsPerPx:%u", (pfe >> 16) & 0xFF);
idx = pfe >> 24;
printf(" Type:%u(",idx);
switch(idx){
case 0: printf("undefined"); break;
case 1: printf("monochrome with LUT"); break;
case 2: printf("4 bit with LUT"); break;
case 3: printf("8 bit with LUT"); break;
case 4: printf("16 bits grey values"); break;
case 5: printf("16 bit RGB values (5,5,5,(1 ignored))"); break;
case 6: printf("16 bit RGB values (5,6,5)"); break;
case 7: printf("16 bit ARGB values (1 alpha, 5,5,5 colors)"); break;
case 8: printf("24 bit RGB values (8,8.8)"); break;
case 9: printf("32 bit RGB value (8,8,8,(8 ignored))"); break;
case 10: printf("32 bit ARGB values (8 alpha,8,8,8)"); break;
case 11: printf("32 bit PARGB values (8,8,8,8, but RGB already multiplied by A)"); break;
case 12: printf("48 bit RGB (16,16,16)"); break;
case 13: printf("64 bit ARGB (16 alpha, 16,16,16)"); break;
case 14: printf("64 bit PARGB (16,16,16,16, but RGB already multiplied by A)"); break;
default: printf("INVALID(%d)",idx); break;
}
printf(")");
return(1);
}
/**
\brief Print as text a RegionNodeDataType Enumeration
\return 1
\param Type RegionNodeDataType Enumeration
EMF+ manual 2.1.1.27, Microsoft name: RegionNodeDataType Enumeration (U_RNDT_*)
*/
int U_PMF_NODETYPE_print(int Type){
if( Type == U_RNDT_And ){ printf("And" ); }
else if(Type == U_RNDT_Or ){ printf("Or" ); }
else if(Type == U_RNDT_Xor ){ printf("Xor" ); }
else if(Type == U_RNDT_Exclude ){ printf("Exclude" ); }
else if(Type == U_RNDT_Complement){ printf("Complement"); }
else if(Type == U_RNDT_Rect ){ printf("Rect" ); }
else if(Type == U_RNDT_Path ){ printf("Path" ); }
else if(Type == U_RNDT_Empty ){ printf("Empty" ); }
else if(Type == U_RNDT_Infinite ){ printf("Infinite" ); }
else { printf("Undefined" ); return(0); }
return(1);
}
/**
\brief Print data from a U_PMF_BRUSH object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.1, Microsoft name: EmfPlusBrush Object
*/
int U_PMF_BRUSH_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *Data;
int status = U_PMF_BRUSH_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + Brush:");
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" Type:%X(",Type);
(void) U_PMF_BRUSHTYPEENUMERATION_print(Type);
printf(")");
switch(Type){
case U_BT_SolidColor:
status = U_PMF_ARGB_print(Data);
break;
case U_BT_HatchFill:
printf("\n");
status = U_PMF_HATCHBRUSHDATA_print(Data, blimit);
break;
case U_BT_TextureFill:
printf("\n");
status = U_PMF_TEXTUREBRUSHDATA_print(Data, blimit);
break;
case U_BT_PathGradient:
printf("\n");
status = U_PMF_PATHGRADIENTBRUSHDATA_print(Data, blimit);
break;
case U_BT_LinearGradient:
printf("\n");
status = U_PMF_LINEARGRADIENTBRUSHDATA_print(Data, blimit);
break;
default:
status = 0;
}
printf("\n");
}
return(status);
}
/**
\brief Print data from a U_PMF_CUSTOMLINECAP object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param Which A string which is either "Start" or "End".
\param blimit one byte past the end of data
EMF+ manual 2.2.1.2, Microsoft name: EmfPlusCustomLineCap Object
*/
int U_PMF_CUSTOMLINECAP_print(const char *contents, const char *Which, const char *blimit){
uint32_t Version, Type;
const char *Data;
int status = U_PMF_CUSTOMLINECAP_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + %sLineCap:",Which);
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(", Type %X\n",Type);
switch(Type){
case U_CLCDT_Default:
status = U_PMF_CUSTOMLINECAPDATA_print(Data, blimit);
break;
case U_CLCDT_AdjustableArrow:
status = U_PMF_CUSTOMLINECAPARROWDATA_print(Data, blimit);
break;
default:
status = 0;
}
}
return(status);
}
/**
\brief Print data from a U_PMF_FONT object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.3, Microsoft name: EmfPlusFont Object
*/
int U_PMF_FONT_print(const char *contents, const char *blimit){
uint32_t Version, SizeUnit, Length;
U_FLOAT EmSize;
int32_t FSFlags;
const char *Data;
char *string;
int status = U_PMF_FONT_get(contents, &Version, &EmSize, &SizeUnit, &FSFlags, &Length, &Data, blimit);
if(status){
printf(" + Font:");
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" EmSize:%f ", EmSize );
printf(" SizeUnit:%d ",SizeUnit);
printf(" FSFlags:%d ", FSFlags );
printf(" Length:%d", Length );
string = U_Utf16leToUtf8((uint16_t *)Data, Length, NULL);
if(string){
printf(" Family:<%s>\n",string);
free(string);
}
else {
printf(" Family:<>\n");
}
}
return(status);
}
/**
\brief Print data from a U_PMF_IMAGE object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.4, Microsoft name: EmfPlusImage Object
*/
int U_PMF_IMAGE_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *Data;
int status = U_PMF_IMAGE_get(contents, &Version, &Type, &Data, blimit);
if(status){
printf(" + Image:");
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" Type:%X\n",Type);
switch(Type){
case U_IDT_Unknown:
printf(" + Unknown Image Type\n");
break;
case U_IDT_Bitmap:
status = U_PMF_BITMAP_print(Data, blimit);
break;
case U_IDT_Metafile:
status = U_PMF_METAFILE_print(Data, blimit);
break;
default:
status = 0;
}
}
return(status);
}
/**
\brief Print data from a U_PMF_IMAGEATTRIBUTES object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.5, Microsoft name: EmfPlusImageAttributes Object
*/
int U_PMF_IMAGEATTRIBUTES_print(const char *contents, const char *blimit){
uint32_t Version, WrapMode, ClampColor, ObjectClamp;
int status = U_PMF_IMAGEATTRIBUTES_get(contents, &Version, &WrapMode, &ClampColor, &ObjectClamp, blimit);
if(status){
printf(" + Image Attributes: ");
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" WrapMode:%X", WrapMode);
printf(" ClampColor:%X", ClampColor);
printf(" ObjectClamp:%X\n", ObjectClamp);
}
return(status);
}
/**
\brief Print data from a U_PMF_PATH object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object
*/
int U_PMF_PATH_print(const char *contents, const char *blimit){
unsigned int i, pos;
uint32_t Version, Count;
uint16_t Flags;
const char *Points;
const char *Types;
int status = U_PMF_PATH_get(contents, &Version, &Count, &Flags, &Points, &Types, blimit);
if(status){
printf(" + Path: Version:%X Count:%d Flags:%X\n",Version, Count, Flags);
/* Points part */
U_PMF_VARPOINTS_print(&Points, Flags, Count, blimit);
/* Types part */
printf(" + Types:");
pos = 0;
for(i=0; i<Count; i++){
/* EMF+ manual says that the first of these two cases can actually contain either type
of PATHPOINT, but it does not say how the program is supposed to figure out which record
is which type. */
if(Flags & U_PPF_R){
printf(" %u:",pos);
pos += U_PMF_PATHPOINTTYPERLE_print(Types, blimit);
Types+=2;
}
else {
printf(" %d:",i);
(void) U_PMF_PATHPOINTTYPE_print(Types, blimit);
Types++;
}
}
printf("\n");
}
return(status);
}
/**
\brief Print data from a U_PMF_PEN object
\return 1 on success, 0 on error
\param contents Record from which to print data
EMF+ manual 2.2.1.7, Microsoft name: EmfPlusPen Object
*/
int U_PMF_PEN_print(const char *contents, const char *blimit){
uint32_t Version, Type;
const char *PenData;
const char *Brush;
int status = U_PMF_PEN_get(contents, &Version, &Type, &PenData, &Brush, blimit);
if(status){
printf(" + Pen: Version:%X Type:%d\n",Version,Type);
(void) U_PMF_PENDATA_print(PenData, blimit);
(void) U_PMF_BRUSH_print(Brush, blimit);
}
return(status);
}
/**
\brief Print data from a U_PMF_REGION object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.8, Microsoft name: EmfPlusRegion Object
*/
int U_PMF_REGION_print(const char *contents, const char *blimit){
uint32_t Version, Count;
const char *Nodes;
int status = U_PMF_REGION_get(contents, &Version, &Count, &Nodes, blimit);
if(status){
printf(" + ");
(void) U_PMF_GRAPHICSVERSION_memsafe_print((char *)&Version);;
printf(" ChildNodes:%d",Count);
(void) U_PMF_REGIONNODE_print(Nodes, 1, blimit); /* 1 == top level*/
}
return(status);
}
/**
\brief Print data from a U_PMF_STRINGFORMAT object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.9, Microsoft name: EmfPlusStringFormat Object
*/
int U_PMF_STRINGFORMAT_print(const char *contents, const char *blimit){
U_PMF_STRINGFORMAT Sfs;
const char *Data;
int status = U_PMF_STRINGFORMAT_get(contents, &Sfs, &Data, blimit);
if(status){
printf(" + StringFormat: ");
printf(" Version:%X", Sfs.Version );
printf(" Flags:%X", Sfs.Flags );
printf(" Language"); (void) U_PMF_LANGUAGEIDENTIFIER_print(Sfs.Language);
printf(" StringAlignment:%X", Sfs.StringAlignment );
printf(" LineAlign:%X", Sfs.LineAlign );
printf(" DigitSubstitution:%X",Sfs.DigitSubstitution);
printf(" DigitLanguage"); (void) U_PMF_LANGUAGEIDENTIFIER_print(Sfs.DigitLanguage);
printf(" FirstTabOffset:%f", Sfs.FirstTabOffset );
printf(" HotkeyPrefix:%d", Sfs.HotkeyPrefix );
printf(" LeadingMargin:%f", Sfs.LeadingMargin );
printf(" TrailingMargin:%f", Sfs.TrailingMargin );
printf(" Tracking:%f", Sfs.Tracking );
printf(" Trimming:%X", Sfs.Trimming );
printf(" TabStopCount:%u", Sfs.TabStopCount );
printf(" RangeCount:%u", Sfs.RangeCount );
(void) U_PMF_STRINGFORMATDATA_print(Data, Sfs.TabStopCount, Sfs.RangeCount, blimit);
}
return(status);
}
/**
\brief Print data from a U_PMF_ARGB object
\return 1 on success, 0 on error
\param contents Record from which to print data
Does not accept a blimit value.
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
int U_PMF_ARGB_print(const char *contents){
uint8_t Blue, Green, Red, Alpha;
int status = U_PMF_ARGB_get(contents, &Blue, &Green, &Red, &Alpha, contents + sizeof(U_RGBQUAD));
if(status){
printf(" RGBA{%2.2X,%2.2X,%2.2X,%2.2X}", Red, Green, Blue, Alpha);
}
return(status);
}
/**
\brief Print data from a U_PMF_BITMAP object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.2, Microsoft name: EmfPlusBitmap Object
*/
int U_PMF_BITMAP_print(const char *contents, const char *blimit){
U_PMF_BITMAP Bs;
const char *Data;
int status = U_PMF_BITMAP_get(contents, &Bs, &Data, blimit);
if(status){
printf(" + Bitmap: Width:%d Height:%d Stride:%d\n",Bs.Width, Bs.Height, Bs.Stride);
U_PMF_PX_FMT_ENUM_print(Bs.PxFormat);
switch(Bs.Type){
case 0: printf(" Type:MSBitmap\n"); break;
case 1: printf(" Type:(PNG|JPG|GIF|EXIF|TIFF)\n"); break;
default: printf(" Type:INVALID(%d)\n",Bs.Type); break;
}
/* Pixel data is never shown - it could easily swamp the output for even a smallish picture */
}
return(status);
}
/**
\brief Print data from a U_PMF_BITMAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.3, Microsoft name: EmfPlusBitmapData Object
*/
int U_PMF_BITMAPDATA_print(const char *contents, const char *blimit){
unsigned int i;
U_PMF_PALETTE Ps;
const char *Colors;
const char *Data;
int status = U_PMF_BITMAPDATA_get(contents, &Ps, &Colors, &Data, blimit);
if(status){
status = 0;
printf(" BMData: Flags:%X, Elements:%u Colors:", Ps.Flags, Ps.Elements);
for(i=0; i<Ps.Elements; i++, Colors+=sizeof(U_PMF_ARGB)){
(void) U_PMF_ARGB_print(Colors);
}
}
return(status);
}
/**
\brief Print data from a U_PMF_BLENDCOLORS object
\return size in bytes on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.4, Microsoft name: EmfPlusBlendColors Object
*/
int U_PMF_BLENDCOLORS_print(const char *contents, const char *blimit){
unsigned int i;
uint32_t Elements;
U_FLOAT *Positions;
const char *Colors;
int status = U_PMF_BLENDCOLORS_get(contents, &Elements, &Positions, &Colors, blimit);
if(status){
printf(" + BlendColors: Entries:%d (entry,pos,color): ", Elements);
for(i=0; i<Elements; i++){
printf(" (%d,%f,", i, Positions[i]);
(void) U_PMF_ARGB_print(Colors);
Colors += sizeof(U_PMF_ARGB);
printf(")");
}
status = sizeof(uint32_t) + Elements*sizeof(U_FLOAT) + Elements*sizeof(U_PMF_ARGB);
free(Positions);
}
return(status);
}
/**
\brief Print data from a U_PMF_BLENDFACTORS object
\return size on success, 0 on error
\param type Type of BlendFactors, usually H or V
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
*/
int U_PMF_BLENDFACTORS_print(const char *contents, const char *type, const char *blimit){
unsigned int i;
uint32_t Elements;
U_FLOAT *Positions;
U_FLOAT *Factors;
int status = U_PMF_BLENDFACTORS_get(contents, &Elements, &Positions, &Factors, blimit);
if(status){
printf(" + BlendFactors%s: Entries:%d (entry,pos,factor): ",type, Elements);
for(i=0; i<Elements; i++){
printf(" (%d,%f,%f)", i, Positions[i],Factors[i]);
}
status = sizeof(uint32_t) + Elements*2*sizeof(U_FLOAT);
free(Positions);
free(Factors);
}
return(status);
}
/**
\brief Print data from a U_PMF_BOUNDARYPATHDATA object
\return size on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.6, Microsoft name: EmfPlusBoundaryPathData Object
*/
int U_PMF_BOUNDARYPATHDATA_print(const char *contents, const char * blimit){
int32_t Size;
const char *Data;
int status = U_PMF_BOUNDARYPATHDATA_get(contents, &Size, &Data, blimit);
if(status){
printf(" + BoundaryPathData: Size:%d\n",Size);
(void) U_PMF_PATH_print(Data, blimit);
}
return(status);
}
/**
\brief Print data from a U_PMF_BOUNDARYPOINTDATA object
\return size on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.7, Microsoft name: EmfPlusBoundaryPointData Object
*/
int U_PMF_BOUNDARYPOINTDATA_print(const char *contents, const char *blimit){
int32_t Elements;
U_PMF_POINTF *Points;
int status = U_PMF_BOUNDARYPOINTDATA_get(contents, &Elements, &Points, blimit);
if(status){
printf(" + BoundaryPointData: Elements:%u\n",Elements);
U_PMF_VARPOINTF_S_print(Points, Elements);
free(Points);
}
return(status);
}
/**
\brief Print data from a U_PMF_CHARACTERRANGE object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.8, Microsoft name: EmfPlusCharacterRange Object
*/
int U_PMF_CHARACTERRANGE_print(const char *contents, const char *blimit){
int32_t First, Length;
int status = U_PMF_CHARACTERRANGE_get(contents, &First, &Length, blimit);
if(status){
printf(" {%d,%d}",First,Length);
}
return(status);
}
/**
\brief Print data from a U_PMF_DASHEDLINEDATA object
\return 1 on success, 0 on error
\param blimit one byte past the end of data
\param contents Record from which to print data
EMF+ manual 2.2.2.9, Microsoft name: EmfPlusCompoundLineData Object
*/
int U_PMF_COMPOUNDLINEDATA_print(const char *contents, const char *blimit){
int32_t Elements;
U_FLOAT *Widths;
U_FLOAT *hold;
int status = U_PMF_COMPOUNDLINEDATA_get(contents, &Elements, &Widths, blimit);
if(status){
printf(" + CompoundLineData: Elements:%u {",Elements);
Elements--;
for(hold=Widths; Elements; Elements--,Widths++){ printf("%f, ",*Widths); }
printf("%f}",*Widths);
free(hold);
printf("\n");
}
return(status);
}
/**
\brief Print data from a U_PMF_COMPRESSEDIMAGE object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.10, Microsoft name: EmfPlusCompressedImage Object
This function does not do anything useful, but it is included so that all objects have a corresponding _get().
*/
int U_PMF_COMPRESSEDIMAGE_print(const char *contents, const char *blimit){
const char *Data;
int status = U_PMF_COMPRESSEDIMAGE_get(contents, &Data, blimit);
if(status){
printf("CompressedImage:\n");
}
return(status);
}
/**
\brief Print data from a U_PMF_CUSTOMENDCAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.11, Microsoft name: EmfPlusCustomEndCapData Object
*/
int U_PMF_CUSTOMENDCAPDATA_print(const char *contents, const char *blimit){
int32_t Size;
const char *Data;
int status = U_PMF_CUSTOMENDCAPDATA_get(contents, &Size, &Data, blimit);
if(status){
printf(" + CustomEndCap: Size:%d\n",Size);
(void) U_PMF_CUSTOMLINECAP_print(Data, "End", blimit);
}
return(status);
}
/**
\brief Print data from a U_PMF_CUSTOMLINECAPARROWDATA object
\return 1 on success, 0 on error
\param contents Record from which to print data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.12, Microsoft name: EmfPlusCustomLineCapArrowData Object
*/
int U_PMF_CUSTOMLINECAPARROWDATA_print(const char *contents, const char *blimit){
U_PMF_CUSTOMLINECAPARROWDATA Ccad;
int status = U_PMF_CUSTOMLINECAPARROWDATA_get(contents, &Ccad, blimit);
if(status){
printf("CustomLineCapArrowData: ");
printf(" Width:%f", Ccad.Width );
printf(" Height:%f", Ccad.Height );
printf(" MiddleInset:%f", Ccad.MiddleInset );
printf(" FillState:%u", Ccad.FillState );
printf(" StartCap:%X", Ccad.StartCap );
printf(" EndCap:%X", Ccad.EndCap );
printf(" Join:%X", Ccad.Join );
printf(" MiterLimit:%f", Ccad.MiterLimit );
printf(" WidthScale:%f", Ccad.WidthScale );
printf(" FillHotSpot:{%f,%f}",Ccad.FillHotSpot[0],Ccad.FillHotSpot[1]);
printf(" LineHotSpot:{%f,%f}",Ccad.LineHotSpot[0],Ccad.LineHotSpot[1]);
printf("\n");
}
return(status);