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
|
/*
% Copyright (C) 2003-2020 GraphicsMagick Group
% Copyright (C) 2002 ImageMagick Studio
%
% This program is covered by multiple licenses, which are described in
% Copyright.txt. You should have received a copy of Copyright.txt with this
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W W M M FFFFF %
% W W MM MM F %
% W W W M M M FFF %
% WW WW M M F %
% W W M M F %
% %
% %
% Read Windows Metafile Format. %
% %
% %
% Software Design %
% Bob Friesenhahn %
% Dec 2000 - May 2001 %
% Oct 2001 - May 2002 %
% %
% Port to libwmf 0.2 API %
% Francis J. Franklin %
% May 2001 - Oct 2001 %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
/*
* Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/pixel_cache.h"
#include "magick/color.h"
#include "magick/color_lookup.h"
#include "magick/constitute.h"
#include "magick/draw.h"
#include "magick/log.h"
#include "magick/magick.h"
#include "magick/monitor.h"
#include "magick/paint.h"
#include "magick/transform.h"
#include "magick/utility.h"
#include "magick/version.h"
#if defined(MSWINDOWS)
/* The need for this under Visual C++ is a mystery to me */
# if !defined(M_PI)
# define M_PI MagickPI
# endif
#endif
#if defined(HasWMF) || defined(HasWMFlite)
#undef ERR
#define ERR(API) ((API)->err != wmf_E_None)
#define XC(x) ((double)x)
#define YC(y) ((double)y)
#if defined(HAVE_FT2BUILD_H)
/* Some libwmf/FreeType installs are broken in that the libwmf
headers don't work without including <ft2build.h> first */
# include <ft2build.h>
#endif /* defined(HAVE_FT2BUILD_H) */
#include "libwmf/fund.h"
#include "libwmf/types.h"
#include "libwmf/api.h"
#undef SRCCOPY
#undef SRCPAINT
#undef SRCAND
#undef SRCINVERT
#undef SRCERASE
#undef NOTSRCCOPY
#undef NOTSRCERASE
#undef MERGECOPY
#undef MERGEPAINT
#undef PATCOPY
#undef PATPAINT
#undef PATINVERT
#undef DSTINVERT
#undef BLACKNESS
#undef WHITENESS
/* The following additinal undefs were required for MinGW */
#undef BS_HOLLOW
#undef PS_STYLE_MASK
#undef PS_ENDCAP_ROUND
#undef PS_ENDCAP_SQUARE
#undef PS_ENDCAP_FLAT
#undef PS_ENDCAP_MASK
#undef PS_JOIN_ROUND
#undef PS_JOIN_BEVEL
#undef PS_JOIN_MITER
#undef PS_COSMETIC
#undef PS_GEOMETRIC
#undef PS_TYPE_MASK
#undef STRETCH_ANDSCANS
#undef STRETCH_ORSCANS
#undef STRETCH_DELETESCANS
#undef STRETCH_HALFTONE
#undef ETO_OPAQUE
#undef ETO_CLIPPED
#undef ETO_GLYPH_INDEX
#undef ETO_RTLREADING
#include "libwmf/defs.h"
#include "libwmf/ipa.h"
#include "libwmf/color.h"
#include "libwmf/macro.h"
/* Unit conversions */
#define TWIPS_PER_INCH 1440
#define CENTIMETERS_PER_INCH 2.54
#define POINTS_PER_INCH 72
#if defined(HasWMFlite)
# define wmf_api_create(api,flags,options) wmf_lite_create(api,flags,options)
# define wmf_api_destroy(api) wmf_lite_destroy(api)
# undef WMF_FONT_PSNAME
# define WMF_FONT_PSNAME(F) ((F)->user_data ? ((wmf_magick_font_t*) (F)->user_data)->ps_name : 0)
typedef struct _wmf_magick_font_t wmf_magick_font_t;
struct _wmf_magick_font_t
{
char* ps_name;
double pointsize;
};
#endif
typedef struct _wmf_magick_t wmf_magick_t;
struct _wmf_magick_t
{
/* Bounding box */
wmfD_Rect
bbox;
/* Scale and translation factors */
double
scale_x,
scale_y,
translate_x,
translate_y,
rotate;
/* Vector output */
DrawContext
draw_context;
/* GraphicsMagick image */
Image
*image;
/* ImageInfo */
const ImageInfo
*image_info;
/* DrawInfo */
DrawInfo
*draw_info;
/* Pattern ID */
unsigned long
pattern_id;
/* Clip path flag */
unsigned int
clipping;
/* Clip path ID */
unsigned long
clip_path_id;
/* Push depth */
long
push_depth;
};
#define WMF_MAGICK_GetData(Z) ((wmf_magick_t*)((Z)->device_data))
#define WMF_MAGICK_GetFontData(Z) ((wmf_magick_font_t*)((wmfFontData *)Z->font_data)->user_data)
#define WmfDrawContext (((wmf_magick_t*)((API)->device_data))->draw_context)
/* Enum to control whether util_set_brush applies brush to fill or
stroke. */
typedef enum
{
BrushApplyFill,
BrushApplyStroke
} BrushApply;
/* Enum to specify arc type */
typedef enum
{
magick_arc_ellipse = 0,
magick_arc_open,
magick_arc_pie,
magick_arc_chord
}
magick_arc_t;
#if defined(HasWMFlite)
static void lite_font_init (wmfAPI* API, wmfAPI_Options* options);
static void lite_font_map(wmfAPI* API,wmfFont* font);
static float lite_font_stringwidth(wmfAPI* API, wmfFont* font, char* str);
#endif
static void draw_color_fill_rgb(wmfAPI* API, const wmfRGB* rgb);
static void draw_color_stroke_rgb(wmfAPI* API, const wmfRGB* rgb);
static void draw_pattern_push(wmfAPI* API, unsigned long id, unsigned long columns, unsigned long rows);
static int ipa_blob_read(void* context);
static int ipa_blob_seek(void* context,long position);
static long ipa_blob_tell(void* context);
static void ipa_bmp_draw(wmfAPI * API, wmfBMP_Draw_t * bmp_draw);
static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp);
static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read);
static void ipa_device_begin(wmfAPI * API);
static void ipa_device_close(wmfAPI * API);
static void ipa_device_end(wmfAPI * API);
static void ipa_device_open(wmfAPI * API);
static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc);
static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc);
static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc);
static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line);
static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc);
static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel);
static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * poly_line);
#if defined(HasWMFlite)
static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon);
#endif
static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect);
static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text);
static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood);
static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood);
static void ipa_functions(wmfAPI * API);
static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * poly_line);
static void ipa_region_clip(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw);
static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata);
static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata);
static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata);
static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata);
static int magick_progress_callback(void* context,float quantum);
static void util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish);
#if defined(HasWMFlite)
static int util_font_weight( const char* font );
#endif
static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height);
static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply);
static void util_set_pen(wmfAPI * API, wmfDC * dc);
/* Progress callback */
static int magick_progress_callback (void* context,float quantum)
{
Image
*image;
unsigned int
status = 0;
image=(Image *) context;
if (MagickMonitorFormatted((ExtendedSignedIntegralType)floor(quantum*100),100,
&image->exception,(char*)context,
image->filename) == False)
status = 1;
return status;
}
/* Set fill color */
static void draw_color_fill_rgb( wmfAPI* API, const wmfRGB* rgb )
{
PixelPacket
fill_color;
fill_color.red = ScaleCharToQuantum(rgb->r);
fill_color.green = ScaleCharToQuantum(rgb->g);
fill_color.blue = ScaleCharToQuantum(rgb->b);
fill_color.opacity = OpaqueOpacity;
DrawSetFillColor(WmfDrawContext,&fill_color);
}
/* Set stroke color */
static void draw_color_stroke_rgb( wmfAPI* API, const wmfRGB* rgb )
{
PixelPacket
stroke_color;
stroke_color.red = ScaleCharToQuantum(rgb->r);
stroke_color.green = ScaleCharToQuantum(rgb->g);
stroke_color.blue = ScaleCharToQuantum(rgb->b);
stroke_color.opacity = OpaqueOpacity;
DrawSetStrokeColor(WmfDrawContext,&stroke_color);
}
static void draw_pattern_push( wmfAPI* API,
unsigned long id,
unsigned long columns,
unsigned long rows )
{
char
pattern_id[MaxTextExtent];
FormatString(pattern_id,"brush_%lu",id);
DrawPushPattern(WmfDrawContext,pattern_id,0,0,columns,rows);
}
/* Pattern/Bit BLT with raster operation (ROP) support. Invoked by
META_PATBLT, which is equivalent to Windows PatBlt() call, or by
META_DIBBITBLT which is equivalent to Windows BitBlt() call. */
/* The BitBlt function transfers pixels from a rectangular area in one
device context called the 'source', to a rectangular area of the
same size in another device context, called the 'destination'. */
static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw)
{
/* wmfBrush */
/* *brush = WMF_DC_BRUSH(rop_draw->dc); */
/* wmfBMP */
/* *brush_bmp = WMF_BRUSH_BITMAP(brush); */
if (!TO_FILL(rop_draw))
return;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
/* FIXME: finish implementing (once we know what it is supposed to do!) */
/*
struct _wmfROP_Draw_t
{ wmfDC* dc;
wmfD_Coord TL;
wmfD_Coord BR;
U32 ROP;
double pixel_width;
double pixel_height;
};
*/
/* if(brush_bmp && brush_bmp->data != 0) */
/* printf("Have an image!\n"); */
switch (rop_draw->ROP) /* Ternary raster operations */
{
case SRCCOPY: /* dest = source */
(void) printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n");
break;
case SRCPAINT: /* dest = source OR dest */
(void) printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n");
break;
case SRCAND: /* dest = source AND dest */
(void) printf("ipa_rop_draw SRCAND ROP mode not implemented\n");
break;
case SRCINVERT: /* dest = source XOR dest */
(void) printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n");
break;
case SRCERASE: /* dest = source AND (NOT dest) */
(void) printf("ipa_rop_draw SRCERASE ROP mode not implemented\n");
break;
case NOTSRCCOPY: /* dest = (NOT source) */
(void) printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n");
break;
case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
(void) printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n");
break;
case MERGECOPY: /* dest = (source AND pattern) */
(void) printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n");
break;
case MERGEPAINT: /* dest = (NOT source) OR dest */
(void) printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n");
break;
case PATCOPY: /* dest = pattern */
util_set_brush(API, rop_draw->dc, BrushApplyFill);
break;
case PATPAINT: /* dest = DPSnoo */
(void) printf("ipa_rop_draw PATPAINT ROP mode not implemented\n");
break;
case PATINVERT: /* dest = pattern XOR dest */
(void) printf("ipa_rop_draw PATINVERT ROP mode not implemented\n");
break;
case DSTINVERT: /* dest = (NOT dest) */
(void) printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n");
break;
case BLACKNESS: /* dest = BLACK */
DrawSetFillColorString(WmfDrawContext,"black");
break;
case WHITENESS: /* dest = WHITE */
DrawSetFillColorString(WmfDrawContext,"white");
break;
default:
(void) printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP);
break;
}
DrawRectangle(WmfDrawContext,
XC(rop_draw->TL.x), YC(rop_draw->TL.y),
XC(rop_draw->BR.x), YC(rop_draw->BR.y));
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_bmp_draw(wmfAPI *API, wmfBMP_Draw_t *bmp_draw)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
ExceptionInfo
exception;
Image
*image;
double
height,
width;
MonitorHandler
handler;
PixelPacket
white;
if (bmp_draw->bmp.data == 0)
return;
GetExceptionInfo(&exception);
image = (Image*)bmp_draw->bmp.data;
if(!image)
{
CopyException(&ddata->image->exception,&exception);
return;
}
if(bmp_draw->crop.x || bmp_draw->crop.y ||
(bmp_draw->crop.w != bmp_draw->bmp.width) ||
(bmp_draw->crop.h != bmp_draw->bmp.height))
{
/* Image needs to be cropped */
Image
*crop_image;
RectangleInfo
crop_info;
crop_info.x = bmp_draw->crop.x;
crop_info.y = bmp_draw->crop.y;
crop_info.width = bmp_draw->crop.w;
crop_info.height = bmp_draw->crop.h;
handler=SetMonitorHandler((MonitorHandler) NULL);
crop_image = CropImage( image, &crop_info, &exception );
(void) SetMonitorHandler(handler);
if(crop_image)
{
DestroyImageList(image);
image = crop_image;
bmp_draw->bmp.data = (void*)image;
}
else
CopyException(&ddata->image->exception,&exception);
}
(void) QueryColorDatabase( "white", &white, &exception );
if ( ddata->image_info->texture ||
!(ColorMatch(&ddata->image_info->background_color, &white)) ||
ddata->image_info->background_color.opacity != OpaqueOpacity )
{
/*
Set image white background to transparent so that it may be
overlaid over non-white backgrounds.
*/
(void) TransparentImage( image, white, MaxRGB );
}
width = AbsoluteValue(bmp_draw->pixel_width * (double) bmp_draw->crop.w);
height = AbsoluteValue(bmp_draw->pixel_height * (double) bmp_draw->crop.h);
DrawComposite(WmfDrawContext, CopyCompositeOp, XC(bmp_draw->pt.x), YC(bmp_draw->pt.y),
width, height, image );
#if 0
printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data);
printf("registry id = %li\n", id);
/* printf("pixel_width = %.4g\n", bmp_draw->pixel_width); */
/* printf("pixel_height = %.4g\n", bmp_draw->pixel_height); */
printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height);
printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h);
printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y);
printf("image size WxH = %lux%lu\n", image->columns, image->rows);
#endif
}
static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) {
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
ExceptionInfo
exception;
ImageInfo
*image_info;
Image
*image;
MonitorHandler
handler;
bmp_read->bmp.data = 0;
GetExceptionInfo(&exception);
image_info = CloneImageInfo((ImageInfo *) 0);
(void) strcpy(image_info->magick, "DIB");
if(bmp_read->width || bmp_read->height)
{
char
size[MaxTextExtent];
FormatString(size,"%ux%u",bmp_read->width,bmp_read->height);
(void) CloneString(&image_info->size,size);
}
#if 0
printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n",
(long) bmp_read->buffer, bmp_read->length,
bmp_read->width, bmp_read->height);
#endif
handler=SetMonitorHandler((MonitorHandler) NULL);
image = BlobToImage(image_info, (const void *) bmp_read->buffer,
bmp_read->length, &exception);
(void) SetMonitorHandler(handler);
DestroyImageInfo(image_info);
if (!image)
{
char
description[MaxTextExtent];
FormatString(description,"packed DIB at offset %ld", bmp_read->offset);
ThrowException2(&ddata->image->exception,CorruptImageError,
exception.reason,exception.description);
}
else
{
#if 0
printf("ipa_bmp_read: rows=%ld,columns=%ld\n\n", image->rows, image->columns);
#endif
bmp_read->bmp.data = (void*)image;
bmp_read->bmp.width = (U16)image->columns;
bmp_read->bmp.height = (U16)image->rows;
}
}
static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp)
{
ARG_NOT_USED(API);
DestroyImageList((Image*)bmp->data);
bmp->data = (void*) 0;
bmp->width = (U16) 0;
bmp->height = (U16) 0;
}
/*
This is called by wmf_play() the *first* time the meta file is played
*/
static void ipa_device_open(wmfAPI * API)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData (API);
ddata->pattern_id = 0;
ddata->clipping = False;
ddata->clip_path_id = 0;
ddata->push_depth = 0;
ddata->draw_context = DrawAllocateContext(ddata->draw_info,ddata->image);
}
/*
This is called by wmf_api_destroy()
*/
static void ipa_device_close(wmfAPI * API)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
if (ddata->draw_context != (DrawContext) NULL)
{
DrawDestroyContext(ddata->draw_context);
ddata->draw_context = (DrawContext) NULL;
}
if (ddata->draw_info != (DrawInfo *) NULL)
{
DestroyDrawInfo(ddata->draw_info);
ddata->draw_info = (DrawInfo *) NULL;
}
MagickFreeMemory(WMF_MAGICK_GetFontData(API)->ps_name);
}
/*
This is called from the beginning of each play for initial page setup
*/
static void ipa_device_begin(wmfAPI * API)
{
char
comment[MaxTextExtent];
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
/* Make SVG output happy */
DrawPushGraphicContext(WmfDrawContext);
DrawSetViewbox(WmfDrawContext, 0, 0, ddata->image->columns, ddata->image->rows );
FormatString(comment,"Created by %s",
GetMagickVersion((unsigned long *) NULL));
DrawComment(WmfDrawContext,comment);
/* Scale width and height to image */
DrawScale(WmfDrawContext, ddata->scale_x, ddata->scale_y);
/* Translate to TL corner of bounding box */
DrawTranslate(WmfDrawContext, ddata->translate_x, ddata->translate_y);
/* Apply rotation */
DrawRotate(WmfDrawContext, ddata->rotate);
if(ddata->image_info->texture == NULL)
{
/* Draw rectangle in background color */
DrawSetFillColor(WmfDrawContext,&ddata->image->background_color);
DrawRectangle(WmfDrawContext,
XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
}
else
{
/* Draw rectangle with texture image the SVG way */
Image
*image;
ImageInfo
*image_info;
ExceptionInfo
exception;
GetExceptionInfo(&exception);
image_info = CloneImageInfo((ImageInfo *) 0);
(void) strlcpy(image_info->filename, ddata->image_info->texture,
sizeof(image_info->filename));
if ( ddata->image_info->size )
(void) CloneString(&image_info->size,ddata->image_info->size);
image = ReadImage(image_info,&exception);
DestroyImageInfo(image_info);
if(image)
{
char
pattern_id[MaxTextExtent];
(void) strlcpy(image->magick,"MIFF",sizeof(image->magick));
DrawPushDefs(WmfDrawContext);
draw_pattern_push(API, ddata->pattern_id, image->columns, image->rows);
DrawComposite(WmfDrawContext, CopyCompositeOp, 0, 0, image->columns, image->rows, image);
DrawPopPattern(WmfDrawContext);
DrawPopDefs(WmfDrawContext);
FormatString(pattern_id,"#brush_%lu",ddata->pattern_id);
DrawSetFillPatternURL(WmfDrawContext,pattern_id);
++ddata->pattern_id;
DrawRectangle(WmfDrawContext,
XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
DestroyImageList(image);
}
else
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"reading texture image failed!");
CopyException(&ddata->image->exception,&exception);
}
}
DrawSetClipRule(WmfDrawContext,EvenOddRule); /* Default for WMF is ALTERNATE polygon fill mode */
DrawSetFillColorString(WmfDrawContext,"none"); /* Default brush is WHITE_BRUSH */
DrawSetStrokeColorString(WmfDrawContext,"none"); /* Default pen is BLACK_PEN */
DrawSetStrokeLineCap(WmfDrawContext,ButtCap); /* Default linecap is PS_ENDCAP_FLAT */
DrawSetStrokeLineJoin(WmfDrawContext,MiterJoin); /* Default linejoin is PS_JOIN_MITER */
DrawSetTextUnderColorString(WmfDrawContext,"white"); /* Default text box is white */
}
/*
This is called from the end of each play for page termination
*/
static void ipa_device_end(wmfAPI * API)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
/* Reset any existing clip paths by popping context */
if(ddata->clipping)
DrawPopGraphicContext(WmfDrawContext);
ddata->clipping = False;
/* Make SVG output happy */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
draw_color_fill_rgb(API,&(flood->color));
DrawColor(WmfDrawContext,XC(flood->pt.x), YC(flood->pt.y),
FillToBorderMethod);
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
draw_color_fill_rgb(API,&(flood->color));
if (flood->type == FLOODFILLSURFACE)
DrawColor(WmfDrawContext, XC(flood->pt.x), YC(flood->pt.y),
FloodfillMethod);
else
DrawColor(WmfDrawContext, XC(flood->pt.x), YC(flood->pt.y),
FillToBorderMethod);
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
DrawSetStrokeColorString(WmfDrawContext,"none");
draw_color_fill_rgb(API,&(draw_pixel->color));
DrawRectangle(WmfDrawContext,
XC(draw_pixel->pt.x),
YC(draw_pixel->pt.y),
XC(draw_pixel->pt.x + draw_pixel->pixel_width),
YC(draw_pixel->pt.y + draw_pixel->pixel_height));
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc)
{
util_draw_arc(API, draw_arc, magick_arc_pie);
}
static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc)
{
util_draw_arc(API, draw_arc, magick_arc_chord);
}
static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc)
{
util_draw_arc(API, draw_arc, magick_arc_open);
}
static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc)
{
util_draw_arc(API, draw_arc, magick_arc_ellipse);
}
static void util_draw_arc(wmfAPI * API,
wmfDrawArc_t * draw_arc,
magick_arc_t finish)
{
wmfD_Coord
BR,
O,
TL,
centre,
end,
start;
double
phi_e = 360,
phi_s = 0;
double
Rx,
Ry;
end.x=0;
end.y=0;
start.x=0;
start.y=0;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
if (TO_FILL(draw_arc) || TO_DRAW(draw_arc))
{
centre.x = (draw_arc->TL.x + draw_arc->BR.x) / 2;
centre.y = (draw_arc->TL.y + draw_arc->BR.y) / 2;
if (finish != magick_arc_ellipse)
{
draw_arc->start.x += centre.x;
draw_arc->start.y += centre.y;
draw_arc->end.x += centre.x;
draw_arc->end.y += centre.y;
}
TL = draw_arc->TL;
BR = draw_arc->BR;
O = centre;
if (finish != magick_arc_ellipse)
{
start = draw_arc->start;
end = draw_arc->end;
}
Rx = (BR.x - TL.x) / 2;
Ry = (BR.y - TL.y) / 2;
if (finish != magick_arc_ellipse)
{
start.x -= O.x;
start.y -= O.y;
end.x -= O.x;
end.y -= O.y;
phi_s = atan2((double) start.y, (double) start.x) * 180 / MagickPI;
phi_e = atan2((double) end.y, (double) end.x) * 180 / MagickPI;
if (phi_e <= phi_s)
phi_e += 360;
}
util_set_pen(API, draw_arc->dc);
if (finish == magick_arc_open)
DrawSetFillColorString(WmfDrawContext,"none");
else
util_set_brush(API, draw_arc->dc, BrushApplyFill);
if (finish == magick_arc_ellipse)
DrawEllipse(WmfDrawContext, XC(O.x), YC(O.y), Rx, Ry, 0, 360);
else if (finish == magick_arc_pie)
{
DrawPathStart(WmfDrawContext);
DrawPathMoveToAbsolute(WmfDrawContext,
XC(O.x+start.x),YC(O.y+start.y));
DrawPathEllipticArcAbsolute(WmfDrawContext, Rx, Ry, 0, 0, 1,
XC(O.x+end.x),YC(O.y+end.y));
DrawPathLineToAbsolute(WmfDrawContext, XC(O.x), YC(O.y));
DrawPathClose(WmfDrawContext);
DrawPathFinish(WmfDrawContext);
}
else if (finish == magick_arc_chord)
{
DrawArc(WmfDrawContext,
XC(draw_arc->TL.x), YC(draw_arc->TL.y),
XC(draw_arc->BR.x), XC(draw_arc->BR.y),
phi_s, phi_e);
DrawLine(WmfDrawContext,
XC(draw_arc->BR.x-start.x), YC(draw_arc->BR.y-start.y),
XC(draw_arc->BR.x-end.x), YC(draw_arc->BR.y-end.y));
}
else /* if (finish == magick_arc_open) */
DrawArc(WmfDrawContext,
XC(draw_arc->TL.x), YC(draw_arc->TL.y),
XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
if (TO_DRAW(draw_line))
{
util_set_pen(API, draw_line->dc);
DrawLine(WmfDrawContext,
XC(draw_line->from.x), YC(draw_line->from.y),
XC(draw_line->to.x), YC(draw_line->to.y));
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * polyline)
{
if (polyline->count <= 2)
return;
if (TO_DRAW(polyline))
{
int
point;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
util_set_pen(API, polyline->dc);
DrawPathStart(WmfDrawContext);
DrawPathMoveToAbsolute(WmfDrawContext,
XC(polyline->pt[0].x),
YC(polyline->pt[0].y));
for (point = 1; point < polyline->count; point++)
{
DrawPathLineToAbsolute(WmfDrawContext,
XC(polyline->pt[point].x),
YC(polyline->pt[point].y));
}
DrawPathFinish(WmfDrawContext);
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
}
static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * polyline)
{
if (polyline->count <= 2)
return;
if (TO_FILL(polyline) || TO_DRAW(polyline))
{
int
point;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
util_set_pen(API, polyline->dc);
util_set_brush(API, polyline->dc, BrushApplyFill);
DrawPathStart(WmfDrawContext);
DrawPathMoveToAbsolute(WmfDrawContext,
XC(polyline->pt[0].x),
YC(polyline->pt[0].y));
for (point = 1; point < polyline->count; point++)
{
DrawPathLineToAbsolute(WmfDrawContext,
XC(polyline->pt[point].x),
YC(polyline->pt[point].y));
}
DrawPathClose(WmfDrawContext);
DrawPathFinish(WmfDrawContext);
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
}
/* Draw a polypolygon. A polypolygon is a list of polygons */
#if defined(HasWMFlite)
static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
{
if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
{
int
polygon,
point;
wmfPolyLine_t
polyline;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
util_set_pen(API, polypolygon->dc);
util_set_brush(API, polypolygon->dc, BrushApplyFill);
DrawPathStart(WmfDrawContext);
for (polygon = 0; polygon < polypolygon->npoly; polygon++)
{
polyline.dc = polypolygon->dc;
polyline.pt = polypolygon->pt[polygon];
polyline.count = polypolygon->count[polygon];
if ((polyline.count > 2) && polyline.pt)
{
DrawPathMoveToAbsolute(WmfDrawContext,
XC(polyline.pt[0].x),
YC(polyline.pt[0].y));
for (point = 1; point < polyline.count; point++)
{
DrawPathLineToAbsolute(WmfDrawContext,
XC(polyline.pt[point].x),
YC(polyline.pt[point].y));
}
DrawPathClose(WmfDrawContext);
}
}
DrawPathFinish(WmfDrawContext);
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
}
#endif
static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
if (TO_FILL(draw_rect) || TO_DRAW(draw_rect))
{
util_set_pen(API, draw_rect->dc);
util_set_brush(API, draw_rect->dc, BrushApplyFill);
if ((draw_rect->width > 0) || (draw_rect->height > 0))
DrawRoundRectangle(WmfDrawContext,
XC(draw_rect->TL.x), YC(draw_rect->TL.y),
XC(draw_rect->BR.x), YC(draw_rect->BR.y),
draw_rect->width / 2, draw_rect->height / 2);
else
DrawRectangle(WmfDrawContext,
XC(draw_rect->TL.x), YC(draw_rect->TL.y),
XC(draw_rect->BR.x), YC(draw_rect->BR.y));
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
/* Draw an un-filled rectangle using the current brush */
static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
{
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
if (TO_FILL(poly_rect) || TO_DRAW(poly_rect))
{
unsigned int
i;
DrawSetFillColorString(WmfDrawContext,"none");
util_set_brush(API, poly_rect->dc, BrushApplyStroke);
for (i = 0; i < poly_rect->count; i++)
{
DrawRectangle(WmfDrawContext,
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
}
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
{
if (poly_rect->count == 0)
return;
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
if (TO_FILL (poly_rect))
{
unsigned int
i;
DrawSetStrokeColorString(WmfDrawContext,"none");
util_set_brush(API, poly_rect->dc, BrushApplyFill);
for (i = 0; i < poly_rect->count; i++)
{
DrawRectangle(WmfDrawContext,
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
}
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
}
static void ipa_region_clip(wmfAPI *API, wmfPolyRectangle_t *poly_rect)
{
unsigned int
i;
wmf_magick_t
*ddata = WMF_MAGICK_GetData (API);
/* Reset any existing clip paths by popping context */
if(ddata->clipping)
DrawPopGraphicContext(WmfDrawContext);
ddata->clipping = False;
if(poly_rect->count > 0)
{
char
clip_path_id[MaxTextExtent];
/* Define clip path */
ddata->clip_path_id++;
DrawPushDefs(WmfDrawContext);
FormatString(clip_path_id,"clip_%lu",ddata->clip_path_id);
DrawPushClipPath(WmfDrawContext,clip_path_id);
DrawPushGraphicContext(WmfDrawContext);
for (i = 0; i < poly_rect->count; i++)
{
DrawRectangle(WmfDrawContext,
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
}
DrawPopGraphicContext(WmfDrawContext);
DrawPopClipPath(WmfDrawContext);
DrawPopDefs(WmfDrawContext);
/* Push context for new clip paths */
DrawPushGraphicContext(WmfDrawContext);
DrawSetClipPath(WmfDrawContext,clip_path_id);
ddata->clipping = True;
}
}
static void ipa_functions(wmfAPI *API)
{
wmf_magick_t
*ddata = 0;
wmfFunctionReference
*FR = (wmfFunctionReference *) API->function_reference;
/*
IPA function reference links
*/
FR->device_open = ipa_device_open;
FR->device_close = ipa_device_close;
FR->device_begin = ipa_device_begin;
FR->device_end = ipa_device_end;
FR->flood_interior = ipa_flood_interior;
FR->flood_exterior = ipa_flood_exterior;
FR->draw_pixel = ipa_draw_pixel;
FR->draw_pie = ipa_draw_pie;
FR->draw_chord = ipa_draw_chord;
FR->draw_arc = ipa_draw_arc;
FR->draw_ellipse = ipa_draw_ellipse;
FR->draw_line = ipa_draw_line;
FR->poly_line = ipa_poly_line;
FR->draw_polygon = ipa_draw_polygon;
#if defined(HasWMFlite)
FR->draw_polypolygon = ipa_draw_polypolygon;
#endif
FR->draw_rectangle = ipa_draw_rectangle;
FR->rop_draw = ipa_rop_draw;
FR->bmp_draw = ipa_bmp_draw;
FR->bmp_read = ipa_bmp_read;
FR->bmp_free = ipa_bmp_free;
FR->draw_text = ipa_draw_text;
FR->udata_init = ipa_udata_init;
FR->udata_copy = ipa_udata_copy;
FR->udata_set = ipa_udata_set;
FR->udata_free = ipa_udata_free;
FR->region_frame = ipa_region_frame;
FR->region_paint = ipa_region_paint;
FR->region_clip = ipa_region_clip;
/*
Allocate device data structure
*/
ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t));
if (ERR(API))
return;
(void) memset((void *) ddata, 0, sizeof(wmf_magick_t));
API->device_data = (void *) ddata;
/*
Device data defaults
*/
ddata->image = 0;
}
static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text)
{
double
angle = 0, /* text rotation angle */
pointsize = 0; /* pointsize to output font with desired height */
TypeMetric
metrics;
#if !defined(HasWMFlite)
double
bbox_height, /* bounding box height */
bbox_width /* bounding box width */
wmfD_Coord
BL, /* bottom left of bounding box */
BR, /* bottom right of bounding box */
TL, /* top left of bounding box */
TR; /* top right of bounding box */
#endif
wmfD_Coord
point; /* text placement point */
wmfFont
*font;
wmf_magick_t
* ddata = WMF_MAGICK_GetData(API);
point = draw_text->pt;
/* Choose bounding box and calculate its width and height */
#if !defined(HasWMFlite)
{
double
dx,
dy;
if( draw_text->flags)
{
TL = draw_text->TL;
BR = draw_text->BR;
TR.x = draw_text->BR.x;
TR.y = draw_text->TL.y;
BL.x = draw_text->TL.x;
BL.y = draw_text->BR.y;
}
else
{
TL = draw_text->bbox.TL;
BR = draw_text->bbox.BR;
TR = draw_text->bbox.TR;
BL = draw_text->bbox.BL;
}
dx = ((TR.x - TL.x) + (BR.x - BL.x)) / 2;
dy = ((TR.y - TL.y) + (BR.y - BL.y)) / 2;
bbox_width = sqrt(dx * dx + dy * dy);
dx = ((BL.x - TL.x) + (BR.x - TR.x)) / 2;
dy = ((BL.y - TL.y) + (BR.y - TR.y)) / 2;
bbox_height = sqrt(dx * dx + dy * dy);
}
}
#endif
font = WMF_DC_FONT(draw_text->dc);
/* Convert font_height to equivalent pointsize */
pointsize = util_pointsize( API, font, draw_text->str, draw_text->font_height);
/* Save graphic context */
DrawPushGraphicContext(WmfDrawContext);
#if 0
printf("\nipa_draw_text\n");
printf("Text = \"%s\"\n", draw_text->str);
/* printf("WMF_FONT_NAME: = \"%s\"\n", WMF_FONT_NAME(font)); */
printf("WMF_FONT_PSNAME: = \"%s\"\n", WMF_FONT_PSNAME(font));
printf("Bounding box TL=%.4g,%.4g BR=%.4g,%.4g\n",
TL.x, TL.y, BR.x, BR.y );
/* printf("Text box = %.4gx%.4g\n", bbox_width, bbox_height); */
/* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
printf("Pointsize = %.4g\n", pointsize);
fflush(stdout);
#endif
/*
* Obtain font metrics if required
*
*/
if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER) ||
(WMF_TEXT_UNDERLINE(font)) || (WMF_TEXT_STRIKEOUT(font)))
{
Image
*image = ddata->image;
DrawInfo
*draw_info;
draw_info=ddata->draw_info;
draw_info->font=WMF_FONT_PSNAME(font);
draw_info->pointsize = pointsize;
draw_info->text=draw_text->str;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
{
/* Center the text if it is not yet centered and should be */
if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER))
{
double
text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
#if defined(HasWMFlite)
point.x -= text_width / 2;
#else
point.x += bbox_width / 2 - text_width / 2;
#endif
}
}
draw_info->font=NULL;
draw_info->text=NULL;
}
/* Set text background color */
if (draw_text->flags & ETO_OPAQUE)
{
/* Draw bounding-box background color (META_EXTTEXTOUT mode) */
DrawSetStrokeColorString(WmfDrawContext,"none");
draw_color_fill_rgb(API,WMF_DC_BACKGROUND(draw_text->dc));
DrawRectangle(WmfDrawContext,
XC(draw_text->TL.x),YC(draw_text->TL.y),
XC(draw_text->BR.x),YC(draw_text->BR.y));
DrawSetFillColorString(WmfDrawContext,"none");
}
else
{
/* Set text undercolor */
if (WMF_DC_OPAQUE(draw_text->dc))
{
wmfRGB
*box = WMF_DC_BACKGROUND(draw_text->dc);
PixelPacket
under_color;
under_color.red = ScaleCharToQuantum(box->r);
under_color.green = ScaleCharToQuantum(box->g);
under_color.blue = ScaleCharToQuantum(box->b);
under_color.opacity = OpaqueOpacity;
DrawSetTextUnderColor(WmfDrawContext,&under_color);
}
else
DrawSetTextUnderColorString(WmfDrawContext,"none");
}
/* Set text clipping (META_EXTTEXTOUT mode) */
if( draw_text->flags & ETO_CLIPPED)
{
}
/* Set stroke color */
DrawSetStrokeColorString(WmfDrawContext,"none");
/* Set fill color */
draw_color_fill_rgb(API,WMF_DC_TEXTCOLOR(draw_text->dc));
/* Output font size */
DrawSetFontSize(WmfDrawContext,pointsize);
/* Output Postscript font name */
DrawSetFont(WmfDrawContext, WMF_FONT_PSNAME(font));
/* Translate coordinates so target is 0,0 */
DrawTranslate(WmfDrawContext, XC(point.x), YC(point.y));
/* Transform horizontal scale to draw text at 1:1 ratio */
DrawScale(WmfDrawContext, ddata->scale_y / ddata->scale_x, 1.0);
/* Apply rotation */
/* GraphicsMagick's drawing rotation is clockwise from horizontal
while WMF drawing rotation is counterclockwise from horizontal */
angle = AbsoluteValue(RadiansToDegrees(2 * MagickPI - WMF_TEXT_ANGLE(font)));
if (angle == 360)
angle = 0;
if (angle != 0)
DrawRotate(WmfDrawContext, angle);
/*
* Render text
*
*/
/* Output string */
DrawAnnotation(WmfDrawContext, 0, 0, (unsigned char*)draw_text->str);
/* Underline text the Windows way (at the bottom) */
if (WMF_TEXT_UNDERLINE(font))
{
double
line_height;
wmfD_Coord
ulBR, /* bottom right of underline rectangle */
ulTL; /* top left of underline rectangle */
line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
if(metrics.underline_thickness < 1.5)
line_height *= 0.55;
ulTL.x = 0;
ulTL.y = AbsoluteValue(metrics.descent) - line_height;
ulBR.x = metrics.width;
ulBR.y = AbsoluteValue(metrics.descent);
DrawRectangle(WmfDrawContext,
XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
}
/* Strikeout text the Windows way */
if (WMF_TEXT_STRIKEOUT(font))
{
double line_height;
wmfD_Coord
ulBR, /* bottom right of strikeout rectangle */
ulTL; /* top left of strikeout rectangle */
line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
if(metrics.underline_thickness < 2.0)
line_height *= 0.55;
ulTL.x = 0;
ulTL.y = -(((double) metrics.ascent) / 2 + line_height / 2);
ulBR.x = metrics.width;
ulBR.y = -(((double) metrics.ascent) / 2 - line_height / 2);
DrawRectangle(WmfDrawContext,
XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
}
/* Restore graphic context */
DrawPopGraphicContext(WmfDrawContext);
#if 0
DrawPushGraphicContext(WmfDrawContext);
DrawSetStrokeColorString(WmfDrawContext,"red");
DrawSetFillColorString(WmfDrawContext,"none");
DrawRectangle(WmfDrawContext,
XC(TL.x), YC(TL.y),
XC(BR.x), YC(BR.y));
DrawSetStrokeColorString(WmfDrawContext,"none");
DrawPopGraphicContext(WmfDrawContext);
#endif
}
static void ipa_udata_init(wmfAPI *API, wmfUserData_t *userdata)
{
ARG_NOT_USED(API);
ARG_NOT_USED(userdata);
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
}
static void ipa_udata_copy(wmfAPI *API, wmfUserData_t *userdata)
{
ARG_NOT_USED(API);
ARG_NOT_USED(userdata);
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
}
static void ipa_udata_set(wmfAPI *API, wmfUserData_t *userdata)
{
ARG_NOT_USED(API);
ARG_NOT_USED(userdata);
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
}
static void ipa_udata_free(wmfAPI *API, wmfUserData_t *userdata)
{
ARG_NOT_USED(API);
ARG_NOT_USED(userdata);
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
}
static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
wmfBrush
*brush = WMF_DC_BRUSH(dc);
/* Set polygon fill rule */
switch (WMF_DC_POLYFILL(dc)) /* Is this correct ?? */
{
case WINDING:
DrawSetClipRule(WmfDrawContext,NonZeroRule);
break;
case ALTERNATE:
default:
DrawSetClipRule(WmfDrawContext,EvenOddRule);
break;
}
switch (WMF_BRUSH_STYLE(brush))
{
case BS_SOLID /* 0 */:
/* WMF_BRUSH_COLOR specifies brush color, WMF_BRUSH_HATCH
ignored */
{
if( brush_apply == BrushApplyStroke )
draw_color_stroke_rgb(API,WMF_BRUSH_COLOR(brush));
else
draw_color_fill_rgb(API,WMF_BRUSH_COLOR(brush));
break;
}
case BS_HOLLOW /* 1 */: /* BS_HOLLOW & BS_NULL share enum */
/* WMF_BRUSH_COLOR and WMF_BRUSH_HATCH ignored */
{
if( brush_apply == BrushApplyStroke )
DrawSetStrokeColorString(WmfDrawContext,"none");
else
DrawSetFillColorString(WmfDrawContext,"none");
break;
}
case BS_HATCHED /* 2 */:
/* WMF_BRUSH_COLOR specifies the hatch color, WMF_BRUSH_HATCH
specifies the hatch brush style. If WMF_DC_OPAQUE, then
WMF_DC_BACKGROUND specifies hatch background color. */
{
DrawPushDefs(WmfDrawContext);
draw_pattern_push(API, ddata->pattern_id, 8, 8);
DrawPushGraphicContext(WmfDrawContext);
if (WMF_DC_OPAQUE(dc))
{
if( brush_apply == BrushApplyStroke )
draw_color_stroke_rgb(API,WMF_DC_BACKGROUND(dc));
else
draw_color_fill_rgb(API,WMF_DC_BACKGROUND(dc));
DrawRectangle(WmfDrawContext, 0, 0, 7, 7 );
}
DrawSetStrokeAntialias(WmfDrawContext, False);
DrawSetStrokeWidth(WmfDrawContext, 1);
draw_color_stroke_rgb(API,WMF_BRUSH_COLOR(brush));
switch ((unsigned int) WMF_BRUSH_HATCH(brush))
{
case HS_HORIZONTAL: /* ----- */
{
DrawLine(WmfDrawContext, 0, 3, 7,3);
break;
}
case HS_VERTICAL: /* ||||| */
{
DrawLine(WmfDrawContext, 3, 0, 3, 7);
break;
}
case HS_FDIAGONAL: /* \\\\\ */
{
DrawLine(WmfDrawContext, 0, 0, 7, 7);
break;
}
case HS_BDIAGONAL: /* ///// */
{
DrawLine(WmfDrawContext, 0, 7, 7, 0 );
break;
}
case HS_CROSS: /* +++++ */
{
DrawLine(WmfDrawContext, 0, 3, 7, 3 );
DrawLine(WmfDrawContext, 3, 0, 3, 7 );
break;
}
case HS_DIAGCROSS: /* xxxxx */
{
DrawLine(WmfDrawContext, 0, 0, 7, 7 );
DrawLine(WmfDrawContext, 0, 7, 7, 0 );
break;
}
default:
{
(void) printf("util_set_brush: unexpected brush hatch enumeration %u\n",
(unsigned int)WMF_BRUSH_HATCH(brush));
}
}
DrawPopGraphicContext(WmfDrawContext);
DrawPopPattern(WmfDrawContext);
DrawPopDefs(WmfDrawContext);
{
char
pattern_id[MaxTextExtent];
FormatString(pattern_id, "#brush_%lu", ddata->pattern_id);
if( brush_apply == BrushApplyStroke )
DrawSetStrokePatternURL(WmfDrawContext,pattern_id);
else
DrawSetFillPatternURL(WmfDrawContext,pattern_id);
++ddata->pattern_id;
}
break;
}
case BS_PATTERN /* 3 */:
/* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides handle to
bitmap */
{
(void) printf("util_set_brush: BS_PATTERN not supported\n");
break;
}
case BS_INDEXED /* 4 */:
{
(void) printf("util_set_brush: BS_INDEXED not supported\n");
break;
}
case BS_DIBPATTERN /* 5 */:
{
wmfBMP
*brush_bmp = WMF_BRUSH_BITMAP(brush);
if (brush_bmp && brush_bmp->data != 0)
{
CompositeOperator
mode;
const Image
*image;
ExceptionInfo
exception;
GetExceptionInfo(&exception);
image = (Image*)brush_bmp->data;
mode = CopyCompositeOp; /* Default is copy */
switch (WMF_DC_ROP(dc))
{
/* Binary raster ops */
case R2_BLACK:
(void) printf("util_set_brush: R2_BLACK ROP2 mode not supported!\n");
break;
case R2_NOTMERGEPEN:
(void) printf("util_set_brush: R2_NOTMERGEPEN ROP2 mode not supported!\n");
break;
case R2_MASKNOTPEN:
(void) printf("util_set_brush R2_MASKNOTPEN ROP2 mode not supported!\n");
break;
case R2_NOTCOPYPEN:
(void) printf("util_set_brush: R2_NOTCOPYPEN ROP2 mode not supported!\n");
break;
case R2_MASKPENNOT:
(void) printf("util_set_brush: R2_MASKPENNOT ROP2 mode not supported!\n");
break;
case R2_NOT:
(void) printf("util_set_brush: R2_NOT ROP2 mode not supported!\n");
break;
case R2_XORPEN:
(void) printf("util_set_brush: R2_XORPEN ROP2 mode not supported!\n");
break;
case R2_NOTMASKPEN:
(void) printf("util_set_brush: R2_NOTMASKPEN ROP2 mode not supported!\n");
break;
case R2_MASKPEN:
(void) printf("util_set_brush: R2_MASKPEN ROP2 mode not supported!\n");
break;
case R2_NOTXORPEN:
(void) printf("util_set_brush: R2_NOTXORPEN ROP2 mode not supported!\n");
break;
case R2_NOP:
(void) printf("util_set_brush: R2_NOP ROP2 mode not supported!\n");
break;
case R2_MERGENOTPEN:
(void) printf("util_set_brush: R2_MERGENOTPEN ROP2 mode not supported!\n");
break;
case R2_COPYPEN:
mode = CopyCompositeOp;
break;
case R2_MERGEPENNOT:
(void) printf("util_set_brush: R2_MERGEPENNOT ROP2 mode not supported!\n");
break;
case R2_MERGEPEN:
(void) printf("util_set_brush: R2_MERGEPEN ROP2 mode not supported!\n");
break;
case R2_WHITE:
(void) printf("util_set_brush: R2_WHITE ROP2 mode not supported!\n");
break;
default:
{
(void) printf("util_set_brush: unexpected ROP2 enumeration %u!\n",
(unsigned int)WMF_DC_ROP(dc));
}
}
DrawPushDefs(WmfDrawContext);
draw_pattern_push(API, ddata->pattern_id, brush_bmp->width, brush_bmp->height);
DrawComposite(WmfDrawContext,mode, 0, 0, brush_bmp->width, brush_bmp->height, image);
DrawPopPattern(WmfDrawContext);
DrawPopDefs(WmfDrawContext);
{
char
pattern_id[MaxTextExtent];
FormatString(pattern_id, "#brush_%lu", ddata->pattern_id);
if( brush_apply == BrushApplyStroke )
DrawSetStrokePatternURL(WmfDrawContext,pattern_id);
else
DrawSetFillPatternURL(WmfDrawContext,pattern_id);
++ddata->pattern_id;
}
}
else
(void) printf("util_set_brush: no BMP image data!\n");
break;
}
case BS_DIBPATTERNPT /* 6 */:
/* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides pointer to
DIB */
{
(void) printf("util_set_brush: BS_DIBPATTERNPT not supported\n");
break;
}
case BS_PATTERN8X8 /* 7 */:
{
(void) printf("util_set_brush: BS_PATTERN8X8 not supported\n");
break;
}
case BS_DIBPATTERN8X8 /* 8 */:
{
(void) printf("util_set_brush: BS_DIBPATTERN8X8 not supported\n");
break;
}
default:
{
}
}
}
static void util_set_pen(wmfAPI * API, wmfDC * dc)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
wmfPen
*pen = 0;
double
pen_width,
pixel_width;
unsigned int
pen_style;
/* unsigned int */
/* pen_type; */
pen = WMF_DC_PEN(dc);
pen_width = (WMF_PEN_WIDTH(pen) + WMF_PEN_HEIGHT(pen)) / 2;
/* Pixel width is inverse of pixel scale */
pixel_width = (((double) 1 / (ddata->scale_x)) +
((double) 1 / (ddata->scale_y))) / 2;
/* Don't allow pen_width to be much less than pixel_width in order
to avoid dissapearing or spider-web lines */
pen_width = Max(pen_width, pixel_width*0.8);
pen_style = (unsigned int) WMF_PEN_STYLE(pen);
/* pen_type = (unsigned int) WMF_PEN_TYPE(pen); */
/* Pen style specified? */
if (pen_style == PS_NULL)
{
DrawSetStrokeColorString(WmfDrawContext,"none");
return;
}
DrawSetStrokeAntialias(WmfDrawContext, 1 );
DrawSetStrokeWidth(WmfDrawContext, Max(0, pen_width));
{
LineCap
linecap;
switch ((unsigned int) WMF_PEN_ENDCAP(pen))
{
case PS_ENDCAP_SQUARE:
linecap = SquareCap;
break;
case PS_ENDCAP_ROUND:
linecap = RoundCap;
break;
case PS_ENDCAP_FLAT:
default:
linecap = ButtCap;
break;
}
DrawSetStrokeLineCap(WmfDrawContext, linecap);
}
{
LineJoin
linejoin;
switch ((unsigned int) WMF_PEN_JOIN(pen))
{
case PS_JOIN_BEVEL:
linejoin = BevelJoin;
break;
case PS_JOIN_ROUND:
linejoin = RoundJoin;
break;
case PS_JOIN_MITER:
default:
linejoin = MiterJoin;
break;
}
DrawSetStrokeLineJoin(WmfDrawContext,linejoin);
}
{
double
dasharray[7];
switch (pen_style)
{
case PS_DASH: /* ------- */
{
/* Pattern 18,7 */
dasharray[0] = pixel_width * 18;
dasharray[1] = pixel_width * 7;
dasharray[2] = 0;
DrawSetStrokeAntialias(WmfDrawContext,False);
DrawSetStrokeDashArray(WmfDrawContext,2,dasharray);
break;
}
case PS_ALTERNATE:
case PS_DOT: /* ....... */
{
/* Pattern 3,3 */
dasharray[0] = pixel_width * 3;
dasharray[1] = pixel_width * 3;
dasharray[2] = 0;
DrawSetStrokeAntialias(WmfDrawContext,False);
DrawSetStrokeDashArray(WmfDrawContext,2,dasharray);
break;
}
case PS_DASHDOT: /* _._._._ */
{
/* Pattern 9,6,3,6 */
dasharray[0] = pixel_width * 9;
dasharray[1] = pixel_width * 6;
dasharray[2] = pixel_width * 3;
dasharray[3] = pixel_width * 6;
dasharray[4] = 0;
DrawSetStrokeAntialias(WmfDrawContext,False);
DrawSetStrokeDashArray(WmfDrawContext,4,dasharray);
break;
}
case PS_DASHDOTDOT: /* _.._.._ */
{
/* Pattern 9,3,3,3,3,3 */
dasharray[0] = pixel_width * 9;
dasharray[1] = pixel_width * 3;
dasharray[2] = pixel_width * 3;
dasharray[3] = pixel_width * 3;
dasharray[4] = pixel_width * 3;
dasharray[5] = pixel_width * 3;
dasharray[6] = 0;
DrawSetStrokeAntialias(WmfDrawContext,False);
DrawSetStrokeDashArray(WmfDrawContext,6,dasharray);
break;
}
case PS_INSIDEFRAME: /* There is nothing to do in this case... */
case PS_SOLID:
default:
{
DrawSetStrokeDashArray(WmfDrawContext,0,(double *)NULL);
break;
}
}
}
draw_color_stroke_rgb(API,WMF_PEN_COLOR(pen));
}
/* Estimate font pointsize based on Windows font parameters */
static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height)
{
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
Image
*image = ddata->image;
TypeMetric
metrics;
DrawInfo
*draw_info;
double
pointsize = 0.0;
draw_info=ddata->draw_info;
if (draw_info == (const DrawInfo *) NULL)
return 0;
draw_info->font=WMF_FONT_PSNAME(font);
draw_info->pointsize=font_height;
draw_info->text=str;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
{
if(strlen(str) == 1)
{
pointsize = (font_height *
( font_height / (metrics.ascent + AbsoluteValue(metrics.descent))));
draw_info->pointsize = pointsize;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
pointsize *= (font_height / ( metrics.ascent + AbsoluteValue(metrics.descent)));
}
else
{
pointsize = (font_height * (font_height / (metrics.height)));
draw_info->pointsize = pointsize;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
pointsize *= (font_height / metrics.height);
}
#if 0
draw_info->pointsize = pointsize;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
pointsize *= (font_height / (metrics.ascent + AbsoluteValue(metrics.descent)));
pointsize *= 1.114286; /* Magic number computed through trial and error */
#endif
}
draw_info->font=NULL;
draw_info->text=NULL;
#if 0
printf("String = %s\n", str);
printf("Font = %s\n", WMF_FONT_PSNAME(font));
printf("lfHeight = %.4g\n", font_height);
printf("bounds = %.4g,%.4g %.4g,%.4g\n", metrics.bounds.x1, metrics.bounds.y1,
metrics.bounds.x2,metrics.bounds.y2);
printf("ascent = %.4g\n", metrics.ascent);
printf("descent = %.4g\n", metrics.descent);
printf("height = %.4g\n", metrics.height);
printf("Pointsize = %.4g\n", pointsize);
#endif
return floor(pointsize);
}
#if defined(HasWMFlite)
/* Estimate weight based on font name */
static int util_font_weight( const char* font )
{
int
weight;
weight = 400;
if((strstr(font,"Normal") || strstr(font,"Regular")))
weight = 400;
else if( strstr(font,"Bold") )
{
weight = 700;
if((strstr(font,"Semi") || strstr(font,"Demi")))
weight = 600;
if( (strstr(font,"Extra") || strstr(font,"Ultra")))
weight = 800;
}
else if( strstr(font,"Light") )
{
weight = 300;
if( (strstr(font,"Extra") || strstr(font,"Ultra")))
weight = 200;
}
else if((strstr(font,"Heavy") || strstr(font,"Black")))
weight = 900;
else if( strstr(font,"Thin") )
weight = 100;
return weight;
}
/*
* Returns width of string in points, assuming (unstretched) font size of 1pt
* (similar to wmf_ipa_font_stringwidth)
*
* This is extremely odd at best, particularly since player/meta.h has access
* to the corrected font_height (as drawtext.font_height) when it invokes the
* stringwidth callback. It should be possible to compute the real stringwidth!
*
* For the moment it seems to do the least harm to simply return 0.
*/
static float lite_font_stringwidth( wmfAPI* API, wmfFont* font, char* str)
{
#if 0
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
Image
*image = ddata->image;
DrawInfo
*draw_info;
TypeMetric
metrics;
float
stringwidth = 0;
double
orig_x_resolution,
orig_y_resolution;
ResolutionType
orig_resolution_units;
orig_x_resolution = image->x_resolution;
orig_y_resolution = image->y_resolution;
orig_resolution_units = image->units;
draw_info=ddata->draw_info;
if (draw_info == (const DrawInfo *) NULL)
return 0;
draw_info->font=WMF_FONT_PSNAME(font);
draw_info->pointsize=12;
draw_info->text=str;
image->x_resolution = 72;
image->y_resolution = 72;
image->units = PixelsPerInchResolution;
if (GetTypeMetrics(image, draw_info, &metrics) != False)
stringwidth = ((metrics.width * 72)/(image->x_resolution * draw_info->pointsize)); /* *0.916348; */
draw_info->font=NULL;
draw_info->text=NULL;
#if 0
printf("\nlite_font_stringwidth\n");
printf("string = \"%s\"\n", str);
printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
printf("stringwidth = %.4g\n", stringwidth);
/* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
/* printf("WMF_FONT_WIDTH = %i\n", (int)WMF_FONT_WIDTH(font)); */
fflush(stdout);
#endif
image->x_resolution = orig_x_resolution;
image->y_resolution = orig_y_resolution;
image->units = orig_resolution_units;
return stringwidth;
#else
(void) API;
(void) font;
(void) str;
return 0;
#endif
}
/* Map font (similar to wmf_ipa_font_map) */
/* Mappings to Postscript fonts: family, normal, italic, bold, bolditalic */
static const struct
{
char name[17]; /* wmf font name */
char normal[12]; /* postscript font names */
char italic[18];
char bold[15];
char bolditalic[22];
} WMFFontMap[] = {
{ "Courier", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Helvetica", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique" },
{ "Modern", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Monotype Corsiva", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "News Gothic", "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique" },
{ "Symbol", "Symbol", "Symbol", "Symbol", "Symbol" },
{ "System", "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique" },
{ "Times", "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic" }
};
/* Mapping between base name and Ghostscript family name */
static const struct
{
char name[10];
char mapping[10];
} SubFontMap[] = {
{ "Arial", "Helvetica" },
{ "Courier", "Courier" },
{ "Fixed", "Courier" },
{ "Helvetica", "Helvetica" },
{ "Sans", "Helvetica" },
{ "Sym", "Symbol" },
{ "Terminal", "Courier" },
{ "Times", "Times" },
{ "Wingdings", "Symbol" }
};
static void lite_font_map( wmfAPI* API, wmfFont* font)
{
wmfFontData
*font_data;
wmf_magick_font_t
*magick_font;
wmf_magick_t
*ddata = WMF_MAGICK_GetData(API);
ExceptionInfo
exception;
const TypeInfo
*type_info,
*type_info_base;
const char
*wmf_font_name;
if (font == 0)
return;
font_data = (wmfFontData*)API->font_data;
font->user_data = font_data->user_data;
magick_font = (wmf_magick_font_t*)font->user_data;
wmf_font_name = WMF_FONT_NAME(font);
MagickFreeMemory(magick_font->ps_name);
GetExceptionInfo(&exception);
type_info_base=GetTypeInfo("*",&exception);
if(type_info_base == 0)
{
CopyException(&ddata->image->exception,&exception);
return;
}
/* Certain short-hand font names are not the proper Windows names
and should be promoted to the proper names */
if(LocaleCompare(wmf_font_name,"Times") == 0)
wmf_font_name = "Times New Roman";
else if(LocaleCompare(wmf_font_name,"Courier") == 0)
wmf_font_name = "Courier New";
/* Look for a family-based best-match */
if(!magick_font->ps_name)
{
int
target_weight,
best_weight = 0;
if( WMF_FONT_WEIGHT(font) == 0 )
target_weight = 400;
else
target_weight = WMF_FONT_WEIGHT(font);
/* printf("Desired weight = %i\n", WMF_FONT_WEIGHT(font)); */
for ( type_info=(TypeInfo *) type_info_base; type_info != 0; type_info=type_info->next )
{
if(LocaleCompare(wmf_font_name,type_info->family) == 0)
{
int
weight;
/* printf("Considering font %s\n", type_info->description); */
if( WMF_FONT_ITALIC(font) && !(strstr(type_info->description,"Italic") ||
strstr(type_info->description,"Oblique")) )
continue;
weight = util_font_weight( type_info->description );
/* printf("Estimated weight = %.4g\n", weight); */
if( abs(weight - target_weight) < abs(best_weight - target_weight) )
{
best_weight = weight;
(void) CloneString(&magick_font->ps_name,type_info->name);
}
}
}
}
/* Look for exact full match */
if(!magick_font->ps_name)
{
for ( type_info=(TypeInfo *) type_info_base; type_info != 0; type_info=type_info->next)
{
if(LocaleCompare(wmf_font_name,type_info->description) == 0)
{
(void) CloneString(&magick_font->ps_name,type_info->name);
break;
}
}
}
/* Now let's try simple substitution mappings from WMFFontMap */
if(!magick_font->ps_name)
{
unsigned int
i;
int
target_weight = 400,
want_italic = False,
want_bold = False;
char
target[MaxTextExtent];
if( WMF_FONT_WEIGHT(font) != 0 )
target_weight = WMF_FONT_WEIGHT(font);
if( (target_weight > 550) || ((strstr(wmf_font_name,"Bold") ||
strstr(wmf_font_name,"Heavy") ||
strstr(wmf_font_name,"Black"))) )
want_bold = True;
if( (WMF_FONT_ITALIC(font)) || ((strstr(wmf_font_name,"Italic") ||
strstr(wmf_font_name,"Oblique"))) )
want_italic = True;
(void) strcpy(target,"Times");
for( i=0; i < ArraySize(SubFontMap); i++ )
{
if(LocaleCompare(wmf_font_name, SubFontMap[i].name) == 0)
{
(void) strlcpy(target,SubFontMap[i].mapping,sizeof(target));
break;
}
}
for( i=0; i < ArraySize(WMFFontMap); i++ )
{
if(LocaleNCompare(WMFFontMap[i].name,target,strlen(WMFFontMap[i].name)) == 0)
{
if(want_bold && want_italic)
(void) CloneString(&magick_font->ps_name,WMFFontMap[i].bolditalic);
else if(want_italic)
(void) CloneString(&magick_font->ps_name,WMFFontMap[i].italic);
else if(want_bold)
(void) CloneString(&magick_font->ps_name,WMFFontMap[i].bold);
else
(void) CloneString(&magick_font->ps_name,WMFFontMap[i].normal);
}
}
}
#if 0
printf("\nlite_font_map\n");
printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
printf("WMF_FONT_WEIGHT = %i\n", WMF_FONT_WEIGHT(font));
printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
fflush(stdout);
#endif
}
/* Initialize API font structures */
static void lite_font_init( wmfAPI* API, wmfAPI_Options* options)
{
wmfFontData
*font_data;
ARG_NOT_USED(options);
API->fonts = 0;
/* Allocate wmfFontData data structure */
API->font_data = wmf_malloc(API,sizeof(wmfFontData));
if (ERR (API))
return;
font_data = (wmfFontData*)API->font_data;
/* Assign function to map font (type wmfMap) */
font_data->map = lite_font_map;
/* Assign function to return string width in points (type wmfStringWidth) */
font_data->stringwidth = lite_font_stringwidth;
/* Assign user data, not used by libwmflite (type void*) */
font_data->user_data = wmf_malloc(API,sizeof(wmf_magick_font_t));
if(ERR(API))
return;
((wmf_magick_font_t*)font_data->user_data)->ps_name = 0;
((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
}
#endif /* HasWMFlite */
/* BLOB read byte */
static int ipa_blob_read(void* context)
{
return ReadBlobByte((Image*)context);
}
/* BLOB seek */
static int ipa_blob_seek(void* context,long position)
{
return (int)SeekBlob((Image*)context,(ExtendedSignedIntegralType)position,SEEK_SET);
}
/* BLOB tell */
static long ipa_blob_tell(void* context)
{
return (long)TellBlob((Image*)context);
}
static Image *ReadWMFImage(const ImageInfo * image_info, ExceptionInfo * exception)
{
Image
*image;
float
wmf_width,
wmf_height;
double
bounding_height,
bounding_width,
image_height,
image_height_inch,
image_width,
image_width_inch,
resolution_y,
resolution_x,
units_per_inch;
unsigned int
logging;
unsigned long
wmf_options_flags = 0;
wmf_error_t
wmf_error_code;
wmf_magick_t
*ddata = 0;
wmfAPI
*API = 0;
wmfAPI_Options
wmf_api_options;
wmfD_Rect
bbox;
logging=LogMagickEvent(CoderEvent,GetMagickModule(),"enter ReadWMFImage()");
image = AllocateImage(image_info);
if (!OpenBlob(image_info,image,ReadBinaryBlobMode,exception))
{
if(logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," OpenBlob failed");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
}
/*
* Create WMF API
*
*/
/* Register callbacks */
wmf_options_flags |= WMF_OPT_FUNCTION;
(void) memset(&wmf_api_options, 0, sizeof(wmf_api_options));
wmf_api_options.function = ipa_functions;
/* Ignore non-fatal errors */
wmf_options_flags |= WMF_OPT_IGNORE_NONFATAL;
wmf_error_code = wmf_api_create(&API, wmf_options_flags, &wmf_api_options);
if (wmf_error_code != wmf_E_None)
{
if (API)
(void) wmf_api_destroy(API);
if(logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," wmf_api_create failed");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ThrowReaderException(DelegateError,UnableToInitializeWMFLibrary,image);
}
/* Register progress monitor */
wmf_status_function(API,(void*)"[%s] Parsing vectors...", magick_progress_callback);
ddata = WMF_MAGICK_GetData(API);
ddata->image = image;
ddata->image_info = image_info;
ddata->draw_info = CloneDrawInfo((const ImageInfo *) NULL, (const DrawInfo *) NULL);
MagickFreeMemory(ddata->draw_info->font);
MagickFreeMemory(ddata->draw_info->text);
#if defined(HasWMFlite)
/* Must initialize font subystem for WMFlite interface */
lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
/* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
#endif
/*
* Open BLOB input via libwmf API
*
*/
wmf_error_code = wmf_bbuf_input(API,ipa_blob_read,ipa_blob_seek,
ipa_blob_tell,(void*)image);
if (wmf_error_code != wmf_E_None)
{
if(logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," wmf_bbuf_input failed");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ipa_device_close(API);
(void) wmf_api_destroy(API);
ThrowReaderException(FileOpenError,UnableToOpenFile, image);
}
/*
* Scan WMF file
*
*/
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Scanning WMF to obtain bounding box");
wmf_error_code = wmf_scan(API, 0, &bbox);
if (wmf_error_code != wmf_E_None)
{
if (logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," wmf_scan failed with wmf_error_code %d", wmf_error_code);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ipa_device_close(API);
(void) wmf_api_destroy(API);
ThrowReaderException(DelegateError,FailedToScanFile,image);
}
/*
* Compute dimensions and scale factors
*
*/
ddata->bbox = bbox;
/* User specified resolution */
resolution_y = 72.0;
if (image->y_resolution > 0)
{
resolution_y = image->y_resolution;
if (image->units == PixelsPerCentimeterResolution)
resolution_y *= CENTIMETERS_PER_INCH;
}
resolution_x = 72.0;
if (image->x_resolution > 0)
{
resolution_x = image->x_resolution;
if (image->units == PixelsPerCentimeterResolution)
resolution_x *= CENTIMETERS_PER_INCH;
}
/* Obtain output size expressed in metafile units */
wmf_error_code = wmf_size(API, &wmf_width, &wmf_height);
if (wmf_error_code != wmf_E_None)
{
if (logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," wmf_size failed with wmf_error_code %d", wmf_error_code);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ipa_device_close(API);
(void) wmf_api_destroy(API);
ThrowReaderException(DelegateError,FailedToComputeOutputSize,image);
}
/* Obtain (or guess) metafile units */
if ((API)->File->placeable && (API)->File->pmh->Inch)
units_per_inch = (API)->File->pmh->Inch;
else if( (wmf_width*wmf_height) < 1024*1024)
units_per_inch = POINTS_PER_INCH; /* MM_TEXT */
else
units_per_inch = TWIPS_PER_INCH; /* MM_TWIPS */
/* Calculate image width and height based on specified DPI
resolution */
image_width_inch = (double) wmf_width / units_per_inch;
image_height_inch = (double) wmf_height / units_per_inch;
image_width = image_width_inch * resolution_x;
image_height = image_height_inch * resolution_y;
/* Compute bounding box scale factors and origin translations
*
* This is all just a hack since libwmf does not currently seem to
* provide the mapping between LOGICAL coordinates and DEVICE
* coordinates. This mapping is necessary in order to know
* where to place the logical bounding box within the image.
*
*/
bounding_width = bbox.BR.x - bbox.TL.x;
bounding_height = bbox.BR.y - bbox.TL.y;
if ((bounding_width == 0) || (bounding_height == 0))
{
/*
It is not clear what we can do if the reported bounding box is
empty or if this could be a valid case. Reject such files
until evidence is found to the contrary.
*/
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Empty Bounding Box! %.4g,%.4g %.4g,%.4g",
bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
ipa_device_close(API);
(void) wmf_api_destroy(API);
ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
}
ddata->scale_x = image_width/bounding_width;
ddata->translate_x = 0-bbox.TL.x;
ddata->rotate = 0;
/* Heuristic: guess that if the vertical coordinates mostly span
negative values, then the image must be inverted. */
if( AbsoluteValue(bbox.BR.y) > AbsoluteValue(bbox.TL.y) )
{
/* Normal (Origin at top left of image) */
ddata->scale_y = (image_height/bounding_height);
ddata->translate_y = 0-bbox.TL.y;
}
else
{
/* Inverted (Origin at bottom left of image) */
ddata->scale_y = (-image_height/bounding_height);
ddata->translate_y = 0-bbox.BR.y;
}
if (logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Placeable metafile: %s",
(API)->File->placeable ? "Yes" : "No");
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Size in metafile units: %.4gx%.4g",
wmf_width, wmf_height);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Metafile units/inch: %.4g",
units_per_inch);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Size in inches: %.4gx%.4g",
image_width_inch,image_height_inch);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Bounding Box: %.4g,%.4g %.4g,%.4g",
bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Bounding width x height: %.4gx%.4g",
bounding_width, bounding_height);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Output resolution: %.4gx%.4g",
resolution_x, resolution_y);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Image size: %.4gx%.4g",
image_width, image_height);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Bounding box scale factor: %.4g,%.4g",
ddata->scale_x, ddata->scale_y);
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Translation: %.4g,%.4g",
ddata->translate_x, ddata->translate_y);
}
#if 0
#if 0
{
typedef struct _wmfPlayer_t wmfPlayer_t;
struct _wmfPlayer_t
{
wmfPen default_pen;
wmfBrush default_brush;
wmfFont default_font;
wmfDC* dc; /* current dc */
};
wmfDC
*dc;
#define WMF_ELICIT_DC(API) (((wmfPlayer_t*)((API)->player_data))->dc)
dc = WMF_ELICIT_DC(API);
printf("dc->Window.Ox = %d\n", dc->Window.Ox);
printf("dc->Window.Oy = %d\n", dc->Window.Oy);
printf("dc->Window.width = %d\n", dc->Window.width);
printf("dc->Window.height = %d\n", dc->Window.height);
printf("dc->pixel_width = %.4g\n", dc->pixel_width);
printf("dc->pixel_height = %.4g\n", dc->pixel_height);
#if defined(HasWMFlite) /* Only in libwmf 0.3 */
printf("dc->Ox = %.d\n", dc->Ox);
printf("dc->Oy = %.d\n", dc->Oy);
printf("dc->width = %.d\n", dc->width);
printf("dc->height = %.d\n", dc->height);
#endif
}
#endif
#endif
/*
* Create canvas image
*
*/
image->rows = (unsigned long)ceil(image_height);
image->columns = (unsigned long)ceil(image_width);
if (image_info->ping)
{
ipa_device_close(API);
(void) wmf_api_destroy(API);
CloseBlob(image);
StopTimer(&image->timer);
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
return(image);
}
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Creating canvas image with size %ldx%ld",
image->rows, image->columns);
/*
* Set solid background color
*/
{
unsigned long
column,
row;
PixelPacket
*pixel,
background_color;
background_color = image_info->background_color;
image->background_color = background_color;
if(background_color.opacity != OpaqueOpacity)
image->matte = True;
for (row=0; row < image->rows; row++)
{
pixel=SetImagePixels(image,0,row,image->columns,1);
if (pixel == (PixelPacket *) NULL)
break;
for (column=image->columns; column; column--)
*pixel++ = background_color;
if (!SyncImagePixels(image))
break;
}
}
/*
* Play file to generate Vector drawing commands
*
*/
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Playing WMF to prepare vectors");
wmf_error_code = wmf_play(API, 0, &bbox);
if (wmf_error_code != wmf_E_None)
{
if (logging)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Playing WMF failed with wmf_error_code %d", wmf_error_code);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
}
ipa_device_close(API);
(void) wmf_api_destroy(API);
ThrowReaderException(DelegateError,FailedToRenderFile,image);
}
/*
* Scribble on canvas image
*
*/
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule()," Rendering WMF vectors");
(void) DrawRender(ddata->draw_context);
/* Cleanup allocated data */
(void) wmf_api_destroy(API);
CloseBlob(image);
StopTimer(&image->timer);
/* Check for and report any rendering error */
if(image->exception.severity != UndefinedException)
ThrowException2(exception,
CoderWarning,
image->exception.reason,
image->exception.description);
if(logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
/* Return image */
return image;
}
/* #endif */
#endif /* HasWMF || HasWMFlite */
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r W M F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method RegisterWMFImage adds attributes for the WMF image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterWMFImage method is:
%
% RegisterWMFImage(void)
%
*/
ModuleExport void RegisterWMFImage(void)
{
#if defined(HasWMF) || defined(HasWMFlite)
MagickInfo
*entry;
static const char
WMFNote[] =
{
"Use density to adjust scale (default 72DPI). Use background or\n"
"texture to apply a background color or texture under the image."
};
entry = SetMagickInfo("WMF");
entry->decoder = ReadWMFImage;
entry->description = "Windows Meta File";
entry->note=WMFNote;
entry->blob_support = True;
entry->seekable_stream=True;
entry->module = "WMF";
(void) RegisterMagickInfo(entry);
#endif /* HasWMF || HasWMFlite */
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r W M F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method UnregisterWMFImage removes format registrations made by the
% WMF module from the list of supported formats.
%
% The format of the UnregisterWMFImage method is:
%
% UnregisterWMFImage(void)
%
*/
ModuleExport void UnregisterWMFImage(void)
{
#if defined(HasWMF) || defined(HasWMFlite)
(void) UnregisterMagickInfo("WMF");
#endif /* defined(HasWMF) */
}
|