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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
|
/**
@file upmf.c
@brief Functions for manipulating EMF+ files and structures.
EMF+ is much more object based than is EMF or WMF, so the U_PMR_*_set and most U_PMF_*_set functions
return a pointer to a PseudoObject. PseudoObjects are structs that contain a data field to hold the
object in EMF+ file byte order, size information, and some type information. This is sufficient to allow
complex records to be built up from the various sorts of nested objects which they normally contain.
If something goes wrong a NULL pointer is returned and recsize is set to 0.
EMF+ does not use a separate set of endian functions, _get and _set routines convert from/to
the EMF+ file byte order on the fly.
WARNING: Microsoft's EMF+ documentation is little-endian for everything EXCEPT
bitfields, which are big-endian. See EMF+ manual section 1.3.2
That documentation also uses 0 as the MOST significant bit, N-1 as the least.
This code is little-endian throughout, and 0 is the LEAST significant bit
*/
/*
File: upmf.c
Version: 0.0.13
Date: 21-MAR-2019
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
Copyright: 2019 David Mathog and California Institute of Technology (Caltech)
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iconv.h>
#include <wchar.h>
#include <errno.h>
#include <string.h>
#include <limits.h> // for INT_MAX, INT_MIN
#include <math.h> // for sin, cos, tan2, use U_ROUND() instead of roundf()
#include <stddef.h> /* for offsetof() macro */
#if 0
#include <windef.h> //Not actually used, looking for collisions
#include <winnt.h> //Not actually used, looking for collisions
#include <wingdi.h> //Not actually used, looking for collisions
#endif
#include "upmf.h" // includes uemf.h
#include "uemf_endian.h" // for U_swap* functions
//! \cond
/// things Doxygen should not process
/* remove this after debugging is completed */
void dumphex(uint8_t *buf,unsigned int num){
for(; num; num--,buf++){
printf("%2.2X",*buf);
}
}
/* Prototypes for functions used here and defined in uemf_endian.c, but which are not supposed
to be used in end user code. */
void U_swap2(void *ul, unsigned int count);
void U_swap4(void *ul, unsigned int count);
//! \endcond
/**
\brief Utility function for writing one or more EMF+ records in a PseudoObject to the EMF output file
\return 1 on success, 0 on error.
\param po U_PSEUDO_OBJ to write, it is deleted after it is written
\param sum U_PSEUDO_OBJ to use for scratch space
\param et EMFTRACK used to write records to EMF file
*/
int U_PMR_write(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *sum, EMFTRACK *et){
char *rec;
int status = 0;
sum->Used = 0; /* clean it out, retaining allocated memory */
sum = U_PO_append(sum, "EMF+", 4); /* indicates that this comment holds an EMF+ record */
if(!sum)goto end;
sum = U_PO_append(sum, po->Data, po->Used); /* the EMF+ record itself */
if(!sum)goto end;
U_PO_free(&po); /* delete the PseudoObject */
rec = U_EMRCOMMENT_set(sum->Used, sum->Data); /* stuff it into the EMF comment */
if(!emf_append((PU_ENHMETARECORD)rec, et, 1))goto end; /* write it to the EMF file, delete the record, check status */
status = 1;
end:
return(status);
}
/**
\brief Utility function to draw a line.
\return 1 on success, 0 on error.
\param PenID Index of U_PMF_PEN object to use in the EMF+ object table (0-63, inclusive)
\param PathID Index of U_PMF_PATH object to use in the EMF+ object table (0-63, inclusive)
\param Start U_PMF_POINTF coordinates of start of line.
\param End U_PMF_POINTF coordinates of end of line.
\param Dashed Set if the line is dashed, clear if it is not.
\param sum PseudoObject used for scratch space
\param et EMFTRACK used to write records to EMF file
*/
int U_PMR_drawline(uint32_t PenID, uint32_t PathID, U_PMF_POINTF Start, U_PMF_POINTF End, int Dashed, U_PSEUDO_OBJ *sum, EMFTRACK *et){
U_DPSEUDO_OBJ *dpath;
U_PSEUDO_OBJ *poPath;
U_PSEUDO_OBJ *po;
int status=0;
int PTP_value = ( Dashed ? U_PTP_DashMode : U_PTP_None);
dpath = U_PATH_create(0, NULL, 0, 0); /* create an empty path*/
if(dpath){
if(U_PATH_moveto(dpath, Start, PTP_value) && U_PATH_lineto(dpath, End, PTP_value)){
poPath = U_PMF_PATH_set2(U_PMF_GRAPHICSVERSIONOBJ_set(2), dpath);
if(poPath){
po = U_PMR_OBJECT_PO_set(PathID, poPath);
U_PO_free(&poPath);
if(po){
U_PMR_write(po, sum, et);
po = U_PMR_DRAWPATH_set(PathID, PenID);
if(po){
U_PMR_write(po, sum, et);
status = 1;
}
}
}
}
U_DPO_free(&dpath);
}
return(status);
}
/**
\brief Utility function for drawing strings onto the baseline in one call.
\return 1 on success, 0 on error.
\param string Text to draw in UTF-8 format
\param Vpos StringAlignment Enumeration. Always drawn on baseline, but using one of these three modes.
\param FontID Index of U_PMF_FONT object to use in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param FormatID index of U_PMF_STRINGFORMAT object to use in the EMF+ Object Table.
\param Sfs StringFormat structure. Ignored values: StringAlignment, LineAlign, Flags
\param FontName Name of font to draw with
\param Height Height of font in pixels (positive)
\param fip U_FontInfoParams (ascent, descent, and so forth)
\param FontFlags FontStyle Flags
\param x X position in pixels of left side of EM box of first character
\param y Y position in pixels of baseline of first character
\param sum PseudoObject used for scratch space
\param et EMFTRACK used to write records to EMF file
EMF+ manual 2.3.4.14, Microsoft name: EmfPlusDrawString Record, Index 0x1C
For most fonts Ascent and Descent are used to adjust the bounding box to properly position the
baseline. Some fonts, like Verdana, are strange and they position the baseline on the bottom of
the bounding box if that box has the same height as the font. For those fonts specify 0.0 for
both Ascent and Descent.
*/
int U_PMR_drawstring( const char *string, int Vpos, uint32_t FontID, const U_PSEUDO_OBJ *BrushID, uint32_t FormatID,
U_PMF_STRINGFORMAT Sfs, const char *FontName, U_FLOAT Height, U_FontInfoParams *fip, uint32_t FontFlags,
U_FLOAT x, U_FLOAT y, U_PSEUDO_OBJ *sum, EMFTRACK *et){
U_PSEUDO_OBJ *po;
U_PSEUDO_OBJ *poSF;
U_PSEUDO_OBJ *poFont;
U_PSEUDO_OBJ *poRect;
U_FLOAT rx,ry,rw,rh,rd;
uint16_t *UFontName;
uint16_t *Text16;
int slen;
int status = 0;
double aval, dval;
Sfs.Flags = U_SF_NoFitBlackBox + U_SF_NoClip;
if(Vpos < U_SA_Near || Vpos > U_SA_Far)return(0);
Sfs.StringAlignment = U_SA_Near; // Horizontal
Sfs.LineAlign = Vpos; // Vertical
UFontName = U_Utf8ToUtf16le(FontName, 0, NULL);
slen = strlen(FontName);
poFont = U_PMF_FONT_set(U_PMF_GRAPHICSVERSIONOBJ_set(2), Height, U_UT_World, FontFlags, slen, UFontName);
if(poFont){
po = U_PMR_OBJECT_PO_set(FontID, poFont); /* font to use */
if(po){
U_PMR_write(po, sum, et);
poSF = U_PMF_STRINGFORMAT_set(&Sfs, NULL);
if(poSF){
po = U_PMR_OBJECT_PO_set(FormatID, poSF);
U_PO_free(&poSF);
if(po){
U_PMR_write(po, sum, et);
rw = 4*Height*slen; /* This could probably be any value */
rh = Height;
rx = x;
if(fip->LineGap > -fip->Descent){ aval = fip->yMax; } // sylfaen, palatino
else { aval = fip->Ascent; } // others
if(fip->LineGap && (fip->LineGap < -fip->Descent)){ dval = ((double) (fip->Descent - fip->LineGap)) / ((double) fip->EmSize); } //shruti and some others
else { dval = ((double) fip->Descent ) / ((double) fip->EmSize); }
switch(Vpos){
case U_SA_Near:
rd = Height * aval / ((double) fip->EmSize);
break;
case U_SA_Center:
rd = 0.5 * ( Height * aval / ((double) fip->EmSize) + Height * ( 1.0 + dval));
break;
case U_SA_Far:
rd = Height * ( 1.0 + dval);
break;
}
ry = y - rd; /* draw from upper left corner, which is shifted to put baseline on y */
poRect = U_PMF_RECTF4_set(rx, ry, rw, rh);
#if 0
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x-100, ry}, (U_PMF_POINTF){x+100, ry}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x-100, ry+rh}, (U_PMF_POINTF){x+100, ry+rh}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x-100, ry}, (U_PMF_POINTF){x-100, ry + Height * (double) fip->Ascent / ((double) fip->EmSize)}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x- 90, ry}, (U_PMF_POINTF){x- 90, ry - Height * (double) fip->Descent / ((double) fip->EmSize)}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x- 80, ry}, (U_PMF_POINTF){x- 80, ry + Height * (double) fip->yMax / ((double) fip->EmSize)}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x- 70, ry}, (U_PMF_POINTF){x- 70, ry - Height * (double) fip->yMin / ((double) fip->EmSize)}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x- 60, ry}, (U_PMF_POINTF){x- 60, ry + Height * (double) fip->LineGap / ((double) fip->EmSize)}, 0, sum, et);
(void) U_PMR_drawline(OBJ_PEN_BLACK_1,OBJ_PATH_1, (U_PMF_POINTF){x- 50, ry}, (U_PMF_POINTF){x- 50, ry + Height * ( 1.0 - (((double) (fip->LineGap - fip->Descent)) / ((double) fip->EmSize)) )}, 0, sum, et);
#endif
Text16 = U_Utf8ToUtf16le(string, 0, NULL);
slen = strlen(string);
po = U_PMR_DRAWSTRING_set(FontID, BrushID, FormatID, slen, poRect, Text16);
if(po){
U_PMR_write(po, sum, et);
status = 1; /* Success!!! */
}
U_PO_free(&poRect);
free(Text16);
}
}
}
U_PO_free(&poFont);
}
free(UFontName);
return(status);
}
/**
\brief Allocate and construct an array of U_POINT16 objects from a set of U_PMF_POINTF objects, endianness in and out is LE
\returns pointer to an array of U_POINT16 structures.
\param points pointer to the source U_POINT structures
\param count number of members in points
If a coordinate is out of range it saturates at boundary.
*/
U_PMF_POINT *POINTF_To_POINT16_LE(U_PMF_POINTF *points, int count){
U_PMF_POINT *newpts;
U_PMF_POINTF ptfl;
int i;
newpts = (U_PMF_POINT *) malloc(count * sizeof(U_PMF_POINT));
for(i=0; i<count; i++){
memcpy(&ptfl, &(points[i]), 8);
if(U_BYTE_SWAP){ U_swap4(&ptfl,2); } /* on BE platforms swap going in and coming out */
newpts[i].X = U_MNMX(ptfl.X, INT16_MIN, INT16_MAX);
newpts[i].Y = U_MNMX(ptfl.Y, INT16_MIN, INT16_MAX);
if(U_BYTE_SWAP){ U_swap2(&(newpts[i]),2); }
}
return(newpts);
}
/**
\brief Look up the name of the EMR+ record by type. Returns U_EMR_INVALID if out of range.
\return name of the PMR record, "U_EMR_INVALID" if out of range.
\param idx PMR record type WITHOUT the U_PMR_RECFLAG bit.
*/
char *U_pmr_names(unsigned int idx){
if(idx<U_PMR_MIN || idx > U_PMR_MAX){ idx = 0; }
static char *U_PMR_NAMES[U_PMR_MAX+1]={
"U_PMR_INVALID",
"U_PMR_Header",
"U_PMR_EndOfFile",
"U_PMR_Comment",
"U_PMR_GetDC",
"U_PMR_MultiFormatStart",
"U_PMR_MultiFormatSection",
"U_PMR_MultiFormatEnd",
"U_PMR_Object",
"U_PMR_Clear",
"U_PMR_FillRects",
"U_PMR_DrawRects",
"U_PMR_FillPolygon",
"U_PMR_DrawLines",
"U_PMR_FillEllipse",
"U_PMR_DrawEllipse",
"U_PMR_FillPie",
"U_PMR_DrawPie",
"U_PMR_DrawArc",
"U_PMR_FillRegion",
"U_PMR_FillPath",
"U_PMR_DrawPath",
"U_PMR_FillClosedCurve",
"U_PMR_DrawClosedCurve",
"U_PMR_DrawCurve",
"U_PMR_DrawBeziers",
"U_PMR_DrawImage",
"U_PMR_DrawImagePoints",
"U_PMR_DrawString",
"U_PMR_SetRenderingOrigin",
"U_PMR_SetAntiAliasMode",
"U_PMR_SetTextRenderingHint",
"U_PMR_SetTextContrast",
"U_PMR_SetInterpolationMode",
"U_PMR_SetPixelOffsetMode",
"U_PMR_SetCompositingMode",
"U_PMR_SetCompositingQuality",
"U_PMR_Save",
"U_PMR_Restore",
"U_PMR_BeginContainer",
"U_PMR_BeginContainerNoParams",
"U_PMR_EndContainer",
"U_PMR_SetWorldTransform",
"U_PMR_ResetWorldTransform",
"U_PMR_MultiplyWorldTransform",
"U_PMR_TranslateWorldTransform",
"U_PMR_ScaleWorldTransform",
"U_PMR_RotateWorldTransform",
"U_PMR_SetPageTransform",
"U_PMR_ResetClip",
"U_PMR_SetClipRect",
"U_PMR_SetClipPath",
"U_PMR_SetClipRegion",
"U_PMR_OffsetClip",
"U_PMR_DrawDriverstring",
"U_PMR_StrokeFillPath",
"U_PMR_SerializableObject",
"U_PMR_SetTSGraphics",
"U_PMR_SetTSClip"
};
return(U_PMR_NAMES[idx]);
}
/**
\brief Convert from PseudoObject OID to ObjectType enumeration.
\returns OT value on success, 0 if no match
\param OID PseudoObject OID (based on EMF+ manual chapter number. )
Only OTs that may be stored in the EMF+ object table are supported.
*/
int U_OID_To_OT(uint32_t OID){
int otype;
if( OID==U_PMF_BRUSH_OID ){ otype = U_OT_Brush; }
else if(OID==U_PMF_PEN_OID ){ otype = U_OT_Pen; }
else if(OID==U_PMF_PATH_OID ){ otype = U_OT_Path; }
else if(OID==U_PMF_REGION_OID ){ otype = U_OT_Region; }
else if(OID==U_PMF_IMAGE_OID ){ otype = U_OT_Image; }
else if(OID==U_PMF_FONT_OID ){ otype = U_OT_Font; }
else if(OID==U_PMF_STRINGFORMAT_OID ){ otype = U_OT_StringFormat; }
else if(OID==U_PMF_IMAGEATTRIBUTES_OID){ otype = U_OT_ImageAttributes; }
else if(OID==U_PMF_CUSTOMLINECAP_OID ){ otype = U_OT_CustomLineCap; }
else { otype = U_OT_Invalid; }
return(otype);
}
/**
\brief Convert from PseudoObject OID to BrushType enumeration.
\returns BT value on success, -1 if no match
\param OID PseudoObject OID (based on EMF+ manual chapter number. )
Only OIDs that map to BT's are supported.
*/
int U_OID_To_BT(uint32_t OID){
int otype;
if( OID==U_PMF_HATCHBRUSHDATA_OID ){ otype = U_BT_HatchFill; }
else if(OID==U_PMF_LINEARGRADIENTBRUSHDATA_OID ){ otype = U_BT_LinearGradient; }
else if(OID==U_PMF_PATHGRADIENTBRUSHDATA_OID ){ otype = U_BT_PathGradient; }
else if(OID==U_PMF_SOLIDBRUSHDATA_OID ){ otype = U_BT_SolidColor; }
else if(OID==U_PMF_TEXTUREBRUSHDATA_OID ){ otype = U_BT_TextureFill; }
else { otype = -1; }
return(otype);
}
/**
\brief Convert from PseudoObject OID to CustomLineCapDataType Enumeration.
\returns BT value on success, -1 if no match
\param OID PseudoObject OID (based on EMF+ manual chapter number. )
Only OIDs that map to CLCDT's are supported.
*/
int U_OID_To_CLCDT(uint32_t OID){
int otype;
if( OID==U_PMF_CUSTOMLINECAPDATA_OID ){ otype = U_CLCDT_Default; }
else if(OID==U_PMF_CUSTOMLINECAPARROWDATA_OID ){ otype = U_CLCDT_AdjustableArrow; }
else { otype = -1; }
return(otype);
}
/**
\brief Convert from PseudoObject OID to ImageDataType Enumeration.
\returns BT value on success, -1 if no match
\param OID PseudoObject OID (based on EMF+ manual chapter number. )
Only OIDs that map to IDT's are supported.
*/
int U_OID_To_IDT(uint32_t OID){
int otype;
if( OID==U_PMF_BITMAP_OID ){ otype = U_IDT_Bitmap; }
else if(OID==U_PMF_METAFILE_OID ){ otype = U_IDT_Metafile; }
else { otype = -1; }
return(otype);
}
/**
\brief Convert from PseudoObject OID to RegionNodeDataType Enumeration.
\returns BT value on success, -1 if no match
\param OID PseudoObject OID (based on EMF+ manual chapter number. )
Only OIDs that map to RNDT's are supported.
*/
int U_OID_To_RNDT(uint32_t OID){
int otype;
if( OID==U_PMF_REGIONNODECHILDNODES_OID ){ otype = U_RNDT_Kids; } /* there are 5 types, which must be specified separately */
else if(OID==U_PMF_RECTF_OID ){ otype = U_RNDT_Rect; }
else if(OID==U_PMF_REGIONNODEPATH_OID ){ otype = U_RNDT_Path; }
else { otype = -1; }
return(otype);
}
/**
\brief Append data to an U_OBJ_ACCUM structure.
\param oa pointer to the U_OBJ_ACCUM structure
\param data data to add
\param size bytes in data
\param Type object type
\param Id Object ID
\returns 0 on success, !0 on error. -1 on Type change, -2 on Id change
Safe to test for Id, Type changes by calling with size=0.
*/
int U_OA_append(U_OBJ_ACCUM *oa, const char *data, int size, int Type, int Id){
int tail;
if(!oa)return(2);
if(oa->used){
if(oa->Type != Type)return(-1);
if(oa->Id != Id)return(-2);
}
tail = oa->used;
if(oa->used + size >= oa->space){
oa->space += size;
char *newaccum = (char *) realloc(oa->accum, oa->space);
if(!newaccum){
oa->space -= size; /* put it back the way it was */
return(1);
}
oa->accum = newaccum;
}
memcpy(oa->accum + tail,data,size);
oa->used += size;
oa->Type = Type;
oa->Id = Id;
return(0);
}
/**
\brief Clear an U_OBJ_ACCUM structure. Accumulated storage is retained.
\param oa pointer to the U_OBJ_ACCUM structure
\returns 0 on success, !0 on error.
*/
int U_OA_clear(U_OBJ_ACCUM *oa){
if(!oa)return(2);
oa->used=0;
/* Type and Id may be ignored as they are reset on the first append */
return(0);
}
/**
\brief Release an U_OBJ_ACCUM structure. Accumulated storage is free'd.
\param oa pointer to the U_OBJ_ACCUM structure
\returns 0 on success, !0 on error.
*/
int U_OA_release(U_OBJ_ACCUM *oa){
if(!oa)return(2);
oa->used=0;
oa->space = 0;
if(oa->accum)free(oa->accum);
oa->accum=NULL;
return(0);
}
/**
\brief Create and set an U_PSEUDO_OBJ
\returns pointer to the U_PSEUDO_OBJ, NULL on error
\param Data Data to copy into the PseudoObject's data. If NULL, space is allocated, but is cleared instead of filled.
\param Size Number of bytes to allocate for Data (may be >Use if padding is present)
\param Use Number of data bytes in Data (whether or not Data is actually copied)
\param Type Type numbers are from manual section: 1.2.3.47 -> 0x01020347
If Data is NULL and Size is 0 an empty PseudoObject is created. One byte of storage
is allocated for Data, Size is set to 1, and Used to 0.
If Data is NULL and Size is !0 a zero filled PseudoObject is created.
If Data is !Null and Size is !0 a data filled PseudoObject is created.
*/
U_PSEUDO_OBJ *U_PO_create(char *Data, size_t Size, size_t Use, uint32_t Type){
if(Use>Size)return(NULL);
size_t tSize = (Size ? Size : 1);
U_PSEUDO_OBJ *po = (U_PSEUDO_OBJ *)malloc(sizeof(U_PSEUDO_OBJ));
if(po){
po->Data = malloc(tSize);
if(po->Data){
po->Size = tSize;
po->Used = Use;
po->Type = Type;
if(Data){ memcpy(po->Data, Data, Use); } /* if Use < Size uninitialized bytes will be present! */
else { memset(po->Data, 0, tSize); }
}
else {
free(po);
po=NULL;
}
}
return(po);
}
/**
\brief Append data to a U_PSEUDO_OBJ object and return it
\returns pointer to the U_PSEUDO_OBJ object, NULL on error
\param po PseudoObject to append to. Cannot be NULL.
\param Data Data to copy into the PseudoObject's data. If NULL, space is allocated (if necessary) and cleared instead of filled.
\param Size Number of data bytes in Data
*/
U_PSEUDO_OBJ *U_PO_append(U_PSEUDO_OBJ *po, const char *Data, size_t Size){
/* po cannot be NULL,as in U_PO_po_append(), because there would be no way to determine the TYPE of the resulting PO */
if(po){
if(!po->Data || po->Used + Size > po->Size){
po->Size = po->Used + Size;
char *newData = realloc(po->Data, po->Size);
if(!newData){
po->Size -= Size; /* put it back the way it was*/
po=NULL; /* skip the rest of the actions, does not affect po in caller */
}
else {
po->Data = newData;
}
}
if(po){ /* po->Data ready to append new data */
if(Data){ memcpy(po->Data + po->Used, Data, Size); }
else { memset(po->Data + po->Used, 0, Size); }
po->Used += Size;
}
}
return(po);
}
/**
\brief Append data to a U_PSEUDO_OBJ object and return it
\returns pointer to the U_PSEUDO_OBJ object, NULL on error
\param po PseudoObject to append to. May be NULL.
\param Src PseudoObject to append.
\param StripE Set: leading Elements in Src->Data is not copied, Clear: it is copied.
*/
U_PSEUDO_OBJ *U_PO_po_append(U_PSEUDO_OBJ *po, U_PSEUDO_OBJ *Src, int StripE){
if(!Src){ return(NULL); }
if((StripE && (Src->Used == 4)) || !Src->Used){ return(po); } /* appending nothing is not an error */
char *Data = Src->Data;
size_t Size = Src->Used; /* append only what is used */
U_PSEUDO_OBJ *ipo = po;
if(StripE){ Size -= 4; }
if(!ipo){
ipo = U_PO_create(NULL, 0, 0, Src->Type); /* create an empty pseudoobject */
}
if(ipo){
if(!ipo->Data || ipo->Used + Size > ipo->Size){
ipo->Size = ipo->Used + Size;
char *newData = realloc(ipo->Data, ipo->Size);
if(!newData){
if(ipo != po)U_PO_free(&ipo);
}
else {
ipo->Data = newData;
}
}
if(ipo){
if(Data){
if(StripE){ memcpy(ipo->Data + ipo->Used, Data + 4, Size); } /* Size is already 4 less, skip the leading Elements value */
else { memcpy(ipo->Data + ipo->Used, Data, Size); } /* copy everything */
}
else { memset(ipo->Data + ipo->Used, 0, Size); } /* set everything */
ipo->Used += Size;
}
}
return(ipo);
}
/**
\brief Free an U_PSEUDO_OBJ structure. All associated memory is released.
\param po Address of a pointer to the U_PSEUDO_OBJ structure, Pointer is set to NULL.
\returns 1 on success, 0 on error.
*/
int U_PO_free(U_PSEUDO_OBJ **po){
if(!po)return(0);
if(!*po)return(1);
if((*po)->Data)free((*po)->Data);
free(*po);
*po=NULL;
return(1);
}
/** \brief create a PseudoObject with data in the correct byte order for an EMF+ file.
\returns The PseudoObject on success, NULL on error.
\param Type the type of the PseudoObject that is created. Allowed values are in U_PID_Values.
\param List an array of U_SERIAL_DESC structures containing the data to store.
The U_PMF_SERIAL_set() function should not ever be called directly by end user code.
Each U_SERIAL_DESC element in List consists of Data fields and a description of that data. List is terminated
by the first U_SERIAL_DESC element having a TE value of U_XX.
Data fields: an array of a basic type of Units bytes repeated Reps times with the target byte order
described in TE.
Ptrs: Address of the first byte of the data fields.
Units: Number of bytes of in each data field unit
Reps: Number of repeats of the unit in data fields.
If a Ptr is NULL, and Units*Reps is not zero, then Units*Reps 0x00 bytes are stored.
If a Ptr is NULL, and Units*Reps is zero, this U_SERIAL_DESC is ignored.
if a Ptr is NOT NULL, and Units * Reps is not zero, then the data is stored in the indicated byte order.
If a Ptr is NOT NULL, and Units or Reps is zero an error is signaled.
TE: (Target Endian) the byte order in which to store each unit of a data field as defined in U_Endian.
Byte swapping is only enabled when Units is 2 or 4. In addition to the byte order values U_XE, U_LE,
and U_BE, and the array terminator U_XX, the value may also be U_RP. U_RP means there is only a
single unit in the data fields, but it is to be copied to the target Reps times. That is, the data
was passed in with a form of run length encoding.
Creates an empty PseudoObject if all pointers are NULL and all sizes are zero.
*/
U_PSEUDO_OBJ *U_PMF_SERIAL_set(uint32_t Type, const U_SERIAL_DESC *List){
U_PSEUDO_OBJ *po=NULL;
size_t Total=0;
size_t FSize;
char *cptr;
char *hptr;
const U_SERIAL_DESC *lptr;
if(!List)return(NULL);
for(lptr=List; lptr->TE != U_XX; lptr++){
if(!(lptr->Units * lptr->Reps) && lptr->Ptr)return(po);
Total += lptr->Units * lptr->Reps;
}
po = U_PO_create(NULL, Total, Total, Type);
if(po){
cptr = po->Data;
for(lptr=List; lptr->TE != U_XX; lptr++){
FSize = lptr->Units * lptr->Reps;
if(FSize){ /* Ptr is not NULL, that would have been detected already */
hptr = cptr;
if(lptr->TE & U_RP){ U_PMF_REPCPY_DSTSHIFT(&cptr, lptr->Ptr, lptr->Units, lptr->Reps); }
else { U_PMF_MEMCPY_DSTSHIFT(&cptr, lptr->Ptr, FSize); }
if(((lptr->TE & U_LE) && U_IS_BE) || ((lptr->TE & U_BE) && U_IS_LE)){
if(lptr->Units==2){ U_swap2(hptr,lptr->Reps); }
else if(lptr->Units==4){ U_swap4(hptr,lptr->Reps); }
}
}
}
}
return(po);
}
/**
\brief Create U_DPSEUDO_OBJ's for the Points and Types of a path
\param Elements Number of elements in Points. May be zero, which creates an empty path.
\param Points Array of U_PMF_POINTF values.
\param First Apply to first point, unsigned byte, lower 4 bits hold the PathPointType flag upper 4 bits hold the PathPointType enumeration. Must have U_PPT_Start set.
\param Others Apply to all other points, unsigned byte, lower 4 bits hold the PathPointType flag upper 4 bits hold the PathPointType enumeration. Must have U_PPT_Line or U_PPT_Bezier set.
\returns pointer to the DU_PSEUDO_OBJ object, NULL on error
*/
U_DPSEUDO_OBJ *U_PATH_create(int Elements, const U_PMF_POINTF *Points, uint8_t First, uint8_t Others){
if(Elements){
if(!Points){ return(NULL); }
if( (First & U_PPT_MASK) != U_PPT_Start ){ return(NULL); }
if(!(Others & U_PPT_Bezier)){ return(NULL); } /* will pass if either line or bezier is set */
}
U_DPSEUDO_OBJ *Path = (U_DPSEUDO_OBJ *)calloc(sizeof(U_DPSEUDO_OBJ),1); /* make poTypes and poPoints NULL */
const U_SERIAL_DESC List[] = { {NULL,0,0,U_XX} };
if(Path){
Path->Elements = Elements;
Path->poPoints = U_PMF_SERIAL_set(U_PMF_RAW_OID, List); /* Empty PO to hold points as raw data */
if(!Elements){
Path->poTypes = U_PMF_SERIAL_set(U_PMF_RAW_OID, List); /* Empty PO to hold types as raw data */
}
else {
Path->poPoints = U_PO_append(Path->poPoints, (char *)Points, Elements*sizeof(U_PMF_POINTF));
if(Path->poPoints){
U_PSEUDO_OBJ *tpo = U_PMF_PATHPOINTTYPE_set2(Elements, First | U_PPT_Start, Others); /* PO holding types, has leading Elements value */
Path->poTypes = U_PO_po_append(NULL, tpo, U_PMF_DROP_ELEMENTS); /* remove the leading Elements value*/
U_PO_free(&tpo);
if(!Path->poTypes){ U_PO_free(&Path->poPoints); }
}
if(!Path->poPoints){ U_DPO_free(&Path); }
}
}
return(Path);
}
/**
\brief Free U_DPSEUDO_OBJ's
\returns 1 on success, 0 on error.
*/
int U_DPO_free(U_DPSEUDO_OBJ **dpo){
if(!dpo){ return(0); }
if(!*dpo){ return(1); }
U_DPSEUDO_OBJ *kpo = *dpo;
if(kpo->poPoints){ U_PO_free(&kpo->poPoints); }
if(kpo->poTypes){ U_PO_free(&kpo->poTypes); }
free(*dpo);
*dpo=NULL;
return(1);
}
/**
\brief Clear U_DPSEUDO_OBJ's. Memory is retained, Elements and Used values are set to 0.
\returns 1 on success, 0 on error.
It is much more efficient to clear a DPO and reuse it than to free that DPO and create another.
*/
int U_DPO_clear(U_DPSEUDO_OBJ *dpo){
if(!dpo){ return(0); }
if(dpo->poPoints){ dpo->poPoints->Used = 0; }
if(dpo->poTypes){ dpo->poTypes->Used = 0; }
dpo->Elements = 0;
return(1);
}
/**
\brief Append a "moveto" point to a path
\param Path Address of a DoublePseudoObject holding the path to append to.
\param Point Point to move to.
\param Flags Flags may be (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, U_PTP_CloseSubpath)
\returns 1 on success, 0 on error.
*/
int U_PATH_moveto(U_DPSEUDO_OBJ *Path, U_PMF_POINTF Point, uint8_t Flags){
if(!Path){ return(0); }
U_PSEUDO_OBJ *tpo;
U_PSEUDO_OBJ *tpo2;
uint8_t Type = (Flags & U_PTP_NotClose) | U_PPT_Start;
tpo = U_PMF_POINTF_set(1, &Point);
if(!tpo){ return(0); }
tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poPoints = tpo2;
tpo = U_PMF_PATHPOINTTYPE_set(1, &Type);
if(!tpo){ return(0); }
tpo2= U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poTypes = tpo2;
Path->Elements++;
return(1);
}
/**
\brief Append a "lineto" point to a path
\param Path Address of a DoublePseudoObject holding the path to append to.
\param Point U_PMF_POINTF point to draw to.
\param Flags Flags may be (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, U_PTP_CloseSubpath)
\returns 1 on success, 0 on error.
*/
int U_PATH_lineto(U_DPSEUDO_OBJ *Path, U_PMF_POINTF Point, uint8_t Flags){
if(!Path || !Path->Elements){ return(0); } /* must be at least one point to extend from */
if(Path->poTypes->Data[Path->Elements - 1] & U_PTP_CloseSubpath){ return(0); } /* cannot extend a closed subpath */
U_PSEUDO_OBJ *tpo;
U_PSEUDO_OBJ *tpo2;
uint8_t Type = (Flags & U_PTP_NotClose) | U_PPT_Line;
tpo = U_PMF_POINTF_set(1, &Point);
if(!tpo){ return(0); }
tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poPoints = tpo2;
tpo = U_PMF_PATHPOINTTYPE_set(1, &Type);
if(!tpo){ return(0); }
tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poTypes = tpo2;
Path->Elements++;
return(1);
}
/**
\brief Set the closepath bit in the last point
\param Path Address of a DoublePseudoObject holding the path to act upon.
\returns 1 on success, 0 on error.
*/
int U_PATH_closepath(U_DPSEUDO_OBJ *Path){
if(!Path || !Path->poTypes){ return(0); }
uint32_t Elements = Path->Elements;
uint8_t *Type = (uint8_t *)(Path->poTypes->Data) + Elements - 1;
if(*Type & U_PPT_Start){ return(0); } /* single point closed path makes no sense */
*Type = *Type | U_PTP_CloseSubpath;
return(1);
}
/**
\brief Append a "polylineto" set of point to a path
\param Path Address of a DoublePseudoObject holding the path to append to.
\param Elements number of Points and Flags
\param Points Line points.
\param Flags Flags (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, but NOT U_PTP_CloseSubpath)
\param StartSeg If set, use U_PPT_Start PathPointType enumeration for first point, otherwise use U_PPT_Line.
\returns 1 on success, 0 on error.
*/
int U_PATH_polylineto(U_DPSEUDO_OBJ *Path, uint32_t Elements, const U_PMF_POINTF *Points, uint8_t Flags, uint8_t StartSeg){
if(!Path || !Points){ return(0); }
if(!Elements){ return(1); } /* harmless - do nothing */
U_PSEUDO_OBJ *tpo;
U_PSEUDO_OBJ *tpo2;
uint8_t First, Others;
tpo = U_PMF_POINTF_set(Elements, Points);
tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poPoints = tpo2;
if(StartSeg){ First = (Flags & U_PTP_NotClose) | U_PPT_Start; }
else { First = (Flags & U_PTP_NotClose) | U_PPT_Line; }
Others = (Flags & U_PTP_NotClose) | U_PPT_Line;
tpo = U_PMF_PATHPOINTTYPE_set2(Elements, First, Others);
if(!tpo){ return(0); }
tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poTypes = tpo2;
Path->Elements += Elements;
return(1);
}
/**
\brief Append a "polybezierto" set of point to a path
\param Path Address of a DoublePseudoObject holding the path to append to.
\param Elements number of Points
\param Points Bezier points. Optional starting point, then N sets of 3, example: [P1] (Q12A Q12B P2) (Q23A Q23B P3).
\param Flags Flags (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, but NOT U_PTP_CloseSubpath)
\param StartSeg If set, use U_PPT_Start PathPointType enumeration for first point, otherwise use U_PPT_Bezier.
\returns 1 on success, 0 on error.
If Start is set Elements must be 1 + multiple of 3. Ie, P1 Q12A Q12B P2 Q23A Q23B P3
If Start is clear Elements must be a multiple of 3. Ie, (P1, already in path) Q12A Q12B P2 Q23A Q23B P3
*/
int U_PATH_polybezierto(U_DPSEUDO_OBJ *Path, uint32_t Elements, const U_PMF_POINTF *Points, uint8_t Flags, uint8_t StartSeg){
if(!Path || !Points){ return(0); }
if(!Elements){
if(StartSeg){ return(0); } /* cannot have both a NEW segment and ZERO points */
else{ return(1); } /* harmless - do nothing */
}
if(StartSeg && ((Elements - 1) % 3)){ return(0); } /* new segment must be 1 + N*3 points */
if(!StartSeg && (Elements % 3)){ return(0); } /* extend segment must be N*3 points */
U_PSEUDO_OBJ *tpo;
U_PSEUDO_OBJ *tpo2;
uint8_t First, Others;
tpo = U_PMF_POINTF_set(Elements, Points);
tpo2 = U_PO_po_append(Path->poPoints, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poPoints = tpo2;
if(StartSeg){ First = (Flags & U_PTP_NotClose) | U_PPT_Start; }
else { First = (Flags & U_PTP_NotClose) | U_PPT_Bezier; }
Others = (Flags & U_PTP_NotClose) | U_PPT_Bezier;
tpo = U_PMF_PATHPOINTTYPE_set2(Elements, First, Others);
if(!tpo){ return(0); }
tpo2 = U_PO_po_append(Path->poTypes, tpo, U_PMF_DROP_ELEMENTS);
U_PO_free(&tpo);
if(!tpo2)return(0);
Path->poTypes = tpo2;
Path->Elements += Elements;
return(1);
}
/**
\brief Append a "polygon" set of points to a path.
\param Path Address of a DoublePseudoObject holding the path to append to.
\param Elements number of Points and Flags
\param Points Line points.
\param Flags Flags (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, but NOT U_PTP_CloseSubpath)
\returns 1 on success, 0 on error.
*/
int U_PATH_polygon(U_DPSEUDO_OBJ *Path, uint32_t Elements, const U_PMF_POINTF *Points, uint8_t Flags){
int status = U_PATH_polylineto(Path, Elements, Points, Flags, U_SEG_NEW);
if(status){
status = U_PATH_closepath(Path);
}
return(status);
}
//! \cond
// These are not exposed in the API
/* Parameterized Ellipse coordinates */
U_PMF_POINTF U_eparam(U_FLOAT a, U_FLOAT b, U_PMF_POINTF *center, double Ang, double Theta){
U_PMF_POINTF point;
point.X = center->X + a*cos(Theta)*cos(Ang) - b*sin(Theta)*sin(Ang);
point.Y = center->Y + a*sin(Theta)*cos(Ang) + b*cos(Theta)*sin(Ang);
return(point);
}
/* Parameterized Ellipse derivative */
U_PMF_POINTF U_eparam2(U_FLOAT a, U_FLOAT b, double Ang, double Theta){
U_PMF_POINTF point;
point.X = -a*cos(Theta)*sin(Ang) - b*sin(Theta)*cos(Ang);
point.Y = -a*sin(Theta)*sin(Ang) + b*cos(Theta)*cos(Ang);
return(point);
}
double U_aparam(double Ang1, double Ang2){
double Alpha;
double t2;
t2 = tan((Ang2 - Ang1)/2.0);
t2 *= t2;
Alpha = sin(Ang2 - Ang1) * (sqrt(4 + 3*t2) -1.0)/3.0;
return(Alpha);
}
/* Parameterized Bezier point Q1 or Q2 derivative */
U_PMF_POINTF U_qparam(double Alpha, double a, double b, U_PMF_POINTF *Point, double Ang, double Theta, int mode){
U_PMF_POINTF Q, Prime;
Prime = U_eparam2(a,b,Ang,Theta);
if(mode==1){ /* Q1, anything else is Q2*/
Q.X = Point->X + Alpha * Prime.X;
Q.Y = Point->Y + Alpha * Prime.Y;
}
else {
Q.X = Point->X - Alpha * Prime.X;
Q.Y = Point->Y - Alpha * Prime.Y;
}
return(Q);
}
//! \endcond
/**
\brief Append an "arcto" set of points to a path (Bezier points are calculated, and these are appended
\param Path Address of a pointer to the U_PSEUDO_OBJ that holds points
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rot Rotation angle to apply to coordinate system (Start and Rect), positive is degrees clockwise
\param Rect U_PMF_RECTF that defines the bounding rectangle.
\param Flags Flags (U_PTP_None, U_PTP_DashMode, U_PTP_PathMarker, U_PTP_NoBit, but NOT U_PTP_CloseSubpath)
\param StartSeg If set, the arc starts a new segment, if clear, continue the existing segment. Starting a new segment does not automatically apply U_PATH_closepath to the existing path.
\returns 1 on success, 0 on error.
Based on Luc Maisonobe's work, http://www.spaceroots.org/documents/ellipse/
*/
int U_PATH_arcto(U_DPSEUDO_OBJ *Path, U_FLOAT Start, U_FLOAT Sweep, U_FLOAT Rot, U_PMF_RECTF *Rect, uint8_t Flags, int StartSeg){
U_PMF_POINTF Bz[3];
U_PMF_POINTF Center;
U_PMF_POINTF P1,P2;
double a, b;
int done = 0;
int fpoint = 0;
double L1, L2; /* These are degrees CounterClockwise from 3:00 */
double Ang1, Ang2; /* These are parametric angles, derived from L1, L2*/
double Alpha; /* Dimensionless number used for Q1, Q2 */
double Theta; /* Rot in radians */
double Slop; /* do not let rounding errors cause spurious end points */
if(!Path){ return(0); }
if((Sweep > 360.0) || (Sweep < -360.0)){ return(0); }
/* Start should be between 0 and 360 degrees, but it does not really matter because sin, and cos will accept anything */
/* the sign on Sweep and Start is correct bacause LM's derivation has y positive up, but GDI+ has y positive down. */
a = Rect->Width/2.0;
b = Rect->Height/2.0;
if(!a || !b){ return(0); }
Center.X = Rect->X + a;
Center.Y = Rect->Y + b;
/* convert to radians */
Start = (2.0 * U_PI * Start)/360.0;
Sweep = (2.0 * U_PI * Sweep)/360.0;
Theta = (2.0 * U_PI * Rot )/360.0;
Slop = Sweep/100000.0;
L1 = Start;
while(!done){
if(Sweep < 0){
L2 = L1 - U_PI/2.0;
if(L2 <= Sweep + Start - Slop){ L2 = Sweep + Start; done = 1; }
else {done = 0; }
}
else {
L2 = L1 + U_PI/2.0;
if(L2 >= Sweep + Start + Slop){ L2 = Sweep + Start; done = 1; }
else {done = 0; }
}
Ang1 = atan2(sin(L1)/b, cos(L1)/a);
Ang2 = atan2(sin(L2)/b, cos(L2)/a);
Alpha = U_aparam(Ang1, Ang2);
P1 = U_eparam(a, b, &Center, Ang1, Theta); /* P1 */
P2 = U_eparam(a, b, &Center, Ang2, Theta); /* P2 */
Bz[0] = U_qparam(Alpha, a, b, &P1, Ang1, Theta, 1); /* Q1 */
Bz[1] = U_qparam(Alpha, a, b, &P2, Ang2, Theta, 2); /* Q2 */
Bz[2] = P2;
if(!fpoint){
if(StartSeg){ U_PATH_moveto(Path, P1, Flags); }
else { U_PATH_lineto(Path, P1, Flags); }
fpoint = 1;
}
U_PATH_polybezierto(Path, 3, Bz, Flags, U_SEG_OLD );
L1 = L2;
}
return(1);
}
/**
\brief Allocate and construct an array of U_PMF_POINTF objects which have been subjected to a U_XFORM
\returns pointer to an array of U_PMF_POINTF structures.
\param points pointer to the source U_PMF_POINTF structures
\param count number of members in points
\param xform U_XFORM to apply
*/
U_PMF_POINTF *pointfs_transform(U_PMF_POINTF *points, int count, U_XFORM xform){
U_PMF_POINTF *newpts=NULL;;
int i;
float X,Y;
newpts = (U_PMF_POINTF *) malloc(count * sizeof(U_PMF_POINTF));
if(newpts){
for(i=0; i<count; i++){
X = points[i].X;
Y = points[i].Y;
newpts[i].X = U_ROUND(X * xform.eM11 + Y * xform.eM21 + xform.eDx);
newpts[i].Y = U_ROUND(X * xform.eM12 + Y * xform.eM22 + xform.eDy);
}
}
return(newpts);
}
/**
\brief Allocate and construct an array of U_PMF_RECTF objects which have been subjected to a U_XFORM
\returns pointer to an array of U_PMF_RECTF structures.
\param Rects pointer to the source U_PMF_RECTF structures
\param Count number of members in Rects
\param Xform U_XFORM to apply. Rotation is ignored, only translation is applied.
*/
U_PMF_RECTF *rectfs_transform(U_PMF_RECTF *Rects, int Count, U_XFORM Xform){
U_PMF_RECTF *newRects;
int i;
newRects = (U_PMF_RECTF *) malloc(Count * sizeof(U_PMF_RECTF));
if(newRects){
for(i=0; i<Count; i++){
newRects[i].X = U_ROUND(Rects[i].X + Xform.eDx);
newRects[i].Y = U_ROUND(Rects[i].Y + Xform.eDy);
newRects[i].Width = U_ROUND(Rects[i].Width);
newRects[i].Height = U_ROUND(Rects[i].Height);
}
}
return(newRects);
}
/**
\brief Utility function calculate the transformation matrix needed to make a gradient run precisely corner to corner of a rectangle
\param Angle Rotation in degrees clockwise of the gradient. 0 is horizontal gradient.
\param w Width of the rectangle
\param h Height of the rectangle
\param x X coordinate of upper left corner of rectangle
\param y Y coordinate of upper left corner of rectangle
\param Periods Periods of gradient corner to corner. 1.0 is one, corner to corner.
\return Transformation matrix. All values are zero if Periods, w, or h are less than or equal to zero.
*/
U_PMF_TRANSFORMMATRIX tm_for_gradrect(U_FLOAT Angle, U_FLOAT w, U_FLOAT h, U_FLOAT x, U_FLOAT y, U_FLOAT Periods){
//! \cond
#define CLOSE_TO_IS_REALLY_ZERO(A) ((A) > 1.0e-10 || (A) < -1.0e-10 ? (A) : 0.0) //! \hideinitializer
//! \endcond
U_PMF_TRANSFORMMATRIX tm;
double dang = Angle * 2*U_PI /360.0;
double scale;
double cd,sd;
if((Periods <=0.0) || (w <= 0.0) || (h <= 0.0)){
tm.m11 = tm.m12 = tm.m21 = tm.m22 = tm.dX = tm.dY = 0.0;
}
else {
/*
scale is gradient period divided by w
The scale value sets the gradient period to match exactly with the inscribed (w,h) rectangle
in the direction specified by the angle.
The numberator of scale is the max of the four dot product values of the rotated X basis unit vector with (w,h),
with each of the vectors {w,h}, {-w,h}, {-w,-h}, {w,h}. Those vectors run from each corner in turn
to the opposite corner. The one most parallel to the rotated unit vector will have both terms positive.
Trig results like cos(pi/2) are not stable between platforms due to minor differences in the
implementation. Detect these and make them zero, which then allows binary comparison of output files.
Otherwise the binary comparisons between platforms would fail because of a bunch of insignificant digits.
*/
cd = CLOSE_TO_IS_REALLY_ZERO(cos(dang));
sd = CLOSE_TO_IS_REALLY_ZERO(sin(dang));
scale = (w*fabs(cd) + h*fabs(sd))/(w*Periods);
tm.m11 = scale * cd;
tm.m12 = -scale * sd;
tm.m21 = scale * sd;
tm.m22 = scale * cd;
/* offset is to one corner of the square, depending on which quadrant the rotation selects. */
if(cos(dang)>=0){
tm.dX = x;
if(sin(dang)>=0){tm.dY = y + h; } // LL corner
else { tm.dY = y; } // UL corner
}
else {
tm.dX = x + w;
if(sin(dang)>=0){ tm.dY = y + h; } // LR corner
else { tm.dY = y; } // UR corner
}
}
return tm;
#undef CLOSE_TO_IS_REALLY_ZERO
}
/**
\brief Create a U_PSEUDO_OBJ containing a U_PMR_FILLPATH and U_PMR_DRAWPATH records.
\returns pointer to U_PSEUDO_OBJ or NULL on error.
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
*/
U_PSEUDO_OBJ *U_PMR_drawfill(uint32_t PathID, uint32_t PenID, const U_PSEUDO_OBJ *BrushID){
U_PSEUDO_OBJ *po = U_PMR_FILLPATH_set(PathID, BrushID);
if(po){
U_PSEUDO_OBJ *tpo = U_PMR_DRAWPATH_set(PathID, PenID);
po = U_PO_po_append(po, tpo, U_PMF_KEEP_ELEMENTS);
U_PO_free(&tpo);
}
return(po);
}
/**
\brief Extract a single data field from a source.
\returns 1 on success, 0 on error.
\param Src where the data is coming from. It is incremented by the number of bytes retrieved.
\param Dst where the data will be stored. This must either be NULL (in which case the Src
is advanced and nothing is stored, or it must be allocated to Reps * Units bytes!!!!
\param Units number of bytes in each unit of the data field
\param Reps number of repeats of units in the data field.
If a Ptr is NULL, then Units*Reps 0 bytes are stored.
If a Ptr is NOT NULL, and Units or Reps, is zero an error is signaled.
If a Ptr is NULL and Units*Reps is 0, nothing happens.
\param SE logical (Source Endian). Only relevant for Sizes of 2 or 4
Indicates when Bytes may need to be rearranged when they are retrieved.
U_XE no change (this is used when the data has already been set to the proper orientation or it is not known)
U_LE source is Little Endian
U_BE source is Big Endian.
U_XX error
*/
int U_PMF_SERIAL_get(const char **Src, void *Dst, size_t Units, size_t Reps, int SE){
if(!Src || !*Src || SE == U_XX){ return(0); }
U_PMF_MEMCPY_SRCSHIFT(Dst, Src, Units * Reps);
if(!Dst){ return(1); } /* "fake" get, no data was retrieved, so we are done */
if(SE == U_XE){ return(1); }
if(SE == U_LE && U_IS_LE){ return(1); }
if(SE == U_BE && U_IS_BE){ return(1); }
/* need to swap */
if( Units==2){ U_swap2(Dst,Reps); }
else if(Units==4){ U_swap4(Dst,Reps); }
return(1);
}
/**
\brief Conditionally extract an array of data from a source, allocating space to hold it.
\returns 1 on success, 0 on error.
\param Src where the data is coming from. It is incremented by the number of bytes retrieved.
\param Dst Caller must free. Where the pointer to the data will be stored. Reps * Units bytes will be allocated,
\param Units number of bytes in each unit of the data field
\param Reps number of repeats of units in the data field.
If a Ptr is NULL, then Units*Reps 0 bytes are stored.
If a Ptr is NOT NULL, and Units or Reps, is zero an error is signaled.
If a Ptr is NULL and Units*Reps is 0, nothing happens.
\param SE logical (Source Endian). Only relevant for Sizes of 2 or 4
Indicates when Bytes may need to be rearranged when they are retrieved.
U_XE no change (this is used when the data has already been set to the proper orientation or it is not known)
U_LE source is Little Endian
U_BE source is Big Endian.
U_XX error
\param Cond Store the data into *Dst if true, set *Dst to NULL otherwise.
*/
int U_PMF_SERIAL_array_copy_get(const char **Src, void **Dst, size_t Units, size_t Reps, int SE, int Cond){
if(!Src || !*Src || !Dst || SE == U_XX){ return(0); }
if(!Cond){
*Src += Units * Reps;
*Dst = NULL;
return(1);
}
*Dst = malloc(Units * Reps);
if(!*Dst){ return(1); } /* "fake" get, no data was retrieved, so we are done */
U_PMF_MEMCPY_SRCSHIFT(*Dst, Src, Units * Reps);
if(SE == U_XE){ return(1); }
if(SE == U_LE && U_IS_LE){ return(1); }
if(SE == U_BE && U_IS_BE){ return(1); }
/* need to swap */
if( Units==2){ U_swap2(*Dst,Reps); }
else if(Units==4){ U_swap4(*Dst,Reps); }
return(1);
}
/**
\brief Calculate the length in bytes of a relative path object composed of U_PMF_INTEGER7 and U_PMF_INTER15 values
\return >=0 length == success, <0 error
\param contents Start of a relative path consisting of int7 and int15 X,Y pairs.
\param Elements number of relative X,Y pairs in the object
*/
int U_PMF_LEN_REL715(const char *contents, int Elements){
int length=0;
Elements *= 2; /* N pairs = 2N values */
for( ; Elements; Elements--){
/* X or Y value */
if(*contents & U_TEST_INT7){ contents +=2; length +=2; } //int15
else { contents +=1; length +=1; } //int7
}
return(length);
}
/**
\brief Calculate the length in bytes of objects which are a 4 byte Count followed by Count * float bytes
\return >=0 length == success, <0 error
Object types whose size may be derived with this function are:
U_PMF_COMPOUNDLINEDATA
U_PMF_DASHEDLINEDATA
*/
int U_PMF_LEN_FLOATDATA(const char *contents){
int Size;
U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE);
Size = 4*Size + 4;
return(Size);
}
/**
\brief Calculate the length in bytes of objects which are a 4 byte count followed by count bytes
\return >=0 length == success, <0 error
Object types whose size may be derived with this function are:
U_PMF_BOUNDARYPATHDATA
U_PMF_BOUNDARYPOINTDATA
U_PMF_CUSTOMSTARTCAPDATA
U_PMF_PATH
U_PMF_LINEPATH
U_PMF_REGIONNODEPATH
*/
int U_PMF_LEN_BYTEDATA(const char *contents){
int Size;
U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE);
Size += 4;
return(Size);
}
/**
\brief Create a string containing the curly bracket form of the 16 byte GUID value
\return number of bytes in record, 0 on error
\param GUID pointer to the 16 unsigned bytes
\return string in curly bracket form.
http://msdn.microsoft.com/en-us/library/cc230316.aspx
Text form is Data1-Data2-Data3-Data4, the first 3 are stored as little endian integers, the last as a string (big endian).
*/
char *U_PMF_CURLYGUID_set(uint8_t *GUID){
char *string=malloc(64);
if(string){
sprintf(string,"{%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X}",
GUID[3],GUID[2],GUID[1],GUID[0],
GUID[5],GUID[4],
GUID[7],GUID[6],
GUID[8],GUID[9],
GUID[10],GUID[11],GUID[12],GUID[13],GUID[14],GUID[15]
);
}
return(string);
}
/**
\brief Identify a known curly GUID
\param string Curly GUID form.
\return EmageEffects Enumerator
EMF+ manual 2.1.3.1, Microsoft name: ImageEffects Identifier
*/
int U_PMF_KNOWNCURLYGUID_set(const char *string){
int status;
if( !strcmp(string,"{633C80A4-1843-482B-9EF2-BE2834C5FDD4}")){ status = U_IEE_BlurEffectGuid; }
else if(!strcmp(string,"{D3A1DBE1-8EC4-4C17-9F4C-EA97AD1C343D}")){ status = U_IEE_BrightnessContrastEffectGuid; }
else if(!strcmp(string,"{537E597D-251E-48DA-9664-29CA496B70F8}")){ status = U_IEE_ColorBalanceEffectGuid; }
else if(!strcmp(string,"{DD6A0022-58E4-4A67-9D9B-D48EB881A53D}")){ status = U_IEE_ColorCurveEffectGuid; }
else if(!strcmp(string,"{A7CE72A9-0F7F-40D7-B3CC-D0C02D5C3212}")){ status = U_IEE_ColorLookupTableEffectGuid; }
else if(!strcmp(string,"{718F2615-7933-40E3-A511-5F68FE14DD74}")){ status = U_IEE_ColorMatrixEffectGuid; }
else if(!strcmp(string,"{8B2DD6C3-EB07-4D87-A5F0-7108E26A9C5F}")){ status = U_IEE_HueSaturationLightnessEffectGuid;}
else if(!strcmp(string,"{99C354EC-2A31-4F3A-8C34-17A803B33A25}")){ status = U_IEE_LevelsEffectGuid; }
else if(!strcmp(string,"{74D29D05-69A4-4266-9549-3CC52836B632}")){ status = U_IEE_RedEyeCorrectionEffectGuid; }
else if(!strcmp(string,"{63CBF3EE-C526-402C-8F71-62C540BF5142}")){ status = U_IEE_SharpenEffectGuid; }
else if(!strcmp(string,"{1077AF00-2848-4441-9489-44AD4C2D7A2C}")){ status = U_IEE_TintEffectGuid; }
else { status = U_IEE_Unknown; }
return(status);
}
/** \brief Load a GUID from text format into EMF+ file binary format.
\param string Curly GUID as text, minus the barckets and dashes.
\return GUID in EMF+ file binary format.
This accepts a string that is 16 bytes long = 32 characters hex (no dash spaces or brackets) as text.
Text form is; Data1|Data2|Data3|Data4, first three are stored as little endian integers of 4,2,2 bytes, respectively,
last is stored like a string (big endian), after conversion from text hex to binary.
This function is not normally called by end user code.
*/
uint8_t *U_LOAD_GUID(char *string){
uint32_t Data1,tData2,tData3,tByte;
uint16_t Data2,Data3;
char *Data4 = string + 16;
uint8_t *hold = malloc(16);
char *lf = (char *) hold;
int i;
if(hold){
Data1=tData2=tData3=0;
if(3 != sscanf(string + 0,"%8X",&Data1) +
sscanf(string + 8,"%4X",&tData2) +
sscanf(string + 12,"%4X",&tData3)){
free(hold);
hold = NULL;
goto bye;
}
Data2=tData2;
Data3=tData3;
U_PMF_MEMCPY_DSTSHIFT(&lf, &Data1, 4);
U_PMF_MEMCPY_DSTSHIFT(&lf, &Data2, 2);
U_PMF_MEMCPY_DSTSHIFT(&lf, &Data3, 2);
if(U_IS_BE){ /* these fields are stored little endian */
U_swap4(hold,1);
U_swap2(hold+4,2);
}
/* remainder is converted byte by byte and stored in that order */
for(i=0;i<8;i++,Data4+=2,lf++){
if(1 != sscanf(Data4,"%2X",&tByte)){
free(hold);
hold = NULL;
goto bye;
}
*lf=tByte;
}
}
bye:
return(hold);
}
/**
\brief Generate the 16 byte form from OID of the ImageEffects Identifier
\param OID OID of the ImageEffects Identifier
\return pointer to 16 byte buffer holding the long GUID binary form, or NULL on error.
EMF+ manual 2.1.3.1, Microsoft name: ImageEffects Identifier
*/
uint8_t *U_OID_To_GUID(uint32_t OID){
uint8_t *lf = NULL;
if( OID == U_PMF_IE_BLUR_OID ){ lf = U_LOAD_GUID("633C80A41843482B9EF2BE2834C5FDD4"); }
else if(OID == U_PMF_IE_BRIGHTNESSCONTRAST_OID ){ lf = U_LOAD_GUID("D3A1DBE18EC44C179F4CEA97AD1C343D"); }
else if(OID == U_PMF_IE_COLORBALANCE_OID ){ lf = U_LOAD_GUID("537E597D251E48DA966429CA496B70F8"); }
else if(OID == U_PMF_IE_COLORCURVE_OID ){ lf = U_LOAD_GUID("DD6A002258E44A679D9BD48EB881A53D"); }
else if(OID == U_PMF_IE_COLORLOOKUPTABLE_OID ){ lf = U_LOAD_GUID("A7CE72A90F7F40D7B3CCD0C02D5C3212"); }
else if(OID == U_PMF_IE_COLORMATRIX_OID ){ lf = U_LOAD_GUID("718F2615793340E3A5115F68FE14DD74"); }
else if(OID == U_PMF_IE_HUESATURATIONLIGHTNESS_OID){ lf = U_LOAD_GUID("8B2DD6C3EB074D87A5F07108E26A9C5F"); }
else if(OID == U_PMF_IE_LEVELS_OID ){ lf = U_LOAD_GUID("99C354EC2A314F3A8C3417A803B33A25"); }
else if(OID == U_PMF_IE_REDEYECORRECTION_OID ){ lf = U_LOAD_GUID("74D29D0569A4426695493CC52836B632"); }
else if(OID == U_PMF_IE_SHARPEN_OID ){ lf = U_LOAD_GUID("63CBF3EEC526402C8F7162C540BF5142"); }
else if(OID == U_PMF_IE_TINT_OID ){ lf = U_LOAD_GUID("1077AF0028484441948944AD4C2D7A2C"); }
return(lf);
}
/**
\brief copy data and shift source pointer by the amount of data moved
\param Dst Destination in memory
\param Src Source in memory
\param Size Number of bytes to move
*/
void U_PMF_MEMCPY_SRCSHIFT(void *Dst, const char **Src, size_t Size){
if(Dst)memcpy(Dst, *Src, Size);
*Src += Size;
}
/**
\brief copy data and shift destination pointer by the amount of data moved
\param Dst Destination in memory (this must not be NULL)
\param Src Source in memory (if this is NULL, fill with that many zero bytes instead)
\param Size Number of bytes to move
*/
void U_PMF_MEMCPY_DSTSHIFT(char **Dst, const void *Src, size_t Size){
if(Src){ memcpy(*Dst, Src, Size); }
else { memset(*Dst, 0, Size); }
*Dst += Size;
}
/**
\brief Copy the single instance at Src repeatedly to Dst.
\param Dst Destination in memory
\param Src Source in memory (if this is NULL, fill with that many zero bytes instead)
\param Size number of bytes in single instance that is template.
\param Reps Number of instances of the template to opy
*/
void U_PMF_REPCPY_DSTSHIFT(char **Dst, const void *Src, size_t Size, size_t Reps){
for(;Reps;Reps--){
if(Src){ memcpy(*Dst, Src, Size); }
else { memset(*Dst, 0, Size); }
*Dst += Size;
}
}
/**
\brief save pointer to data and shift source pointer by the amount of data moved
\param Dst Destination in memory
\param Src Source in memory or NULL. If NULL Dst is set to NULL.
\param Size Number of bytes to move
*/
void U_PMF_PTRSAV_SHIFT(const char **Dst, const char **Src, size_t Size){
if(*Src){
if(Dst)*Dst = *Src;
*Src += Size;
}
else {
if(Dst)*Dst = NULL;
}
}
/**
\brief save pointer to data and shift source pointer by the amount of data moved
\return 1 on sucess, 0 on error
\param Dst Destination in memory
\param Src Source in memory or NULL. If NULL Dst is set to NULL.
\param Doit Assign if true, otherwise, set to NULL
*/
int U_PMF_PTRSAV_COND(const char **Dst, const char *Src, int Doit){
if(!Dst){ return(0); }
if(Src && Doit){ *Dst = Src; }
else { *Dst = NULL; }
return(1);
}
/*
=====================================================================================
start of U_PMF_*_get() functions
*/
/**
\brief Get the 16 bit unsigned Flags field from a header.
\param contents Record from which to extract data, will be incremented by header size.
\return Flags field
In many records the only value needed from the header is Flags. Rather than mapping
the entire Header and returning it, in these instances this function may be called to
just get this one value.
*/
uint16_t U_PMF_HEADERFLAGS_get(const char *contents){
uint16_t Flags;
const char *cptr = contents + offsetof(U_PMF_CMN_HDR,Flags);
U_PMF_SERIAL_get(&cptr, &Flags, 2, 1, U_LE); /* EMF+ manual documents it as BE, but this code implements it as LE*/
return(Flags);
}
/**
\brief Retrieve whichever header fields are requested. NULL pointers do not retrieve.
\param contents Record from which to extract data, will be incremented by header size.
\param Type Record type
\param Flags Record flags
\param Size Records size
\param Datasize Data size
\return 1 on success, 0 on failure.
*/
int U_PMF_HEADERFIELDS_get(const char *contents,
uint16_t *Type, uint16_t *Flags, uint32_t *Size, uint32_t *Datasize){
if(!contents){ return(0); }
U_PMF_SERIAL_get(&contents, Type, 2, 1, U_LE);
U_PMF_SERIAL_get(&contents, Flags, 2, 1, U_LE); /* EMF+ manual documents it as BE, but this code implements it as LE*/
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Datasize, 4, 1, U_LE);
return(1);
}
/**
\brief Get the entire EMF+ record header.
\param contents Record from which to extract data, will be offset by header size.
\param Header Location to store data (may be NULL)
\returns 1
If Header is Null, nothing is stored but contents is still offset.
*/
int U_PMF_CMN_HDR_get(const char **contents, U_PMF_CMN_HDR *Header){
if(!contents || !*contents){ return(0); }
if(Header){
U_PMF_SERIAL_get(contents, &(Header->Type), 2, 1, U_LE);
U_PMF_SERIAL_get(contents, &(Header->Flags), 2, 1, U_LE); /* EMF+ manual documents it as BE, but this code implements it as LE*/
U_PMF_SERIAL_get(contents, &(Header->Size), 4, 1, U_LE);
U_PMF_SERIAL_get(contents, &(Header->DataSize), 4, 1, U_LE);
}
else {
*contents += sizeof(U_PMF_CMN_HDR);
}
return(1);
}
/**
\brief return the size in bytes of the EMF+ record
\param contents Record from which to extract data, will not be modified.
\returns size, or 0 if contents is Null
*/
int U_PMF_RECORD_SIZE_get(const char *contents){
if(!contents){ return(0); }
int Size;
const char *from = contents + 4;
U_PMF_SERIAL_get(&from, &Size, 4, 1, U_LE);
return(Size);
}
/**
\brief Return the size of a PenData object from an EMF+ record.
\param PenData Address in memory where the PenData object starts.
\returns size of the object in bytes
*/
int U_PMF_LEN_PENDATA(const char *PenData){
uint32_t Flags;
int length=12; /* Flags, Unit, Width */
U_PMF_SERIAL_get(&PenData, &Flags, 4, 1, U_LE);
PenData += 8; /* skip Unit and Width */
length += U_PMF_LEN_OPTPENDATA(PenData, Flags);
return(length);
}
/**
\brief Return the size of an OptPenData object from an EMF+ record.
\param PenData Address in memory where the PenData object starts.
\param Flags PenData Flags that indicate which fields are present.
\returns size of the object in bytes
*/
int U_PMF_LEN_OPTPENDATA(const char *PenData, uint32_t Flags){
int length=0;
if(Flags & U_PD_Transform){ length += sizeof(U_PMF_TRANSFORMMATRIX); }
if(Flags & U_PD_StartCap){ length += sizeof(int32_t); }
if(Flags & U_PD_EndCap){ length += sizeof(int32_t); }
if(Flags & U_PD_Join){ length += sizeof(uint32_t); }
if(Flags & U_PD_MiterLimit){ length += sizeof(U_FLOAT); }
if(Flags & U_PD_LineStyle){ length += sizeof(int32_t); }
if(Flags & U_PD_DLCap){ length += sizeof(int32_t); }
if(Flags & U_PD_DLOffset){ length += sizeof(int32_t); }
if(Flags & U_PD_DLData){ length += U_PMF_LEN_FLOATDATA(PenData + length); }
if(Flags & U_PD_NonCenter){ length += sizeof(int32_t); }
if(Flags & U_PD_CLData){ length += U_PMF_LEN_FLOATDATA(PenData + length); }
if(Flags & U_PD_CustomStartCap){ length += U_PMF_LEN_BYTEDATA(PenData + length); }
if(Flags & U_PD_CustomEndCap){ length += U_PMF_LEN_BYTEDATA(PenData + length); }
return(length);
}
/**
\brief Create and set a U_PMF_BRUSH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Bd U_PSEUDO_OBJ containing one of the 5 types of Brush data
EMF+ manual 2.2.1.1, Microsoft name: EmfPlusBrush Object
*/
U_PSEUDO_OBJ *U_PMF_BRUSH_set(uint32_t Version, const U_PSEUDO_OBJ *Bd){
if(!Bd){ return(NULL); }
int32_t Type = U_OID_To_BT(Bd->Type);
if(Type < 0){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Type, 4, 1, U_LE},
{Bd->Data, Bd->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BRUSH_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMLINECAP PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Ld U_PSEUDO_OBJ containing one of the 2 types of Linecap data
EMF+ manual 2.2.1.2, Microsoft name: EmfPlusCustomLineCap Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAP_set(uint32_t Version, const U_PSEUDO_OBJ *Ld){
if(!Ld){ return(NULL); }
int32_t Type = U_OID_To_CLCDT(Ld->Type);
if(Type<0){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Type, 4, 1, U_LE},
{Ld->Data, Ld->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMLINECAP_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_FONT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param EmSize em size in units of SizeUnit
\param SizeUnit UnitType enumeration
\param FSFlags FontStyle flags
\param Length Number of Unicode Characters in FamilyName
\param Font Unicode (UTF-16LE) fontname
EMF+ manual 2.2.1.3, Microsoft name: EmfPlusFont Object
*/
U_PSEUDO_OBJ *U_PMF_FONT_set(uint32_t Version, U_FLOAT EmSize, uint32_t SizeUnit,
int32_t FSFlags, uint32_t Length, const uint16_t *Font){
uint32_t cbFont = 2 * wchar16len(Font); /* this need not be 2*Length parameter */
uint32_t pad = (0x3 & cbFont ? 2 : 0);
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&EmSize, 4, 1, U_LE},
{&SizeUnit,4, 1, U_LE},
{&FSFlags, 4, 1, U_LE},
{NULL, 4, 1, U_LE}, /* NULL is for Reserved field */
{&Length, 4, 1, U_LE},
{Font, cbFont, 1, U_LE},
{NULL, pad, (pad ? 1 : 0), (pad ? U_XE : U_XX)}, /* Entire record must be a multiple of 4 */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_FONT_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IMAGE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Id U_PSEUDO_OBJ containing one of the 2 types of image data
EMF+ manual 2.2.1.4, Microsoft name: EmfPlusImage Object
*/
U_PSEUDO_OBJ *U_PMF_IMAGE_set(uint32_t Version, const U_PSEUDO_OBJ *Id){
if(!Id){ return(NULL); }
int32_t Type = U_OID_To_IDT(Id->Type);
if(Type<0){ return(NULL);}
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Type, 4, 1, U_LE},
{Id->Data, Id->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IMAGE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IMAGEATTRIBUTES PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param WrapMode WrapMode object
\param ClampColor EmfPlusARGB object
\param ObjectClamp ObjectClamp Identifiers
EMF+ manual 2.2.1.5, Microsoft name: EmfPlusImageAttributes Object
*/
U_PSEUDO_OBJ *U_PMF_IMAGEATTRIBUTES_set(uint32_t Version, uint32_t WrapMode, uint32_t ClampColor, uint32_t ObjectClamp){
uint32_t Reserved=0;
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Reserved, 4, 1, U_LE},
{&WrapMode, 4, 1, U_LE},
{&ClampColor, 4, 1, U_LE},
{&ObjectClamp, 4, 1, U_LE},
{&Reserved, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IMAGEATTRIBUTES_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Points U_PSEUDO_OBJ containing array of points (of type PMFPointR, PMFPoint, or PMFPointF, determined by U_PPF_P and U_PPF_C bits in Flags)
\param Types U_PSEUDO_OBJ containing array of types (U_PMF_PATHPOINTTYPE or U_PMF_PATHPOINTTYPERLE, determined by U_PPF_R big in Flags)
EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object
*/
U_PSEUDO_OBJ *U_PMF_PATH_set(uint32_t Version, const U_PSEUDO_OBJ *Points, const U_PSEUDO_OBJ *Types){
int ctype, RelAbs, rtype;
int pad;
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(Types){
if( Types->Type == (U_PMF_PATHPOINTTYPERLE_OID | U_PMF_ARRAY_OID)){ rtype = 1; }
else if(Types->Type == (U_PMF_PATHPOINTTYPE_OID | U_PMF_ARRAY_OID)){ rtype = 0; }
else { return(NULL); }
}
else { return(NULL); }
uint16_t Flags = (rtype ? U_PPF_R : 0) | (ctype ? U_PPF_C : 0)| (RelAbs ? U_PPF_P : 0);
pad = (0x3 & (Points->Used + Types->Used));
if(pad){ pad = 4 - pad; }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE },
{Points->Data, 4, 1, U_XE }, /* Elements from Points */
{&Flags, 2, 1, U_LE },
{NULL, 2, 1, U_LE }, /* Reserved field */
{Points->Data + 4, Points->Used - 4, 1, U_XE }, /* omit Points Elements */
{Types->Data +4, Types->Used - 4, 1, U_XE }, /* omit Types Elements */
{NULL, pad, (pad ? 1 : 0), (pad ? U_XE : U_XX)}, /* if no padding is needed the Units will be zero and nothing will happen */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATH_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PATH PseudoObject that uses U_PMF_POINTF coordinates
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Path U_DPSEUDO_OBJ containing a path.
EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object
*/
U_PSEUDO_OBJ *U_PMF_PATH_set2(uint32_t Version, const U_DPSEUDO_OBJ *Path){
if(!Path || !Path->Elements){ return(NULL); }
uint16_t Flags = 0;
int pad = (0x3 & Path->Elements);
if(pad){ pad = 4 - pad; }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE },
{&Path->Elements, 4, 1, U_LE },
{&Flags, 2, 1, U_LE },
{NULL, 2, 1, U_LE }, /* Reserved field */
{Path->poPoints->Data, 4, 2*Path->Elements,U_XE }, /* raw OID, so no leading Elements to omit */
{Path->poTypes->Data, 1, Path->Elements, U_XE }, /* raw OID, so no leading Elements to omit */
{NULL, pad, (pad ? 1 : 0), (pad ? U_XE : U_XX)}, /* if no padding is needed the Units will be zero and nothing will happen */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATH_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PATH PseudoObject that uses U_PMF_POINT (int 16) coordinates
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Path U_DPSEUDO_OBJ containing a path.
EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object
*/
U_PSEUDO_OBJ *U_PMF_PATH_set3(uint32_t Version, const U_DPSEUDO_OBJ *Path){
if(!Path || !Path->Elements){return(NULL); }
uint16_t Flags = U_PPF_C;
int pad = (0x3 & Path->Elements);
if(pad){ pad = 4 - pad; }
U_PMF_POINT *Points16 = POINTF_To_POINT16_LE((U_PMF_POINTF *)Path->poPoints->Data, Path->Elements);
if(!Points16){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE },
{&Path->Elements, 4, 1, U_LE },
{&Flags, 2, 1, U_LE },
{NULL, 2, 1, U_LE }, /* Reserved field */
{Points16, 2, 2*Path->Elements,U_XE }, /* raw data, so no leading Elements to omit */
{Path->poTypes->Data, 1, Path->Elements, U_XE }, /* raw data, so no leading Elements to omit */
{NULL, pad, (pad ? 1 : 0), (pad ? U_XE : U_XX)}, /* if no padding is needed the Units will be zero and nothing will happen */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATH_OID, List);
free(Points16);
return(po);
}
/**
\brief Create and set a U_PMF_PEN PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param PenData U_PSEUDO_OBJ containing U_PMF_PENDATA object
\param Brush U_PSEUDO_OBJ containing U_PMF_BRUSH object
EMF+ manual 2.2.1.7, Microsoft name: EmfPlusPen Object
*/
U_PSEUDO_OBJ *U_PMF_PEN_set(uint32_t Version, const U_PSEUDO_OBJ *PenData, const U_PSEUDO_OBJ *Brush){
if(!PenData || (PenData->Type != U_PMF_PENDATA_OID)){ return(NULL); }
if(!Brush || (Brush->Type != U_PMF_BRUSH_OID) ){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{NULL, 4, 1, U_LE},
{PenData->Data, PenData->Used, 1, U_XE},
{Brush->Data, Brush->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PEN_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_REGION PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Version EmfPlusGraphicsVersion object
\param Count Number of CHILD nodes. This is one less than the total number of U_PMF_REGIONNODE objects in Nodes.
\param Nodes U_PSEUDO_OBJ containing U_PMF_REGIONNODE object (Nodes defining region, may be a single element or a binary tree)
EMF+ manual 2.2.1.8, Microsoft name: EmfPlusRegion Object
*/
U_PSEUDO_OBJ *U_PMF_REGION_set(uint32_t Version, uint32_t Count, const U_PSEUDO_OBJ *Nodes){
if(!Nodes || Nodes->Type != U_PMF_REGIONNODE_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Count, 4, 1, U_LE},
{Nodes->Data, Nodes->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_REGION_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_STRINGFORMAT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Sfs pointer to U_PMF_STRINGFORMAT structure, with no variable part
\param Sfd (optional) U_PSEUDO_OBJ containing U_PMF_STRINGFORMATDATA object
EMF+ manual 2.2.1.9, Microsoft name: EmfPlusStringFormat Object
*/
U_PSEUDO_OBJ *U_PMF_STRINGFORMAT_set(U_PMF_STRINGFORMAT *Sfs, const U_PSEUDO_OBJ *Sfd){
if(!Sfs){ return(NULL); }
if(Sfd){
if((!Sfs->TabStopCount && !Sfs->RangeCount) || (Sfd->Type != U_PMF_STRINGFORMATDATA_OID))return(NULL);
}
else {
if(Sfs->TabStopCount || Sfs->RangeCount)return(NULL);
}
const U_SERIAL_DESC List[] = {
{&Sfs->Version, 4, 1, U_LE},
{&Sfs->Flags, 4, 1, U_LE},
{&Sfs->Language, 4, 1, U_LE},
{&Sfs->StringAlignment, 4, 1, U_LE},
{&Sfs->LineAlign, 4, 1, U_LE},
{&Sfs->DigitSubstitution, 4, 1, U_LE},
{&Sfs->DigitLanguage, 4, 1, U_LE},
{&Sfs->FirstTabOffset, 4, 1, U_LE},
{&Sfs->HotkeyPrefix, 4, 1, U_LE},
{&Sfs->LeadingMargin, 4, 1, U_LE},
{&Sfs->TrailingMargin, 4, 1, U_LE},
{&Sfs->Tracking, 4, 1, U_LE},
{&Sfs->Trimming, 4, 1, U_LE},
{&Sfs->TabStopCount, 4, 1, U_LE},
{&Sfs->RangeCount, 4, 1, U_LE},
{(Sfd ? Sfd->Data : NULL), (Sfd ? Sfd->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_STRINGFORMAT_OID, List);
return(po);
}
/**
\brief Create and set a PMF_4NUM PseudoObject (used for BrushID's)
\return Pointer to PseudoObject, NULL on error
\param BrushID U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
*/
U_PSEUDO_OBJ *U_PMF_4NUM_set(uint32_t BrushID){
if(BrushID>63){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&BrushID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_4NUM_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_ARGB PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Alpha Alpha (0-255)
\param Red Red color (0-255)
\param Green Green color (0-255)
\param Blue Blue color (0-255)
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
U_PSEUDO_OBJ *U_PMF_ARGB_set(uint8_t Alpha, uint8_t Red, uint8_t Green, uint8_t Blue){
const U_SERIAL_DESC List[] = {
{&Blue, 1, 1, U_XE},
{&Green, 1, 1, U_XE},
{&Red, 1, 1, U_XE},
{&Alpha, 1, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_ARGB_OID, List);
return(po);
}
/**
\brief Create and set an Array of U_PMF_ARGB valus in a PseudoObject
\return Pointer to PseudoObject containing the count, followed by the array of colors, NULL on error
\param Count Number of entries in Colors
\param Colors Array of ARGB values
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
U_PSEUDO_OBJ *U_PMF_ARGBN_set(uint32_t Count, U_PMF_ARGB *Colors){
const U_SERIAL_DESC List[] = {
{&Count, 4, 1, U_LE},
{Colors, 4, Count, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_ARGB_OID | U_PMF_ARRAY_OID, List);
return(po);
}
/**
\brief Set a U_PMF_ARGB object
\return Object
\param Alpha Alpha (0-255)
\param Red Red color (0-255)
\param Green Green color (0-255)
\param Blue Blue color (0-255)
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
U_PMF_ARGB U_PMF_ARGBOBJ_set(uint8_t Alpha, uint8_t Red, uint8_t Green, uint8_t Blue){
U_PMF_ARGB argb;
char *ptr = (char *) &argb;
U_PMF_MEMCPY_DSTSHIFT(&ptr, &Blue, 1);
U_PMF_MEMCPY_DSTSHIFT(&ptr, &Green, 1);
U_PMF_MEMCPY_DSTSHIFT(&ptr, &Red, 1);
U_PMF_MEMCPY_DSTSHIFT(&ptr, &Alpha, 1);
return(argb);
}
/**
\brief Create and set a U_PMF_BITMAP PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Bs pointer to U_PMF_BITMAP structure, with no variable part
\param Bm U_PSEUDO_OBJ containing an U_PMF_BITMAPDATA or U_PMF_COMPRESSEDIMAGE object
EMF+ manual 2.2.2.2, Microsoft name: EmfPlusBitmap Object
*/
U_PSEUDO_OBJ *U_PMF_BITMAP_set(const U_PMF_BITMAP *Bs, const U_PSEUDO_OBJ *Bm){
if(!Bs)return(NULL);
if(Bm->Type != U_PMF_BITMAPDATA_OID &&
Bm->Type != U_PMF_COMPRESSEDIMAGE_OID )return(NULL);
uint32_t Pad = UP4(Bm->Used) - Bm->Used; /* undocumented padding, must be present for at least PNG */
const U_SERIAL_DESC List[] = {
{Bs, 4, 5, U_LE},
{Bm->Data, Bm->Used, 1, U_XE},
{NULL, (Pad ? Pad : 0), (Pad ? 1 : 0), U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BITMAP_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_BITMAPDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Ps (optional) U_PSEUDO_OBJ containing a U_PMF_PALETTE structure
\param cbBm Bytes in Bm
\param Bm An array of bytes, meaning depends on fields in U_PMF_BITMAP object and the PixelFormat enumeration.
EMF+ manual 2.2.2.3, Microsoft name: EmfPlusBitmapData Object
*/
U_PSEUDO_OBJ *U_PMF_BITMAPDATA_set( const U_PSEUDO_OBJ *Ps, int cbBm, const char *Bm){
if(Ps && (Ps->Type != U_PMF_PALETTE_OID))return(NULL);
if(!Bm && cbBm)return(NULL);
const U_SERIAL_DESC List[] = {
{(Ps ? Ps->Data : NULL), (Ps ? Ps->Used : 0), (Ps ? 1 : 0), U_LE},
{Bm, cbBm, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BITMAPDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_BLENDCOLORS PseudoObject
\return Pointer to PseudoObject, NULL on Positions and Colors
\param Elements number of elements in Positions, must agree with the number of Colors.
\param Positions positions along gradient line. The first position MUST be 0.0 and the last MUST be 1.0.
\param Colors U_PSEUDO_OBJ containing an array of U_PMF_ARGB objects: object colors at positions on gradient line
EMF+ manual 2.2.2.4, Microsoft name: EmfPlusBlendColors Object
*/
U_PSEUDO_OBJ *U_PMF_BLENDCOLORS_set(uint32_t Elements, const U_FLOAT *Positions, const U_PSEUDO_OBJ *Colors){
if(!Colors || !Positions || Colors->Type != (U_PMF_ARGB_OID | U_PMF_ARRAY_OID)){ return(NULL); }
uint32_t CElements = (Colors->Used - 4)/4;
if(CElements != Elements){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&CElements, 4, 1, U_LE},
{Positions, 4, CElements, U_LE},
{Colors->Data + 4, Colors->Used - 4, 1, U_XE}, /* omit Elements part of this PseudoObject */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BLENDCOLORS_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_BLENDCOLORS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements members in osition, inluding Start and End (0.0 - 1.0)
\param StartColor Start Color (U_PMF_ARGB)
\param EndColor End Color (U_PMF_ARGB)
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
Positions always start at 0.0 and always end at 1.0. It is not well documented but other
start and end values generally do not work.
*/
U_PSEUDO_OBJ *U_PMF_BLENDCOLORS_linear_set(uint32_t Elements, U_PMF_ARGB StartColor, U_PMF_ARGB EndColor){
double dP,dR,dG,dB,dA,P,R,G,B,A;
U_FLOAT StartPos = 0.0;
U_FLOAT EndPos = 1.0;
U_FLOAT *Positions;
U_FLOAT *pP;
U_PMF_ARGB *Colors;
U_PMF_ARGB *pC;
unsigned int i;
if(Elements <= 2 ){ return(NULL); }
pP = Positions = (U_FLOAT *)malloc(Elements *sizeof(U_FLOAT));
if(!Positions){ return(NULL); }
pC = Colors = (U_PMF_ARGB *)malloc(Elements *sizeof(U_PMF_ARGB));
if(!Colors){
free(Positions);
return(NULL);
}
dP = (EndPos - StartPos )/(float)(Elements - 1);
dB = ((double)EndColor.Blue - (double)StartColor.Blue )/(double)(Elements - 1);
dG = ((double)EndColor.Green - (double)StartColor.Green)/(double)(Elements - 1);
dR = ((double)EndColor.Red - (double)StartColor.Red )/(double)(Elements - 1);
dA = ((double)EndColor.Alpha - (double)StartColor.Alpha)/(double)(Elements - 1);
P = StartPos;
B = StartColor.Blue;
G = StartColor.Green;
R = StartColor.Red;
A = StartColor.Alpha;
for(i=0;i<Elements;i++,pC++,pP++){ /* hopefully the rounding errors are not a problem, used doubles to minimize that */
*pP = P;
P += dP;
*pC = (U_PMF_ARGB){B,G,R,A};
B += dB;
G += dG;
R += dR;
A += dA;
}
U_PSEUDO_OBJ *poColors = U_PMF_ARGBN_set(Elements, Colors);
U_PSEUDO_OBJ *po = U_PMF_BLENDCOLORS_set(Elements, Positions, poColors);
U_PO_free(&poColors);
free(Positions);
free(Colors);
return(po);
}
/**
\brief Create and set a U_PMF_BLENDFACTORS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements members in each array
\param Positions positions along gradient line. The first position MUST be 0.0 and the last MUST be 1.0.
\param Factors blending factors, 0.0->1.0 values, inclusive
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
*/
U_PSEUDO_OBJ *U_PMF_BLENDFACTORS_set(uint32_t Elements, const U_FLOAT *Positions, const U_FLOAT *Factors){
if(!Positions || !Factors)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Positions, 4, Elements, U_LE},
{Factors, 4, Elements, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BLENDFACTORS_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_BLENDFACTORS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements members in osition, inluding Start and End (0.0 - 1.0)
\param StartFactor Start Factor (0.0 - 1.0)
\param EndFactor End Factor (0.0 - 1.0)
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
Positions always start at 0.0 and always end at 1.0. It is not well documented but other
start and end values generally do not work.
*/
U_PSEUDO_OBJ *U_PMF_BLENDFACTORS_linear_set(uint32_t Elements, U_FLOAT StartFactor, U_FLOAT EndFactor){
double dP,dF,P,F;
U_FLOAT StartPos = 0.0;
U_FLOAT EndPos = 1.0;
U_FLOAT *Positions;
U_FLOAT *Factors;
U_FLOAT *pP;
U_FLOAT *pF;
unsigned int i;
if(Elements <= 2 ){ return(NULL); }
pP = Positions = (U_FLOAT *)malloc(Elements *sizeof(U_FLOAT));
if(!Positions){ return(NULL); }
pF = Factors = (U_FLOAT *)malloc(Elements *sizeof(U_FLOAT));
if(!Factors){
free(Positions);
return(NULL);
}
dP = (EndPos - StartPos )/(float)(Elements - 1);
dF = (EndFactor - StartFactor)/(float)(Elements - 1);
P = StartPos;
F = StartFactor;
for(i=0;i<Elements;i++){ /* hopefully the rounding errors are not a problem, used doubles to minimize that */
*pP++ = P; P += dP;
*pF++ = F; F += dF;
}
U_PSEUDO_OBJ *po = U_PMF_BLENDFACTORS_set(Elements, Positions, Factors);
free(Positions);
free(Factors);
return(po);
}
/**
\brief Create and set a U_PMF_BOUNDARYPATHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Path U_PSEUDO_OBJ containing U_PMF_PATH object
EMF+ manual 2.2.2.6, Microsoft name: EmfPlusBoundaryPathData Object
*/
U_PSEUDO_OBJ *U_PMF_BOUNDARYPATHDATA_set(const U_PSEUDO_OBJ *Path){
if(!Path || Path->Type != U_PMF_PATH_OID)return(NULL);
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Path->Used;
const U_SERIAL_DESC List[] = {
{&Used, 4, 1, U_LE},
{Path->Data, Path->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BOUNDARYPATHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_BOUNDARYPOINTDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements members in each array
\param Points array of U_PMF_POINTF
EMF+ manual 2.2.2.7, Microsoft name: EmfPlusBoundaryPointData Object
*/
U_PSEUDO_OBJ *U_PMF_BOUNDARYPOINTDATA_set(uint32_t Elements, const U_PMF_POINTF *Points){
if(!Points)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Points, 4, 2*Elements,U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_BOUNDARYPOINTDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CHARACTERRANGE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param First First position in range
\param Length Range length
EMF+ manual 2.2.2.8, Microsoft name: EmfPlusCharacterRange Object
*/
U_PSEUDO_OBJ *U_PMF_CHARACTERRANGE_set(int32_t First, int32_t Length){
const U_SERIAL_DESC List[] = {
{&First, 4, 1, U_LE},
{&Length, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CHARACTERRANGE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_COMPOUNDLINEDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements Members in Widths
\param Widths Array of U_FLOAT Line or gap widths (0.0 <-> 1.0, fraction of total line width )
EMF+ manual 2.2.2.9, Microsoft name: EmfPlusCompoundLineData Object
*/
U_PSEUDO_OBJ *U_PMF_COMPOUNDLINEDATA_set(int32_t Elements, const char *Widths){
if(!Widths)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements ,4, 1, U_LE},
{Widths, 4, Elements,U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_COMPOUNDLINEDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_COMPRESSEDIMAGE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param cbImage Bytes in Image
\param Image Stored image in one of the supported formats (GIF, PNG, etc.).
EMF+ manual 2.2.2.10, Microsoft name: EmfPlusCompressedImage Object
*/
U_PSEUDO_OBJ *U_PMF_COMPRESSEDIMAGE_set(int32_t cbImage, const char *Image){
if(!cbImage || !Image)return(NULL);
const U_SERIAL_DESC List[] = {
{Image, cbImage, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_COMPRESSEDIMAGE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMENDCAPDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Clc U_PSEUDO_OBJ containing a U_PMF_CUSTOMLINECAP object
EMF+ manual 2.2.2.11, Microsoft name: EmfPlusCustomEndCapData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMENDCAPDATA_set(const U_PSEUDO_OBJ *Clc){
if(!Clc || Clc->Type != U_PMF_CUSTOMLINECAP_OID)return(NULL);
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Clc->Used;
const U_SERIAL_DESC List[] = {
{&Used, 4, 1, U_LE},
{Clc->Data, Clc->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMENDCAPDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMLINECAPARROWDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Width Arrow cap width (is multiplied by line width before draw)
\param Height Arrow cap length (is multiplied by line width before draw)
\param MiddleInset Pixels between outer edge and filled region
\param FillState If set, fill, otherwise, only border
\param StartCap LineCap enumeration (type of cap)
\param EndCap LineCap enumeration
\param Join LineJoin enumeration
\param MiterLimit Maximum (miter length / line width)
\param WidthScale Scale for U_PMF_CUSTOMLINECAP object
EMF+ manual 2.2.2.12, Microsoft name: EmfPlusCustomLineCapArrowData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPARROWDATA_set(U_FLOAT Width, U_FLOAT Height,
U_FLOAT MiddleInset, uint32_t FillState, uint32_t StartCap, uint32_t EndCap, uint32_t Join,
U_FLOAT MiterLimit, U_FLOAT WidthScale
){
const U_SERIAL_DESC List[] = {
{&Width, 4, 1, U_LE},
{&Height ,4, 1, U_LE},
{&MiddleInset, 4, 1, U_LE},
{&FillState, 4, 1, U_LE},
{&StartCap, 4, 1, U_LE},
{&EndCap, 4, 1, U_LE},
{&Join, 4, 1, U_LE},
{&MiterLimit, 4, 1, U_LE},
{&WidthScale, 4, 1, U_LE},
{NULL, 8, 2, U_LE}, /* FillHotSpots and LineHotSpots */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMLINECAPARROWDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMLINECAPDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags CustomLineCapData flags
\param Cap LineCap enumeration (type of cap)
\param Inset Distance line cap start -> line end
\param StartCap LineCap enumeration
\param EndCap LineCap enumeration
\param Join LineJoin enumeration
\param MiterLimit Maximum (miter length / line width)
\param WidthScale Scale for U_PMF_CUSTOMLINECAP object
\param Clcod U_PSEUDO_OBJ containing a U_PMF_CUSTOMLINECAPOPTIONALDATA object
EMF+ manual 2.2.2.13, Microsoft name: EmfPlusCustomLineCapData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPDATA_set(uint32_t Flags, uint32_t Cap,
U_FLOAT Inset, uint32_t StartCap, uint32_t EndCap,
uint32_t Join, U_FLOAT MiterLimit, U_FLOAT WidthScale,
const U_PSEUDO_OBJ *Clcod
){
if(!Clcod || Clcod->Type != U_PMF_CUSTOMLINECAPOPTIONALDATA_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{&Cap, 4, 1, U_LE},
{&Inset, 4, 1, U_LE},
{&StartCap, 4, 1, U_LE},
{&EndCap, 4, 1, U_LE},
{&Join, 4, 1, U_LE},
{&MiterLimit, 4, 1, U_LE},
{&WidthScale, 4, 1, U_LE},
{NULL, 8, 2, U_LE}, /* FillHotSpots and LineHotSpots */
{Clcod->Data, Clcod->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMLINECAPDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMLINECAPOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Fill U_PSEUDO_OBJ containing a U_PMF_FILLPATHOBJ object (optional)
\param Line U_PSEUDO_OBJ containing a U_PMF_LINEPATH object (optional)
EMF+ manual 2.2.2.14, Microsoft name: EmfPlusCustomLineCapOptionalData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPOPTIONALDATA_set(const U_PSEUDO_OBJ *Fill, const U_PSEUDO_OBJ *Line){
if(Fill && (Fill->Type != U_PMF_FILLPATHOBJ_OID))return(NULL);
if(Line && (Line->Type != U_PMF_LINEPATH_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{(Fill ? Fill->Data : NULL), (Fill ? Fill->Used : 0), 1, U_XE},
{(Line ? Line->Data : NULL), (Line ? Line->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMLINECAPOPTIONALDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_CUSTOMSTARTCAPDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Clc U_PSEUDO_OBJ containing a U_PMF_CUSTOMLINECAPDATA object
EMF+ manual 2.2.2.15, Microsoft name: EmfPlusCustomStartCapData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMSTARTCAPDATA_set(const U_PSEUDO_OBJ *Clc){
if(!Clc || Clc->Type != U_PMF_CUSTOMLINECAP_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{Clc->Data, Clc->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMSTARTCAPDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_DASHEDLINEDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements Members in Lengths
\param Lengths Array of U_FLOAT holding lengths of dashes and spaces.
EMF+ manual 2.2.2.16, Microsoft name: EmfPlusDashedLineData Object
*/
U_PSEUDO_OBJ *U_PMF_DASHEDLINEDATA_set(int32_t Elements, const U_FLOAT *Lengths){
if(!Lengths)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Lengths, 4, Elements, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_DASHEDLINEDATA_OID, List);
return(po);
}
/**
\brief Utility function to create and set a U_PMF_DASHEDLINEDATA PseudoObject from one of a predefined set of patterns
\return Pointer to PseudoObject, NULL on error
\param Unit Length of the repeat unit
\param StdPat Members in Lengths
EMF+ manual 2.2.2.16, Microsoft name: EmfPlusDashedLineData Object
*/
U_PSEUDO_OBJ *U_PMF_DASHEDLINEDATA_set2(U_FLOAT Unit, int StdPat){
uint32_t Elements;
uint8_t *p;
U_FLOAT SubUnit;
U_FLOAT Lengths[8]; /* This is the most dash/spaces that will be needed*/
int i;
/* Dot = 1, Dash = 2; Long = 3, 0 = terminate pattern */
uint8_t SB[U_DD_Types][5] =
{
{0,0,0,0,0}, // Solid
{2,0,0,0,0}, // Dash
{2,2,0,0,0}, // DashDash
{2,2,2,0,0}, // DashDashDash
{2,2,2,2,0}, // DashDashDashDash
{1,0,0,0,0}, // Dot
{1,1,0,0,0}, // DotDot
{1,1,1,0,0}, // DotDotDot
{1,1,1,1,0}, // DotDotDotDot
{2,1,0,0,0}, // DashDot
{2,2,1,0,0}, // DashDashDot
{2,2,1,1,0}, // DashDashDotDot
{2,2,2,1,0}, // DashDashDashDot
{2,1,1,0,0}, // DashDotDot
{2,1,1,1,0}, // DashDotDotDot
{2,1,2,1,0}, // DashDotDashDot
{3,0,0,0,0}, // Long
{3,3,0,0,0}, // LongLong
{3,3,3,0,0}, // LongLongLong
{3,3,3,3,0}, // LongLongLongLong
{3,1,0,0,0}, // LongDot
{3,3,1,0,0}, // LongLongDot
{3,3,1,1,0}, // LongLongDotDot
{3,3,3,1,0}, // LongLongLongDot
{3,1,1,0,0}, // LongDotDot
{3,1,1,1,0}, // LongDotDotDot
{3,1,3,1,0} // LongDotLongDot
};
if(Unit <= 0 ){ return(NULL); }
if((StdPat <= 0) || (StdPat > U_DD_LongDotLongDot)){ return(NULL); }
p = &(SB[StdPat][0]);
for(Elements = 0; *p; p++, Elements++){}
SubUnit = Unit/((U_FLOAT) Elements);
Elements *= 2;
p = &(SB[StdPat][0]);
for(i=0; *p; p++){
switch(*p){
case 0: break;
case 1: /* dot */
Lengths[i++] = SubUnit * 0.125;
Lengths[i++] = SubUnit * 0.875;
break;
case 2: /* dash */
Lengths[i++] = SubUnit * 0.5;
Lengths[i++] = SubUnit * 0.5;
break;
case 3: /* long */
Lengths[i++] = SubUnit * 0.75;
Lengths[i++] = SubUnit * 0.25;
break;
}
}
U_PSEUDO_OBJ *po = U_PMF_DASHEDLINEDATA_set(Elements, Lengths);
return(po);
}
/**
\brief Utility function to create and set a U_PMF_DASHEDLINEDATA PseudoObject from the bits that are set in a uint32_t
\return Pointer to PseudoObject, NULL on error
\param Unit Length of the repeat unit
\param BitPat uint32_t holding the bit pattern, the lowest order bit MUST be set and the highest order MUST be clear.
Make a line with a dot/dash pattern defined by the bits in the BitPat value. If a bit is set it is drawn,
if clear it is not. Every bit drawn has length Unit/32, and consecutive drawn bits are merged together.
The lowest order bit is the first bit that may be drawn, the highest the last.
Example: if the integer has value 0x13 the pattern produced will be:
0 -> 2*unit/32 drawn
2*unit/32 -> 5*unit/32 not drawn
5*unit/32 -> 6*unit/32 drawn
6*unit/32 -> unit not drawn
EMF+ manual 2.2.2.16, Microsoft name: EmfPlusDashedLineData Object
*/
U_PSEUDO_OBJ *U_PMF_DASHEDLINEDATA_set3(U_FLOAT Unit, uint32_t BitPat){
uint32_t Elements=0;
U_FLOAT SubUnit = Unit/32.0;
U_FLOAT Lengths[32]; /* This is the most dash/spaces that will be needed*/
if(!(0x00000001 & BitPat))return(NULL); /* Pattern must start with a drawn segment, this bit must be set */
if( 0x80000000 & BitPat )return(NULL); /* Pattern must end with an undrawn segment, this bit must be clear */
int i=0;
int k;
int lastType=1;
int newType=0;
uint32_t j=1;
Lengths[0]=0;
for(k=0; k<32; k++, j=j<<1){
if(j & BitPat){
if(!lastType){
newType=1;
}
}
else {
if(lastType){
newType=1;
}
}
if(newType){
i++;
Lengths[i]=0;
Elements++;
lastType = !lastType;
newType = 0;
}
Lengths[i] += SubUnit;
}
Elements = i+1;
U_PSEUDO_OBJ *po = U_PMF_DASHEDLINEDATA_set(Elements, Lengths);
return(po);
}
/**
\brief Create and set a U_PMF_FILLPATHOBJ PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Path U_PSEUDO_OBJ containing a U_PMF_PATH object
EMF+ manual 2.2.2.17, Microsoft name: EmfPlusFillPath Object
*/
U_PSEUDO_OBJ *U_PMF_FILLPATHOBJ_set(const U_PSEUDO_OBJ *Path){
if(!Path || (Path->Type != U_PMF_PATH_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{Path->Data, Path->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_FILLPATHOBJ_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_FOCUSSCALEDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ScaleX value 0.0 <-> 1.0
\param ScaleY value 0.0 <-> 1.0
EMF+ manual 2.2.2.18, Microsoft name: EmfPlusFocusScaleData Object
*/
U_PSEUDO_OBJ *U_PMF_FOCUSSCALEDATA_set(U_FLOAT ScaleX, U_FLOAT ScaleY){
uint32_t tmp = 2;
const U_SERIAL_DESC List[] = {
{&tmp, 4, 1, U_LE},
{&ScaleX, 4, 1, U_LE},
{&ScaleY, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_FOCUSSCALEDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_GRAPHICSVERSION object (Signature always set to 0xDBC01)
\return Pointer to PseudoObject, NULL on error
\param GrfVersion GraphicsVersion enumeration
EMF+ manual 2.2.2.19, Microsoft name: EmfPlusGraphicsVersion Object
*/
U_PSEUDO_OBJ *U_PMF_GRAPHICSVERSION_set(int GrfVersion){
uint32_t tmp;
tmp = U_GFVR_PMF << 12; /* signature, can only have this value */
tmp |= (GrfVersion & U_GFVR_MASKLO);
const U_SERIAL_DESC List[] = {
{&tmp, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_GRAPHICSVERSION_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_GRAPHICSVERSION object Structure (Signature always set to 0xDBC01)
\return U_PMF_GRAPHICSVERSION
\param GrfVersion GraphicsVersion enumeration
EMF+ manual 2.2.2.19, Microsoft name: EmfPlusGraphicsVersion Object
*/
U_PMF_GRAPHICSVERSION U_PMF_GRAPHICSVERSIONOBJ_set(int GrfVersion){
uint32_t tmp;
tmp = U_GFVR_PMF << 12; /* signature, can only have this value */
tmp |= (GrfVersion & U_GFVR_MASKLO);
return(tmp);
}
/**
\brief Create and set a U_PMF_HATCHBRUSHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Style HatchStyle enumeration
\param Fg U_PSEUDO_OBJ containing a U_ARGB object, Foreground hatch pattern line color
\param Bg U_PSEUDO_OBJ containing a U_ARGB object, Background hatch pattern line color
EMF+ manual 2.2.2.20, Microsoft name: EmfPlusHatchBrushData Object
*/
U_PSEUDO_OBJ *U_PMF_HATCHBRUSHDATA_set(uint32_t Style, const U_PSEUDO_OBJ *Fg, const U_PSEUDO_OBJ *Bg){
if(!Fg ||(Fg->Type != U_PMF_ARGB_OID))return(NULL);
if(!Bg ||(Bg->Type != U_PMF_ARGB_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{&Style, 4, 1, U_LE},
{Fg->Data, Fg->Used, 1, U_XE},
{Bg->Data, Bg->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_HATCHBRUSHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_INTEGER7 PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Value 7 bit signed integer (stored in an integer, range 63 <-> -64, inclusive)
EMF+ manual 2.2.2.21, Microsoft name: EmfPlusInteger7 Object
*/
U_PSEUDO_OBJ *U_PMF_INTEGER7_set(int Value){
uint8_t utmp;
if(Value < -64 || Value > 63)return(NULL);
utmp = U_MASK_INT7 & *(unsigned int *)&Value;
U_PSEUDO_OBJ *po = U_PO_create((char *)&utmp, 1, 1, U_PMF_INTEGER7_OID); /* simple method is OK, no possibility of Endian issues */
return(po);
}
/**
\brief Create and set a U_PMF_INTEGER15 PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Value 15 bit signed integer (stored in an integer, range 32677 <-> -32678, inclusive)
EMF+ manual 2.2.2.22, Microsoft name: EmfPlusInteger15 Object
*/
U_PSEUDO_OBJ *U_PMF_INTEGER15_set(int Value){
uint16_t utmp;
if(Value < -32678 || Value > 32677)return(NULL);
utmp = U_TEST_INT15 | (U_MASK_INT15 & *(unsigned int *)&Value);
const U_SERIAL_DESC List[] = {
{&utmp, 2, 1, U_BE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_INTEGER15_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_LANGUAGEIDENTIFIER value in 4 byte unsigned int, in NATIVE byte order
\return LID value in least significant two bytes and 0 in most significant two bytes.
\param SubLId Example: code for USA
\param PriLId Example: code for English
EMF+ manual 2.2.2.23, Microsoft name: EmfPlusLanguageIdentifier Object
*/
U_PMF_LANGUAGEIDENTIFIER U_PMF_LANGUAGEIDENTIFIEROBJ_set(int SubLId, int PriLId){
U_PMF_LANGUAGEIDENTIFIER utmp32;
utmp32 = ((SubLId & U_FF_MASK_SUBLID) << U_FF_SHFT_SUBLID) | ((PriLId & U_FF_MASK_PRILID) << U_FF_SHFT_PRILID);
return(utmp32);
}
/**
\brief Create and set a U_PMF_LANGUAGEIDENTIFIER PseudoObject
\return Pointer to PseudoObject, NULL on error
\param LId Language Identifier as produced by U_PMF_LANGUAGEIDENTIFIEROBJ_set().
EMF+ manual 2.2.2.23, Microsoft name: EmfPlusLanguageIdentifier Object
*/
U_PSEUDO_OBJ *U_PMF_LANGUAGEIDENTIFIER_set(U_PMF_LANGUAGEIDENTIFIER LId){
uint16_t utmp16;
utmp16 = (LId & U_FF_MASK_LID) << U_FF_SHFT_LID;
const U_SERIAL_DESC List[] = {
{&utmp16, 2, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_LANGUAGEIDENTIFIER_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_LINEARGRADIENTBRUSHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Lgbd U_PMF_LINEARGRADIENTBRUSHDATA object (constant part)
\param Lgbod U_PSEUDO_OBJ containing a U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA object (variable part of a U_PMF_LINEARGRADIENTBRUSHDATA object)
EMF+ manual 2.2.2.24, Microsoft name: EmfPlusLinearGradientBrushData Object
*/
U_PSEUDO_OBJ *U_PMF_LINEARGRADIENTBRUSHDATA_set(const U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const U_PSEUDO_OBJ *Lgbod){
if(!Lgbd || !Lgbod || (Lgbod->Type != U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{Lgbd, 4, 6, U_LE},
{&(Lgbd->StartColor), 4, 2, U_XE},
{&(Lgbd->StartColor), 4, 2, U_XE}, /* repeat the start/end colors. Supposedly reserved. */
// {NULL, 4, 2, U_LE}, /* zero fill the two Reserved fields, no matter what is passed in */
{(Lgbod->Used ? Lgbod->Data : NULL), Lgbod->Used, 1, U_XE}, /* optional Data can exist and Used can be zero, SERIAL_set would throw an error on that */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_LINEARGRADIENTBRUSHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags Bits are set that indicate which of the following were included. The caller must clear before passing it in.
\param Tm (optional) U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX object
\param Bc (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDCOLORS object or NULL
\param BfH (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (H) object or NULL
\param BfV (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (V) object or NULL (WARNING, GDI+ defines this field but does not render it. DO NOT USE.)
EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object
The rectangular gradients repeat in a tiled pattern. Tm can rotate and offset the gradient within each tile.
The gradient wraps when it is offset.
*/
U_PSEUDO_OBJ *U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_set(uint32_t *Flags, const U_PSEUDO_OBJ *Tm,
const U_PSEUDO_OBJ *Bc, const U_PSEUDO_OBJ *BfH, const U_PSEUDO_OBJ *BfV){
if(!Flags )return(NULL);
if(Tm && (Tm->Type != U_PMF_TRANSFORMMATRIX_OID))return(NULL);
if(Bc && (Bc->Type != U_PMF_BLENDCOLORS_OID) )return(NULL);
if(BfH && (BfH->Type != U_PMF_BLENDFACTORS_OID) )return(NULL);
if(BfV && (BfV->Type != U_PMF_BLENDFACTORS_OID) )return(NULL);
if(Bc && (BfH || BfV) )return(NULL);
const U_SERIAL_DESC List[] = {
{(Tm ? Tm->Data : NULL), (Tm ? Tm->Used : 0), 1, U_XE},
{(Bc ? Bc->Data : NULL), (Bc ? Bc->Used : 0), 1, U_XE},
{(BfH ? BfH->Data : NULL), (BfH ? BfH->Used : 0), 1, U_XE},
{(BfV ? BfV->Data : NULL), (BfV ? BfV->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_OID, List);
if(Tm ){ *Flags |= U_BD_Transform; }
if(Bc ){ *Flags |= U_BD_PresetColors; }
if(BfH){ *Flags |= U_BD_BlendFactorsH; }
if(BfV){ *Flags |= U_BD_BlendFactorsV; }
return(po);
}
/**
\brief Create and set a U_PMF_LINEPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Path U_PSEUDO_OBJ containing a U_PMF_PATH object
EMF+ manual 2.2.2.26, Microsoft name: EmfPlusLinePath Object
*/
U_PSEUDO_OBJ *U_PMF_LINEPATH_set(const U_PSEUDO_OBJ *Path){
if(!Path || (Path->Type != U_PMF_PATH_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{&Path->Data, Path->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_LINEPATH_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_METAFILE object (NOT SUPPORTED!)
\return Null
EMF+ manual 2.2.2.27, Microsoft name: EmfPlusMetafile Object
*/
U_PSEUDO_OBJ *U_PMF_METAFILE_set(void){
return(NULL);
}
/**
\brief Create and set a U_PMF_PALETTE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags PaletteStyle flags
\param Elements Members in Lengths
\param Pd Array of U_PMF_ARGB holding colors of palettes. (Palette Data)
EMF+ manual 2.2.2.28, Microsoft name: EmfPlusPalette Object
*/
U_PSEUDO_OBJ *U_PMF_PALETTE_set(uint32_t Flags, uint32_t Elements, const U_PMF_ARGB *Pd){
if(!Pd)return(NULL);
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{&Elements, 4, 1, U_LE},
{Pd, 4, Elements, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PALETTE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PATHGRADIENTBRUSHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags PaletteStyle flags
\param WrapMode WrapMode enumeration
\param CenterColor U_PMF_ARGB Center color
\param Center Center coordinates
\param Gradient U_PSEUDO_OBJ containing an Array of U_PMF_ARGB holding colors of Gradient
\param Boundary U_PSEUDO_OBJ containing a U_PMF_BOUNDARYPATHDATA or U_PMF_BOUNDARYPOINTDATA object. (Boundary Data)
\param Data variable part of U_PMF_LINEARGRADIENTBRUSHDATA, exact composition depends on Flags
EMF+ manual 2.2.2.29, Microsoft name: EmfPlusPathGradientBrushData Object
*/
U_PSEUDO_OBJ *U_PMF_PATHGRADIENTBRUSHDATA_set(uint32_t Flags, int32_t WrapMode, U_PMF_ARGB CenterColor,
U_PMF_POINTF Center,
const U_PSEUDO_OBJ *Gradient, const U_PSEUDO_OBJ *Boundary, const U_PSEUDO_OBJ *Data){
if( (Flags & U_BD_Path) && (!Boundary || (Boundary->Type != U_PMF_BOUNDARYPATHDATA_OID)))return(NULL);
if(!(Flags & U_BD_Path) && (!Boundary || (Boundary->Type != U_PMF_BOUNDARYPOINTDATA_OID)))return(NULL);
if(!Gradient || (Gradient->Type != (U_PMF_ARGB_OID | U_PMF_ARRAY_OID)))return(NULL);
if(!(Flags & U_BD_Transform) &&
!(Flags & U_BD_PresetColors) &&
!(Flags & U_BD_BlendFactorsH) &&
!(Flags & U_BD_FocusScales) &&
(!Data || (Data->Type != U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_OID)))return(NULL);
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{&WrapMode, 4, 1, U_LE},
{&CenterColor, 4, 1, U_XE},
{&Center.X, 4, 2, U_LE},
{Gradient->Data, Gradient->Used, 1, U_XE}, /* includes Elements */
{Boundary->Data, Boundary->Used, 1, U_XE},
{(Data ? Data->Data : NULL), (Data ? Data->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATHGRADIENTBRUSHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PATHGRADIENTBRUSHOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags PaletteStyle flags
\param Tm U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX. (Transformation matrix)
\param Pd U_PSEUDO_OBJ containing a U_PMF_BLENDCOLORS or U_PMF_BLENDFACTORS object. (Pattern Data)
\param Fsd U_PSEUDO_OBJ containing a U_PMF_FOCUSSSCALEDATA object. (Focus Scale Data)
EMF+ manual 2.2.2.30, Microsoft name: EmfPlusPathGradientBrushOptionalData Object
*/
U_PSEUDO_OBJ *U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_set(uint32_t Flags,
const U_PSEUDO_OBJ *Tm, const U_PSEUDO_OBJ *Pd, const U_PSEUDO_OBJ *Fsd){
if(Tm && (Tm->Type != U_PMF_TRANSFORMMATRIX_OID))return(NULL);
if(Pd && !(Flags & (U_BD_PresetColors | U_BD_BlendFactorsH)))return(NULL);
if( (Flags & U_BD_PresetColors) && ((Flags & U_BD_BlendFactorsH) || !Pd || (Pd->Type != U_PMF_BLENDCOLORS_OID) ))return(NULL);
if( (Flags & U_BD_BlendFactorsH) && ((Flags & U_BD_PresetColors) || !Pd || (Pd->Type != U_PMF_BLENDFACTORS_OID)))return(NULL);
if(Fsd && !(Flags & U_BD_FocusScales))return(NULL);
if( (Flags & U_BD_FocusScales) && (!Fsd || (Fsd->Type != U_PMF_BLENDCOLORS_OID) ))return(NULL);
const U_SERIAL_DESC List[] = {
{(Tm ? Tm->Data : NULL), (Tm ? Tm->Used : 0), 1, U_XE},
{(Pd ? Pd->Data : NULL), (Pd ? Pd->Used : 0), 1, U_XE},
{(Fsd ? Fsd->Data : NULL), (Fsd ? Fsd->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_PATHPOINTTYPE objects
\return Pointer to PseudoObject, NULL on error
\param Elements Number of entries in Flags and Enumerations
\param Ppt Array of unsigned bytes, lower 4 bits hold the PathPointType flag upper 4 bits hold the PathPointType enumeration.
EMF+ manual 2.2.2.31, Microsoft name: EmfPlusPathPointType Object
*/
U_PSEUDO_OBJ *U_PMF_PATHPOINTTYPE_set(uint32_t Elements, const uint8_t *Ppt){
if(!Elements || !Ppt)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Ppt, 1, Elements, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATHPOINTTYPE_OID | U_PMF_ARRAY_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_PATHPOINTTYPE objects, with a preceding Elements count
\return Pointer to PseudoObject, NULL on error
\param Elements Number of elements to add. First is added once and Others Elements-1 times.
\param First Apply to first point, unsigned byte, lower 4 bits hold the PathPointType flag upper 4 bits hold the PathPointType enumeration.
\param Others Apply to all other points, unsigned byte, lower 4 bits hold the PathPointType flag upper 4 bits hold the PathPointType enumeration.
EMF+ manual 2.2.2.31, Microsoft name: EmfPlusPathPointType Object
*/
U_PSEUDO_OBJ *U_PMF_PATHPOINTTYPE_set2(uint32_t Elements, uint8_t First, uint8_t Others){
if(!Elements)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_XE},
{&First, 1, 1, U_XE},
{&Others, 1, Elements-1, U_RP}, /* replicate the one value N-1 times */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PATHPOINTTYPE_OID | U_PMF_ARRAY_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_PATHPOINTTYPERLE objects
\return Pointer to PseudoObject containing first the number of elements, then an array of U_PMF_PATHPOINTTYPERLE, NULL on error
\param Elements Number of entries in the arrays
\param Bz Array of unsigned bytes, if not zero, element has Bezier bit set
\param RL Array of unsigned bytes, Run lengths.
\param Ppte Array of unsigned bytes, PathPointType enumerations.
EMF+ manual 2.2.2.32, Microsoft name: EmfPlusPathPointTypeRLE Object
*/
U_PSEUDO_OBJ *U_PMF_PATHPOINTTYPERLE_set(uint32_t Elements, const uint8_t *Bz, const uint8_t *RL, const uint8_t *Ppte){
uint8_t utmp;
if(!Bz || !RL || !Ppte)return(NULL);
/* allocate space in the structure but put no data in */
U_PSEUDO_OBJ *po = U_PO_create(NULL, 4 + 2*Elements, 0, U_PMF_PATHPOINTTYPERLE_OID | U_PMF_ARRAY_OID);
U_PSEUDO_OBJ *holdpo = po;
if(po){
U_PSEUDO_OBJ *poi = U_PMF_4NUM_set(Elements);
if(!poi)goto end;
po = U_PO_append(po, poi->Data, poi->Used);
U_PO_free(&poi);
if(!po)goto end;
for( ;Elements; Elements--, Bz++, RL++, Ppte++){
po = U_PO_append(po, (char *)Ppte, 1);
if(!po)goto end;
if(*RL > 0x3F) goto end; /* run length too big for field */
utmp = (*Bz ? 1 : 0) | ((*RL & 0x3F)<<2); /* bit 1 is not used and is set to 0 */
po = U_PO_append(po, (char *)&utmp, 1);
if(!po)goto end;
}
}
end:
if(!po)U_PO_free(&holdpo);
return(holdpo);
}
/**
\brief Create and set a U_PMF_PENDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Unit UnitType enumeration
\param Width Width in units set by Unit
\param Pod U_PSEUDO_OBJ containing first the PenData flags then a U_PMF_PENOPTIONALDATA object (the second part
may be an empty if Flags is 0)
EMF+ manual 2.2.2.33, Microsoft name: EmfPlusPenData Object
*/
U_PSEUDO_OBJ *U_PMF_PENDATA_set(uint32_t Unit, U_FLOAT Width, const U_PSEUDO_OBJ *Pod){
if(Pod && ((Pod->Type != U_PMF_PENOPTIONALDATA_OID) || Pod->Used < 4))return(NULL);
const U_SERIAL_DESC List[] = {
{(Pod ? Pod->Data : NULL), 4, 1, U_XE}, /* the Flags field, clear if no optional data */
{&Unit, 4, 1, U_LE},
{&Width, 4, 1, U_LE},
/* next is the (optional) U_PMF_PENOPTIONALDATA part or a terminator */
{(Pod ? Pod->Data + 4 : NULL), (Pod ? Pod->Used - 4 : 0), (Pod ? 1 : 0), (Pod ? U_XE : U_XX)},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PENDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_PENOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error. Returned PO contains first the Flags, then the PO proper.
\param Flags Determines which of the values are stored.
\param Tm U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX object (Transformation matrix)
\param StartCap LineCapType enumeration
\param EndCap LineCapType enumeration
\param Join LineJoinType enumeration
\param MiterLimit Maximum (miter length / line width)
\param Style LineStyle enumeration
\param DLCap DashedLineCapType enumeration
\param DLOffset Distance line start to first dash start
\param DLData U_PSEUDO_OBJ containing a U_PMF_DASHEDLINEDATA object Dash and space widths
\param PenAlignment PenAlignment enumeration
\param CmpndLineData U_PSEUDO_OBJ containing a U_PMF_COMPOUNDLINEDATA object Compount Line (parallel lines drawn instead of one)
\param CSCapData U_PSEUDO_OBJ containing a U_PMF_CUSTOMSTARTCAPDATA object Custom start cap
\param CECapData U_PSEUDO_OBJ containing a U_PMF_CUSTOMENDCAPDATA object Custom end cap
EMF+ manual 2.2.2.34, Microsoft name: EmfPlusPenOptionalData Object
*/
U_PSEUDO_OBJ *U_PMF_PENOPTIONALDATA_set(uint32_t Flags, U_PSEUDO_OBJ *Tm, int32_t StartCap, int32_t EndCap, uint32_t Join,
U_FLOAT MiterLimit, int32_t Style, int32_t DLCap, U_FLOAT DLOffset,
U_PSEUDO_OBJ *DLData, int32_t PenAlignment, U_PSEUDO_OBJ *CmpndLineData, U_PSEUDO_OBJ *CSCapData,
U_PSEUDO_OBJ *CECapData
){
if((Flags & U_PD_Transform) && (!Tm || (Tm->Type != U_PMF_TRANSFORMMATRIX_OID)) )return(NULL);
if((Flags & U_PD_DLData) && (!DLData || (DLData->Type != U_PMF_DASHEDLINEDATA_OID)) )return(NULL);
if((Flags & U_PD_CLData) && (!CmpndLineData || (CmpndLineData->Type != U_PMF_COMPOUNDLINEDATA_OID)) )return(NULL);
if((Flags & U_PD_CustomStartCap) && (!CSCapData || (CSCapData->Type != U_PMF_CUSTOMSTARTCAPDATA_OID)))return(NULL);
if((Flags & U_PD_CustomEndCap) && (!CECapData || (CECapData->Type != U_PMF_CUSTOMENDCAPDATA_OID)) )return(NULL);
/* prepend the Flags field to the PseudoObject proper */
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{((Flags & U_PD_Transform) ? Tm->Data : NULL), ((Flags & U_PD_Transform) ? Tm->Used : 0), 1, U_XE},
{((Flags & U_PD_StartCap ) ? (char *)&StartCap : NULL), ((Flags & U_PD_StartCap ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_EndCap ) ? (char *)&EndCap : NULL), ((Flags & U_PD_EndCap ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_Join ) ? (char *)&Join : NULL), ((Flags & U_PD_Join ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_MiterLimit ) ? (char *)&MiterLimit : NULL), ((Flags & U_PD_MiterLimit ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_LineStyle ) ? (char *)&Style : NULL), ((Flags & U_PD_LineStyle ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_DLCap ) ? (char *)&DLCap : NULL), ((Flags & U_PD_DLCap ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_DLOffset ) ? (char *)&DLOffset : NULL), ((Flags & U_PD_DLOffset ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_DLData ) ? DLData->Data : NULL), ((Flags & U_PD_DLData ) ? DLData->Used : 0), 1, U_XE},
{((Flags & U_PD_NonCenter ) ? (char *)&PenAlignment : NULL), ((Flags & U_PD_NonCenter ) ? 4 : 0), 1, U_LE},
{((Flags & U_PD_CLData ) ? CmpndLineData->Data : NULL), ((Flags & U_PD_CLData ) ? CmpndLineData->Used : 0), 1, U_XE},
{((Flags & U_PD_CustomStartCap) ? CSCapData->Data : NULL), ((Flags & U_PD_CustomStartCap) ? CSCapData->Used : 0), 1, U_XE},
{((Flags & U_PD_CustomEndCap ) ? CECapData->Data : NULL), ((Flags & U_PD_CustomEndCap ) ? CECapData->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_PENOPTIONALDATA_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_POINT objects
\return Pointer to PseudoObject, NULL on error
\param Elements Number of pairs of points in Coords
\param Coords Array of X,Y pairs.
EMF+ manual 2.2.2.35, Microsoft name: EmfPlusPoint Object
*/
U_PSEUDO_OBJ *U_PMF_POINT_set(uint32_t Elements, const U_PMF_POINT *Coords){
if(!Elements || !Coords)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{ Coords, 2, 2*Elements, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_POINT_OID | U_PMF_ARRAY_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_POINTF objects, with a leading Elements value
\return Pointer to PseudoObject, NULL on error
\param Elements Number of pairs of points in Coords
\param Coords Array of X,Y pairs.
EMF+ manual 2.2.2.36, Microsoft name: EmfPlusPointF Object
*/
U_PSEUDO_OBJ *U_PMF_POINTF_set(uint32_t Elements, const U_PMF_POINTF *Coords){
if(!Elements || !Coords)return(NULL);
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Coords, 4, 2*Elements, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_POINTF_OID | U_PMF_ARRAY_OID, List);
return(po);
}
/**
\brief Create and set an ARRAY of U_PMF_POINTR objects
\return Pointer to PseudoObject, NULL on error
\param Elements Number of pairs of points in Coords
\param Coords Array of X,Y pairs. These are absolute coordinates, they are converted to Relative here.
EMF+ manual 2.2.2.37, Microsoft name: EmfPlusPointR Object
*/
U_PSEUDO_OBJ *U_PMF_POINTR_set(uint32_t Elements, const U_PMF_POINTF *Coords){
int X,Y;
U_FLOAT Xf,Yf;
U_PSEUDO_OBJ *poi;
/* Worst case scenario it is 4 bytes per coord, plus the count */
U_PSEUDO_OBJ *po = U_PO_create(NULL, 4 + 4*Elements, 0, U_PMF_POINTR_OID); /* not exactly an array, so no U_PMF_ARRAY_OID */
U_PSEUDO_OBJ *holdpo = po;
if(!po)goto end;
poi = U_PMF_4NUM_set(Elements);
po = U_PO_append(po, poi->Data, poi->Used);
U_PO_free(&poi);
if(!po)goto end;
for(Xf = Yf = 0.0 ;Elements; Elements--, Coords++){
Xf = U_ROUND(Coords->X) - Xf;
Yf = U_ROUND(Coords->Y) - Yf;
X = ( Xf >= UINT16_MAX ? UINT16_MAX : ( Xf <= INT16_MIN ? INT16_MIN : Xf));
Y = ( Yf >= UINT16_MAX ? UINT16_MAX : ( Yf <= INT16_MIN ? INT16_MIN : Yf));
Xf = U_ROUND(Coords->X);
Yf = U_ROUND(Coords->Y);
/* this is not a very efficient method, too much mucking around with memory */
poi = U_PMF_INTEGER7_set(X);
if(!poi)poi = U_PMF_INTEGER15_set(X); /* This one must work because of the range checking, above */
po = U_PO_append(po, poi->Data, poi->Used);
U_PO_free(&poi);
if(!po)goto end;
poi = U_PMF_INTEGER7_set(Y);
if(!poi)poi = U_PMF_INTEGER15_set(Y); /* This one must work because of the range checking, above */
po = U_PO_append(po, poi->Data, poi->Used);
U_PO_free(&poi);
if(!po)goto end;
}
/* Because the values stored were some unpredictable combination of 1 and 2 bytes, the last byte may not end
on a 4 byte boundary. Make it do so by padding with up to 3 zero bytes. */
int residual;
residual = 3 & po->Used;
if(residual){
po = U_PO_append(po, NULL, (4 - residual));
if(!po)goto end;
}
end:
if(!po)U_PO_free(&holdpo);
return(holdpo);
}
/**
\brief Create and set a U_PMF_RECT object
\return Pointer to PseudoObject, NULL on error
\param X UL X value
\param Y UL Y value
\param Width Width
\param Height Height
EMF+ manual 2.2.2.38, Microsoft name: EmfPlusRect Object
*/
U_PSEUDO_OBJ *U_PMF_RECT4_set(int16_t X, int16_t Y, int16_t Width, int16_t Height){
const U_SERIAL_DESC List[] = {
{&X, 2, 1, U_LE},
{&Y, 2, 1, U_LE},
{&Width, 2, 1, U_LE},
{&Height, 2, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECT_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_RECT object
\return Pointer to PseudoObject, NULL on error
\param Rect U_PMF_RECT structures
EMF+ manual 2.2.2.38, Microsoft name: EmfPlusRect Object
*/
U_PSEUDO_OBJ *U_PMF_RECT_set(U_PMF_RECT *Rect){
const U_SERIAL_DESC List[] = {
{Rect, 2, 4, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECT_OID, List);
return(po);
}
/**
\brief Create and set an array of U_PMF_RECT objects in a PseudoObject
\return Pointer to PseudoObject, NULL on error. PseudoObject contains Elements followed by the array of U_PMF_RECT objects.
\param Elements Number of elements in Rects
\param Rects Array of U_PMF_RECT structures
EMF+ manual 2.2.2.38, Microsoft name: EmfPlusRect Object
*/
U_PSEUDO_OBJ *U_PMF_RECTN_set(uint32_t Elements, U_PMF_RECT *Rects){
if(!Rects){ return(NULL); }
uint32_t count = Elements;
U_SERIAL_DESC *List = (U_SERIAL_DESC *) malloc((Elements + 2) * sizeof(U_SERIAL_DESC));
U_SERIAL_DESC *Lptr = List;
if(!List){ return(NULL); }
*Lptr++ = (U_SERIAL_DESC){&Elements, 4, 1, U_LE};
for(; count; count--, Lptr++, Rects++){
*Lptr = (U_SERIAL_DESC){Rects, 2, 4, U_LE};
}
*Lptr = (U_SERIAL_DESC){NULL,0,0,U_XX};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECT_OID | U_PMF_ARRAY_OID, List);
free(List);
return(po);
}
/**
\brief Create and set a U_PMF_RECTF object in a PseudoObject
\return Pointer to PseudoObject, NULL on error
\param X UL X value
\param Y UL Y value
\param Width Width
\param Height Height
EMF+ manual 2.2.2.39, Microsoft name: EmfPlusRectF Object
*/
U_PSEUDO_OBJ *U_PMF_RECTF4_set(U_FLOAT X, U_FLOAT Y, U_FLOAT Width, U_FLOAT Height){
const U_SERIAL_DESC List[] = {
{&X, 4, 1, U_LE},
{&Y, 4, 1, U_LE},
{&Width, 4, 1, U_LE},
{&Height, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECTF_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_RECTF object in a PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Rect U_PMF_RECTF structure
EMF+ manual 2.2.2.39, Microsoft name: EmfPlusRectF Object
*/
U_PSEUDO_OBJ *U_PMF_RECTF_set(U_PMF_RECTF *Rect){
const U_SERIAL_DESC List[] = {
{Rect, 4, 4, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECTF_OID, List);
return(po);
}
/**
\brief Create and set an array of U_PMF_RECTF objects in a PseudoObject
\return Pointer to PseudoObject, NULL on error. PseudoObject contains Elements followed by the array of U_PMF_RECTF objects.
\param Elements Number of elements in Rects
\param Rects Array of U_PMF_RECTF structures
EMF+ manual 2.2.2.39, Microsoft name: EmfPlusRectF Object
*/
U_PSEUDO_OBJ *U_PMF_RECTFN_set(uint32_t Elements, U_PMF_RECTF *Rects){
if(!Rects){ return(NULL); }
uint32_t count = Elements;
U_SERIAL_DESC *List = (U_SERIAL_DESC *) malloc((Elements + 2) * sizeof(U_SERIAL_DESC));
U_SERIAL_DESC *Lptr = List;
if(!List){ return(NULL); }
*Lptr++ = (U_SERIAL_DESC){&Elements, 4, 1, U_LE};
for(; count; count--, Lptr++, Rects++){
*Lptr = (U_SERIAL_DESC){Rects, 4, 4, U_LE};
}
*Lptr = (U_SERIAL_DESC){NULL,0,0,U_XX};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECTF_OID | U_PMF_ARRAY_OID, List);
free(List);
return(po);
}
/**
\brief Create and set a U_PMF_REGIONNODE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Type RegionNodeDataType Enumeration
\param Rnd (optional) U_PSEUDO_OBJ containing a U_PMF_REGIONNODEPATH, U_PMF_RECTF, or U_PMF_REGIONNODECHILDNODES object (Region Node Data)
EMF+ manual 2.2.2.40, Microsoft name: EmfPlusRegionNode Object
*/
U_PSEUDO_OBJ *U_PMF_REGIONNODE_set(int32_t Type, const U_PSEUDO_OBJ *Rnd){
int32_t pType;
/* make sure that the type of Rnd agrees with Type */
if(Rnd){
pType = U_OID_To_RNDT(Rnd->Type);
if( pType < 0){ return(NULL); }
if((pType > 0) && (pType != Type)){ return(NULL); }
if((pType == 0) &&
(
(Type < U_RNDT_And) ||
(Type > U_RNDT_Complement)
)
){ return(NULL); }
if((Type == U_RNDT_Rect) && (Rnd->Type != U_PMF_RECTF_OID)){ return(NULL); }
if((Type == U_RNDT_Path) && (Rnd->Type != U_PMF_REGIONNODEPATH_OID)){ return(NULL); }
}
else { /* only U_RNDT_Empty and U_RNDT_Infinite do not have data */
if((Type != U_RNDT_Empty) ||
(Type != U_RNDT_Infinite) ){ return(NULL); }
}
const U_SERIAL_DESC List[] = {
{&Type, 4, 1, U_LE},
{(Rnd ? Rnd->Data : NULL), (Rnd ? Rnd->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_REGIONNODE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_REGIONNODECHILDNODES PseudoObject
\return Pointer to PseudoObject containing a U_PMF_REGIONNODECHILDNODES_OID object, NULL on error
\param Left U_PSEUDO_OBJ containing a U_PMF_REGIONNODE object
\param Right U_PSEUDO_OBJ containing a U_PMF_REGIONNODE object
EMF+ manual 2.2.2.41, Microsoft name: EmfPlusRegionNodeChildNodes Object
*/
U_PSEUDO_OBJ *U_PMF_REGIONNODECHILDNODES_set(const U_PSEUDO_OBJ *Left, const U_PSEUDO_OBJ *Right){
if(!Left || (Left->Type != U_PMF_REGIONNODE_OID)){ return(NULL); }
if(!Right || (Right->Type != U_PMF_REGIONNODE_OID)){ return(NULL); }
const U_SERIAL_DESC List[] = {
{Left->Data, Left->Used, 1, U_XE},
{Right->Data, Right->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_REGIONNODECHILDNODES_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_REGIONNODEPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Path U_PSEUDO_OBJ containing a U_PMF_PATH object
EMF+ manual 2.2.2.42, Microsoft name: EmfPlusRegionNodePath Object
*/
U_PSEUDO_OBJ *U_PMF_REGIONNODEPATH_set(const U_PSEUDO_OBJ *Path){
if(!Path || (Path->Type != U_PMF_PATH_OID)){ return(NULL); }
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Path->Used;
const U_SERIAL_DESC List[] = {
{&Used, 4, 1, U_LE},
{Path->Data, Path->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_REGIONNODEPATH_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_SOLIDBRUSHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Color U_PSEUDO_OBJ containing a U_PMF_ARGB object
EMF+ manual 2.2.2.43, Microsoft name: EmfPlusSolidBrushData Object
*/
U_PSEUDO_OBJ *U_PMF_SOLIDBRUSHDATA_set(const U_PSEUDO_OBJ *Color){
if(!Color || (Color->Type != U_PMF_ARGB_OID)){ return(NULL); }
const U_SERIAL_DESC List[] = {
{Color->Data, Color->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_SOLIDBRUSHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_STRINGFORMATDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param TabStopCount Entries in TabStop array
\param TabStops (optional) Array of tabstop locations
\param Ranges (optional) U_PSEUDO_OBJ containing an array of U_PMF_CHARACTERRANGE objects
EMF+ manual 2.2.2.44, Microsoft name: EmfPlusStringFormatData Object
*/
U_PSEUDO_OBJ *U_PMF_STRINGFORMATDATA_set(uint32_t TabStopCount, U_FLOAT *TabStops, const U_PSEUDO_OBJ *Ranges){
if(Ranges && (Ranges->Type != (U_PMF_CHARACTERRANGE_OID | U_PMF_ARRAY_OID))){ return(NULL); }
const U_SERIAL_DESC List[] = {
{TabStops, TabStopCount*4, 1, U_LE},
{(Ranges ? Ranges->Data : NULL), (Ranges ? Ranges->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_STRINGFORMATDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_TEXTUREBRUSHDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags BrushData flags
\param WrapMode WrapMode enumeration
\param Tbod U_PSEUDO_OBJ containing an U_PMF_TEXTUREBRUSHOPTIONALDATA object
EMF+ manual 2.2.2.45, Microsoft name: EmfPlusTextureBrushData Object
*/
U_PSEUDO_OBJ *U_PMF_TEXTUREBRUSHDATA_set(uint32_t Flags, uint32_t WrapMode, const U_PSEUDO_OBJ *Tbod){
if(Flags & ~U_BD_MASKB){ return(NULL); } /* a bit was set that is not supported for this record */
if(WrapMode > U_WM_Clamp){ return(NULL); }
if(!Tbod || (Tbod->Type != (U_PMF_TEXTUREBRUSHOPTIONALDATA_OID))){ return(NULL); }
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{&WrapMode, 4, 1, U_LE},
{Tbod->Data, Tbod->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_TEXTUREBRUSHDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_TEXTUREBRUSHOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Tm (optional) U_PSEUDO_OBJ containing an U_PMF_TRANSFORMMATRIX object
\param Image (optional) U_PSEUDO_OBJ containing an U_PMF_IMAGE object
EMF+ manual 2.2.2.46, Microsoft name: EmfPlusTextureBrushOptionalData Object
*/
U_PSEUDO_OBJ *U_PMF_TEXTUREBRUSHOPTIONALDATA_set(const U_PSEUDO_OBJ *Tm, const U_PSEUDO_OBJ *Image){
if(Tm && (Tm->Type != (U_PMF_TRANSFORMMATRIX_OID))){ return(NULL); }
if(Image && (Image->Type != (U_PMF_IMAGE_OID))){ return(NULL); }
const U_SERIAL_DESC List[] = {
{(Tm ? Tm->Data : NULL), (Tm ? Tm->Used : 0), 1, U_XE},
{(Image ? Image->Data : NULL), (Image ? Image->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_TEXTUREBRUSHOPTIONALDATA_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_TRANSFORMMATRIX PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Tm U_PMF_TRANSFORMMATRIX_ object
EMF+ manual 2.2.2.47, Microsoft name: EmfPlusTransformMatrix Object
*/
U_PSEUDO_OBJ *U_PMF_TRANSFORMMATRIX_set(U_PMF_TRANSFORMMATRIX *Tm){
if(!Tm){ return(NULL); }
const U_SERIAL_DESC List[] = {
{Tm, 4, 6, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_TRANSFORMMATRIX_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_BLUR PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Radius Blur radius in pixels
\param ExpandEdge 1: expand bitmap by Radius; 0: bitmap size unchanged
EMF+ manual 2.2.3.1, Microsoft name: BlurEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_BLUR_set(U_FLOAT Radius, uint32_t ExpandEdge){
const U_SERIAL_DESC List[] = {
{&Radius, 4, 1, U_LE},
{&ExpandEdge, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_BLUR_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_BRIGHTNESSCONTRAST PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Brightness -255 to 255, 0 is unchanged, positive increases, negative decreases
\param Contrast -100 to 100, 0 is unchanged, positive increases, negative decreases
EMF+ manual 2.2.3.2, Microsoft name: BrightnessContrastEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_BRIGHTNESSCONTRAST_set(int32_t Brightness, int32_t Contrast){
const U_SERIAL_DESC List[] = {
{&Brightness, 4, 1, U_LE},
{&Contrast, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_BRIGHTNESSCONTRAST_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_COLORBALANCE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param CyanRed -100 to 100, 0 is unchanged, positive increases Red & decreases Cyan, negative is opposite
\param MagentaGreen -100 to 100, 0 is unchanged, positive increases Green & decreases Magenta, negative is opposite
\param YellowBlue -100 to 100, 0 is unchanged, positive increases Blue & decreases Yellow, negative is opposite
EMF+ manual 2.2.3.3, Microsoft name: ColorBalanceEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_COLORBALANCE_set(int32_t CyanRed, int32_t MagentaGreen, int32_t YellowBlue){
const U_SERIAL_DESC List[] = {
{&CyanRed, 4, 1, U_LE},
{&MagentaGreen, 4, 1, U_LE},
{&YellowBlue, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_COLORBALANCE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_COLORCURVE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Adjust CurveAdjustment enumeration
\param Channel CurveChannel enumeration
\param Intensity adjustment to apply. "Adjust" determines what field this is and range values.
EMF+ manual 2.2.3.4, Microsoft name: ColorCurveEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_COLORCURVE_set(uint32_t Adjust, uint32_t Channel, int32_t Intensity){
const U_SERIAL_DESC List[] = {
{&Adjust, 4, 1, U_LE},
{&Channel, 4, 1, U_LE},
{&Intensity, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_COLORCURVE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_COLORLOOKUPTABLE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param BLUT Blue color lookup table
\param GLUT Green color lookup table
\param RLUT Red color lookup table
\param ALUT Alpha color lookup table
EMF+ manual 2.2.3.5, Microsoft name: ColorLookupTableEffect Object.
All tables have 256 entries.
*/
U_PSEUDO_OBJ *U_PMF_IE_COLORLOOKUPTABLE_set(const uint8_t *BLUT, const uint8_t *GLUT, const uint8_t *RLUT, const uint8_t *ALUT){
if(!BLUT || !GLUT || !RLUT || !ALUT)return(NULL);
const U_SERIAL_DESC List[] = {
{BLUT, 1, 256, U_XE},
{GLUT, 1, 256, U_XE},
{RLUT, 1, 256, U_XE},
{ALUT, 1, 256, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_COLORLOOKUPTABLE_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_COLORMATRIX PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Matrix 5 x 5 color transformation matrix, First 4 rows are [{4 multiplier values},0.0] for R,G,B,A, last Row is [{4 color translation valuess}, 1.0]
EMF+ manual 2.2.3.6, Microsoft name: ColorMatrixEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_COLORMATRIX_set(const U_FLOAT *Matrix){
if(!Matrix)return(NULL);
const U_SERIAL_DESC List[] = {
{Matrix, 4, 25, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_COLORMATRIX_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_HUESATURATIONLIGHTNESS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Hue -180 to 180, 0 is unchanged
\param Saturation -100 to 100, 0 is unchanged
\param Lightness -100 to 100, 0 is unchanged
EMF+ manual 2.2.3.7, Microsoft name: HueSaturationLightnessEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_HUESATURATIONLIGHTNESS_set(int32_t Hue, int32_t Saturation, int32_t Lightness){
const U_SERIAL_DESC List[] = {
{&Hue, 4, 1, U_LE},
{&Saturation, 4, 1, U_LE},
{&Lightness, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_HUESATURATIONLIGHTNESS_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_LEVELS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Highlight 0 to 100, 100 is unchanged
\param Midtone -100 to 0, 0 is unchanged
\param Shadow 0 to 100, 0 is unchanged
EMF+ manual 2.2.3.8, Microsoft name: LevelsEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_LEVELS_set(int32_t Highlight, int32_t Midtone, int32_t Shadow){
const U_SERIAL_DESC List[] = {
{&Highlight, 4, 1, U_LE},
{&Midtone, 4, 1, U_LE},
{&Shadow, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_LEVELS_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_REDEYECORRECTION PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Elements Number of members in Rects
\param Rects Array of U_RECTL rectangular area(s) to apply red eye correction
EMF+ manual 2.2.3.9, Microsoft name: RedEyeCorrectionEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_REDEYECORRECTION_set(uint32_t Elements, const U_RECTL *Rects){
if(!Elements || !Rects){return(NULL);}
const U_SERIAL_DESC List[] = {
{&Elements, 4, 1, U_LE},
{Rects, 4*4, Elements,U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_REDEYECORRECTION_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_SHARPEN PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Radius Sharpening radius in pixels
\param Sharpen 0 to 100, 0 is unchanged
EMF+ manual 2.2.3.10, Microsoft name: SharpenEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_SHARPEN_set(U_FLOAT Radius, int32_t Sharpen){
const U_SERIAL_DESC List[] = {
{&Radius, 4, 1, U_LE},
{&Sharpen, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_SHARPEN_OID, List);
return(po);
}
/**
\brief Create and set a U_PMF_IE_TINT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Hue -180 to 180, [positive==clockwise] rotation in degrees starting from blue
\param Amount -100 [add black] to 100[add white], 0 is unchanged. Change in hue on specified axis
EMF+ manual 2.2.3.11, Microsoft name: TintEffect Object
*/
U_PSEUDO_OBJ *U_PMF_IE_TINT_set(const int32_t Hue, const int32_t Amount){
const U_SERIAL_DESC List[] = {
{&Hue, 4, 1, U_LE},
{&Amount, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_IE_TINT_OID, List);
return(po);
}
//! \cond
/* internal routine, not part of the API.
Returns a PseudoObject containing a U_PMR_CMN_HDR_OID object.
The type is something like U_PMR_OFFSETCLIP (the record type, NOT the U_PMR_OFFSETCLIP_OID PseudoObject Type!).
The U_PMR_RECFLAG bit is added both in the data and in the Type of the PseudoObject.
If that bit is already set no harm, no foul.
*/
U_PSEUDO_OBJ *U_PMR_CMN_HDR_set(uint32_t Type, uint16_t Flags, uint32_t DataSize){
uint32_t Size = 12 + UP4(DataSize); /* The header itself is always 12, PMR records must be a multiple of 4 */
Type |= U_PMR_RECFLAG;
uint16_t utmp16 = Type;
const U_SERIAL_DESC List[] = {
{&utmp16, 2, 1, U_LE},
{&Flags, 2, 1, U_LE}, /* Microsoft EMF+ manual is BE, but this field in this implementation is LE */
{&Size, 4, 1, U_LE},
{&DataSize, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_CMN_HDR_OID, List);
return(po);
}
//! \endcond
/**
\brief Create and set a U_PMR_STROKEFILLPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
EMF+ manual mentioned in 2.1.1.1, not otherwise documented, Microsoft name: EmfPlusStrokeFillPath Record, Index 0x37
"This record closes any open figures in a path, strokes the outline of
the path by using the current pen, and fills its interior by using the current brush."
*/
U_PSEUDO_OBJ *U_PMR_STROKEFILLPATH_set(void){
int Size = 0;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_STROKEFILLPATH,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_STROKEFILLPATH_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_OFFSETCLIP PseudoObject
\return Pointer to PseudoObject, NULL on error
\param dX horizontal translation offset to apply to clipping region
\param dY vertical translation offset to apply to clipping region
EMF+ manual 2.3.1.1, Microsoft name: EmfPlusOffsetClip Record, Index 0x35
*/
U_PSEUDO_OBJ *U_PMR_OFFSETCLIP_set(U_FLOAT dX, U_FLOAT dY){
int Size = 2*4;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_OFFSETCLIP,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&dX, 4, 1, U_LE},
{&dY, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_OFFSETCLIP_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_RESETCLIP PseudoObject
\return Pointer to PseudoObject, NULL on error
EMF+ manual 2.3.1.2, Microsoft name: EmfPlusResetClip Record, Index 0x31
*/
U_PSEUDO_OBJ *U_PMR_RESETCLIP_set(void){
int Size = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_RESETCLIP,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_RESETCLIP_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETCLIPPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param CMenum CombineMode enumeration..
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.1.3, Microsoft name: EmfPlusSetClipPath Record, Index 0x33
*/
U_PSEUDO_OBJ *U_PMR_SETCLIPPATH_set(uint32_t PathID, uint32_t CMenum){
if(PathID>63)return(NULL);
int Size=0;
uint16_t utmp16 = ((PathID & U_FF_MASK_OID8) << U_FF_SHFT_OID8) | ((CMenum & U_FF_MASK_CM4) << U_FF_SHFT_CM4);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETCLIPPATH,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETCLIPPATH_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETCLIPRECT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param CMenum CombineMode enumeration..
\param Rect U_PSEUDO_OBJ containing an U_PMF_RECTF object or an array of U_PMF_RECTF objects (the first is used)
EMF+ manual 2.3.1.4, Microsoft name: EmfPlusSetClipRect Record, Index 0x32
*/
U_PSEUDO_OBJ *U_PMR_SETCLIPRECT_set(uint32_t CMenum, const U_PSEUDO_OBJ *Rect){
int Size=4*4;
const char *start;
uint16_t utmp16 = ((CMenum & U_FF_MASK_CM4) << U_FF_SHFT_CM4);
if(Rect){
if( Rect->Type == U_PMF_RECTF_OID){
start = Rect->Data;
}
else if(Rect->Type == (U_PMF_RECTF_OID | U_PMF_ARRAY_OID)){
start = Rect->Data + 4;
}
else { return(0); }
}
else { return(0); }
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETCLIPRECT,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{start, 4, 4, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETCLIPRECT_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETCLIPREGION PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param CMenum CombineMode enumeration..
EMF+ manual 2.3.1.5, Microsoft name: EmfPlusSetClipRegion Record, Index 0x34
*/
U_PSEUDO_OBJ *U_PMR_SETCLIPREGION_set(uint32_t PathID, uint32_t CMenum){
if(PathID>63)return(NULL);
int Size=0;
uint16_t utmp16 = ((PathID & U_FF_MASK_OID8) << U_FF_SHFT_OID8) | ((CMenum & U_FF_MASK_CM4) << U_FF_SHFT_CM4);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETCLIPREGION,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETCLIPREGION_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_COMMENT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param cbData Number of bytes in Data, must be a multiple of 4
\param Data Private data, may be anything. Stored in PseudoObject without adjusting byte order.
EMF+ manual 2.3.2.1, Microsoft name: EmfPlusComment Record, Index 0x03
*/
U_PSEUDO_OBJ *U_PMR_COMMENT_set(size_t cbData, const void *Data){
if(UP4(cbData) != cbData){ return(NULL); }
if(cbData && !Data){ return(NULL); }
int Size=cbData;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_COMMENT,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Data, cbData, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_COMMENT_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_ENDOFFILE PseudoObject
\return Pointer to PseudoObject, NULL on error
EMF+ manual 2.3.3.1, Microsoft name: EmfPlusEndOfFile Record, Index 0x02
*/
U_PSEUDO_OBJ *U_PMR_ENDOFFILE_set(void){
int Size=0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_ENDOFFILE,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_ENDOFFILE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_GETDC PseudoObject
\return Pointer to PseudoObject, NULL on error
EMF+ manual 2.3.3.2, Microsoft name: EmfPlusGetDC Record, Index 0x04
*/
U_PSEUDO_OBJ *U_PMR_GETDC_set(void){
int Size=0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_GETDC,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_GETDC_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_HEADER PseudoObject
\return Pointer to PseudoObject, NULL on error
\param IsDual set = Dual-mode file, clear= EMF+ only file.
\param IsVideo set = video device, clear= printer. Ignore all other bits.
\param Version U_PSEUDO_OBJ containing a U_PMF_GRAPHICSVERSION object
\param LogicalDpiX Horizontal resolution reference device in DPI
\param LogicalDpiY Vertical resolution reference device in DPI
EMF+ manual 2.3.3.3, Microsoft name: EmfPlusHeader Record, Index 0x01
*/
U_PSEUDO_OBJ *U_PMR_HEADER_set(int IsDual, int IsVideo, const U_PSEUDO_OBJ *Version,
uint32_t LogicalDpiX, uint32_t LogicalDpiY){
if(!Version || (Version->Type != U_PMF_GRAPHICSVERSION_OID)){ return(NULL); }
int Size=Version->Used + 3*4;
uint16_t utmp16 = (IsDual ? U_PPF_DM : 0);
uint32_t Flags = (IsVideo ? U_PPF_VIDEO : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_HEADER,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Version->Data, Version->Used, 1, U_XE},
{&Flags, 4, 1, U_LE},
{&LogicalDpiX, 4, 1, U_LE},
{&LogicalDpiY, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_HEADER_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_CLEAR PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Color U_PSEUDO_OBJ containing a U_PMF_ARGB object.
EMF+ manual 2.3.4.1, Microsoft name: EmfPlusClear Record, Index 0x09
Erase everything preceding, set background ARGB to Color.
*/
U_PSEUDO_OBJ *U_PMR_CLEAR_set(const U_PSEUDO_OBJ *Color){
if(!Color || (Color->Type != U_PMF_ARGB_OID)){ return(NULL); }
int Size=Color->Used;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_CLEAR,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Color->Data, Color->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_CLEAR_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWARC PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.2, Microsoft name: EmfPlusDrawArc Record, Index 0x12
*/
U_PSEUDO_OBJ *U_PMR_DRAWARC_set(uint32_t PenID, U_FLOAT Start, U_FLOAT Sweep, const U_PSEUDO_OBJ *Rect){
int ctype;
if(PenID>63)return(NULL);
if(!Rect){ return(NULL); }
else {
if( Rect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(Rect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
int Size = 2*4 + Rect->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWARC,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Start, 4, 1, U_LE},
{&Sweep, 4, 1, U_LE},
{Rect->Data, Rect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWARC_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWBEZIERS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Points U_PSEUDO_OBJ containing first Elements, then a U_PMF_POINT, U_PMF_POINTR or U_PMF_POINTF object
EMF+ manual 2.3.4.3, Microsoft name: EmfPlusDrawBeziers Record, Index 0x19
*/
U_PSEUDO_OBJ *U_PMR_DRAWBEZIERS_set(uint32_t PenID, const U_PSEUDO_OBJ *Points){
int ctype, RelAbs;
if(PenID>63)return(NULL);
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = Points->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (RelAbs ? U_PPF_P : 0) |(PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWBEZIERS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Points->Data, Points->Used, 1, U_XE}, /* Includes Elements */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWBEZIERS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWCLOSEDCURVE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Points U_PSEUDO_OBJ containing a U_PMF_POINT, U_PMF_POINTR or U_PMF_POINTF object
EMF+ manual 2.3.4.4, Microsoft name: EmfPlusDrawClosedCurve Record, Index 0x17
Curve is a cardinal spline.
References sent by MS support:
http://alvyray.com/Memos/CG/Pixar/spline77.pdf
http://msdn.microsoft.com/en-us/library/4cf6we5y(v=vs.110).aspx
*/
U_PSEUDO_OBJ *U_PMR_DRAWCLOSEDCURVE_set(uint32_t PenID, U_FLOAT Tension, const U_PSEUDO_OBJ *Points){
int ctype, RelAbs;
if(PenID>63)return(NULL);
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = 4 + Points->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (RelAbs ? U_PPF_P : 0) |(PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWCLOSEDCURVE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Tension, 4, 1, U_LE},
{Points->Data, Points->Used, 1, U_XE}, /* includes Elements*/
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWCLOSEDCURVE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWCURVE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Offset The starting point in the list of points, 0 is first.
\param NSegs Number of segments to draw. Starting at Offset go NSegs straight lines, must not run out of points..
\param Points U_PSEUDO_OBJ containing an element count then a series of U_PMF_POINT or U_PMF_POINTF object
EMF+ manual 2.3.4.5, Microsoft name: EmfPlusDrawCurve Record, Index 0x18
Curve is a cardinal spline, using doubled terminator points to generate curves for the terminal segments.
References sent by MS support:
http://alvyray.com/Memos/CG/Pixar/spline77.pdf
http://msdn.microsoft.com/en-us/library/4cf6we5y(v=vs.110).aspx
*/
U_PSEUDO_OBJ *U_PMR_DRAWCURVE_set(uint32_t PenID, U_FLOAT Tension, uint32_t Offset, uint32_t NSegs, const U_PSEUDO_OBJ *Points){
int ctype;
if(PenID>63)return(NULL);
if(!Points){ return(NULL); }
if(!NSegs){ return(NULL); }
else {
if( Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ ctype = 0; }
else { return(NULL); }
}
uint32_t Elements = (Points->Used - 4)/(ctype ? 4 : 8); /* This way do not need to worry about byte order */
if(Offset + NSegs + 1 > Elements){ return(NULL); }
int Size = 3*4 + Points->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) |(PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWCURVE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Tension, 4, 1, U_LE},
{&Offset, 4, 1, U_LE},
{&NSegs, 4, 1, U_LE},
{Points->Data, Points->Used, 1, U_XE}, /* Elements, points */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWCURVE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWDRIVERSTRING PseudoObject
\return Pointer to PseudoObject, NULL on error
\param FontID U_PMF_FONT object in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param DSOFlags DriverStringOptions flags
\param HasMatrix If 1 record contains a TransformMatrix field, if 0 it does not.
\param GlyphCount The number of Elements in Glyphs, must agree with the number of elements in Points.
\param Glyphs If U_DSO_CmapLookup is set in DSOFlags this is an array of UTF16LE characters, otherwise, it is an array of indices into the U_PMF_FONT object indexed by Object_ID in flags.
\param Points U_PSEUDO_OBJ containing a U_PMF_POINTF object
\param Tm U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX object. Apply to Glyphs & Positions. Present if HasMatrix is 1
EMF+ manual 2.3.4.6, Microsoft name: EmfPlusDrawDriverString Record, Index 0x36
*/
U_PSEUDO_OBJ *U_PMR_DRAWDRIVERSTRING_set(uint32_t FontID, const U_PSEUDO_OBJ *BrushID,
uint32_t DSOFlags, uint32_t HasMatrix, uint32_t GlyphCount,
const uint16_t *Glyphs, const U_PSEUDO_OBJ *Points, const U_PSEUDO_OBJ *Tm){
int btype;
if(FontID>63){ return(NULL); }
if(!Glyphs){ return(NULL); }
if(!Points || (Points->Type != (U_PMF_POINTF_OID | U_PMF_ARRAY_OID))){ return(NULL); }
uint32_t Elements = (Points->Used -4)/4;
if(GlyphCount != Elements){ return(NULL); }
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = 4 + BrushID->Used + 3*4 + Elements*2 + (Points->Used - 4);
if(HasMatrix){
if(!Tm){ return(NULL); }
else if(Tm->Type != (U_PMF_TRANSFORMMATRIX_OID)){ return(NULL); }
Size += Tm->Used;
}
uint16_t utmp16 = (btype ? U_PPF_B : 0) |(FontID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWDRIVERSTRING,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data,ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{&DSOFlags, 4, 1, U_LE},
{&HasMatrix, 4, 1, U_LE},
{&Elements, 4, 1, U_LE},
{Glyphs, 2, Elements, U_LE},
{Points->Data + 4, Points->Used - 4, 1, U_XE}, /* omit Elements */
{(HasMatrix ? Tm->Data : NULL), (HasMatrix ? Tm->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWDRIVERSTRING_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWELLIPSE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.7, Microsoft name: EmfPlusDrawEllipse Record, Index 0x0F
*/
U_PSEUDO_OBJ *U_PMR_DRAWELLIPSE_set(uint32_t PenID, const U_PSEUDO_OBJ *Rect){
if(PenID>63)return(NULL);
int ctype;
if(!Rect){ return(NULL); }
else {
if( Rect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(Rect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
int Size = Rect->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWELLIPSE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Rect->Data, Rect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWELLIPSE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWIMAGE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ImgID U_PMF_IMAGE object in the EMF+ object table (0-63, inclusive)
\param ImgAttrID index of a U_PMF_IMAGEATTRIBUTES object in the object table
\param SrcUnit UnitType enumeration
\param SrcRect U_PSEUDO_OBJ containing a U_PMF_RECTF object, Source region of image
\param DstRect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.8, Microsoft name: EmfPlusDrawImage Record, Index 0x1A
*/
U_PSEUDO_OBJ *U_PMR_DRAWIMAGE_set(uint32_t ImgID,
int32_t ImgAttrID, int32_t SrcUnit, const U_PSEUDO_OBJ *SrcRect, const U_PSEUDO_OBJ *DstRect){
int ctype;
if(ImgID>63)return(NULL);
if(!SrcRect || (SrcRect->Type != U_PMF_RECTF_OID)){ return(NULL); }
if(!DstRect){ return(NULL); }
else {
if( DstRect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(DstRect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
int Size = 2*4 + SrcRect->Used + DstRect->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (ImgID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWIMAGE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&ImgAttrID, 4, 1, U_LE},
{&SrcUnit, 4, 1, U_LE},
{SrcRect->Data, SrcRect->Used, 1, U_XE},
{DstRect->Data, DstRect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWIMAGE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWIMAGEPOINTS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ImgID U_PMF_IMAGE object in the EMF+ object table (0-63, inclusive)
\param etype Set: effect from previous U_PMR_SERIALIZABLEOBJECT record will be applied; Clear: no effect applied
\param ImgAttrID index of a U_PMF_IMAGEATTRIBUTES object in the object table
\param SrcUnit UnitType enumeration
\param SrcRect U_PSEUDO_OBJ containing a U_PMF_RECTF object, Source region of image
\param Points U_PSEUDO_OBJ containing an array of 3 (U_PMF_POINT, U_PMF_POINTF, or U_PMF_POINTF) objects. These points are the UL, UR, and LL vertices of a parallelogram.
EMF+ manual 2.3.4.9, Microsoft name: EmfPlusDrawImagePoints Record, Index 0x1B
WARNING! Windows XP Preview does not show filter effects, whether or not U_PPF_E is set. They are visible if the EMF+
file is inserted as an image into PowerPoint.
*/
U_PSEUDO_OBJ *U_PMR_DRAWIMAGEPOINTS_set(uint32_t ImgID, int etype,
int32_t ImgAttrID, int32_t SrcUnit, const U_PSEUDO_OBJ *SrcRect,
const U_PSEUDO_OBJ *Points){
int ctype, RelAbs;
if(ImgID>63){ return(NULL); }
if(!SrcRect || (SrcRect->Type != U_PMF_RECTF_OID)){ return(NULL); }
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = 2*4 + SrcRect->Used + Points->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (etype ? U_PPF_E : 0) | (RelAbs ? U_PPF_P : 0) | (ImgID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWIMAGEPOINTS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&ImgAttrID, 4, 1, U_LE},
{&SrcUnit, 4, 1, U_LE},
{SrcRect->Data, SrcRect->Used, 1, U_XE},
{Points->Data, Points->Used, 1, U_XE}, /* includes Elements*/
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWIMAGEPOINTS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWLINES PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param dtype Set: path must be closed, Clear: path is open
\param Points U_PSEUDO_OBJ containing an array of 3 U_PMF_POINT, U_PMF_POINTR, or U_PMF_POINTF objects
EMF+ manual 2.3.4.10, Microsoft name: EmfPlusDrawLines Record, Index 0x0D
*/
U_PSEUDO_OBJ *U_PMR_DRAWLINES_set(uint32_t PenID, int dtype, const U_PSEUDO_OBJ *Points){
int ctype, RelAbs;
if(PenID>63){ return(NULL); }
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = Points->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (dtype ? U_PPF_D : 0) | (RelAbs ? U_PPF_P : 0) | (PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWLINES,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Points->Data, Points->Used, 1, U_XE}, /* includes Elements */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWLINES_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.4.11, Microsoft name: EmfPlusDrawPath Record, Index 0x15
*/
U_PSEUDO_OBJ *U_PMR_DRAWPATH_set(uint32_t PathID, uint32_t PenID){
if(PathID>63)return(NULL);
if(PenID>63)return(NULL);
int Size = 4;
uint16_t utmp16 = (PathID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWPATH,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&PenID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWPATH_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWPIE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.12, Microsoft name: EmfPlusDrawPie Record, Index 0x0D
*/
U_PSEUDO_OBJ *U_PMR_DRAWPIE_set(uint32_t PenID,
U_FLOAT Start, U_FLOAT Sweep, const U_PSEUDO_OBJ *Rect){
int ctype;
if(PenID>63)return(NULL);
if(!Rect){ return(NULL); }
else {
if( Rect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(Rect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
int Size = 2*4 + Rect->Used;
uint16_t utmp16 = (ctype ? U_PPF_C : 0) | (PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWPIE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Start, 4, 1, U_LE},
{&Sweep, 4, 1, U_LE},
{Rect->Data, Rect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWPIE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWRECTS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param Rects U_PSEUDO_OBJ containing 1 rect OR a count N follwed by N rects. Rects may be either U_PMF_RECT or U_PMF_RECTF
EMF+ manual 2.3.4.13, Microsoft name: EmfPlusDrawRects Record, Index 0x0B
*/
U_PSEUDO_OBJ *U_PMR_DRAWRECTS_set(uint32_t PenID, const U_PSEUDO_OBJ *Rects){
int ctype;
int just1;
uint32_t Elements=1; /* only used when a single rect is passed in, not an array, not even an array with one member*/
if(PenID>63){ return(NULL); }
if(Rects){
if( (Rects->Type & U_PMF_MASK_OID) == U_PMF_RECT_OID ){ ctype = 1; }
else if( (Rects->Type & U_PMF_MASK_OID) == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
just1 = (Rects->Type & U_PMF_ARRAY_OID ? 0 : 1);
int Size = Rects->Used + (just1 ? 4 : 0); /* Elements in Rects for array, not for single */
uint16_t utmp16 = (ctype ? U_PPF_C : 0)| (PenID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWRECTS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{(just1 ? (char *)&Elements : NULL), (just1 ? 4: 0), 1, U_LE}, /* element count if a single Rect was passed in, empty otherwise */
{Rects->Data, Rects->Used, 1, U_XE}, /* Elements + Array, already stored in Rects, if an array was passed in, just rect if a single */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWRECTS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_DRAWSTRING PseudoObject
\return Pointer to PseudoObject, NULL on error
\param FontID U_PMF_FONT object in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param FormatID U_PMF_STRINGFORMAT object in EMF+ Object Table.
\param Length Number of characters in the string.
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECTF object, string's bounding box
\param Text Array of UFT-16LE unicode characters.
EMF+ manual 2.3.4.14, Microsoft name: EmfPlusDrawString Record, Index 0x1C
*/
U_PSEUDO_OBJ *U_PMR_DRAWSTRING_set(uint32_t FontID, const U_PSEUDO_OBJ *BrushID,
uint32_t FormatID, uint32_t Length, const U_PSEUDO_OBJ *Rect, const uint16_t *Text){
int btype;
if(FontID>63){ return(NULL); }
if(!Length){ return(NULL); }
else if (!Text){ return(NULL); }
if(!Rect || Rect->Type != U_PMF_RECTF_OID){ return(NULL); }
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = BrushID->Used + 2*4 + Rect->Used +2*Length;
uint16_t utmp16 = (btype ? U_PPF_B : 0)| (FontID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
uint32_t pad = (0x1 & Length ? 2 : 0);
Size+=pad;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_DRAWSTRING,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{&FormatID, 4, 1, U_LE},
{&Length, 4, 1, U_LE},
{Rect->Data, Rect->Used, 1, U_XE},
{Text, 2*Length, 1, U_XE},
{NULL, pad, (pad ? 1 : 0), (pad ? U_XE : U_XX)}, /* Entire record must be a multiple of 4 */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_DRAWSTRING_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLCLOSEDCURVE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ftype If U_WINDING use winding fill, else use fill
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Points U_PSEUDO_OBJ containing a U_PMF_POINT, U_PMF_POINTR or U_PMF_POINTF object
EMF+ manual 2.3.4.15, Microsoft name: EmfPlusFillClosedCurve Record, Index 0x16
*/
U_PSEUDO_OBJ *U_PMR_FILLCLOSEDCURVE_set(int ftype, U_FLOAT Tension, const U_PSEUDO_OBJ *BrushID, const U_PSEUDO_OBJ *Points){
int btype, ctype, RelAbs;
int Size=0;
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
Size = BrushID->Used + 4 + Points->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (ctype ? U_PPF_C : 0) |((ftype == U_WINDING) ? U_PPF_F : 0) |(RelAbs ? U_PPF_P : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLCLOSEDCURVE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{&Tension, 4, 1, U_LE},
{Points->Data, Points->Used, 1, U_XE}, /* includes Elements */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLCLOSEDCURVE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLELLIPSE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.16, Microsoft name: EmfPlusFillEllipse Record, Index 0x0E
*/
U_PSEUDO_OBJ *U_PMR_FILLELLIPSE_set(const U_PSEUDO_OBJ *BrushID, const U_PSEUDO_OBJ *Rect){
int btype, ctype;
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(Rect){
if( Rect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(Rect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = BrushID->Used + Rect->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (ctype ? U_PPF_C : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLELLIPSE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{Rect->Data, Rect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLELLIPSE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLPATH PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.4.17, Microsoft name: EmfPlusFillPath Record, Index 0x14
*/
U_PSEUDO_OBJ *U_PMR_FILLPATH_set(uint32_t PathID, const U_PSEUDO_OBJ *BrushID){
int btype;
int Size=0;
if(PathID>63)return(NULL);
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
Size = BrushID->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (PathID & U_FF_MASK_OID8) << U_FF_SHFT_OID8 ;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLPATH,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLPATH_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLPIE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param Rect U_PSEUDO_OBJ containing a U_PMF_RECT or U_PMF_RECTF object
EMF+ manual 2.3.4.18, Microsoft name: EmfPlusFillPie Record, Index 0x10
*/
U_PSEUDO_OBJ *U_PMR_FILLPIE_set(U_FLOAT Start, U_FLOAT Sweep, const U_PSEUDO_OBJ *BrushID, const U_PSEUDO_OBJ *Rect){
int btype, ctype;
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(!Rect){ return(NULL); }
else {
if( Rect->Type == U_PMF_RECT_OID ){ ctype = 1; }
else if(Rect->Type == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
int Size = BrushID->Used + 2*4 + Rect->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (ctype ? U_PPF_C : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLPIE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{&Start, 4, 1, U_LE},
{&Sweep, 4, 1, U_LE},
{Rect->Data, Rect->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLPIE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLPOLYGON PseudoObject
\return Pointer to PseudoObject, NULL on error
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param Points U_PSEUDO_OBJ containing an array of 3 U_PMF_POINT, U_PMF_POINTR, or U_PMF_POINTF objects
EMF+ manual 2.3.4.19, Microsoft name: EmfPlusFillPolygon Record, Index 0x0C
*/
U_PSEUDO_OBJ *U_PMR_FILLPOLYGON_set(const U_PSEUDO_OBJ *BrushID, const U_PSEUDO_OBJ *Points){
int btype, ctype, RelAbs;
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(Points){
if( Points->Type == U_PMF_POINTR_OID){ RelAbs = 1; ctype = 0; }
else if(Points->Type == (U_PMF_POINT_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 1; }
else if(Points->Type == (U_PMF_POINTF_OID | U_PMF_ARRAY_OID)){ RelAbs = 0; ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = BrushID->Used + Points->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (ctype ? U_PPF_C : 0) |(RelAbs ? U_PPF_P : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLPOLYGON,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{Points->Data, Points->Used, 1, U_XE}, /* includes Elements */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLPOLYGON_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLRECTS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
\param Rects U_PSEUDO_OBJ containing 1 rect OR a count N followed by N rects. Rects may be either U_PMF_RECT or U_PMF_RECTF
EMF+ manual 2.3.4.20, Microsoft name: EmfPlusFillRects Record, Index 0x0A
*/
U_PSEUDO_OBJ *U_PMR_FILLRECTS_set(const U_PSEUDO_OBJ *BrushID, const U_PSEUDO_OBJ *Rects){
int btype, ctype;
int just1;
uint32_t Elements=1; /* only used when a single rect is passed in, not an array, not even an array with one member*/
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
if(Rects){
if( (Rects->Type & U_PMF_MASK_OID) == U_PMF_RECT_OID ){ ctype = 1; }
else if( (Rects->Type & U_PMF_MASK_OID) == U_PMF_RECTF_OID){ ctype = 0; }
else { return(NULL); }
}
else { return(NULL); }
just1 = (Rects->Type & U_PMF_ARRAY_OID ? 0 : 1);
int Size = BrushID->Used + Rects->Used + (just1 ? 4 : 0); /* Elements in Rects for array, not for single */
uint16_t utmp16 = (btype ? U_PPF_B : 0)|(ctype ? U_PPF_C : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLRECTS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{(just1 ? (char *)&Elements : NULL), (just1 ? 4: 0), 1, U_LE}, /* element count if a single Rect was passed in, empty otherwise */
{Rects->Data, Rects->Used, 1, U_XE}, /* Elements + Array, already stored in Rects, if an array was passed in, just rect if a single */
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLRECTS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_FILLREGION PseudoObject
\return Pointer to PseudoObject, NULL on error
\param RgnID U_PMF_REGION object in the EMF+ object table (0-63, inclusive)
\param BrushID U_PSEUDO_OBJ containing a U_PMF_ARGB or a U_PMF_4NUM. Color or U_PMF_BRUSH object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.4.21, Microsoft name: EmfPlusFillRegion Record, Index 0x13
*/
U_PSEUDO_OBJ *U_PMR_FILLREGION_set(uint32_t RgnID, const U_PSEUDO_OBJ *BrushID){
int btype;
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
else if( BrushID->Type == U_PMF_ARGB_OID){ btype = 1; }
else if( BrushID->Type == U_PMF_4NUM_OID){ btype = 0; }
else { return(NULL); }
}
else { return(NULL); }
int Size = BrushID->Used;
uint16_t utmp16 = (btype ? U_PPF_B : 0) | (RgnID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_FILLREGION,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{BrushID->Data, BrushID->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_FILLREGION_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_OBJECT PseudoObject from another PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ObjID Index for this object in the EMF+ object table (0-63, inclusive)
\param Po U_PSEUDO_OBJ containing an object type that may be stored in the EMF+ object table
*/
U_PSEUDO_OBJ *U_PMR_OBJECT_PO_set(uint32_t ObjID, U_PSEUDO_OBJ *Po){
if(!Po){ return(NULL); }
int otype = U_OID_To_OT(Po->Type); /* This will return 0 if the type is not valid for an object */
if(!otype){ return(NULL); }
U_PSEUDO_OBJ *po = U_PMR_OBJECT_set(ObjID, otype, 0, 0, Po->Used, Po->Data); /* 0,0 = rec. not continued, TSize value (ignored) */
return(po);
}
/**
\brief Create and set a U_PMR_OBJECT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param ObjID Index for this object in the EMF+ object table (0-63, inclusive)
\param otype ObjectType enumeration for this Object
\param ntype Set: object definition continues in next record; Clear: this is the sole object definition record
\param TSize If ntype is set the total number of data bytes split across multiple records. If ntype is clear, it is ignored.
\param cbData Object's data size, in bytes.
\param Data Object's data. Type from otype.
EMF+ manual 2.3.5.1, Microsoft name: EmfPlusObject Record, Index 0x13
Normally this is only called by U_PMR_OBJECT_PO_set().
U_PMR_OBJECT records can only hold a maximum of 65020 bytes of data. If the object is larger than that
then multiple U_PMR_OBJECT records are created, one after the other. If this
happens each record has cbData following ph, and the ntype flag is set. If all of the data is less than 65020
then cbData is NOT entered following ph, and the ntype flag is clear.
Call initially in all cases with ntype clear and TSize = 0. If the record needs to be fragmented
the function will call itself recursively to do so.
*/
U_PSEUDO_OBJ *U_PMR_OBJECT_set(uint32_t ObjID, int otype, int ntype, uint32_t TSize, size_t cbData, const char *Data){
uint32_t CSize;
int Pad = UP4(TSize) - TSize;
if((otype < U_OT_Brush) || (otype > U_OT_CustomLineCap)){ return(NULL); }
if(ntype && (cbData > U_OBJRECLIM)){ return(NULL); }
if(!Data || !cbData){ return(NULL); }
U_PSEUDO_OBJ *po;
if(!ntype && !TSize && (cbData > U_OBJRECLIM)){
ntype = 1;
TSize = cbData;
po = U_PO_create(NULL, TSize + 16 * (1 + (TSize/cbData)), 0, U_PMR_OBJECT_OID);
if(po){
while(cbData){
CSize = (cbData > U_OBJRECLIM ? U_OBJRECLIM : cbData);
U_PSEUDO_OBJ *pot = U_PMR_OBJECT_set(ObjID, otype, ntype, TSize, CSize, Data);
if(!pot)break;
U_PSEUDO_OBJ *newpo = U_PO_po_append(po, pot, U_PMF_KEEP_ELEMENTS);
U_PO_free(&pot);
if(!newpo)break;
po = newpo;
Data += U_OBJRECLIM;
cbData -= CSize;
}
if(cbData){ /* some error */
U_PO_free(&po);
}
}
}
else {
/* Send in DataSize, U_PMR_CMN_HDR_set will adjust Header Size with 1-3 pad bytes if needed */
uint16_t utmp16 = otype << 8 | (ntype ? U_PPF_N : 0) | (ObjID & U_FF_MASK_OID8) << U_FF_SHFT_OID8;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_OBJECT,utmp16,cbData + (ntype ? 4 : 0));
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE },
{(ntype ? &TSize : NULL), (ntype ? 4 : 0), (ntype ? 1 : 0), U_LE },
{Data, cbData, 1, U_XE },
{NULL, (Pad ? Pad : 0), (Pad ? 1 : 0), (Pad ? U_XE : U_XX)}, /* Either 1-3 pad bytes or a terminator */
{NULL,0,0,U_XX} /* terminator, possibly a second in the list, which is harmless */
};
po = U_PMF_SERIAL_set(U_PMR_OBJECT_OID, List);
U_PO_free(&ph);
}
return(po);
}
/**
\brief Create and set a U_PMR_SERIALIZABLEOBJECT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Siepb U_PSEUDO_OBJ containing a "Serialized image effects parameter block". One of the ImageEffects objects.
EMF+ manual 2.3.5.2, Microsoft name: EmfPlusSerializableObject Record, Index 0x38
This sets an ImageEffect in the renderer, which will be applied to the next EmfPlusDrawImagePoints
record that is encountered. The image effect is "consumed" by that EmfPlusDrawImagePoints record, resetting
the renderer to its original state.\n
WARNING! Windows XP Preview does not show filter effects, whether or not U_PPF_E is set. They are visible if the EMF+
file is inserted as an image into PowerPoint.
*/
U_PSEUDO_OBJ *U_PMR_SERIALIZABLEOBJECT_set(const U_PSEUDO_OBJ *Siepb){
if(!Siepb){ return(NULL); }
uint8_t *GUID = U_OID_To_GUID(Siepb->Type);
if(!GUID){ return(NULL); }
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Siepb->Used;
int Size = 16 + 4 + Siepb->Used;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SERIALIZABLEOBJECT,0,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{GUID, 16, 1, U_XE},
{&Used, 4, 1, U_LE},
{Siepb->Data, Siepb->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SERIALIZABLEOBJECT_OID, List);
U_PO_free(&ph);
free(GUID);
return(po);
}
/**
\brief Create and set a U_PMR_SETANTIALIASMODE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param SMenum SmoothingMode enumeration
\param aatype Set: anti-aliasing on; Clear: anti-aliasing off
EMF+ manual 2.3.6.1, Microsoft name: EmfPlusSetAntiAliasMode Record, Index 0x1E
*/
U_PSEUDO_OBJ *U_PMR_SETANTIALIASMODE_set(int SMenum, int aatype){
int Size = 0;
uint16_t utmp16 = (aatype ? U_PPF_AA : 0) | (SMenum & U_FF_MASK_AA)<<U_FF_SHFT_AA;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETANTIALIASMODE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETANTIALIASMODE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETCOMPOSITINGMODE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param CMenum CompositingMode enumeration
EMF+ manual 2.3.6.2, Microsoft name: EmfPlusSetCompositingMode Record, Index 0x23
*/
U_PSEUDO_OBJ *U_PMR_SETCOMPOSITINGMODE_set(int CMenum){
int Size = 0;
uint16_t utmp16 = (CMenum & U_FF_MASK_CM)<<U_FF_SHFT_CM;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETCOMPOSITINGMODE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETCOMPOSITINGMODE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETCOMPOSITINGQUALITY PseudoObject
\return Pointer to PseudoObject, NULL on error
\param CQenum CompositingQuality enumeration
EMF+ manual 2.3.6.3, Microsoft name: EmfPlusSetCompositingQuality Record, Index 0x24
*/
U_PSEUDO_OBJ *U_PMR_SETCOMPOSITINGQUALITY_set(int CQenum){
int Size = 0;
uint16_t utmp16 = (CQenum & U_FF_MASK_CQ)<<U_FF_SHFT_CQ;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETCOMPOSITINGQUALITY,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETCOMPOSITINGQUALITY_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETINTERPOLATIONMODE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param IMenum InterpolationMode enumeration
EMF+ manual 2.3.6.4, Microsoft name: EmfPlusSetInterpolationMode Record, Index 0x21
*/
U_PSEUDO_OBJ *U_PMR_SETINTERPOLATIONMODE_set(int IMenum){
int Size = 0;
uint16_t utmp16 = (IMenum & U_FF_MASK_IM)<<U_FF_SHFT_IM;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETINTERPOLATIONMODE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETINTERPOLATIONMODE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETPIXELOFFSETMODE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param POMenum PixelOffsetMode enumeration
EMF+ manual 2.3.6.5, Microsoft name: EmfPlusSetPixelOffsetMode Record, Index 0x22
*/
U_PSEUDO_OBJ *U_PMR_SETPIXELOFFSETMODE_set(int POMenum){
int Size = 0;
uint16_t utmp16 = (POMenum & U_FF_MASK_PxOffM) << U_FF_SHFT_PxOffM;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETPIXELOFFSETMODE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETPIXELOFFSETMODE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETRENDERINGORIGIN PseudoObject
\return Pointer to PseudoObject, NULL on error
\param X X coordinate of rendering origin.
\param Y Y coordinate of rendering origin.
EMF+ manual 2.3.6.6, Microsoft name: EmfPlusSetRenderingOrigin Record, Index 0x1D
*/
U_PSEUDO_OBJ *U_PMR_SETRENDERINGORIGIN_set(int32_t X, int32_t Y){
int Size = 2*4;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETRENDERINGORIGIN,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&X, 4, 1, U_LE},
{&Y, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETRENDERINGORIGIN_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETTEXTCONTRAST PseudoObject
\return Pointer to PseudoObject, NULL on error
\param TGC Text Gamma correction value (x 1000).
EMF+ manual 2.3.6.7, Microsoft name: EmfPlusSetTextContrast Record, Index 0x20
*/
U_PSEUDO_OBJ *U_PMR_SETTEXTCONTRAST_set(int TGC){
int Size = 0;
uint16_t utmp16 = (TGC & U_FF_MASK_TGC) << U_FF_SHFT_TGC;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETTEXTCONTRAST,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETTEXTCONTRAST_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETTEXTRENDERINGHINT PseudoObject
\return Pointer to PseudoObject, NULL on error
\param TRHenum TextRenderingHint enumeration
EMF+ manual 2.3.6.8, Microsoft name: EmfPlusSetTextRenderingHint Record, Index 0x1F
*/
U_PSEUDO_OBJ *U_PMR_SETTEXTRENDERINGHINT_set(int TRHenum){
int Size = 0;
uint16_t utmp16 = (TRHenum & U_FF_MASK_TRH) << U_FF_SHFT_TRH;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETTEXTRENDERINGHINT,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETTEXTRENDERINGHINT_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_BEGINCONTAINER PseudoObject
\return Pointer to PseudoObject, NULL on error
\param UTenum UnitType enumeration
\param DstRect a U_PSEUDO_OBJ containing a U_PMF_RECTF object. with SrcRect specifies a transformation
\param SrcRect a U_PSEUDO_OBJ containing a U_PMF_RECTF object. with DstRect specifies a transformation
\param StackID EMF+ Object Stack Index to use for this graphics container
EMF+ manual 2.3.7.1, Microsoft name: EmfPlusBeginContainer Record, Index 0x27
*/
U_PSEUDO_OBJ *U_PMR_BEGINCONTAINER_set(int UTenum, U_PSEUDO_OBJ *DstRect, U_PSEUDO_OBJ *SrcRect, uint32_t StackID){
if(UTenum < U_UT_World || UTenum > U_UT_Millimeter){ return(NULL); }
if(!DstRect || (DstRect->Type != U_PMF_RECTF_OID)){ return(NULL); }
if(!SrcRect || (SrcRect->Type != U_PMF_RECTF_OID)){ return(NULL); }
int Size = DstRect->Used + SrcRect->Used + 4;
uint16_t utmp16 = (UTenum & U_FF_MASK_UT) << U_FF_SHFT_UT;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_BEGINCONTAINER,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{DstRect->Data, DstRect->Used, 1, U_XE},
{SrcRect->Data, SrcRect->Used, 1, U_XE},
{&StackID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_BEGINCONTAINER_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_BEGINCONTAINERNOPARAMS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param StackID EMF+ Object Stack Index to use for this graphics container
EMF+ manual 2.3.7.2, Microsoft name: EmfPlusBeginContainerNoParams Record, Index 0x28
*/
U_PSEUDO_OBJ *U_PMR_BEGINCONTAINERNOPARAMS_set(int StackID){
int Size = 4;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_BEGINCONTAINERNOPARAMS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&StackID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_BEGINCONTAINERNOPARAMS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_ENDCONTAINER PseudoObject
\return Pointer to PseudoObject, NULL on error
\param StackID EMF+ Object Stack Index to use for this graphics container
EMF+ manual 2.3.7.3, Microsoft name: EmfPlusEndContainer Record, Index 0x29
*/
U_PSEUDO_OBJ *U_PMR_ENDCONTAINER_set(int StackID){
int Size = 4;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_ENDCONTAINER,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&StackID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_ENDCONTAINER_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_RESTORE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param StackID EMF+ Graphics State Stack to restore from. Must have been put on the GSS with a U_PMR_SAVE.
EMF+ manual 2.3.7.4, Microsoft name: EmfPlusRestore Record, Index 0x26
*/
U_PSEUDO_OBJ *U_PMR_RESTORE_set(int StackID){
int Size = 4;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_RESTORE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&StackID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_RESTORE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SAVE PseudoObject
\return Pointer to PseudoObject, NULL on error
\param StackID EMF+ Graphics State Stack to restore from. Must have been put on the GSS with a U_PMR_SAVE.
EMF+ manual 2.3.7.5, Microsoft name: EmfPlusSave Record, Index 0x25
*/
U_PSEUDO_OBJ *U_PMR_SAVE_set(int StackID){
int Size = 4;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SAVE,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&StackID, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SAVE_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETTSCLIP PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Rects a U_PSEUDO_OBJ containing an array of U_PMF_RECT or U_PMF_RECTF objects.
EMF+ manual 2.3.8.1, Microsoft name: EmfPlusSetTSClip Record, Index 0x3A
*/
U_PSEUDO_OBJ *U_PMR_SETTSCLIP_set(U_PSEUDO_OBJ *Rects){
int ctype;
uint32_t Elements;
if(Rects){
if( Rects->Type == (U_PMF_RECT_OID | U_PMF_ARRAY_OID)){ ctype = 1; Elements = (Rects->Used - 4)/8; }
else if(Rects->Type == (U_PMF_RECTF_OID | U_PMF_ARRAY_OID)){ ctype = 0; Elements = (Rects->Used - 4)/16; }
else { return(NULL); }
}
else { return(NULL); }
int Size = Rects->Used; /* Rects includes Elements */
uint16_t utmp16 = (ctype ? U_PPF_K : 0) | (Elements & U_FF_MASK_TSC) << U_FF_SHFT_TSC;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETTSCLIP,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Rects->Data, Rects->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETTSCLIP_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETTSGRAPHICS PseudoObject
\return Pointer to PseudoObject, NULL on error
\param vgatype Set: Palette is VGA basic colors; Clear: Palette is ???
\param Tsg A U_PMF_SETTSGRAPHICS object
\param Palette (optional) a U_PSEUDO_OBJ containing a U_PMF_PALETTE object.
EMF+ manual 2.3.8.2, Microsoft name: EmfPlusSetTSGraphics Record, Index 0x39
*/
U_PSEUDO_OBJ *U_PMR_SETTSGRAPHICS_set(int vgatype, U_PMF_SETTSGRAPHICS *Tsg, U_PSEUDO_OBJ *Palette){
if(!Tsg){ return(NULL); }
int Size = sizeof(U_PMF_SETTSGRAPHICS) + (Palette ? Palette->Used : 0);
uint16_t utmp16 = (vgatype ? U_PPF_VGA : 0) | (Palette ? U_PPF_PP : 0) ;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETTSGRAPHICS,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&(Tsg->AntiAliasMode), 1, 1, U_XE},
{&(Tsg->TextRenderHint), 1, 1, U_XE},
{&(Tsg->CompositingMode), 1, 1, U_XE},
{&(Tsg->CompositingQuality), 1, 1, U_XE},
{&(Tsg->RenderOriginX), 2, 1, U_LE},
{&(Tsg->RenderOriginY), 2, 1, U_LE},
{&(Tsg->TextContrast), 2, 1, U_LE},
{&(Tsg->FilterType), 1, 1, U_XE},
{&(Tsg->PixelOffset), 1, 1, U_XE},
{&(Tsg->WorldToDevice), 4, 6, U_LE},
{(Palette ? Palette->Data : NULL), (Palette ? Palette->Used: 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETTSGRAPHICS_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_MULTIPLYWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Tm a U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX. (Transformation matrix)
EMF+ manual 2.3.9.1, Microsoft name: EmfPlusMultiplyWorldTransform Record, Index 0x2C
*/
U_PSEUDO_OBJ *U_PMR_MULTIPLYWORLDTRANSFORM_set(int xmtype, U_PSEUDO_OBJ *Tm){
if(!Tm || (Tm->Type != U_PMF_TRANSFORMMATRIX_OID)){ return(NULL); }
int Size = Tm->Used;
uint16_t utmp16 = (xmtype ? U_PPF_XM : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_MULTIPLYWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Tm->Data, Tm->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_MULTIPLYWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_RESETWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
EMF+ manual 2.3.9.2, Microsoft name: EmfPlusResetWorldTransform Record, Index 0x2B
*/
U_PSEUDO_OBJ *U_PMR_RESETWORLDTRANSFORM_set(void){
int Size = 0;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_RESETWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_RESETWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_ROTATEWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Angle Rotation angle, in degrees
EMF+ manual 2.3.9.3, Microsoft name: EmfPlusRotateWorldTransform Record, Index 0x2F
*/
U_PSEUDO_OBJ *U_PMR_ROTATEWORLDTRANSFORM_set(int xmtype, U_FLOAT Angle){
int Size = 4;
uint16_t utmp16 = (xmtype ? U_PPF_XM : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_ROTATEWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Angle, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_ROTATEWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SCALEWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param xmtype Set: Post multiply; Clear: Pre multiply
\param X Scale in X
\param Y Scale in Y
EMF+ manual 2.3.9.4, Microsoft name: EmfPlusScaleWorldTransform Record, Index 0x2E
*/
U_PSEUDO_OBJ *U_PMR_SCALEWORLDTRANSFORM_set(int xmtype, U_FLOAT X, U_FLOAT Y){
int Size = 2*4;
uint16_t utmp16 = (xmtype ? U_PPF_XM : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SCALEWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&X, 4, 1, U_LE},
{&Y, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SCALEWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETPAGETRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param PUenum Page Unit, in UnitType enumeration
\param Scale Scale factor to convert page space to device space
EMF+ manual 2.3.9.5, Microsoft name: EmfPlusSetPageTransform Record, Index 0x30
Defines Page Space -> Device Space transformation
*/
U_PSEUDO_OBJ *U_PMR_SETPAGETRANSFORM_set(int PUenum, U_FLOAT Scale){
int Size = 4;
uint16_t utmp16 = (PUenum & U_FF_MASK_PU) << U_FF_SHFT_PU;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETPAGETRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Scale, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETPAGETRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_SETWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Tm a U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX. (Transformation matrix)
EMF+ manual 2.3.9.6, Microsoft name: EmfPlusSetWorldTransform Record, Index 0x2A
Defines World Space -> Page Space transformation
*/
U_PSEUDO_OBJ *U_PMR_SETWORLDTRANSFORM_set(U_PSEUDO_OBJ *Tm){
if(!Tm || (Tm->Type != U_PMF_TRANSFORMMATRIX_OID)){ return(NULL); }
int Size = Tm->Used;
uint16_t utmp16 = 0;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_SETWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{Tm->Data, Tm->Used, 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_SETWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/**
\brief Create and set a U_PMR_TRANSLATEWORLDTRANSFORM PseudoObject
\return Pointer to PseudoObject, NULL on error
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Dx X offset
\param Dy Y offset
EMF+ manual 2.3.9.7, Microsoft name: EmfPlusTranslateWorldTransform Record, Index 0x2D
*/
U_PSEUDO_OBJ *U_PMR_TRANSLATEWORLDTRANSFORM_set(int xmtype, U_FLOAT Dx, U_FLOAT Dy){
int Size = 2*4;
uint16_t utmp16 = (xmtype ? U_PPF_XM : 0);
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_TRANSLATEWORLDTRANSFORM,utmp16,Size);
const U_SERIAL_DESC List[] = {
{ph->Data, ph->Used, 1, U_XE},
{&Dx, 4, 1, U_LE},
{&Dy, 4, 1, U_LE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMR_TRANSLATEWORLDTRANSFORM_OID, List);
U_PO_free(&ph);
return(po);
}
/*
end of U_PMF_*_set() functions
=====================================================================================
start of U_PMF_*_get() functions
These functions all take a blimit value so that they can check if the data description in the fields
they process extend beyond the end of the record.
*/
//! \cond
/* core _get functions, not accessed outside of this routine */
/* get copies of up to 0-6 consecutive 4 byte values and a pointer to the rest */
int U_PMF_CORE1_get(const char *contents, void *v1, void *v2, void *v3, void *v4, void *v5, void *v6, const char **vR){
if(v1){ U_PMF_MEMCPY_SRCSHIFT(v1, &contents, 4);
if(v2){ U_PMF_MEMCPY_SRCSHIFT(v2, &contents, 4);
if(v3){ U_PMF_MEMCPY_SRCSHIFT(v3, &contents, 4);
if(v4){ U_PMF_MEMCPY_SRCSHIFT(v4, &contents, 4);
if(v5){ U_PMF_MEMCPY_SRCSHIFT(v5, &contents, 4);
if(v6){ U_PMF_MEMCPY_SRCSHIFT(v6, &contents, 4); }}}}}}
if(vR){ *vR = contents; }
return(1);
}
//! \endcond
/**
\brief Get data from a U_PMF_BRUSH object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Type BrushType Enumeration
\param Data one of the 5 types of Brush data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.1, Microsoft name: EmfPlusBrush Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_BRUSH_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){
if(!contents || !Version || !Type || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents,sizeof(U_PMF_BRUSH), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_CUSTOMLINECAP object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Type CustomLineCapData Enumeration
\param Data one of the 2 types of Linecap data
\param blimit one byte past the end of data
EMF+ manual 2.2.1.2, Microsoft name: EmfPlusCustomLineCap Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_CUSTOMLINECAP_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){
if(!contents || !Version || !Type || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAP), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_FONT object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param EmSize em size in units of SizeUnit
\param SizeUnit UnitType enumeration
\param FSFlags FontStyle flags
\param Length Number of Unicode Characters in FamilyName
\param Data Unicode (UTF-16LE) name of font family
EMF+ manual 2.2.1.3, Microsoft name: EmfPlusFont Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_FONT_get(const char *contents, uint32_t *Version, U_FLOAT *EmSize, uint32_t *SizeUnit,
int32_t *FSFlags, uint32_t *Length, const char **Data, const char *blimit){
if(!contents || !Version || !EmSize || !SizeUnit || !FSFlags || !Length || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FONT), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, EmSize, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, SizeUnit, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, FSFlags, 4, 1, U_LE);
contents += 4; /* Reserved field, which is ignored */
U_PMF_SERIAL_get(&contents, Length, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_IMAGE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Type ImageDataType Enumeration
\param Data one of the 2 types of image data
EMF+ manual 2.2.1.4, Microsoft name: EmfPlusImage Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_IMAGE_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **Data, const char *blimit){
if(!contents || !Version || !Type || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IMAGE), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_IMAGEATTRIBUTES object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param WrapMode WrapMode object
\param ClampColor EmfPlusARGB object
\param ObjectClamp ObjectClamp Identifiers
EMF+ manual 2.2.1.5, Microsoft name: EmfPlusImageAttributes Object
*/
int U_PMF_IMAGEATTRIBUTES_get(const char *contents, uint32_t *Version, uint32_t *WrapMode, uint32_t *ClampColor,
uint32_t *ObjectClamp, const char *blimit){
if(!contents || !Version || !WrapMode || !ClampColor || !ObjectClamp || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IMAGEATTRIBUTES), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
contents += 4; /* Skip Reserved 1*/
U_PMF_SERIAL_get(&contents, WrapMode, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, ClampColor, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, ObjectClamp,4, 1, U_LE);
/* Skip Reserved 2*/
return(1);
}
/**
\brief Get data from a U_PMF_PATH object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Count Number of points and point types in this object
\param Flags PathPoint Flags
\param Points array of points type PMFPointR, PMFPoint, or PMFPointF
\param Types array of U_PMF_PATHPOINTTYPERLE and/or U_PMF_PATHPOINTTYPE
EMF+ manual 2.2.1.6, Microsoft name: EmfPlusPath Object
Caller must check Types for possible memory access violations if type can be U_PMF_PATHPOINTTYPERLE.
*/
int U_PMF_PATH_get(const char *contents, uint32_t *Version, uint32_t *Count, uint16_t *Flags,
const char **Points, const char **Types, const char *blimit){
if(!contents || !Version || !Count || !Flags || !Points || !Types || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PATH), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Flags, 2, 1, U_LE);
contents+=2; /* reserved */
uint32_t sizeP, sizeT;
if(*Flags & U_PPF_P){
sizeP = U_PMF_LEN_REL715(contents,*Count); //DEBUG
printf("DEBUG U_PMF_PATH_get count:%d LENREL715:%d\n",*Count,sizeP);fflush(stdout);
}
else if(*Flags & U_PPF_C){ sizeP = *Count * sizeof(U_PMF_POINT); }
else { sizeP = *Count * sizeof(U_PMF_POINTF); }
if(IS_MEM_UNSAFE(contents, sizeP, blimit))return(0);
U_PMF_PTRSAV_SHIFT(Points, &contents, 0);
contents += sizeP;
/* this limit is correct if there are only U_PMF_PATHPOINTTYPE PointTypes, it is a lower bound if
there can also be U_PMF_PATHPOINTTYPERLE */
sizeT = *Count * sizeof(U_PMF_PATHPOINTTYPE);
if(IS_MEM_UNSAFE(contents, sizeT, blimit))return(0);
U_PMF_PTRSAV_SHIFT(Types, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_PEN object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Type must be zero
\param PenData Pen description
\param Brush Brush Description
EMF+ manual 2.2.1.7, Microsoft name: EmfPlusPen Object
Caller must check Brush and PenData for possible memory access violations.
*/
int U_PMF_PEN_get(const char *contents, uint32_t *Version, uint32_t *Type, const char **PenData, const char **Brush, const char *blimit){
if(!contents || !Type || !PenData || !Brush || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PEN), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(PenData, &contents, 0);
*Brush = *PenData + U_PMF_LEN_PENDATA(*PenData);
return(1);
}
/**
\brief Get data from a U_PMF_REGION object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Version EmfPlusGraphicsVersion object
\param Count Number of CHILD nodes. This is one less than the total number of U_PMF_REGIONNODE objects in Nodes.
\param Nodes Nodes defining region
EMF+ manual 2.2.1.8, Microsoft name: EmfPlusRegion Object
*/
int U_PMF_REGION_get(const char *contents, uint32_t *Version, uint32_t *Count, const char **Nodes, const char *blimit){
if(!contents || !Version || !Count || !Nodes || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGION), blimit))return(0);
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Nodes, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_STRINGFORMAT object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Sfs pointer to U_PMF_STRINGFORMAT structure, with no variable part
\param Data pointer to variable part
EMF+ manual 2.2.1.9, Microsoft name: EmfPlusStringFormat Object
*/
int U_PMF_STRINGFORMAT_get(const char *contents, U_PMF_STRINGFORMAT *Sfs, const char **Data, const char *blimit){
if(!contents || !Sfs || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_STRINGFORMAT), blimit))return(0);
U_PMF_SERIAL_get(&contents, Sfs, 4, 15, U_LE);
*Data = contents;
return(1);
}
/**
\brief Get data from a U_PMF_ARGB object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Blue Blue color (0-255)
\param Green Green color (0-255)
\param Red Red color (0-255)
\param Alpha Alpha (0-255)
EMF+ manual 2.2.2.1, Microsoft name: EmfPlusARGB Object
*/
int U_PMF_ARGB_get(const char *contents, uint8_t *Blue, uint8_t *Green, uint8_t *Red, uint8_t *Alpha, const char *blimit){
if(!contents || !Blue || !Green || !Red || !Alpha || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_ARGB), blimit))return(0);
U_PMF_SERIAL_get(&contents, Blue, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, Green, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, Red, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, Alpha, 1, 1, U_XE);
return(1);
}
/**
\brief Get data from a U_PMF_BITMAP object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Bs pointer to U_PMF_BITMAP structure, with no variable part
\param Data pointer to variable part
EMF+ manual 2.2.2.2, Microsoft name: EmfPlusBitmap Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_BITMAP_get(const char *contents, U_PMF_BITMAP *Bs, const char **Data, const char *blimit){
if(!contents || !Bs || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BITMAP), blimit))return(0);
U_PMF_SERIAL_get(&contents, Bs, 4, 5, U_LE); // width, height, stride, pixelformat, type
U_PMF_PTRSAV_SHIFT(Data, &contents, 0); // bitmapdata
return(1);
}
/**
\brief Get data from a U_PMF_BITMAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Ps pointer to U_PMF_PALETTE structure, with no variable part
\param Colors Color part of U_PMF_PALETTE object
\param Data An array of bytes, meaning depends on fields in U_PMF_BITMAP object and the PixelFormat enumeration.
EMF+ manual 2.2.2.3, Microsoft name: EmfPlusBitmapData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_BITMAPDATA_get(const char *contents, U_PMF_PALETTE *Ps, const char **Colors, const char **Data, const char *blimit){
if(!contents || !Ps || !Colors || !Data || !blimit){ return(0); }
/* this structure is entirely optional */
if(IS_MEM_UNSAFE(contents, 4*2, blimit))return(0);
U_PMF_SERIAL_get(&contents, Ps, 4, 2, U_LE);
U_PMF_PTRSAV_SHIFT(Colors, &contents, Ps->Elements * sizeof(U_PMF_ARGB));
/* difficult to know how big the actual bitmap will be, just return the pointer to it untested */
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_BLENDCOLORS object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements Number of members in Positions and Colors
\param Positions Caller must free. Pointer to memory holding positions along gradient line.
\param Colors Caller must NOT free memory, Pointer to memory holding colors at positions on gradient line.
EMF+ manual 2.2.2.4, Microsoft name: EmfPlusBlendColors Object
*/
int U_PMF_BLENDCOLORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, const char **Colors, const char *blimit){
if(!contents || !Positions || !Colors || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BLENDCOLORS), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * 4, blimit))return(0);
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Positions, 4, *Elements, U_LE,1)){ return(0); }
U_PMF_PTRSAV_SHIFT(Colors, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_BLENDFACTORS object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements members in each array
\param Positions Caller must free. Pointer to memory holding positions along gradient line.
\param Factors Caller must free. Pointer to memory holding blending factors, 0.0->1.0 values, inclusive along gradient line.
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
*/
int U_PMF_BLENDFACTORS_get(const char *contents, uint32_t *Elements, U_FLOAT **Positions, U_FLOAT **Factors, const char *blimit){
if(!contents || !Elements || !Positions || !Factors || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BLENDFACTORS), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * 4 * 2, blimit))return(0);
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Positions, 4, *Elements, U_LE, 1)){ return(0); }
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Factors, 4, *Elements, U_LE, 1)){
free(*Positions);
return(0);
}
return(1);
}
/**
\brief Get data from a U_PMF_BOUNDARYPATHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size bytes in Data
\param Data boundary of the brush
EMF+ manual 2.2.2.6, Microsoft name: EmfPlusBoundaryPathData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_BOUNDARYPATHDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BOUNDARYPATHDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_BOUNDARYPOINTDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements Members in Points
\param Points Caller must free. Pointer to memory holding points along gradient line. Boundary of the brush.
EMF+ manual 2.2.2.7, Microsoft name: EmfPlusBoundaryPointData Object
*/
int U_PMF_BOUNDARYPOINTDATA_get(const char *contents, int32_t *Elements, U_PMF_POINTF **Points, const char *blimit){
if(!contents || !Elements || !Points || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_BOUNDARYPOINTDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * 2, blimit))return(0);
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Points, 4, *Elements * 2, U_LE, 1)){ return(0); }
return(1);
}
/**
\brief Get data from a U_PMF_CHARACTERRANGE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param First First position in range
\param Length Range length
EMF+ manual 2.2.2.8, Microsoft name: EmfPlusCharacterRange Object
*/
int U_PMF_CHARACTERRANGE_get(const char *contents, int32_t *First, int32_t *Length, const char *blimit){
if(!contents || !First || !Length || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CHARACTERRANGE), blimit))return(0);
U_PMF_SERIAL_get(&contents, First, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Length, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_COMPOUNDLINEDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements Members in the array
\param Widths Caller must free. Pointer to memory holding Line or gap widths (0.0 <-> 1.0, fraction of total line width ).
EMF+ manual 2.2.2.9, Microsoft name: EmfPlusCompoundLineData Object
*/
int U_PMF_COMPOUNDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Widths, const char *blimit){
if(!contents || !Elements || !Widths || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_COMPOUNDLINEDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * sizeof(U_FLOAT), blimit))return(0);
*Widths = (U_FLOAT *)malloc(*Elements * sizeof(U_FLOAT));
if(!*Widths){ return(0); }
U_PMF_SERIAL_get(&contents, *Widths, 4, *Elements, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_COMPRESSEDIMAGE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Data Stored image in one of the supported formats.
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().
Caller must check Data for possible memory access violations.
*/
int U_PMF_COMPRESSEDIMAGE_get(const char *contents, const char **Data, const char *blimit){
if(!contents || !Data || !blimit){ return(0); }
if(contents >= blimit)return(0);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_CUSTOMENDCAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size Bytes in Data
\param Data Description of linecap
EMF+ manual 2.2.2.11, Microsoft name: EmfPlusCustomEndCapData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_CUSTOMENDCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMENDCAPDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_CUSTOMLINECAPARROWDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Ccad pointer to U_PMF_CUSTOMLINECAPARROWDATA structure
EMF+ manual 2.2.2.12, Microsoft name: EmfPlusCustomLineCapArrowData Object
*/
int U_PMF_CUSTOMLINECAPARROWDATA_get(const char *contents, U_PMF_CUSTOMLINECAPARROWDATA *Ccad, const char *blimit){
if(!contents || !Ccad || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAPARROWDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Ccad, 4, 13, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_CUSTOMLINECAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Clcd pointer to U_PMF_CUSTOMLINECAPDATA structure, with no variable part
\param Data variable part of U_PMF_CUSTOMLINECAPDATA
EMF+ manual 2.2.2.13, Microsoft name: EmfPlusCustomLineCapData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_CUSTOMLINECAPDATA_get(const char *contents, U_PMF_CUSTOMLINECAPDATA *Clcd, const char **Data, const char *blimit){
if(!contents || !Clcd || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMLINECAPDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Clcd, 4, 12, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_CUSTOMLINECAPOPTIONALDATA object
\return on success 3,5, or 7 (for varying combinations of data present) or 1 (no data is present), 0 on error
\param contents Record from which to extract data
\param Flags bits set to indicate the presence of FillData and/or LineData
\param FillData Path to fill (optional)
\param LineData Path to stroke (optional)
EMF+ manual 2.2.2.14, Microsoft name: EmfPlusCustomLineCapOptionalData Object
Caller must check LineData for possible memory access violations.
*/
int U_PMF_CUSTOMLINECAPOPTIONALDATA_get(const char *contents, uint32_t Flags, const char **FillData, const char **LineData, const char *blimit){
uint32_t length;
int status = 1;
if(!contents || !*FillData || !*LineData || !blimit){ return(0); }
/* this structure is entirely optional */
if(Flags & U_CLCD_FillPath){
if(!FillData){ return(0); }
if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, &length, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, length, blimit))return(0);
contents -= 4; /* undo the unneeded shift from preceding */
U_PMF_PTRSAV_SHIFT(FillData, &contents, 4 + length);
status += 2;
}
else { *FillData = NULL; }
if(Flags & U_CLCD_LinePath){
if(!LineData){ return(0); }
if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, &length, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, length, blimit))return(0);
contents -= 4; /* undo the unneeded shift from preceding */
U_PMF_PTRSAV_SHIFT(LineData, &contents, 0);
status += 4;
}
else { *LineData = NULL; }
return(status);
}
/**
\brief Get data from a U_PMF_CUSTOMSTARTCAPDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size Bytes in Data
\param Data Description of linecap
EMF+ manual 2.2.2.15, Microsoft name: EmfPlusCustomStartCapData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_CUSTOMSTARTCAPDATA_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_CUSTOMSTARTCAPDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_DASHEDLINEDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements Members in the array
\param Lengths Caller must free. Pointer to memory holding lengths of dashes and spaces.
EMF+ manual 2.2.2.16, Microsoft name: EmfPlusDashedLineData Object
*/
int U_PMF_DASHEDLINEDATA_get(const char *contents, int32_t *Elements, U_FLOAT **Lengths, const char *blimit){
if(!contents || !Elements || !Lengths || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_DASHEDLINEDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * sizeof(U_FLOAT), blimit))return(0);
*Lengths = (U_FLOAT *)malloc(*Elements * sizeof(U_FLOAT));
if(!*Lengths){ return(0); }
U_PMF_SERIAL_get(&contents, *Lengths, 4, *Elements, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_FILLPATHOBJ object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size Bytes in Data
\param Data Path specification
EMF+ manual 2.2.2.17, Microsoft name: EmfPlusFillPath Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_FILLPATHOBJ_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FILLPATHO), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_FOCUSSCALEDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Count must be 2
\param ScaleX value 0.0 <-> 1.0
\param ScaleY value 0.0 <-> 1.0
EMF+ manual 2.2.2.18, Microsoft name: EmfPlusFocusScaleData Object
*/
int U_PMF_FOCUSSCALEDATA_get(const char *contents, uint32_t *Count, U_FLOAT *ScaleX, U_FLOAT *ScaleY, const char *blimit){
if(!contents || !Count || !ScaleX || !ScaleY || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FOCUSSCALEDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Count, 4, 1, U_LE);
if(*Count != 2){ return(0); }
U_PMF_SERIAL_get(&contents, ScaleX, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, ScaleY, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_GRAPHICSVERSION object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Signature Must be U_GFVR_PMF (0xDBC01)
\param GrfVersion GraphicsVersion enumeration
EMF+ manual 2.2.2.19, Microsoft name: EmfPlusGraphicsVersion Object
*/
int U_PMF_GRAPHICSVERSION_get(const char *contents, int *Signature, int *GrfVersion, const char *blimit){
uint32_t tmp;
if(!contents || !Signature || !GrfVersion || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_GRAPHICSVERSION), blimit))return(0);
memcpy(&tmp, contents, 4);
*Signature = tmp >> 12;
*GrfVersion = tmp & U_GFVR_MASKLO;
return(1);
}
/**
\brief Get data from a U_PMF_HATCHBRUSHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Style HatchStyle enumeration
\param Foreground Hatch pattern line color
\param Background Hatch pattern bkground color
EMF+ manual 2.2.2.20, Microsoft name: EmfPlusHatchBrushData Object
*/
int U_PMF_HATCHBRUSHDATA_get(const char *contents, uint32_t *Style, U_PMF_ARGB *Foreground, U_PMF_ARGB *Background, const char *blimit){
if(!contents || !Style || !Foreground || !Background || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_HATCHBRUSHDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Style, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Foreground, 4, 1, U_XE);
U_PMF_SERIAL_get(&contents, Background, 4, 1, U_XE);
return(1);
}
/**
\brief Get data from a U_PMF_INTEGER7 object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Value 7 bit signed integer (stored in an integer)
\param blimit one byte past the end of data
EMF+ manual 2.2.2.21, Microsoft name: EmfPlusInteger7 Object
*/
int U_PMF_INTEGER7_get(const char **contents, U_FLOAT *Value, const char *blimit){
uint8_t tmp;
if(!contents || !*contents || !Value || !blimit){ return(0); }
if(IS_MEM_UNSAFE(*contents, 1, blimit))return(0); /* past end of buffer */
if(**contents & U_TEST_INT7)return(0); /* this bit must be 0 in this object type */
U_PMF_SERIAL_get(contents, &tmp, 1, 1, U_XE);
if(tmp & U_SIGN_INT7){
tmp |= U_TEST_INT7; /* now it has the bit pattern of a signed int8_t */
*Value = *(int8_t *)&tmp;
}
else {
*Value = tmp;
}
return(1);
}
/**
\brief Get data from a U_PMF_INTEGER15 object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Value 15 bit signed integer (stored in an integer)
\param blimit one byte past the end of data
EMF+ manual 2.2.2.22, Microsoft name: EmfPlusInteger15 Object
*/
int U_PMF_INTEGER15_get(const char **contents, U_FLOAT *Value, const char *blimit){
if(!contents || !*contents || !Value || !blimit){ return(0); }
uint16_t tmp;
if(IS_MEM_UNSAFE(*contents, 2, blimit))return(0); /* past end of buffer */
if(!(**contents & U_TEST_INT7))return(0); /* this bit must be 1 in this object type */
U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_BE);
tmp &= U_MASK_INT15; /* drop the 7/15 flag from the most significant bit */
if(tmp & U_SIGN_INT15){
tmp |= U_TEST_INT15; /* now it has the bit pattern of a signed int16_t */
*Value = *(int16_t *)&tmp;
}
else {
*Value = tmp;
}
return(1);
}
/**
\brief Get data from a U_PMF_LANGUAGEIDENTIFIER object
\return 1 on success, 0 on error
\param LId U_PMF_LANGUAGEIDENTIFIER from which to extract data
\param SubLId Example: code for USA
\param PriLId Example: code for English
EMF+ manual 2.2.2.23, Microsoft name: EmfPlusLanguageIdentifier Object
This type is defined as 16 bits in the manual section, but it is only ever used as part of a 32 bit field!
*/
int U_PMF_LANGUAGEIDENTIFIER_get(U_PMF_LANGUAGEIDENTIFIER LId, int *SubLId, int *PriLId){
if(!SubLId || !PriLId){ return(0); }
*SubLId = (LId >> U_FF_SHFT_SUBLID ) & U_FF_MASK_SUBLID;
*PriLId = (LId >> U_FF_SHFT_PRILID ) & U_FF_MASK_PRILID;
/* 16 bits above that are not used */
return(1);
}
/**
\brief Get data from a U_PMF_LINEARGRADIENTBRUSHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Lgbd U_PMF_LINEARGRADIENTBRUSHDATA structure, with no variable part
\param Data variable part of U_PMF_LINEARGRADIENTBRUSHDATA
\param blimit one byte past the end of data
EMF+ manual 2.2.2.24, Microsoft name: EmfPlusLinearGradientBrushData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_LINEARGRADIENTBRUSHDATA_get(const char *contents, U_PMF_LINEARGRADIENTBRUSHDATA *Lgbd, const char **Data, const char *blimit){
if(!contents || !Lgbd || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_LINEARGRADIENTBRUSHDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Lgbd, 4, 6, U_LE); /* Flags, WrapMode, RectF*/
U_PMF_SERIAL_get(&contents, &(Lgbd->StartColor), 4, 4, U_XE); /* StartColor, EndColor, Reserved1 & 2 */
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags BrushData flags - indicates which of the following date fields are present.
\param Tm Transformation matrix
\param Bc U_PMF_BLENDCOLORS object or NULL
\param BfH U_PMF_BLENDFACTORS (H) object or NULL
\param BfV U_PMF_BLENDFACTORS (V) object or NULL (WARNING, GDI+ defines this field but does not render it. DO NOT USE.)
\param blimit one byte past the end of data
EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object
*/
int U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Tm,
const char **Bc, const char **BfH, const char **BfV, const char *blimit){
uint32_t Elements;
if(!contents || !Tm|| !Bc || !BfH || !BfV || !blimit){ return(0); }
/* all of the fields are optional! */
*Bc = *BfH = *BfV = NULL;
if(Flags & U_BD_Transform){
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_ROTMATRIX), blimit))return(0);
U_PMF_SERIAL_get(&contents, Tm, 4, 6, U_LE);
}
if(Flags & U_BD_PresetColors){
if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/
if(IS_MEM_UNSAFE(contents, Elements * ( sizeof(U_FLOAT) + sizeof(U_PMF_ARGB)), blimit))return(0);
contents-=4; /* back up to the front of the count, as it is part of the data field */
U_PMF_PTRSAV_SHIFT(Bc, &contents, 0);
}
else if(Flags & U_BD_BlendFactorsH){
U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/
if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0);
contents-=4; /* back up to the front of the count, as it is part of the data field */
U_PMF_PTRSAV_SHIFT(BfH, &contents, 4 + (Elements * 2 * sizeof(U_FLOAT))); /* 4 byte count + 2 * 4bytes * Elements */
if(Flags & U_BD_BlendFactorsV){
if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0);
U_PMF_PTRSAV_SHIFT(BfV, &contents, 0);
}
}
else if(Flags & U_BD_BlendFactorsV){
U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE); /* starts with a 4 byte count*/
if(IS_MEM_UNSAFE(contents, Elements * 2 * sizeof(U_FLOAT), blimit))return(0);
contents-=4; /* back up to the front of the count, as it is part of the data field */
U_PMF_PTRSAV_SHIFT(BfV, &contents, 0);
}
return(1);
}
/**
\brief Get data from a U_PMF_LINEPATH object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size Bytes in Data
\param Data Outline path
\param blimit one byte past the end of data
EMF+ manual 2.2.2.26, Microsoft name: EmfPlusLinePath Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_LINEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_LINEPATH), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_METAFILE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Type
\param Size Bytes in Data
\param Data Various types of data, like an EMF metafile, WMF metafile, another EMF+ metafile
\param blimit one byte past the end of data
EMF+ manual 2.2.2.27, Microsoft name: EmfPlusMetafile Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_METAFILE_get(const char *contents, uint32_t *Type, uint32_t *Size, const char **Data, const char *blimit){
if(!contents || !Type || !Size || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_METAFILE), blimit))return(0);
U_PMF_SERIAL_get(&contents, &Type, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_PALETTE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags PaletteStyle flags
\param Elements Members in the array
\param Colors Palette data (array of colors)
\param blimit one byte past the end of data
EMF+ manual 2.2.2.28, Microsoft name: EmfPlusPalette Object
*/
int U_PMF_PALETTE_get(const char *contents, uint32_t *Flags, uint32_t *Elements, const char **Colors, const char *blimit){
if(!contents || !Flags || !Elements || !Colors || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PALETTE), blimit))return(0);
U_PMF_SERIAL_get(&contents, &Flags, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements*sizeof(U_RGBQUAD), blimit))return(0);
U_PMF_PTRSAV_SHIFT(Colors, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_PATHGRADIENTBRUSHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Pgbd constant part of U_PMF_PATHGRADIENTBRUSHDATA object
\param Gradient variable part of U_PMF_LINEARGRADIENTBRUSHDATA, Color Gradient with Elements members
\param Boundary variable part of U_PMF_LINEARGRADIENTBRUSHDATA, U_PMF_BOUNDARYPATHDATA object if BrushDataPath bit set in Flag, else U_PMF_BOUNDARYPOINTDATA object
\param Data variable part of U_PMF_LINEARGRADIENTBRUSHDATA, exact composition depends on Flags
\param blimit one byte past the end of data
EMF+ manual 2.2.2.29, Microsoft name: EmfPlusPathGradientBrushData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_PATHGRADIENTBRUSHDATA_get(const char *contents, U_PMF_PATHGRADIENTBRUSHDATA *Pgbd, const char **Gradient,
const char **Boundary, const char **Data, const char *blimit){
if(!contents || !Pgbd || !Gradient || !Boundary || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_PATHGRADIENTBRUSHDATA), blimit))return(0);
uint32_t Size;
U_PMF_SERIAL_get(&contents, Pgbd, 4, 2, U_LE); /* Flags and WrapMode*/
U_PMF_SERIAL_get(&contents, &(Pgbd->CenterColor), 4, 1, U_XE);
U_PMF_SERIAL_get(&contents, &(Pgbd->Center), 4, 3, U_LE); /* Center and Elements */
if(IS_MEM_UNSAFE(contents, Pgbd->Elements * sizeof(U_PMF_ARGB), blimit))return(0);
U_PMF_PTRSAV_SHIFT(Gradient, &contents, Pgbd->Elements * sizeof(U_PMF_ARGB));
U_PMF_PTRSAV_SHIFT(Boundary, &contents, 0);
U_PMF_SERIAL_get(&contents, &Size, 4, 1, U_LE); /* The first 4 bytes of the Boundary are always a size */
if(Pgbd->Flags & U_BD_Path){ contents += Size; } // U_PMF_BOUNDARYPATHDATA
else { contents += Size*2*sizeof(U_FLOAT); } // U_PMF_BOUNDARYPOINTDATA
if(Pgbd->Flags & (U_BD_Transform |U_BD_PresetColors | U_BD_BlendFactorsH| U_BD_FocusScales)){ // optional data present
if(contents >= blimit)return(0); // the size is variable but this must still hold
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
}
else { *Data = NULL; } // no optional data present
return(1);
}
/**
\brief Get data from a U_PMF_PATHGRADIENTBRUSHOPTIONALDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags bits set to indicate the presence of FillData and/or LineData
\param Matrix Transformation matrix
\param Pattern Blend Pattern
\param Data Focus scales for the brush
\param blimit one byte past the end of data
EMF+ manual 2.2.2.30, Microsoft name: EmfPlusPathGradientBrushOptionalData Object
*/
int U_PMF_PATHGRADIENTBRUSHOPTIONALDATA_get(const char *contents, uint32_t Flags, U_PMF_TRANSFORMMATRIX *Matrix,
const char **Pattern, const char **Data, const char *blimit){
int varsize;
if(!contents || !Flags || !Matrix || !Pattern || !Data || !blimit){ return(0); }
/* this structure is entirely optional */
if(Flags & U_BD_Transform){
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0);
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
}
if(Flags & (U_BD_PresetColors | U_BD_BlendFactorsH)){
if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
uint32_t Elements;
U_PMF_SERIAL_get(&contents, &Elements, 4, 1, U_LE);
contents -= 4;
varsize=(Elements * 4 * (Flags & U_BD_BlendFactorsH ? 2 :1));
if(IS_MEM_UNSAFE(contents, varsize, blimit))return(0);
U_PMF_PTRSAV_SHIFT(Pattern, &contents, varsize);
}
else { *Pattern=NULL; }
if(Flags & U_BD_FocusScales){
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_FOCUSSCALEDATA), blimit))return(0);
U_PMF_PTRSAV_SHIFT(Data, &contents, sizeof(U_PMF_FOCUSSCALEDATA));
}
else { *Data=NULL; }
return(1);
}
/**
\brief Get data from a U_PMF_PATHPOINTTYPE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags PathPointType flags
\param Type PathPointType enumeration
\param blimit one byte past the end of data
EMF+ manual 2.2.2.31, Microsoft name: EmfPlusPathPointType Object
Note: order of 4bit fields appears to be shown in the LE column, not as
documented in the BE column.
*/
int U_PMF_PATHPOINTTYPE_get(const char *contents, int *Flags, int *Type, const char *blimit){
if(!contents || !Flags || !Type || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, 1, blimit))return(0);
uint8_t tmp;
memcpy(&tmp, contents, 1);
*Flags =(tmp & U_PTP_MASK) >> U_PTP_SHIFT;
*Type = (tmp & U_PPT_MASK);
return(1);
}
/**
\brief Get data from a U_PMF_PATHPOINTTYPERLE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Bezier Set: Bezier curve, Clear: straight line
\param RL Run Length
\param Ppt PathPointType enumeration
\param blimit one byte past the end of data
EMF+ manual 2.2.2.32, Microsoft name: EmfPlusPathPointTypeRLE Object
*/
int U_PMF_PATHPOINTTYPERLE_get(const char *contents, int *Bezier, int *RL, int *Ppt, const char *blimit){
if(!contents || !Bezier || !RL || !Ppt || !blimit){ return(0); }
uint16_t tmp;
if(IS_MEM_UNSAFE(contents, 2, blimit))return(0);
U_PMF_SERIAL_get(&contents, &tmp, 2, 1, U_LE);
*Bezier = tmp & U_PPF_BZ;
*RL = (tmp >> U_FF_SHFT_RL) & U_FF_MASK_RL;
*Ppt = (tmp >> U_FF_SHFT_PPT) & U_FF_MASK_PPT;
return(1);
}
/**
\brief Get data from a U_PMF_PENDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags PenData flags
\param Unit UnitType enumeration
\param Width Width in units set by Unit
\param Data Optional pen data, exact composition depends on Flags
\param blimit one byte past the end of data
EMF+ manual 2.2.2.33, Microsoft name: EmfPlusPenData Object
*/
int U_PMF_PENDATA_get(const char *contents, uint32_t *Flags, uint32_t *Unit, U_FLOAT *Width, const char **Data, const char *blimit){
if(!contents || !Flags || !Unit || !Width || !Data || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, 3*4, blimit))return(0);
U_PMF_SERIAL_get(&contents, Flags, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Unit, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Width, 4, 1, U_LE);
if(contents >= blimit)return(0); // variable data will extend farther, but this much at least must be true
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_PENOPTIONALDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags; PenData Flags - indicated which of the many fields are present.
\param Matrix; Transformation matrix
\param StartCap LineCapType enumeration
\param EndCap LineCapType enumeration
\param Join LineJoinType enumeration
\param MiterLimit Maximum (miter length / line width)
\param Style LineStyle enumeration
\param DLCap DashedLineCapType enumeration
\param DLOffset Distance line start to first dash start
\param DLData Dash and space widths
\param Alignment PenAlignment enumeration
\param CmpndLineData Compount Line (parallel lines drawn instead of one)
\param CSCapData Custom start cap
\param CECapData Custom end cap
\param blimit one byte past the end of data
EMF+ manual 2.2.2.34, Microsoft name: EmfPlusPenOptionalData Object
This object consists of a large number of optional and or variable values, which
are returned, or not, depending on bits in Flags.
*/
int U_PMF_PENOPTIONALDATA_get(
const char *contents,
uint32_t Flags, // determines which fields are filled
U_PMF_TRANSFORMMATRIX *Matrix,
int32_t *StartCap,
int32_t *EndCap,
uint32_t *Join,
U_FLOAT *MiterLimit,
int32_t *Style,
int32_t *DLCap,
U_FLOAT *DLOffset,
const char **DLData,
int32_t *Alignment,
const char **CmpndLineData,
const char **CSCapData,
const char **CECapData,
const char *blimit){
if(!contents ||
!Flags || !Matrix || !StartCap || !EndCap ||
!Join || !MiterLimit || !Style || !DLCap ||
!DLOffset || !DLData || !Alignment || !CmpndLineData ||
!CSCapData || !CECapData || !blimit){ return(0); }
if(Flags & U_PD_Transform){ if(IS_MEM_UNSAFE(contents, 4*6, blimit))return(0);
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
}
if(Flags & U_PD_StartCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, StartCap, 4, 1, U_LE);
}
if(Flags & U_PD_EndCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, EndCap, 4, 1, U_LE);
}
if(Flags & U_PD_Join){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, Join, 4, 1, U_LE);
}
if(Flags & U_PD_MiterLimit){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, MiterLimit, 4, 1, U_LE);
}
if(Flags & U_PD_LineStyle){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, Style, 4, 1, U_LE);
}
if(Flags & U_PD_DLCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, DLCap, 4, 1, U_LE);
}
if(Flags & U_PD_DLOffset){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, DLOffset, 4, 1, U_LE);
}
if(Flags & U_PD_DLData){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
if(IS_MEM_UNSAFE(contents, U_PMF_LEN_FLOATDATA(contents), blimit))return(0);
U_PMF_PTRSAV_SHIFT( DLData, &contents, U_PMF_LEN_FLOATDATA(contents));
}
if(Flags & U_PD_NonCenter){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
U_PMF_SERIAL_get(&contents, Alignment, 4, 1, U_LE); }
if(Flags & U_PD_CLData){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
if(IS_MEM_UNSAFE(contents, U_PMF_LEN_FLOATDATA(contents), blimit))return(0);
U_PMF_PTRSAV_SHIFT( CmpndLineData, &contents, U_PMF_LEN_FLOATDATA(contents));
}
if(Flags & U_PD_CustomStartCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
if(IS_MEM_UNSAFE(contents, U_PMF_LEN_BYTEDATA(contents), blimit))return(0);
U_PMF_PTRSAV_SHIFT( CSCapData, &contents, U_PMF_LEN_BYTEDATA(contents));
}
if(Flags & U_PD_CustomEndCap){ if(IS_MEM_UNSAFE(contents, 4, blimit))return(0);
if(IS_MEM_UNSAFE(contents, U_PMF_LEN_BYTEDATA(contents), blimit))return(0);
U_PMF_PTRSAV_SHIFT( CECapData, &contents, U_PMF_LEN_BYTEDATA(contents));
}
return(1);
}
/**
\brief Get data from a U_PMF_POINT object
\return 1 on success, 0 on error
\param contents Record from which to extract data. On return position is offset by sizeof(U_PMF_POINT).
\param X X coordinate
\param Y Y coordinate
\param blimit one byte past the end of data
EMF+ manual 2.2.2.35, Microsoft name: EmfPlusPoint Object
*/
int U_PMF_POINT_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){
if(!contents || !X || !Y || !blimit){ return(0); }
int16_t tmp;
if(IS_MEM_UNSAFE(*contents, 2*2, blimit))return(0);
U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_LE); *X = tmp;
U_PMF_SERIAL_get(contents, &tmp, 2, 1, U_LE); *Y = tmp;
return(1);
}
/**
\brief Get data from a U_PMF_POINTF object
\return 1 on success, 0 on error
\param contents Record from which to extract data. On return position is offset by sizeof(U_PMF_POINTF).
\param X X coordinate
\param Y Y coordinate
\param blimit one byte past the end of data
EMF+ manual 2.2.2.36, Microsoft name: EmfPlusPointF Object
*/
int U_PMF_POINTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){
if(!contents || !X || !Y || !blimit){ return(0); }
if(IS_MEM_UNSAFE(*contents, 4*2, blimit))return(0);
U_PMF_SERIAL_get(contents, X, 4, 1, U_LE);
U_PMF_SERIAL_get(contents, Y, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_POINTR object
\return size in bytes traversed on success, 0 on error
\param contents Record from which to extract data. On return position is offset by returned size.
\param X X coordinate
\param Y Y coordinate
\param blimit one byte past the end of data
EMF+ manual 2.2.2.37, Microsoft name: EmfPlusPointR Object
*/
int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, const char *blimit){
if(!contents || !*contents || !X || !Y || !blimit){ return(0); }
int size=0;
if( U_PMF_INTEGER7_get( contents, X, blimit)){ size +=1; }
else if(U_PMF_INTEGER15_get(contents, X, blimit)){ size +=2; }
else { return(0); }
if( U_PMF_INTEGER7_get( contents, Y, blimit)){ size +=1; }
else if(U_PMF_INTEGER15_get(contents, Y, blimit)){ size +=2; }
else { return(0); }
return(size);
}
/**
\brief Get data from a variable POINTS object, which may be U_PMF_POINTS, U_PMF_POINTF, or U_PMF_POINTR.
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags Record flags (bits U_PPF_C and U_PPF_P are referenced)
\param Elements Number of points to retrieve.
\param Points Caller must free. Array of U_PMF_POINTF coordinates.
\param blimit one byte past the end of data
This function should never be called directly by end user code.
*/
int U_PMF_VARPOINTS_get(const char *contents, uint16_t Flags, int Elements, U_PMF_POINTF **Points, const char *blimit){
int status = 0;
if(!contents || !Points || !Elements || !blimit){ return(status); }
U_PMF_POINTF *pts = (U_PMF_POINTF *)malloc(Elements * sizeof(U_PMF_POINTF));
if(!pts){ return(status); }
*Points = pts;
U_FLOAT XF, YF;
U_FLOAT XFS, YFS;
if(Flags & U_PPF_P){
for(XFS = YFS = 0.0; Elements; Elements--, pts++){
if(!U_PMF_POINTR_get(&contents, &XF, &YF, blimit))return(0); /* this should never happen */
XFS += XF; /* position relative to previous point, first point is always 0,0 */
YFS += YF;
pts->X = XFS;
pts->Y = YFS;
}
}
else if(Flags & U_PPF_C){
for(XF = YF = 0.0; Elements; Elements--, pts++){
if(!U_PMF_POINT_get(&contents, &XF, &XF, blimit))break; /* this should never happen */
pts->X = XF;
pts->Y = YF;
}
}
else {
for(XF = YF = 0.0; Elements; Elements--, pts++){
(void) U_PMF_POINTF_get(&contents, &XF, &YF, blimit);
pts->X = XF;
pts->Y = YF;
}
}
if(Elements){ /* some error in the preceding */
free(*Points);
*Points = NULL;
}
else {
status = 1;
}
return(status);
}
/**
\brief Get data from a U_PMF_RECT object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param X UL X value
\param Y UL Y value
\param Width Width
\param Height Height
\param blimit one byte past the end of data
EMF+ manual 2.2.2.38, Microsoft name: EmfPlusRect Object
*/
int U_PMF_RECT_get(const char **contents, int16_t *X, int16_t *Y, int16_t *Width, int16_t *Height, const char *blimit){
if(!contents || !X || !Y|| !Width || !Height){ return(0); }
if(IS_MEM_UNSAFE(*contents, 2*4, blimit))return(0);
U_PMF_SERIAL_get(contents, X, 2, 1, U_LE);
U_PMF_SERIAL_get(contents, Y, 2, 1, U_LE);
U_PMF_SERIAL_get(contents, Width, 2, 1, U_LE);
U_PMF_SERIAL_get(contents, Height, 2, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_RECTF object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param X UL X value
\param Y UL Y value
\param Width Width
\param Height Height
\param blimit one byte past the end of data
EMF+ manual 2.2.2.39, Microsoft name: EmfPlusRectF Object
*/
int U_PMF_RECTF_get(const char **contents, U_FLOAT *X, U_FLOAT *Y, U_FLOAT *Width, U_FLOAT *Height, const char *blimit){
if(!contents || !X || !Y|| !Width || !Height){ return(0); }
if(IS_MEM_UNSAFE(*contents, 4*4, blimit))return(0);
U_PMF_SERIAL_get(contents, X, 4, 1, U_LE);
U_PMF_SERIAL_get(contents, Y, 4, 1, U_LE);
U_PMF_SERIAL_get(contents, Width, 4, 1, U_LE);
U_PMF_SERIAL_get(contents, Height, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a variable RECTS object, which may be U_PMF_RECT or U_PMF_RECTF
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags Record flags (bit U_PPF_C is referenced)
\param Elements Number of rects to retrieve.
\param Rects Caller must free. Array of U_PMF_RECTF coordinates.
\param blimit one byte past the end of data
Rects in record may be either U_PMF_RECT or U_PMF_RECTF, but this function always
returns U_PMF_RECTF
*/
int U_PMF_VARRECTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_RECTF **Rects, const char *blimit){
int16_t X16, Y16, Width, Height;
if(!contents || !*contents || !Rects || !blimit){ return(0); }
U_PMF_RECTF *rts = (U_PMF_RECTF *)malloc(Elements * sizeof(U_PMF_RECTF));
if(!rts){
*Rects = NULL;
return(0);
}
*Rects = rts;
if(Flags & U_PPF_C){
if(IS_MEM_UNSAFE(*contents, Elements*sizeof(U_PMF_RECT), blimit)){
free(rts);
return(0);
}
}
else {
if(IS_MEM_UNSAFE(*contents, Elements*sizeof(U_PMF_RECT), blimit)){
free(rts);
return(0);
}
}
for(; Elements; Elements--, rts++){
if(Flags & U_PPF_C){
(void) U_PMF_RECT_get(contents, &X16, &Y16, &Width, &Height, blimit);
rts->X = X16;
rts->Y = Y16;
rts->Width = Width;
rts->Height = Height;
}
else {
(void) U_PMF_RECTF_get(contents, &(rts->X), &(rts->Y), &(rts->Width), &(rts->Height), blimit);
}
}
return(1);
}
/**
\brief Get data from a U_PMF_REGIONNODE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Type RegionNodeDataType
\param Data Depending on Type: U_PMF_REGIONNODEPATH, U_PMF_RECTF, or U_PMF_REGIONNODECHILDNODES
\param blimit one byte past the end of data
EMF+ manual 2.2.2.40, Microsoft name: EmfPlusRegionNode Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_REGIONNODE_get(const char *contents, uint32_t *Type, const char **Data, const char *blimit){
if(!contents || !Type || !Data || !blimit){ return(0); }
/* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGIONNODE), blimit))return(0);
U_PMF_SERIAL_get(&contents, Type, 4, 1, U_LE);
if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true
U_PMF_PTRSAV_COND(Data, contents, !(*Type == U_RNDT_Empty || *Type == U_RNDT_Infinite ));
return(1);
}
/**
There is no U_PMF_REGIONNODECHILDNODES_get!
The Region object is recursive allowing U_PMF_REGIONNODECHILDNODES ->
U_PMF_REGIONNODE -> U_PMF_REGIONNODECHILDNODES etc.
So the data stored in each node must be handled as the tree is followed recursively.
See U_PMF_REGIONNODECHILDNODES_print() and U_PMF_REGIONNODE_print() for an example.
EMF+ manual 2.2.2.41, Microsoft name: EmfPlusRegionNodeChildNodes Object
*/
/**
\brief Get data from a U_PMF_REGIONNODEPATH object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Size Bytes in Data
\param Data Boundary of region node
\param blimit one byte past the end of data
EMF+ manual 2.2.2.42, Microsoft name: EmfPlusRegionNodePath Object
*/
int U_PMF_REGIONNODEPATH_get(const char *contents, int32_t *Size, const char **Data, const char *blimit){
if(!contents || !Size || !Data || !blimit){ return(0); }
/* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_REGIONNODEPATH), blimit))return(0);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_SOLIDBRUSHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Color Color of brush
\param blimit one byte past the end of data
EMF+ manual 2.2.2.43, Microsoft name: EmfPlusSolidBrushData Object
*/
int U_PMF_SOLIDBRUSHDATA_get(const char *contents, U_PMF_ARGB *Color, const char *blimit){
if(!contents || !Color || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_SOLIDBRUSHDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Color, 4, 1, U_XE);
return(1);
}
/**
\brief Get data from a U_PMF_STRINGFORMATDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param TabStopCount Entries in TabStop array
\param RangeCount Entries in CharRange array
\param TabStops Array of tabstop locations
\param CharRange Array of character ranges in the text
\param blimit one byte past the end of data
EMF+ manual 2.2.2.44, Microsoft name: EmfPlusStringFormatData Object
*/
int U_PMF_STRINGFORMATDATA_get(const char *contents, uint32_t TabStopCount, uint32_t RangeCount,
const U_FLOAT **TabStops, const U_PMF_CHARACTERRANGE **CharRange, const char *blimit){
if(!contents || !TabStops|| !CharRange || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, (TabStopCount + 2*RangeCount)*4, blimit))return(0);
*TabStops = NULL;
if(TabStopCount > 0){ U_PMF_SERIAL_get(&contents, TabStops, 4, TabStopCount, U_LE); }
*CharRange = NULL;
if(RangeCount > 0){ U_PMF_SERIAL_get(&contents, CharRange, 4, 2*RangeCount, U_LE); }
return(1);
}
/**
\brief Get data from a U_PMF_TEXTUREBRUSHDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Flags BrushData flags
\param WrapMode WrapMode enumeration
\param Data Optional texture data
\param blimit one byte past the end of data
EMF+ manual 2.2.2.45, Microsoft name: EmfPlusTextureBrushData Object
Caller must check Data for possible memory access violations.
*/
int U_PMF_TEXTUREBRUSHDATA_get(const char *contents, uint32_t *Flags, int32_t *WrapMode, const char **Data, const char *blimit){
if(!contents || !Flags || !WrapMode || !Data || !blimit){ return(0); }
/* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TEXTUREBRUSHDATA), blimit))return(0);
U_PMF_SERIAL_get(&contents, Flags, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, WrapMode, 4, 1, U_LE);
if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMF_TEXTUREBRUSHOPTIONALDATA object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param HasImage True if this object has an Image
\param Matrix Transformation matrix, NULL if Flag BrushDataTransform is not set.
\param Image Image that contains the texture.
\param blimit one byte past the end of data
EMF+ manual 2.2.2.46, Microsoft name: EmfPlusTextureBrushOptionalData Object
Caller must check Image for possible memory access violations.
*/
int U_PMF_TEXTUREBRUSHOPTIONALDATA_get(const char *contents, int HasImage, U_PMF_TRANSFORMMATRIX *Matrix,
const char **Image, const char *blimit){
if(!contents || !Image || !blimit){ return(0); }
if(Matrix){
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0);
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
}
if(HasImage){
if(contents >= blimit)return(0); // returned Data is variable size, this much at least must be true
U_PMF_PTRSAV_COND(Image, contents, HasImage);
}
return(1);
}
/**
\brief Get data from a U_PMF_TRANSFORMMATRIX object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Matrix Transformation matrix, present if Flag BrushDataTransform is set.
\param blimit one byte past the end of data
EMF+ manual 2.2.2.47, Microsoft name: EmfPlusTransformMatrix Object
*/
int U_PMF_TRANSFORMMATRIX_get(const char *contents, U_PMF_TRANSFORMMATRIX *Matrix, const char *blimit){
if(!contents || !Matrix || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_TRANSFORMMATRIX), blimit))return(0);
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_BLUR object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Radius Blur radius in pixels
\param ExpandEdge 1: expand bitmap by Radius; 0: bitmap size unchanged
\param blimit one byte past the end of data
EMF+ manual 2.2.3.1, Microsoft name: BlurEffect Object
*/
int U_PMF_IE_BLUR_get(const char *contents, U_FLOAT *Radius, uint32_t *ExpandEdge, const char *blimit){
if(!contents || !Radius || !ExpandEdge || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_BLUR), blimit))return(0);
U_PMF_SERIAL_get(&contents, Radius, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, ExpandEdge, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_BRIGHTNESSCONTRAST object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Brightness -255 to 255, 0 is unchanged, positive increases, negative decreases
\param Contrast -100 to 100, 0 is unchanged, positive increases, negative decreases
\param blimit one byte past the end of data
EMF+ manual 2.2.3.2, Microsoft name: BrightnessContrastEffect Object
*/
int U_PMF_IE_BRIGHTNESSCONTRAST_get(const char *contents, int32_t *Brightness, int32_t *Contrast, const char *blimit){
if(!contents || !Brightness || !Contrast || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_BRIGHTNESSCONTRAST), blimit))return(0);
U_PMF_SERIAL_get(&contents, Brightness, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Contrast, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_COLORBALANCE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param CyanRed -100 to 100, 0 is unchanged, positive increases Red & decreases Cyan, negative is opposite
\param MagentaGreen -100 to 100, 0 is unchanged, positive increases Green & decreases Magenta, negative is opposite
\param YellowBlue -100 to 100, 0 is unchanged, positive increases Blue & decreases Yellow, negative is opposite
\param blimit one byte past the end of data
EMF+ manual 2.2.3.3, Microsoft name: ColorBalanceEffect Object
*/
int U_PMF_IE_COLORBALANCE_get(const char *contents, int32_t *CyanRed, int32_t *MagentaGreen, int32_t *YellowBlue, const char *blimit){
if(!contents || !CyanRed || !MagentaGreen || !YellowBlue || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORBALANCE), blimit))return(0);
U_PMF_SERIAL_get(&contents, CyanRed, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, MagentaGreen, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, YellowBlue, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_COLORCURVE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Adjust CurveAdjustment enumeration
\param Channel CurveChannel enumeration
\param Intensity adjustment to apply. "Adjust" determines what field this is and range values.
\param blimit one byte past the end of data
EMF+ manual 2.2.3.4, Microsoft name: ColorCurveEffect Object
*/
int U_PMF_IE_COLORCURVE_get(const char *contents, uint32_t *Adjust, uint32_t *Channel, int32_t *Intensity, const char *blimit){
if(!contents || !Adjust || !Channel || !Intensity || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORCURVE), blimit))return(0);
U_PMF_SERIAL_get(&contents, Adjust, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Channel, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Intensity, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_COLORLOOKUPTABLE object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param BLUT Blue color lookup table
\param GLUT Green color lookup table
\param RLUT Red color lookup table
\param ALUT Alpha color lookup table
\param blimit one byte past the end of data
EMF+ manual 2.2.3.5, Microsoft name: ColorLookupTableEffect Object
*/
int U_PMF_IE_COLORLOOKUPTABLE_get(const char *contents,
const uint8_t **BLUT, const uint8_t **GLUT, const uint8_t **RLUT, const uint8_t **ALUT, const char *blimit){
if(!contents || !BLUT || !GLUT || !RLUT || !ALUT || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORLOOKUPTABLE) + 4 * 256, blimit))return(0);
U_PMF_PTRSAV_SHIFT((const char **)BLUT, &contents, 256);
U_PMF_PTRSAV_SHIFT((const char **)GLUT, &contents, 256);
U_PMF_PTRSAV_SHIFT((const char **)RLUT, &contents, 256);
U_PMF_PTRSAV_SHIFT((const char **)ALUT, &contents, 256);
return(1);
}
/**
\brief Get data from a U_PMF_IE_COLORMATRIX object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Matrix 5 x 5 color transformation matrix, First 4 rows are [{4 multiplier values},0.0] for R,G,B,A, last Row is [{4 color translation valuess}, 1.0]
\param blimit one byte past the end of data
EMF+ manual 2.2.3.6, Microsoft name: ColorMatrixEffect Object
*/
int U_PMF_IE_COLORMATRIX_get(const char *contents, U_PMF_IE_COLORMATRIX *Matrix, const char *blimit){
if(!contents || !Matrix || !blimit){ return(0); }
/* Important! This only checks the constant part, the caller must check that returned data doesn't exceed blimit */
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_COLORMATRIX), blimit))return(0);
U_PMF_SERIAL_get(&contents, Matrix, 4, 5*5, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_HUESATURATIONLIGHTNESS object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Hue -180 to 180, 0 is unchanged
\param Saturation -100 to 100, 0 is unchanged
\param Lightness -100 to 100, 0 is unchanged
\param blimit one byte past the end of data
EMF+ manual 2.2.3.7, Microsoft name: HueSaturationLightnessEffect Object
*/
int U_PMF_IE_HUESATURATIONLIGHTNESS_get(const char *contents, int32_t *Hue, int32_t *Saturation, int32_t *Lightness, const char *blimit){
if(!contents || !Hue || !Saturation || !Lightness || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_HUESATURATIONLIGHTNESS), blimit))return(0);
U_PMF_SERIAL_get(&contents, Hue, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Saturation, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Lightness, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_LEVELS object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Highlight 0 to 100, 100 is unchanged
\param Midtone -100 to 100, 0 is unchanged
\param Shadow 0 to 100, 0 is unchanged
\param blimit one byte past the end of data
EMF+ manual 2.2.3.8, Microsoft name: LevelsEffect Object
*/
int U_PMF_IE_LEVELS_get(const char *contents, int32_t *Highlight, int32_t *Midtone, int32_t *Shadow, const char *blimit){
if(!contents || !Highlight || !Midtone || !Shadow || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_LEVELS), blimit))return(0);
U_PMF_SERIAL_get(&contents, Highlight, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Midtone, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Shadow, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_REDEYECORRECTION object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Elements Number of members in Rects
\param Rects Caller must free. Pointer to memory holding an array of U_RECTL.
\param blimit one byte past the end of data
EMF+ manual 2.2.3.9, Microsoft name: RedEyeCorrectionEffect Object
*/
int U_PMF_IE_REDEYECORRECTION_get(const char *contents, int32_t *Elements, U_RECTL **Rects, const char *blimit){
if(!contents || !Elements || !Rects || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_REDEYECORRECTION), blimit))return(0);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * 4, blimit))return(0);
*Rects = (U_RECTL *) malloc(*Elements * sizeof(U_RECTL));
if(!*Rects){ return(0); }
U_PMF_SERIAL_get(&contents, *Rects, 4, *Elements * 4, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_SHARPEN object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Radius Sharpening radius in pixels
\param Sharpen 0 to 100, 0 is unchanged
\param blimit one byte past the end of data
EMF+ manual 2.2.3.10, Microsoft name: SharpenEffect Object
*/
int U_PMF_IE_SHARPEN_get(const char *contents, U_FLOAT *Radius, int32_t *Sharpen, const char *blimit){
if(!contents || !Radius || !Sharpen || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_SHARPEN), blimit))return(0);
U_PMF_SERIAL_get(&contents, Radius, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Sharpen, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMF_IE_TINT object
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Hue -180 to 180, [positive==clockwise] rotation in degrees starting from blue
\param Amount -100 [add black] to 100[add white], 0 is unchanged. Change in hue on specified axis
\param blimit one byte past the end of data
EMF+ manual 2.2.3.11, Microsoft name: TintEffect Object
*/
int U_PMF_IE_TINT_get(const char *contents, int32_t *Hue, int32_t *Amount, const char *blimit){
if(!contents || !Hue || !Amount || !blimit){ return(0); }
if(IS_MEM_UNSAFE(contents, sizeof(U_PMF_IE_TINT), blimit))return(0);
U_PMF_SERIAL_get(&contents, Hue, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Amount, 4, 1, U_LE);
return(1);
}
/*
end of U_PMF_*_get() functions
=====================================================================================
start of U_PMR_*_get() functions
These functions all assume that the size field in the common EMF+ header has already
been checked, so that the extent the record claims exists in the data read in for the file.
Consequently none of them takes a blimit parameter. They generate a new one from the
header size field and contents if needed.
*/
int U_PMR_common_stack_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){
if(!contents || !StackID){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_RESTORE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE);
return(1);
}
/* for records that have a type but no associated flag bits or data */
int U_PMR_common_header_get(const char *contents, U_PMF_CMN_HDR *Header){
/* memory access safe, only uses the common header */
if(!contents){ return(0); }
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_OFFSETCLIP record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
\param dX horizontal translation offset to apply to clipping region
\param dY vertical translation offset to apply to clipping region
EMF+ manual 2.3.1.1, Microsoft name: EmfPlusOffsetClip Record, Index 0x35
*/
int U_PMR_OFFSETCLIP_get(const char *contents, U_PMF_CMN_HDR *Header,
U_FLOAT *dX, U_FLOAT *dY){
if(!contents){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_OFFSETCLIP))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, dX, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, dY, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_RESETCLIP record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual 2.3.1.2, Microsoft name: EmfPlusResetClip Record, Index 0x31
*/
int U_PMR_RESETCLIP_get(const char *contents, U_PMF_CMN_HDR *Header){
if(!contents){ return(0); }
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETCLIPPATH record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param CMenum CombineMode enumeration..
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.1.3, Microsoft name: EmfPlusSetClipPath Record, Index 0x33
*/
int U_PMR_SETCLIPPATH_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PathID, int *CMenum){
if(!contents || !PathID || !CMenum){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETCLIPPATH))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4;
*PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
return(1);
}
/**
\brief Get data from a U_PMR_SETCLIPRECT record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
\param CMenum Combine mode enumeration.
\param Rect Rectangle used with CombineMode enumeration from Header.Flags
EMF+ manual 2.3.1.4, Microsoft name: EmfPlusSetClipRect Record, Index 0x32
*/
int U_PMR_SETCLIPRECT_get(const char *contents, U_PMF_CMN_HDR *Header,
int *CMenum,
U_PMF_RECTF *Rect){
if(!contents || !CMenum || !Rect ){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETCLIPRECT))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4;
U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_SETCLIPREGION record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param CMenum CombineMode enumeration..
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.1.5, Microsoft name: EmfPlusSetClipRegion Record, Index 0x34
*/
int U_PMR_SETCLIPREGION_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PathID, int *CMenum){
if(!contents || !PathID || !CMenum){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETCLIPREGION))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*CMenum = (lclHeader.Flags >> U_FF_SHFT_CM4) & U_FF_MASK_CM4;
*PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
return(1);
}
/**
\brief Get data from a U_PMR_COMMENT record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
\param Data Private data, may be anything
EMF+ manual 2.3.2.1, Microsoft name: EmfPlusComment Record, Index 0x03
Caller must check Data for possible memory access violations.
*/
int U_PMR_COMMENT_get(const char *contents, U_PMF_CMN_HDR *Header,
const char **Data){
if(!contents || !Data){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_COMMENT))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMR_ENDOFFILE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual 2.3.3.1, Microsoft name: EmfPlusEndOfFile Record, Index 0x02
*/
int U_PMR_ENDOFFILE_get(const char *contents, U_PMF_CMN_HDR *Header){
if(!contents){ return(0); }
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_GETDC record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual 2.3.3.2, Microsoft name: EmfPlusGetDC Record, Index 0x04
*/
int U_PMR_GETDC_get(const char *contents, U_PMF_CMN_HDR *Header){
if(!contents){ return(0); }
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_HEADER record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
\param Version EmfPlusGraphicsVersion object
\param IsDual set = Dual-mode file, clear= EMF+ only file.
\param IsVideo set = video device, clear= printer. Ignore all other bits.
\param LogicalDpiX Horizontal resolution reference device in DPI
\param LogicalDpiY Vertical resolution reference device in DPI
EMF+ manual 2.3.3.3, Microsoft name: EmfPlusHeader Record, Index 0x01
*/
int U_PMR_HEADER_get(const char *contents, U_PMF_CMN_HDR *Header,
U_PMF_GRAPHICSVERSION *Version, int *IsDual, int *IsVideo, uint32_t *LogicalDpiX, uint32_t *LogicalDpiY){
if(!contents || !Version || !IsDual || !IsVideo || !LogicalDpiX || !LogicalDpiY){ return(0); }
uint32_t tmp;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_HEADER))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*IsDual = (lclHeader.Flags & U_PPF_DM ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Version, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, &tmp, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, LogicalDpiX, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, LogicalDpiY, 4, 1, U_LE);
*IsVideo = (tmp & U_PPF_VIDEO ? 1 : 0 );
return(1);
}
/**
\brief Get data from a U_PMR_CLEAR record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
\param Color Erase everything preceding, set background ARGB color.
EMF+ manual 2.3.4.1, Microsoft name: EmfPlusClear Record, Index 0x09
*/
int U_PMR_CLEAR_get(const char *contents, U_PMF_CMN_HDR *Header,
U_PMF_ARGB *Color){
if(!contents || !Color){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_CLEAR))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, Color, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWARC record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rect Caller must free. Bounding rectangle. Coordinate type set by ctype.
EMF+ manual 2.3.4.2, Microsoft name: EmfPlusDrawArc Record, Index 0x12
*/
int U_PMR_DRAWARC_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype,
U_FLOAT *Start, U_FLOAT *Sweep,
U_PMF_RECTF *Rect){
if(!contents || !PenID || !ctype || !Start || !Sweep || !Rect){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWARC))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE);
U_PMF_RECTF *Rects = NULL;
if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0);
memcpy(Rect,Rects,sizeof(U_PMF_RECTF));
free(Rects);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWBEZIERS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param RelAbs Set: Coordinates are relative; Clear: Coordinates are absolute and their type is set by ctype
\param Elements Number of members in the Data array
\param Points Caller must free. Array of U_POINT_F = Sequence of points to connect. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.3, Microsoft name: EmfPlusDrawBeziers Record, Index 0x19
*/
int U_PMR_DRAWBEZIERS_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype, int *RelAbs,
uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !PenID || !ctype || !RelAbs || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWBEZIERS))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
int status = U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit );
return(status);
}
/**
\brief Get data from a U_PMR_DRAWCLOSEDCURVE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param RelAbs Set: Coordinates are relative; Clear: Coordinates are absolute and their type is set by ctype
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Elements Number of members in the Data array
\param Points Caller must free. Array of U_POINT_F = Sequence of points to connect. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.4, Microsoft name: EmfPlusDrawClosedCurve Record, Index 0x17
*/
int U_PMR_DRAWCLOSEDCURVE_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype, int *RelAbs,
U_FLOAT *Tension, uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !PenID || !ctype || !RelAbs || !Tension || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWCLOSEDCURVE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWCURVE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Offset Element in Points that is the spline's starting point
\param NSegs Number of segments
\param Elements Number of members in Data array
\param Points Caller must free. Array of U_POINT_F = Sequence of points to connect. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.5, Microsoft name: EmfPlusDrawCurve Record, Index 0x18
*/
int U_PMR_DRAWCURVE_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype,
U_FLOAT *Tension, uint32_t *Offset, uint32_t *NSegs, uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !PenID || !ctype || !Tension || !Offset || !NSegs || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWCURVE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Offset, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, NSegs, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWDRIVERSTRING record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param FontID U_PMF_FONT object in the EMF+ object table (0-63, inclusive)
\param btype Set: BrushID is an U_PFM_ARGB; Clear: index of U_PMF_BRUSH object in EMF+ object table.
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depends on Flags bit0
\param DSOFlags DriverStringOptions flags
\param HasMatrix If 1 record contains a TransformMatrix field, if 0 it does not.
\param Elements Number of members in Glyphs and Positions array
\param Glyphs Caller must free. If U_DSO_CmapLookup is set in DSOFlags this is an array of UTF16LE characters, otherwise, it is an array of indices into the U_PMF_FONT object indexed by Object_ID in flags.
\param Points Caller must free. Coordinates of each member of Glyphs. U_DSO_RealizedAdvance set in DSOFlags Relative then positions are calculated relative to the first glyph which is stored in Positions, otherwise, all glyph positions are stored in Positions.
\param Matrix Caller must free. Transformation to apply to Glyphs & Positions. Present if HasMatrix is 1
EMF+ manual 2.3.4.6, Microsoft name: EmfPlusDrawDriverString Record, Index 0x36
*/
int U_PMR_DRAWDRIVERSTRING_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *FontID, int *btype,
uint32_t *BrushID, uint32_t *DSOFlags, uint32_t *HasMatrix, uint32_t *Elements,
uint16_t **Glyphs, U_PMF_POINTF **Points, U_PMF_TRANSFORMMATRIX **Matrix){
if(!contents || !FontID || !btype || !BrushID ||
!DSOFlags || !HasMatrix || !Elements || !Glyphs || !Points || !Matrix){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWDRIVERSTRING))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*FontID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, DSOFlags, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, HasMatrix, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements*2 + *Elements*2*4 + 24, blimit))return(0);
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Glyphs, 2, *Elements, U_LE, (*DSOFlags & U_DSO_CmapLookup))){ return(0); }
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Points, 4, *Elements *2, U_LE, (*DSOFlags & U_DSO_RealizedAdvance))){ return(0); }
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)Matrix, 4, 6, U_LE, (*HasMatrix))){ return(0); }
return(1);
}
/**
\brief Get data from a U_PMR_DRAWELLIPSE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Rect Caller must free. Bounding rectangle. Coordinate type set by ctype.
EMF+ manual 2.3.4.7, Microsoft name: EmfPlusDrawEllipse Record, Index 0x0F
*/
int U_PMR_DRAWELLIPSE_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype,
U_PMF_RECTF *Rect){
if(!contents || !PenID || !ctype || !Rect){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWELLIPSE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWIMAGE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param ImgID U_PMF_IMAGE object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param ImgAttrID index of a U_PMF_IMAGEATTRIBUTES object in the object table
\param SrcUnit UnitType enumeration
\param SrcRect Region of image
\param DstRect Destination rectangle for image. Coordinate type set by ctype.
EMF+ manual 2.3.4.8, Microsoft name: EmfPlusDrawImage Record, Index 0x1A
*/
int U_PMR_DRAWIMAGE_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *ImgID, int *ctype,
uint32_t *ImgAttrID, int32_t *SrcUnit, U_PMF_RECTF *SrcRect,
U_PMF_RECTF *DstRect){
if(!contents || !ImgID || !ctype || !ImgAttrID || !SrcUnit || !SrcRect || !DstRect){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWIMAGE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*ImgID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, ImgAttrID, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, SrcUnit, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE);
U_PMF_SERIAL_get(&contents, DstRect, 4, 4, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWIMAGEPOINTS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param ImgID U_PMF_IMAGE object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param etype Set: effect from previous U_PMR_SERIALIZABLEOBJECT record will be applied; Clear: no effect applied
\param RelAbs Set: Data is relative, Clear: if it is absolute
\param ImgAttrID EmfPlusImageAttributes object
\param SrcUnit UnitType enumeration
\param SrcRect Region of image
\param Elements Number of members in Points, must be 3
\param Points Caller must free. 3 points of a parallelogram.. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.9, Microsoft name: EmfPlusDrawImagePoints Record, Index 0x1B
*/
int U_PMR_DRAWIMAGEPOINTS_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *ImgID, int *ctype, int *etype, int *RelAbs,
uint32_t *ImgAttrID, int32_t *SrcUnit, U_PMF_RECTF *SrcRect, uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !ImgID || !ctype || !etype || !RelAbs || !ImgAttrID || !SrcUnit || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWIMAGEPOINTS))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*etype = (lclHeader.Flags & U_PPF_E ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 );
*ImgID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, ImgAttrID, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, SrcUnit, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWLINES record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param dtype Set: path must be closed, Clear: path is open
\param RelAbs Set: Coordinates are relative; Clear: Coordinates are absolute and their type is set by ctype
\param Elements Number of members in Points
\param Points Caller must free. Array of U_POINT_F = Sequence of points to connect. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.10, Microsoft name: EmfPlusDrawLines Record, Index 0x0D
*/
int U_PMR_DRAWLINES_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype, int *dtype, int *RelAbs,
uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !PenID || !ctype || !dtype || !RelAbs || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*dtype = (lclHeader.Flags & U_PPF_D ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWPATH record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
EMF+ manual 2.3.4.11, Microsoft name: EmfPlusDrawPath Record, Index 0x15
*/
int U_PMR_DRAWPATH_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PathID, uint32_t *PenID){
if(!contents || !PathID || !PenID){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWPATH))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, PenID, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWPIE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rect Caller must free. Bounding rectangle. Coordinate type set by ctype.
EMF+ manual 2.3.4.12, Microsoft name: EmfPlusDrawPie Record, Index 0x0D
*/
int U_PMR_DRAWPIE_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype,
U_FLOAT *Start, U_FLOAT *Sweep,
U_PMF_RECTF *Rect){
if(!contents || !PenID || !ctype || !Start || !Sweep || !Rect){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE);
U_PMF_RECTF *Rects = NULL;
if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0);
memcpy(Rect,Rects,sizeof(U_PMF_RECTF));
free(Rects);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWRECTS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PenID U_PMF_PEN object in the EMF+ object table (0-63, inclusive)
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Elements Number of members in Rects
\param Rects Caller must free. Array of U_PMF_RECTF rectangles to draw.
EMF+ manual 2.3.4.13, Microsoft name: EmfPlusDrawRects Record, Index 0x0B
Rects in record may be either U_PMF_RECT or U_PMF_RECTF, but this function always
returns U_PMF_RECTF
*/
int U_PMR_DRAWRECTS_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PenID, int *ctype,
uint32_t *Elements,
U_PMF_RECTF **Rects){
if(!contents || !PenID || !Elements || !Rects){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*PenID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_DRAWSTRING record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param FontID U_PMF_FONT object in the EMF+ object table (0-63, inclusive)
\param btype Set: BrushID is an U_PFM_ARGB; Clear: index of U_PMF_BRUSH object in EMF+ object table.
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param FormatID U_PMF_STRINGFORMAT object in EMF+ Object Table.
\param Elements Number of characters in the string.
\param Rect String's bounding box.
\param String Caller must free. Array of UFT-16LE unicode characters.
EMF+ manual 2.3.4.14, Microsoft name: EmfPlusDrawString Record, Index 0x1C
*/
int U_PMR_DRAWSTRING_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *FontID, int *btype,
uint32_t *BrushID, uint32_t *FormatID, uint32_t *Elements, U_PMF_RECTF *Rect,
uint16_t **String){
if(!contents || !FontID || !btype || !BrushID || !FormatID || !Elements || !String){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWPIE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*FontID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, FormatID, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE);
if(IS_MEM_UNSAFE(contents, *Elements * 2, blimit))return(0);
if(!U_PMF_SERIAL_array_copy_get(&contents, (void **)String, 2, *Elements, U_XE, 1)){ return(0); }
return(1);
}
/**
\brief Get data from a U_PMR_FILLCLOSEDCURVE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param ftype Set: winding fill; Clear: alternate fill
\param RelAbs Set: Coordinates are relative; Clear: Coordinates are absolute and their type is set by ctype
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param Tension Controls splines, 0 is straight line, >0 is curved
\param Elements Number of members in Points
\param Points Caller must free. Array of U_POINT_F = Sequence of points to connect. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.15, Microsoft name: EmfPlusFillClosedCurve Record, Index 0x16
*/
int U_PMR_FILLCLOSEDCURVE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *btype, int *ctype, int *ftype, int *RelAbs,
uint32_t *BrushID, U_FLOAT *Tension, uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !btype || !ctype || !ftype || !RelAbs || !BrushID || !Tension || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*ftype = (lclHeader.Flags & U_PPF_F ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_P ? 1 : 0 );
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, Tension, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_FILLELLIPSE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param Rect Caller must free. Bounding box for elliptical pie segment being drawn. Coordinate type set by ctype.
EMF+ manual 2.3.4.16, Microsoft name: EmfPlusFillEllipse Record, Index 0x0E
*/
int U_PMR_FILLELLIPSE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *btype, int *ctype,
uint32_t *BrushID,
U_PMF_RECTF *Rect){
if(!contents || !btype || !ctype || !BrushID || !Rect){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_FILLELLIPSE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, Rect, 4, 4, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_FILLPATH record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param PathID U_PMF_PATH object in the EMF+ object table (0-63, inclusive)
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
EMF+ manual 2.3.4.17, Microsoft name: EmfPlusFillPath Record, Index 0x14
Note: U_PMF_FILLPATHOBJ is the object, U_PMF_FILLPATH is the file record
*/
int U_PMR_FILLPATH_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *PathID, int *btype,
uint32_t *BrushID){
if(!contents || !PathID || !btype || !BrushID){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_FILLPATH))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*PathID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
return(1);
}
/**
\brief Get data from a U_PMR_FILLPIE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param Start Start angle, >=0.0, degrees clockwise from 3:00
\param Sweep Sweep angle, -360<= angle <=360, degrees clockwise from Start
\param Rect Bounding box for elliptical pie segment being filled. Coordinate type set by ctype.
EMF+ manual 2.3.4.18, Microsoft name: EmfPlusFillPie Record, Index 0x10
*/
int U_PMR_FILLPIE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *btype, int *ctype,
uint32_t *BrushID, U_FLOAT *Start, U_FLOAT *Sweep,
U_PMF_RECTF *Rect){
if(!contents || !btype || !ctype || !BrushID || !Start || !Sweep || !Rect){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_FILLPIE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, Start, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Sweep, 4, 1, U_LE);
U_PMF_RECTF *Rects = NULL;
if(!U_PMF_VARRECTS_get(&contents, lclHeader.Flags, 1, &Rects, blimit))return(0);
memcpy(Rect,Rects,sizeof(U_PMF_RECTF));
free(Rects);
return(1);
}
/**
\brief Get data from a U_PMR_FILLPOLYGON record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param RelAbs Set: U_PMF_PathPointTypeRLE and/or U_PMF_PathPointType objects; Clear: only U_PMF_PathPointType
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param Elements Number of members in Data.
\param Points Sequence of points to connect with line segments. Coordinate type set by ctype and RelAbs.
EMF+ manual 2.3.4.19, Microsoft name: EmfPlusFillPolygon Record, Index 0x0C
*/
int U_PMR_FILLPOLYGON_get(const char *contents, U_PMF_CMN_HDR *Header,
int *btype, int *ctype, int *RelAbs,
uint32_t *BrushID, uint32_t *Elements,
U_PMF_POINTF **Points){
if(!contents || !btype || !ctype || !RelAbs || !BrushID || !Elements || !Points){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_DRAWLINES))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*RelAbs = (lclHeader.Flags & U_PPF_R ? 1 : 0 );
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARPOINTS_get(contents, lclHeader.Flags, *Elements, Points, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_FILLRECTS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
\param Elements Number of members in Data.
\param Rects Caller must free. Array of U_PMF_RECTF rectangles to draw.
EMF+ manual 2.3.4.20, Microsoft name: EmfPlusFillRects Record, Index 0x0A
EMF+ files have been encountered where BrushID must be a color, because it has a value like FFFF0000 but
the flags are set wrong, so that U_PPF_B is not set. Detect these by BrushID >63 for btype=0 and correct.
If the opposite problem occurs it cannot be reliably detected, so it cannot be corrected.
Rects in record may be either U_PMF_RECT or U_PMF_RECTF, but this function always
returns U_PMF_RECTF
*/
int U_PMR_FILLRECTS_get(const char *contents, U_PMF_CMN_HDR *Header,
int *btype, int *ctype,
uint32_t *BrushID, uint32_t *Elements,
U_PMF_RECTF **Rects){
if(!contents || !btype || !ctype || !BrushID || !Elements || !Rects){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_FILLRECTS))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
U_PMF_SERIAL_get(&contents, Elements, 4, 1, U_LE);
U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit);
/* correct btype, if necessary, for invalid EMF+ input */
if((*BrushID > 63) & !*btype)*btype=1;
return(1);
}
/**
\brief Get data from a U_PMR_FILLREGION record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param RgnID U_PMF_REGION object in the EMF+ object table (0-63, inclusive)
\param btype Set: BrushID is an U_PFM_ARGB; Clear: is index of U_PMF_BRUSH object in EMF+ object table.
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param BrushID Color or index of U_PMF_BRUSH object in the EMF+ object table, depending on btype.
EMF+ manual 2.3.4.21, Microsoft name: EmfPlusFillRegion Record, Index 0x13
*/
int U_PMR_FILLREGION_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *RgnID, int *btype, int *ctype,
uint32_t *BrushID){
if(!contents || !RgnID || !btype || !ctype || !BrushID){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_FILLREGION))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*btype = (lclHeader.Flags & U_PPF_B ? 1 : 0 );
*ctype = (lclHeader.Flags & U_PPF_C ? 1 : 0 );
*RgnID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
U_PMF_SERIAL_get(&contents, BrushID, 4, 1, (*btype ? U_XE : U_LE)); /* color is not byte swapped, ID integer is */
return(1);
}
/**
\brief Get data from a U_PMR_OBJECT record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param ObjID Index for this object in the EMF+ object table (0-63, inclusive)
\param otype ObjectType enumeration
\param ntype Set: object definition continue bit is set
\param TSize If ntype is set, holds the total number of data bytes split across multiple records. If ntype is clear, has no meaning.
\param Data Object's data. Type from otype.
EMF+ manual 2.3.5.1, Microsoft name: EmfPlusObject Record, Index 0x13
Caller must check Data for possible memory access violations.
OTHER NOTES:
All objects are to be stored in the same table and retrieved by index.
Documentation indicates that this table contains only 64 slots, although the index
field which references it can code for values 0-127.
If a new object has the same index as an existing object the old one is deleted and
the new one goes into its storage slot.
The continuation bit (U_PPF_N) is documented as indicating that the object is continued into
the next record. Examination of emf+ records in emf files produced by PowerPoint 2003
show that changing the ObjID also serves as a continued record terminator, and that it apparently
overrides the value for the continue bit. That is, even though the preceding records said
that it was continued, the change of ObjID terminates that preceding record without adding
any more data to it. In one example the sequential emf+ records were:
ObjID type size continue
0 5 65008 Y
0 5 65008 Y
0 5 63104 Y
1 8 24 N
A DrawImagePoints record followed that referenced ObjID 0.
Examination of the records with continue set showed that data in each
was preceded by a uint32_t size value equivalent to the size of the
data that had been split across multiple records, in this case
0x0002F254 = 193108. It is not clear at present if this size value
will also be present at the end of a continued series that terminates
by not using the continue bit, rather than changing the ObjID.
*/
int U_PMR_OBJECT_get(const char *contents, U_PMF_CMN_HDR *Header,
uint32_t *ObjID, int *otype, int *ntype, uint32_t *TSize,
const char **Data){
if(!contents || !ObjID || !otype || !ntype || !Data){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_OBJECT))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*ntype = (lclHeader.Flags & U_PPF_N ? 1 : 0 );
*ObjID = (lclHeader.Flags >> U_FF_SHFT_OID8) & U_FF_MASK_OID8;
*otype = (lclHeader.Flags >> U_FF_SHFT_OT) & U_FF_MASK_OT;
if(*ntype){ U_PMF_SERIAL_get(&contents, TSize, 4, 1, U_LE); }
else { *TSize = 0; }
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMR_SERIALIZABLEOBJECT record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param GUID ImageEffects identifier.
\param Size Bytes in Data.
\param Data "Serialized image effects parameter block". One of the ImageEffects objects.
EMF+ manual 2.3.5.2, Microsoft name: EmfPlusSerializableObject Record, Index 0x38
Caller must check Data for possible memory access violations.
*/
int U_PMR_SERIALIZABLEOBJECT_get(const char *contents, U_PMF_CMN_HDR *Header,
uint8_t *GUID, uint32_t *Size,
const char **Data){
if(!contents || !GUID || !Size || !Data){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SERIALIZABLEOBJECT))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, GUID, 1, 16, U_XE);
U_PMF_SERIAL_get(&contents, Size, 4, 1, U_LE);
U_PMF_PTRSAV_SHIFT(Data, &contents, 0);
return(1);
}
/**
\brief Get data from a U_PMR_SETANTIALIASMODE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param SMenum SmoothingMode enumeration
\param aatype Set: anti-aliasing on; Clear: anti-aliasing off
EMF+ manual 2.3.6.1, Microsoft name: EmfPlusSetAntiAliasMode Record, Index 0x1E
*/
int U_PMR_SETANTIALIASMODE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *SMenum, int *aatype){
if(!contents || !SMenum || !aatype){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETANTIALIASMODE))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*aatype = (lclHeader.Flags & U_PPF_AA ? 1 : 0 );
*SMenum = (lclHeader.Flags >> U_FF_SHFT_AA) & U_FF_MASK_AA;
return(1);
}
/**
\brief Get data from a U_PMR_SETCOMPOSITINGMODE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param CMenum CompositingMode enumeration
EMF+ manual 2.3.6.2, Microsoft name: EmfPlusSetCompositingMode Record, Index 0x23
*/
int U_PMR_SETCOMPOSITINGMODE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *CMenum){
/* memory access safe, only uses the common header */
if(!contents || !CMenum){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*CMenum = (Flags >> U_FF_SHFT_CM) & U_FF_MASK_CM;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETCOMPOSITINGQUALITY record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param CQenum CompositingQuality enumeration
EMF+ manual 2.3.6.3, Microsoft name: EmfPlusSetCompositingQuality Record, Index 0x24
*/
int U_PMR_SETCOMPOSITINGQUALITY_get(const char *contents, U_PMF_CMN_HDR *Header,
int *CQenum){
/* memory access safe, only uses the common header */
if(!contents || !CQenum){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*CQenum = (Flags >> U_FF_SHFT_CQ) & U_FF_MASK_CQ;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETINTERPOLATIONMODE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param IMenum InterpolationMode enumeration
EMF+ manual 2.3.6.4, Microsoft name: EmfPlusSetInterpolationMode Record, Index 0x21
*/
int U_PMR_SETINTERPOLATIONMODE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *IMenum){
/* memory access safe, only uses the common header */
if(!contents || !IMenum){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*IMenum = (Flags >> U_FF_SHFT_IM) & U_FF_MASK_IM;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETPIXELOFFSETMODE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param POMenum PixelOffsetMode enumeration.
EMF+ manual 2.3.6.5, Microsoft name: EmfPlusSetPixelOffsetMode Record, Index 0x22
*/
int U_PMR_SETPIXELOFFSETMODE_get(const char *contents, U_PMF_CMN_HDR *Header,
int *POMenum){
/* memory access safe, only uses the common header */
if(!contents || !POMenum){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*POMenum = (Flags >> U_FF_SHFT_PxOffM) & U_FF_MASK_PxOffM;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETRENDERINGORIGIN record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header.
\param X X coordinate of rendering origin.
\param Y Y coordinate of rendering origin.
EMF+ manual 2.3.6.6, Microsoft name: EmfPlusSetRenderingOrigin Record, Index 0x1D
*/
int U_PMR_SETRENDERINGORIGIN_get(const char *contents, U_PMF_CMN_HDR *Header,
int32_t *X, int32_t *Y){
if(!contents || !X || !Y){ return(0); }
U_PMF_CMN_HDR lclHeader;
if(!U_PMF_CMN_HDR_get(&contents, &lclHeader))return(0);
if(lclHeader.Size < sizeof(U_PMF_SETRENDERINGORIGIN))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, X, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Y, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_SETTEXTCONTRAST record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header.
\param TGC Text Gamma correction value (x 1000).
EMF+ manual 2.3.6.7, Microsoft name: EmfPlusSetTextContrast Record, Index 0x20
*/
int U_PMR_SETTEXTCONTRAST_get(const char *contents, U_PMF_CMN_HDR *Header,
int *TGC){
/* memory access safe, only uses the common header */
if(!contents || !TGC){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*TGC = (Flags >> U_FF_SHFT_TGC) & U_FF_MASK_TGC;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_SETTEXTRENDERINGHINT record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header.
\param TRHenum TextRenderingHint enumeration
EMF+ manual 2.3.6.8, Microsoft name: EmfPlusSetTextRenderingHint Record, Index 0x1F
*/
int U_PMR_SETTEXTRENDERINGHINT_get(const char *contents, U_PMF_CMN_HDR *Header,
int *TRHenum){
/* memory access safe, only uses the common header */
if(!contents || !TRHenum){ return(0); }
uint16_t Flags = U_PMF_HEADERFLAGS_get(contents);
*TRHenum = (Flags >> U_FF_SHFT_TRH) & U_FF_MASK_TRH;
U_PMF_CMN_HDR_get(&contents, Header);
return(1);
}
/**
\brief Get data from a U_PMR_BEGINCONTAINER record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param UTenum UnitType enumeration
\param DstRect with SrcRect specifies a transformation
\param SrcRect with DstRect specifies a transformation
\param StackID EMF+ Object Stack Index to use for this graphics container
EMF+ manual 2.3.7.1, Microsoft name: EmfPlusBeginContainer Record, Index 0x27
*/
int U_PMR_BEGINCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header,
int *UTenum,
U_PMF_RECTF *DstRect, U_PMF_RECTF *SrcRect, uint32_t *StackID){
if(!contents || !UTenum || !DstRect || !SrcRect || !StackID){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETCLIPREGION))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*UTenum = (lclHeader.Flags >> U_FF_SHFT_UT) & U_FF_MASK_UT;
U_PMF_SERIAL_get(&contents, DstRect, 4, 4, U_LE);
U_PMF_SERIAL_get(&contents, SrcRect, 4, 4, U_LE);
U_PMF_SERIAL_get(&contents, StackID, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_BEGINCONTAINERNOPARAMS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param StackID EMF+ Object Stack Index to use for this graphics container
EMF+ manual 2.3.7.2, Microsoft name: EmfPlusBeginContainerNoParams Record, Index 0x28
*/
int U_PMR_BEGINCONTAINERNOPARAMS_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){
return(U_PMR_common_stack_get(contents, Header, StackID));
}
/**
\brief Get data from a U_PMR_ENDCONTAINER record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param StackID EMF+ Object Stack Index of this graphics container
EMF+ manual 2.3.7.3, Microsoft name: EmfPlusEndContainer Record, Index 0x29
*/
int U_PMR_ENDCONTAINER_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){
return(U_PMR_common_stack_get(contents, Header, StackID));
}
/**
\brief Get data from a U_PMR_RESTORE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param StackID State (level) to restore from the EMF+ Graphics Stack. Must have been put on the GS with a U_PMR_SAVE.
EMF+ manual 2.3.7.4, Microsoft name: EmfPlusRestore Record, Index 0x26
*/
int U_PMR_RESTORE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){
return(U_PMR_common_stack_get(contents, Header, StackID));
}
/**
\brief Get data from a U_PMR_SAVE record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param StackID State (level) to save.on the EMF+ Graphics Stack
EMF+ manual 2.3.7.5, Microsoft name: EmfPlusSave Record, Index 0x25
*/
int U_PMR_SAVE_get(const char *contents, U_PMF_CMN_HDR *Header, uint32_t *StackID){
return(U_PMR_common_stack_get(contents, Header, StackID));
}
/**
\brief Get data from a U_PMR_SETTSCLIP record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param ctype Set: int16_t coordinates; Clear: U_FLOAT coordinates
\param Elements Number of members in Data.
\param Rects Caller must free. Array of rectangles to draw. Coordinate type set by ctype.
EMF+ manual 2.3.8.1, Microsoft name: EmfPlusSetTSClip Record, Index 0x3A
*/
int U_PMR_SETTSCLIP_get(const char *contents, U_PMF_CMN_HDR *Header,
int *ctype, uint32_t *Elements,
U_PMF_RECTF **Rects){
if(!contents || !ctype || !Elements || !Rects){ return(0); }
const char *blimit = contents;
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETTSCLIP))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
blimit += lclHeader.Size;
*ctype = (lclHeader.Flags & U_PPF_K ? 1 : 0 );
*Elements = (lclHeader.Flags >> U_FF_SHFT_TSC) & U_FF_MASK_TSC;
U_PMF_VARRECTS_get(&contents, lclHeader.Flags, *Elements, Rects, blimit);
return(1);
}
/**
\brief Get data from a U_PMR_SETTSGRAPHICS record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param vgatype Set: Palette is VGA basic colors; Clear: Palette is ???
\param pptype Set: Palette is present; Clear: Palette is absent.
\param AntiAliasMode SmoothingMode enumeration
\param TextRenderHint TextRenderingHint enumeration
\param CompositingMode CompositingMode enumeration
\param CompositingQuality CompositingQuality enumeration
\param RenderOriginX Origin X for halftoning and dithering
\param RenderOriginY Origin Y for halftoning and dithering
\param TextContrast Gamma correction, range 0 to 12
\param FilterType FilterType enumeraton
\param PixelOffset PixelOffsetMode enumeration
\param WorldToDevice world to device transform
\param Data Palette (optional)
EMF+ manual 2.3.8.2, Microsoft name: EmfPlusSetTSGraphics Record, Index 0x39
Caller must check Data for possible memory access violations.
*/
int U_PMR_SETTSGRAPHICS_get(const char *contents, U_PMF_CMN_HDR *Header,
int *vgatype, int *pptype,
uint8_t *AntiAliasMode, uint8_t *TextRenderHint, uint8_t *CompositingMode, uint8_t *CompositingQuality,
int16_t *RenderOriginX, int16_t *RenderOriginY, uint16_t *TextContrast, uint8_t *FilterType,
uint8_t *PixelOffset, U_PMF_TRANSFORMMATRIX *WorldToDevice,
const char **Data){
if(!contents || !vgatype || !pptype ||
!AntiAliasMode || !TextRenderHint || !CompositingMode || !CompositingQuality ||
!RenderOriginX || !RenderOriginY || !TextContrast || !FilterType ||
!PixelOffset || !WorldToDevice || !Data){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETTSGRAPHICS))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*vgatype = (lclHeader.Flags & U_PPF_VGA ? 1 : 0 );
*pptype = (lclHeader.Flags & U_PPF_PP ? 1 : 0 );
U_PMF_SERIAL_get(&contents, AntiAliasMode, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, TextRenderHint, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, CompositingMode, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, CompositingQuality, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, RenderOriginX, 2, 1, U_LE);
U_PMF_SERIAL_get(&contents, RenderOriginY, 2, 1, U_LE);
U_PMF_SERIAL_get(&contents, TextContrast, 2, 1, U_LE);
U_PMF_SERIAL_get(&contents, FilterType, 1, 1, U_XE);
U_PMF_SERIAL_get(&contents, WorldToDevice, 4, 6, U_LE);
U_PMF_PTRSAV_COND(Data, contents, *pptype);
return(1);
}
/**
\brief Get data from a U_PMR_MULTIPLYWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Matrix Transformation matrix
EMF+ manual 2.3.9.1, Microsoft name: EmfPlusMultiplyWorldTransform Record, Index 0x2C
*/
int U_PMR_MULTIPLYWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
int *xmtype,
U_PMF_TRANSFORMMATRIX *Matrix){
if(!contents || !xmtype || !Matrix){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_MULTIPLYWORLDTRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_RESETWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
EMF+ manual 2.3.9.2, Microsoft name: EmfPlusResetWorldTransform Record, Index 0x2B
*/
int U_PMR_RESETWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header){
return( U_PMR_common_header_get(contents,Header));
}
/**
\brief Get data from a U_PMR_ROTATEWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Angle Rotation angle, in degrees
EMF+ manual 2.3.9.3, Microsoft name: EmfPlusRotateWorldTransform Record, Index 0x2F
*/
int U_PMR_ROTATEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
int *xmtype,
U_FLOAT *Angle){
if(!contents || !xmtype || !Angle){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_ROTATEWORLDTRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Angle, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_SCALEWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param xmtype Set: Post multiply; Clear: Pre multiply.
\param Sx X scale factor.
\param Sy Y scale factor.
EMF+ manual 2.3.9.4, Microsoft name: EmfPlusScaleWorldTransform Record, Index 0x2E
*/
int U_PMR_SCALEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
int *xmtype,
U_FLOAT *Sx, U_FLOAT *Sy){
if(!contents || !xmtype || !Sx || !Sy){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SCALEWORLDTRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Sx, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Sy, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_SETPAGETRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param PUenum Page Unit, UnitType enumeration
\param Scale Scale factor to convert page space to device space
EMF+ manual 2.3.9.5, Microsoft name: EmfPlusSetPageTransform Record, Index 0x30
*/
int U_PMR_SETPAGETRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
int *PUenum,
U_FLOAT *Scale){
if(!contents || !PUenum || !Scale){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETPAGETRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*PUenum = (lclHeader.Flags >> U_FF_SHFT_PU) & U_FF_MASK_PU;
U_PMF_SERIAL_get(&contents, Scale, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_SETWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param Matrix Transformation matrix
EMF+ manual 2.3.9.6, Microsoft name: EmfPlusSetWorldTransform Record, Index 0x2A
*/
int U_PMR_SETWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
U_PMF_TRANSFORMMATRIX *Matrix){
if(!contents || !Matrix){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_SETWORLDTRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
U_PMF_SERIAL_get(&contents, Matrix, 4, 6, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_TRANSLATEWORLDTRANSFORM record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header
\param xmtype Set: Post multiply; Clear: Pre multiply
\param Dx X offset
\param Dy Y offset
EMF+ manual 2.3.9.7, Microsoft name: EmfPlusTranslateWorldTransform Record, Index 0x2D
*/
int U_PMR_TRANSLATEWORLDTRANSFORM_get(const char *contents, U_PMF_CMN_HDR *Header,
int *xmtype,
U_FLOAT *Dx, U_FLOAT *Dy){
if(!contents || !xmtype || !Dx || !Dy){ return(0); }
U_PMF_CMN_HDR lclHeader;
U_PMF_CMN_HDR_get(&contents, &lclHeader);
if(lclHeader.Size < sizeof(U_PMF_TRANSLATEWORLDTRANSFORM))return(0);
if(Header){ memcpy(Header,&lclHeader,sizeof(U_PMF_CMN_HDR)); }
*xmtype = (lclHeader.Flags & U_PPF_XM ? 1 : 0 );
U_PMF_SERIAL_get(&contents, Dx, 4, 1, U_LE);
U_PMF_SERIAL_get(&contents, Dy, 4, 1, U_LE);
return(1);
}
/**
\brief Get data from a U_PMR_STROKEFILLPATH record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual mentioned in 2.1.1.1, not otherwise documented, Microsoft name: EmfPlusStrokeFillPath Record, Index 0x37
"This record closes any open figures in a path, strokes the outline of
the path by using the current pen, and fills its interior by using the current brush."
*/
int U_PMR_STROKEFILLPATH_get(const char *contents, U_PMF_CMN_HDR *Header){
return( U_PMR_common_header_get(contents,Header));
}
/**
\brief Get data from a U_PMR_MULTIFORMATSTART record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatStart Record, Index 0x05
*/
int U_PMR_MULTIFORMATSTART_get(const char *contents, U_PMF_CMN_HDR *Header){
return( U_PMR_common_header_get(contents,Header));
}
/**
\brief Get data from a U_PMR_MULTIFORMATSECTION record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatSection Record, Index 0x06
*/
int U_PMR_MULTIFORMATSECTION_get(const char *contents, U_PMF_CMN_HDR *Header){
return( U_PMR_common_header_get(contents,Header));
}
/**
\brief Get data from a U_PMR_MULTIFORMATEND record
\return 1 on success, 0 on error
\param contents Record from which to extract data
\param Header Common header (ignore flags)
EMF+ manual mentioned in 2.1.1.1, reserved, not otherwise documented, Microsoft name: EmfPlusMultiFormatEnd Record, Index 0x06
*/
int U_PMR_MULTIFORMATEND_get(const char *contents, U_PMF_CMN_HDR *Header){
return( U_PMR_common_header_get(contents,Header));
}
#ifdef __cplusplus
}
#endif
|