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
|
/******************************************************************************
* program: wp2latex *
* function: convert WordPerfect files into LaTeX *
* modul: images.cc *
* description: Procedures for converting WP images into into PostScripts ones*
* that could be inserted into a LaTeX. *
* licency: GPL *
******************************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
//Atoms library
#include "stringa.h"
#include "lists.h"
#include "sets.h"
#include "wp2latex.h"
#include "cp_lib/cptran.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
#ifdef _MSC_VER
#pragma warning (disable : 4244) /* double to float conversion - stupid warning */
#pragma warning (disable : 4305)
#endif
#include "images/vecimage.h"
#include "images/ras_img.cc"
#include "images.h"
#define PS2WPG(x) ((x)*25.4/71)
#ifdef _REENTRANT
#include "jobs/jobs.h"
class SaveEpsJob: public JobBase
{
public:
string FileName;
Image Img;
FILE *err;
SaveEpsJob(Image &iImg, const string & iFileName, FILE *iErr=NULL)
{Img=iImg; FileName=iFileName; err=iErr;}
SaveEpsJob(Image &iImg, const char *iFileName, FILE *iErr=NULL)
{Img=iImg; FileName=iFileName; err=iErr;}
virtual void Run(void)
{
if(SavePictureEPS(FileName(),Img)<0)
{
if(err!=NULL)
fprintf(err, _("\nError: Cannot save file: \"%s\"!"), FileName());
}
}
virtual ~SaveEpsJob() {err=NULL;}
};
/// Save EPS image from different thread.
void SavePictureEPS_MT(const string &FILE_NAME, Image &IMAGE_OBJ, FILE *ERR_STREAM, Percentor*PPERCENTOR)
{
RunJob(new SaveEpsJob(IMAGE_OBJ, FILE_NAME, ERR_STREAM));
}
#else
/// Save imageas EPS immediatelly.
inline void SavePictureEPS_MT(const string &FILE_NAME, Image &IMAGE_OBJ, FILE *ERR_STREAM, Percentor*PPERCENTOR)
{
if(SavePictureEPS(FILE_NAME(),IMAGE_OBJ) < 0)
{
if(ERR_STREAM != NULL)
{
PPERCENTOR->Hide();
fprintf(ERR_STREAM, _("\nError: Cannot save file: \"%s\"!"), FILE_NAME());
}
}
}
#endif
extern string wpd_filename;
#define DEFAULT_BOX_WIDTH 10 ///< Use 10cm as a default width
string CutFileName(const char *FullFilename); //from wp2lfuti.cc
#ifndef FINAL
void CrackObject(TconvertedPass1 *cq, DWORD end_of_code);
#endif
#define WPGu2PSu(x) ( (float)(x)*71/(25.4*47.0) )
#define mm2PSu(x) ( (float)(x)*71/25.4 )
static SWORD Rd_word_MMX(FILE *F,float &Min,float &Max)
{
SWORD w;
Rd_word(F,(WORD *)&w);
if(w<Min) Min=w;
if(w>Max) Max=w;
return(w);
}
typedef struct EmbeddedImg {
DWORD Offset;
DWORD Length;
char *Extension;
char *ImgName;
struct EmbeddedImg *Next;
}EmbeddedImg;
typedef struct {
DWORD PS_unknown1;
WORD PS_unknown2;
WORD PS_unknown3;
} WPGPSl1Record;
static void Wr_WP_DWORD(FILE *f, DWORD d, char Format=0)
{
unsigned char b;
if(d<0xFF && Format<1)
{
b=d;
fwrite(&b, 1, 1, f);
return;
}
b=0xff;
fwrite(&b, 1, 1, f);
if(d<0x8000 && Format<2)
{
b = d & 255;
fwrite(&b, 1, 1, f);
b = d / 256;
fwrite(&b, 1, 1, f);
return;
}
b = (BYTE)((d >> 8*2) & 0x00ffl);
fwrite( &b, 1,1,f);
b = (BYTE)((d >> 8*3) & 0x00ffl) | 0x80;
fwrite( &b, 1,1,f);
b = (BYTE)((d >> 8*0) & 0x00ffl);
fwrite( &b, 1,1,f);
b = (BYTE)((d >> 8*1) & 0x00ffl);
fwrite( &b, 1,1,f);
return;
}
/** Check for existency of a given file with PS contents. */
static bool CheckPreviousPS(const char *NewFilename)
{
FILE *PostScript;
char c1, c2;
if((PostScript=fopen(NewFilename,"r"))!=NULL)
{
string s;
c1 = getc(PostScript);
c2 = getc(PostScript);
if(c1=='%' && c2=='!')
{
fGets2(PostScript,s);
fGets2(PostScript,s);
fGets2(PostScript,s);
if(!(string("wp2latex") IN s))
{
fclose(PostScript);
return true; //file already exist, do not overwrite
}
}
fclose(PostScript);
}
return false;
}
/** Detection procedure for WPG2 fragment without a header. */
int DetectFragmentWPG2(FILE *wpd, long FileSz)
{
long FilePos, CurrPos;
int CharNo;
WPG2Record Rec2;
CurrPos = FilePos = ftell(wpd);
if(FileSz < 0)
FileSz = filesize(wpd);
CharNo = 0;
while(!feof(wpd) && CurrPos<FileSz && CharNo<0x200)
{
Rec2.Class = fgetc(wpd);
if(Rec2.Class>=10) {CharNo--;break;} // Max known class is 9
Rec2.Type = fgetc(wpd);
if(Rec2.Type>=0x40 || Rec2.Type<=0) {CharNo--;break;} // Max known type is 0x3F
Rd_WP_DWORD(wpd,&Rec2.Extension);
Rd_WP_DWORD(wpd,&Rec2.RecordLength);
if(Rec2.Type==1 && Rec2.RecordLength<0x15) {CharNo--;break;}
CurrPos = ftell(wpd);
CurrPos += Rec2.RecordLength;
if(CurrPos > FileSz) {CharNo--;break;} // Object offset overflows.
fseek(wpd, CurrPos, SEEK_SET);
CharNo++;
}
fseek(wpd,FilePos,SEEK_SET);
return CharNo;
}
/** This procedure creates empty PostScript image with warning about inability to convert given image. */
static void MakeDummyPS(const char *Filename, Image &Img)
{
VectorImage *Vec = new VectorImage();
Vec->PSS.FontSizeW = Vec->PSS.FontSize = 140;
Vec->PSS.LineColor.Red = Vec->PSS.LineColor.Green = Vec->PSS.LineColor.Blue = 255;
Vec->PSS.TextColor.Red = Vec->PSS.TextColor.Green = Vec->PSS.TextColor.Blue = 255;
VectorRectangle *Vr = new VectorRectangle(0,2790, 0,5370);
Vr->LineColor.Red = Vr->LineColor.Green = Vr->LineColor.Blue = 255;
Vr->BrushStyle = 0;
Vr->LineStyle = 1;
Vec->AddObject(Vr);
TextContainer *Tc = new TextContainer();
Tc->AddText("Please convert an image", Vec->PSS);
Tc->PosX=1095; Tc->PosY=2150;
Vec->AddObject(Tc);
Tc = new TextContainer();
Tc->AddText("to the PostScript", Vec->PSS);
Tc->PosX=1615; Tc->PosY=955;
Vec->AddObject(Tc);
Tc = new TextContainer();
Tc->AddText("manually!", Vec->PSS);
Tc->PosX=2020; Tc->PosY=415;
Vec->AddObject(Tc);
Tc = new TextContainer();
int Expand = 0;
int FnameLen = 0;
if(Filename!=NULL)
{
FnameLen = strlen(Filename);
for(int i=0; i<FnameLen; i++)
{
char ch = Filename[i];
if(ch=='\\')
Expand++;
}
}
Tc->PosX = 5370/2 - FnameLen*Vec->PSS.FontSize;
if(Tc->PosX < 0) Tc->PosX = 0;
Tc->PosY = 1525;
if(Expand<=0)
{
Tc->AddText(Filename, Vec->PSS);
}
else // Expand>0
{
char *Text2 = (char*)malloc(FnameLen+Expand+1);
int i = 0;
Expand = 0;
while(i<FnameLen)
{
char ch = Filename[i];
if(ch=='\\')
{
Text2[i+Expand] = '\\';
Expand++;
}
Text2[i+Expand] = ch;
i++;
}
Text2[FnameLen+Expand] = 0;
Tc->AddText(Text2, Vec->PSS);
free(Text2);
}
Vec->AddObject(Tc);
Img.AttachVecImg(Vec);
Img.x = 0; Img.dx = PS2WPG(Vr->RightRect);
Img.y = 0; Img.dy = PS2WPG(Vr->TopRect);
}
static void NoImgMemory(TconvertedPass1 *cq,int Width,int Height)
{
#ifdef DEBUG
fprintf(cq->log,"\n#NoImgMemory() ");fflush(cq->log);
#endif
if (cq->err != NULL)
{
cq->perc.Hide();
if(Width==0 || Height==0)
fprintf(cq->err, _("\nWarning: Zero size raster (%dx%d)?"),Width,Height);
else
fprintf(cq->err, _("\nError: Not enough memory to store image raster (%dx%d)!"),Width,Height);
}
}
/*static int SetCategory(FILE *strip,const set & FixChars)
{
unsigned char ch;
int i=0;
if(strip==NULL) return(0);
for(ch=1;ch<255;ch++)
{
if(FixChars[ch])
{
i++;
fprintf(strip,"\\catcode`\\%c=12\n",ch);
}
}
return(i);
}*/
void AddCharacterToContainer(TextContainer *pTextCont, WORD WchI, CpTranslator *PsNativeCP, CpTranslator *PsNativeSym,
TconvertedPass1 *cq, PS_State &PSS)
{
if(WchI==0) return;
if(PsNativeCP != NULL)
{
char ch = (*PsNativeCP)[WchI];
if(ch == '\\')
{
pTextCont->AddText("\\\\",PSS);
return;
}
if(ch != 0)
{
pTextCont->AddText(ch,PSS);
return;
}
}
if(PsNativeSym != NULL)
{
char ch = (*PsNativeSym)[WchI];
if(ch != 0)
{
pTextCont->AddText(ch,"Symbol",PSS);
return;
}
}
const char *str = Ext_chr_str(WchI, cq);
if(str==NULL)
{
pTextCont->AddText("_",PSS);
return;
}
if(!strcmp(str,"$\\sum$")) // Replace Summation with sigma.
{
pTextCont->AddText("S","Symbol",PSS);
return;
}
{
temp_string contents(str);
contents = replacesubstring(contents,"\\'{\\i}","\\'{\\365}");
contents = replacesubstring(contents,"$-$","-");
contents = replacesubstring(contents,"$>$",">");
contents = replacesubstring(contents,"$<$","<");
contents = replacesubstring(contents,"!`","\\241");
contents = replacesubstring(contents,"{c}\\llap{/}","\\242");
contents = replacesubstring(contents,"\\cent ","\\242");
contents = replacesubstring(contents,"\\textcentoldstyle{}","\\242");
contents = replacesubstring(contents,"\\pounds{}","\\243");
contents = replacesubstring(contents,"\\textyen{}","\\245");
contents = replacesubstring(contents,"\\degrees ","\\312");
contents = replacesubstring(contents,"\\textdegree{}","\\312");
contents = replacesubstring(contents,"$\\tt\\backslash$","\\");
pTextCont->AddText(contents,PSS);
}
}
/** Convert a block of WP5.x text into PostScript. */
static void Textl2_2PS(TconvertedPass1 *cq, VectorList &VectList, long ldblk, PS_State &PSS, WPG_records *WPG)
{
#ifdef DEBUG
fprintf(cq->log,"\n#Textl2_2PS() ");fflush(cq->log);
#endif
BYTE TextColorIdx;
const RGB_Record BkTextColor = PSS.TextColor;
const float BkFontSize = PSS.FontSize;
WORD FontSize = 1100; // Default font size
WORD MaxFontSize = 0;
short LineCount = 1;
const unsigned short CodePageBk = OutCodePage;
long ActualPos;
TconvertedPass1 *cq5;
CpTranslator *PsNativeCP = GetTranslator("internalTOcp1276");
CpTranslator *PsNativeSym = GetTranslator("internalTOsymbol");
if(ldblk<=0) return;
cq5 = GetConverter("WP5.x");
if(cq5==NULL)
{
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: WP5.x converter is not available in this build!"));
}
return;
}
TextContainer *pTextCont = new TextContainer;
//pTextCont->FontOrientation = PSS.FontOrientation10 / 10.0f;
cq5->InitMe(cq->wpd,cq->table,cq->strip,cq->log,cq->err);
cq5->recursion++;
if(cq5->ConvertCpg==NULL)
cq5->ConvertCpg = GetTranslator("wp5TOinternal");
cq5->ActualPos=cq->ActualPos+21;
ldblk+=cq5->ActualPos;
fseek(cq5->wpd,cq5->ActualPos,SEEK_SET);
cq5->flag = Nothing;
OutCodePage = 0;
while(cq5->ActualPos<ldblk)
{
*cq5->ObjType=0;
cq5->by = fgetc(cq5->wpd);
if(feof(cq5->wpd)) break;
if(cq5->by==0xC0)
{
ActualPos = ftell(cq5->wpd);
WORD WChar;
Rd_word(cq->wpd, &WChar);
if(cq5->log != NULL)
fprintf(cq5->log, "[%d,%d]", WChar/255, WChar&0xFF);
if(cq5->ConvertCpg)
AddCharacterToContainer(pTextCont, (*cq5->ConvertCpg)[WChar], PsNativeCP, PsNativeSym, cq, PSS);
fseek(cq5->wpd,ActualPos,SEEK_SET);
}
if(cq5->by == 0x0A || // [HRt]
cq5->by == 0x0D || // [SRt]
cq5->by == 0x8C) // [HRT]
{
pTextCont->AddText('\n',PSS);
LineCount++;
}
if(cq5->by>=32 && cq5->by<=0x80)
{
AddCharacterToContainer(pTextCont, (*cq5->ConvertCpg)[cq5->by], PsNativeCP, PsNativeSym, cq, PSS);
}
if(cq5->by == 0xD1)
{
ActualPos=ftell(cq5->wpd);
fread(&cq5->subby, 1, 1, cq5->wpd);
if(cq5->subby==1)
{
WORD FontSize2;
fseek(cq5->wpd,28+2,SEEK_CUR);
Rd_word(cq5->wpd, &FontSize2);
sprintf(cq5->ObjType,"Font Size %dWPu",FontSize2);
if(FontSize2!=FontSize)
{
FontSize = FontSize2;
PSS.FontSize = WPGu2mm(FontSize);
if(MaxFontSize <= PSS.FontSize) MaxFontSize=PSS.FontSize;
}
}
if(cq5->subby==2)
{
fseek(cq5->wpd,1+2,SEEK_CUR);
TextColorIdx = fgetc(cq5->wpd);
RGB_Record NewColor = WPG_Palette[TextColorIdx];
if(memcmp(&NewColor,&PSS.TextColor,sizeof(PSS.TextColor)))
{
PSS.TextColor = NewColor;
}
}
fseek(cq5->wpd,ActualPos,SEEK_SET);
}
cq5->Dispatch(DISP_PROCESSKEY);
}
if(cq5!=cq)
delete cq5;
OutCodePage = CodePageBk;
if(!pTextCont->isEmpty())
{
if(MaxFontSize <= 0) MaxFontSize=PSS.FontSize;
float y = WPGu2PSu(WPG->TextL2.LowLeftY);
float dy = WPGu2PSu(WPG->TextL2.UpRightY-WPG->TextL2.LowLeftY);
if(LineCount >1)
{
dy /= LineCount;
y += (LineCount-1) * dy;
}
pTextCont->PosX = WPGu2PSu(WPG->TextL2.LowLeftX);
pTextCont->PosY = y;
pTextCont->PosY += dy/2;
pTextCont->PosY -= MaxFontSize*2.66/2;
pTextCont->PosY += 0.15*MaxFontSize*2.66/2; // Shift text slightly up
pTextCont->FontOrientation = WPG->TextL2.RotAngle;
pTextCont->RotCenterX = WPGu2PSu(WPG->TextL2.UpRightX - WPG->TextL2.LowLeftX) / 2;
pTextCont->RotCenterY = dy / 2;
VectList.AddObject(pTextCont);
}
else
delete pTextCont;
PSS.TextColor = BkTextColor;
PSS.FontSize = BkFontSize;
}
extern unsigned char CharsWP6_1_32[0x21];
/** Convert a block of WP6.x text into PostScript. */
static TextContainer *TextWPG2_2PS(TconvertedPass1 *cq, long ldblk, string & PSData, PS_State &PSS,
float x, float y, float dx, float dy, float Angle)
{
#ifdef DEBUG
fprintf(cq->log,"\n#TextWPG2_2PS(%ld) ",ldblk);fflush(cq->log);
#endif
TextContainer *pTxC;
WORD FontSize = 1100;
short LineCount =1;
const unsigned short CodePageBk = OutCodePage;
RGB_Record BkTextColor = PSS.TextColor;
TconvertedPass1 *cq6; // Converter for embedded text fragment
long ActualPos;
CpTranslator *PsNativeCP = GetTranslator("internalTOcp1276");
CpTranslator *PsNativeSym = GetTranslator("internalTOsymbol");
cq6 = GetConverter("WP6.x");
if(cq6==NULL) return NULL;
cq->ActualPos = ftell(cq->wpd);
ldblk+=cq->ActualPos; //end position
// Rd_word(cq->wpd, &StringSize); ?????
cq6->InitMe(cq->wpd,cq->table,cq->strip,cq->log,cq->err);
if(cq6->ConvertCpg==NULL)
cq6->ConvertCpg = GetTranslator("wp6TOinternal");
cq6->recursion++;
cq6->ActualPos=cq->ActualPos;
cq6->flag = Nothing;
pTxC = new TextContainer();
OutCodePage = 0;
while(cq6->ActualPos<ldblk)
{
*cq6->ObjType = 0;
cq6->by = fgetc(cq6->wpd);
if(cq6->by==0xD4 || cq6->by==0xE1)
{
ActualPos = ftell(cq6->wpd);
cq6->subby = fgetc(cq6->wpd);
if(cq6->by==0xD4)
{
if(cq6->subby==0x1B)
{
fseek(cq6->wpd,6+2,SEEK_CUR); //<flags><PIDsNo>[descriptor][NDelSize]
Rd_word(cq6->wpd, &FontSize);
PSS.FontSize = FontSize / (2.66*50);
}
}
if(cq6->by==0xE1)
{
if(cq6->subby==0xC)
{
RGB_Record NewColor;
fseek(cq6->wpd,3+2,SEEK_CUR);
NewColor.Red = fgetc(cq6->wpd);
NewColor.Green = fgetc(cq6->wpd);
NewColor.Blue = fgetc(cq6->wpd);
PSS.TextColor = NewColor;
//transparency is ignored
sprintf(cq6->ObjType,"Pen Fore Color %d,%d,%d",PSS.TextColor.Red,PSS.TextColor.Green,PSS.TextColor.Blue);
}
}
fseek(cq6->wpd,ActualPos,SEEK_SET);
}
if(cq6->by == 0xF0) // Extended character
{
ActualPos = ftell(cq6->wpd);
WORD WChar;
Rd_word(cq->wpd, &WChar);
if(cq6->log != NULL)
fprintf(cq6->log, "[%d,%d]", WChar/255, WChar&0xFF);
AddCharacterToContainer(pTxC, (*cq6->ConvertCpg)[WChar], PsNativeCP, PsNativeSym, cq6, PSS);
fseek(cq6->wpd,ActualPos,SEEK_SET);
}
if(cq6->by>0x20 && cq6->by<=0x7F) // Normal_char
{
AddCharacterToContainer(pTxC, cq6->by, PsNativeCP, PsNativeSym, cq6, PSS);
}
if(cq6->by>=0x01 && cq6->by<=0x20) // Default extended international characters (from 0)
{
const WORD WChar = 0x100 | CharsWP6_1_32[cq6->by];
if(cq6->log != NULL)
fprintf(cq6->log, "[%Xh:%d,%d]", (int)cq6->by, WChar/255, WChar&0xFF);
AddCharacterToContainer(pTxC, (*cq6->ConvertCpg)[WChar], PsNativeCP, PsNativeSym, cq6, PSS);
}
if(cq6->by==0x80 || // Space
cq6->by==0x81) // Hard space
{
pTxC->AddText(" ",PSS);
}
if(cq6->by==0xCC || // HRt
cq6->by==0xC7 ||
cq6->by==0xD0) // HRt/Hpg
{
LineCount++;
pTxC->AddText("\n",PSS);
}
cq6->Dispatch(DISP_PROCESSKEY);
}
if(cq6!=cq)
delete cq6;
OutCodePage = CodePageBk;
PSS.TextColor = BkTextColor;
if(!pTxC->isEmpty())
{
if(LineCount >1)
{
dy /= LineCount;
y += (LineCount-1) * dy;
}
pTxC->PosX = x;
pTxC->PosY = y;
pTxC->PosY += dy/2;
pTxC->PosY -= PSS.FontSize*2.66/2;
pTxC->PosY += 0.15*PSS.FontSize*2.66/2; // Shift text slightly up
pTxC->FontOrientation = Angle;
pTxC->RotCenterX = dx / 2;
pTxC->RotCenterY = dy / 2;
//VectList.AddObject(pTextCont);
}
return pTxC;
}
/** Load array of points word packed. */
float *LoadPoints(TconvertedPass1 *cq, int n, FloatBBox &bbx, AbstractTransformXY *TRx, bool Precision)
{
#ifdef DEBUG
fprintf(cq->log,"\n#LoadPoints(%d) ",n);fflush(cq->log);
#endif
float *Points, *p;
if(n<=0) return(NULL);
p = Points = (float*)calloc(2*n,sizeof(*Points));
if(Points==NULL) return(NULL);
float x, y;
while(n-->0)
{
if(!Precision)
{
SWORD w;
Rd_word(cq->wpd, (WORD *)&w);
x = w;
Rd_word(cq->wpd,(WORD *)&w);
y = w;
}
else
{
SDWORD d;
Rd_dword(cq->wpd, (DWORD *)&d);
x = d / 65536.0;
Rd_dword(cq->wpd,(DWORD *)&d);
y = d / 65536.0;
}
if(TRx) TRx->ApplyTransform(x,y);
if(x<bbx.MinX) bbx.MinX=x;
if(x>bbx.MaxX) bbx.MaxX=x;
if(y<bbx.MinY) bbx.MinY=y;
if(y>bbx.MaxY) bbx.MaxY=y;
*p++ = x;
*p++ = y;
}
#ifdef DEBUG
fprintf(cq->log,"\n#~LoadPoints(%d) ",n);fflush(cq->log);
#endif
return(Points);
}
/** Check capacity of object for a given amount of polygons. */
static void FixPolySize(TconvertedPass1 *cq, WORD *P_size, DWORD ObjSize)
{
if(ObjSize < 2+2*(DWORD)*P_size)
{
if (cq->err != NULL)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: The size of polygon %ld is not enough to fit %d elements!"), (long)ObjSize, *P_size);
}
if(ObjSize<=2) *P_size=0;
else *P_size=(ObjSize-2)/2;
}
}
/** This function generates unique name for the image - if the original one is empty.
* Please use extension maximally 3 characters long, othervise crash occurs. */
char *GetSomeImgName(const char *Ext)
{
static char tmp_img[11] = "00_img.wpg";
char *ptrch;
switch(tmp_img[0]) /*Actualise a name*/
{
case '9':tmp_img[0] = 'a';
break;
case 'z':tmp_img[0] = '0';
switch(tmp_img[1])
{
case '9':tmp_img[1] = 'a'; break;
case 'z':tmp_img[1] = '0';
if(tmp_img[2]=='_') tmp_img[2]='0';
else tmp_img[2]++;
break;
default: tmp_img[1]++; break;
}
break;
default: tmp_img[0]++; break;
}
ptrch=tmp_img+6; /*prepare extension*/
*ptrch=0;
if(Ext)
do
{
*ptrch++=*Ext;
} while(*Ext++!=0);
return(tmp_img);
}
static vecTransform *BuildTransform(const WPG2_Transform &TRx, SDWORD CenterX, SDWORD CenterY)
{
vecTransform *Tx = new vecTransform;
Tx->CenterX = WPGu2PSu(CenterX);
Tx->CenterY = WPGu2PSu(CenterY);
Tx->RotAngle = TRx.RotAngle;
if(TRx.Flags & WPG2_Transform::WPG2_TRN)
{
Tx->TranslateX = WPGu2PSu(TRx.TranslateX);
Tx->TranslateY = WPGu2PSu(TRx.TranslateY);
}
if(TRx.Flags & WPG2_Transform::WPG2_SCL)
{
Tx->ScaleX = TRx.ScaleX * cos(M_PI*Tx->RotAngle/180.0);
Tx->ScaleY = TRx.ScaleY * cos(M_PI*Tx->RotAngle/180.0);
}
return Tx;
}
static void BuildTM(const WPG2_Transform &TRx, float_matrix &TM, bool rotations=false)
{
TM.member(0,0)=TRx.ScaleX; TM.member(1,0)=TRx.SkewY; TM.member(2,0)=TRx.TamperX;
TM.member(0,1)=TRx.SkewX; TM.member(1,1)=TRx.ScaleY; TM.member(2,1)=TRx.TamperY;
TM.member(0,2)=TRx.TranslateX;TM.member(1,2)=TRx.TranslateY;TM.member(2,2)=1;
if(rotations)
{
float val = cos(M_PI*TRx.RotAngle/180.0);
TM.member(0,0) *= val;
TM.member(1,1) *= val;
val = sin(180*TRx.RotAngle/M_PI);
TM.member(1,0) *= val;
TM.member(0,1) *= -val;
}
}
/** This functor class is used for resizing image data. */
class vecResizeCTM: public AbstractTransformXY, public WPG2_Transform
{
public:
vecResizeCTM(void) {}
virtual void ApplyTransform(float &x, float &y) const;
};
void vecResizeCTM::ApplyTransform(float &x, float &y) const
{
const float NewX =
ScaleX*x + SkewX*y + TranslateX;
y = SkewY*x + ScaleY*y + TranslateY;
x = NewX;
}
class TImgConvStatus
{
public:
float x, y, dx, dy, RotAngle;
WORD BrushCount;
WORD MaxBrushes;
Raster2DAbstract **BrushList;
TImgConvStatus(void) {x=y=dx=dy=RotAngle = MaxBrushes=BrushCount=0; BrushList=NULL;}
~TImgConvStatus() {ClearBrushes();}
void ClearBrushes(void);
};
void TImgConvStatus::ClearBrushes(void)
{
if(BrushList==NULL) return;
for(int i=0; i<BrushCount; i++)
{
if(BrushList[i]!=NULL)
{
if(BrushList[i]->UsageCount--<=1) delete BrushList[i];
BrushList[i] = NULL;
}
}
free(BrushList);
BrushList = NULL;
MaxBrushes = BrushCount = 0;
}
/** Processing one token inside separate procedure allows to recurse tokens.
* @param[in,out] bbx Bounding box [WPU].
* @param[in,out] NewObjectPos File position of new object. */
static void ProcessWPG2Token(TconvertedPass1 *cq, WPG2Record & Rec2,
WPG2Start & StartWPG, Image & Img, APalette **Palette,
string & PSData, PS_State & PSS, EmbeddedImg **EmImg,
DWORD & NewObjectPos, DWORD & ResourceEnd, Image **CurrImg,
TImgConvStatus & ImgSts, FloatBBox & bbx, VectorList &VectList)
{
#ifdef DEBUG
fprintf(cq->log,"\n#ProcessWPG2Token() ");fflush(cq->log);
#endif
WORD i;
Raster2DAbstract *Raster = NULL;
long ldblk;
vecResizeCTM TRx;
switch(Rec2.Type)
{
case 0x1:LoadWPG2Start(cq->wpd,StartWPG);
if(StartWPG.PosSizePrecision!=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: Unsupported precision %d, please send me this image for analysis."), (int)StartWPG.PosSizePrecision);
}
// Start extensions must be read separatelly.
cq->recursion++;
while(cq->ActualPos<ResourceEnd && Rec2.Extension-->0)
{
WPG2Record Rec2b;
if(NewObjectPos!=ftell(cq->wpd))
fseek(cq->wpd,NewObjectPos,SEEK_SET);
cq->ActualPos = NewObjectPos;
Rec2b.Class = fgetc(cq->wpd);
Rec2b.Type = fgetc(cq->wpd);
Rd_WP_DWORD(cq->wpd,&Rec2b.Extension);
Rd_WP_DWORD(cq->wpd,&Rec2b.RecordLength);
cq->ActualPos = ftell(cq->wpd);
NewObjectPos = cq->ActualPos + Rec2b.RecordLength;
ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSData, PSS, EmImg, NewObjectPos, ResourceEnd, CurrImg,
ImgSts, bbx, VectList);
if(Rec2b.Type==0x31 || Rec2b.Type==0x32)
{
memcpy(&PSS.PaperBackground, &PSS.FillColor, sizeof(PSS.PaperBackground));
memset(&PSS.FillColor, 0, sizeof(PSS.FillColor)); // Revert initial value.
}
}
cq->recursion--;
strcpy(cq->ObjType,"Start WPG2");
break;
case 0x2:strcpy(cq->ObjType,"End WPG");
NewObjectPos = ResourceEnd; //skip everything after this
break;
case 0x3:strcpy(cq->ObjType,"!Form Settings"); break;
case 0x4:strcpy(cq->ObjType,"!Ruller Settings"); break;
case 0x5:strcpy(cq->ObjType,"!Grid Settings"); break;
case 0x6:strcpy(cq->ObjType,"!Layer"); break;
case 0x7:strcpy(cq->ObjType,"!Object Link"); break;
case 0x8:strcpy(cq->ObjType,"!Pen style definition"); break;
case 0x9: {
ImgSts.ClearBrushes();
WORD PatternIndex;
RdWORD_LoEnd(&PatternIndex,cq->wpd);
sprintf(cq->ObjType,"!Pattern definition #%d", PatternIndex);
WORD NumberOfResolutions;
RdWORD_LoEnd(&NumberOfResolutions,cq->wpd);
ImgSts.MaxBrushes = NumberOfResolutions + 1;
if(ImgSts.MaxBrushes >= 1)
{
ImgSts.BrushList = (Raster2DAbstract**)calloc(ImgSts.MaxBrushes, sizeof(Raster2DAbstract **));
if(ImgSts.BrushList==NULL)
ImgSts.MaxBrushes = 0;
}
break;
}
case 0xA:strcpy(cq->ObjType,"!Comment"); break;
case 0x0B:strcpy(cq->ObjType,"!Color Transfer"); break;
case 0x0C:{
WPG_records WPG;
strcpy(cq->ObjType,"Color Palette");
LoadWPGColormap(cq->wpd,WPG.ColorMapRec); // color map header
if(Palette==NULL) break;
if(*Palette!=NULL && (*Palette)->UsageCount==0) delete *Palette;
*Palette = BuildPalette(WPG.ColorMapRec.NumOfEntries+WPG.ColorMapRec.StartIndex,8);
if(*Palette!=NULL)
{
for(i=WPG.ColorMapRec.StartIndex; i<WPG.ColorMapRec.NumOfEntries; i++)
{
(*Palette)->R(i,fgetc(cq->wpd));
(*Palette)->G(i,fgetc(cq->wpd));
(*Palette)->B(i,fgetc(cq->wpd));
fgetc(cq->wpd);//Opacity?
}
}
}
break;
case 0x0D:{
WPG_records WPG;
strcpy(cq->ObjType,"DP Color Palette");
LoadWPGColormap(cq->wpd,WPG.ColorMapRec); // color map header
if(Palette==NULL) break;
if(*Palette!=NULL && (*Palette)->UsageCount==0) delete *Palette;
*Palette = BuildPalette(WPG.ColorMapRec.NumOfEntries+WPG.ColorMapRec.StartIndex,16);
if(*Palette!=NULL)
{
for(i=WPG.ColorMapRec.StartIndex; i<WPG.ColorMapRec.NumOfEntries; i++)
{
WORD num;
RdWORD_LoEnd(&num,cq->wpd); (*Palette)->R(i,num);
RdWORD_LoEnd(&num,cq->wpd); (*Palette)->G(i,num);
RdWORD_LoEnd(&num,cq->wpd); (*Palette)->B(i,num);
RdWORD_LoEnd(&num,cq->wpd); //Opacity?
}
}
}
break;
case 0x0E:{
WPG_records WPG;
strcpy(cq->ObjType,"Bitmap Data");
LoadWPG2BitmapData(cq->wpd,WPG._2BitmapData);
if(WPG._2BitmapData.Compression>1)
{
cq->perc.Hide();
fprintf(cq->err,_("Error: Unsupported WPG2 compression %d, please report."),WPG._2BitmapData.Compression);
return;
}
switch(WPG._2BitmapData.Depth)
{
case 1:i=1;break;
case 2:i=2;break;
case 3:i=4;break;
case 4:i=8;break;
case 8:i=24;break;
default: return; // Ignore raster with unknown depth.
}
Raster = CreateRaster2D(WPG._2BitmapData.Width,WPG._2BitmapData.Height,i);
if(Raster==NULL)
{NoImgMemory(cq,WPG._2BitmapData.Width,WPG._2BitmapData.Height);return;}
if(WPG._2BitmapData.Compression==1)
{
if(UnpackWPG2Raster(Raster,cq->wpd)<0)
{
Raster->Erase();
if (cq->err != NULL)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: cannot decompress current WPG raster, skipping!"));
}
}
}
if(WPG._2BitmapData.Compression==0)
{
ldblk = (Raster->GetPlanes()*Raster->Size1D+7)/8;
for(i=0;i<Raster->Size2D;i++)
{
if(fread(Raster->GetRow(i),ldblk,1,cq->wpd)!=1) break;
// AlineProc(i,p);
}
}
if(ImgSts.BrushCount<ImgSts.MaxBrushes && ImgSts.BrushList!=NULL)
{ // Read brush pattern and not a regular image.
Raster->UsageCount++;
ImgSts.BrushList[ImgSts.BrushCount] = Raster;
ImgSts.BrushCount++;
Raster = NULL;
return;
}
if(Img.Raster!=NULL)
{
(*CurrImg)->Next = new Image;
(*CurrImg) = (*CurrImg)->Next;
}
if(ImgSts.dx>=0)
{(*CurrImg)->x = ImgSts.x; (*CurrImg)->dx = ImgSts.dx;}
else
{
(*CurrImg)->x = ImgSts.x; (*CurrImg)->dx = -ImgSts.dx;
if(Raster!=NULL) Flip1D(Raster);
}
if(ImgSts.dy>=0)
{(*CurrImg)->y = ImgSts.y; (*CurrImg)->dy = ImgSts.dy;}
else
{
(*CurrImg)->y = ImgSts.y; (*CurrImg)->dy = -ImgSts.dy;
if(Raster!=NULL) Flip2D(Raster);
}
(*CurrImg)->RotAngle = ImgSts.RotAngle;
ImgSts.x = ImgSts.y = ImgSts.dx = ImgSts.dy = 0;
if(Raster!=NULL)
{
(*CurrImg)->Raster=Raster;(*CurrImg)->Raster->UsageCount++;Raster=NULL;
}
AssignPalette(*CurrImg,*Palette);
}
break;
case 0x0F:{//CrackObject(cq,NewObject);
// Debug purpose rectangle
/* VectorRectangle *Vr = new VectorRectangle(WPGu2PSu(ImgSts.y), WPGu2PSu(ImgSts.y+ImgSts.dy), WPGu2PSu(ImgSts.x), WPGu2PSu(ImgSts.x+ImgSts.dx));
PSS.FillPattern = 0;
Vr->AttribFromPSS(PSS);
VectList.AddObject(Vr); */
UpdateBBox(bbx, ImgSts.RotAngle, ImgSts.x,ImgSts.y,ImgSts.dx,ImgSts.dy); // Calculate BBX in [WPU].
TextContainer *TxC = TextWPG2_2PS(cq,Rec2.RecordLength,PSData,PSS,WPGu2PSu(ImgSts.x),WPGu2PSu(ImgSts.y),WPGu2PSu(ImgSts.dx),WPGu2PSu(ImgSts.dy),ImgSts.RotAngle);
if(TxC!=NULL) VectList.AddObject(TxC);
strcpy(cq->ObjType,"Text Data");
break;
}
case 0x10:strcpy(cq->ObjType,"!Chart Style");break;
case 0x11:strcpy(cq->ObjType,"Chart Data");break;
case 0x12:{ // PostScript or another format inside WPG2.
//CrackObject(cq,NewObjectPos);//!!!!
WORD AccessoryDataLen;
Rd_word(cq->wpd,&AccessoryDataLen);
if(Rec2.RecordLength>0x12)
{
if(AccessoryDataLen>0)
fseek(cq->wpd, AccessoryDataLen, SEEK_CUR);
if(DetectFragmentWPG2(cq->wpd,NewObjectPos) >= 1)
{
cq->recursion++;
cq->ActualPos = ftell(cq->wpd);
while(cq->ActualPos < NewObjectPos)
{
WPG2Record Rec2b;
Rec2b.Class = fgetc(cq->wpd);
Rec2b.Type = fgetc(cq->wpd);
Rd_WP_DWORD(cq->wpd,&Rec2b.Extension);
Rd_WP_DWORD(cq->wpd,&Rec2b.RecordLength);
cq->ActualPos = ftell(cq->wpd);
DWORD NewObjectPos2 = cq->ActualPos + Rec2b.RecordLength;
ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSData, PSS, EmImg, NewObjectPos2, NewObjectPos, CurrImg,
ImgSts, bbx, VectList);
if(NewObjectPos2 != ftell(cq->wpd))
fseek(cq->wpd,NewObjectPos2,SEEK_SET);
cq->ActualPos = NewObjectPos2;
}
cq->recursion--;
}
else
{
if(EmImg!=NULL)
{
EmbeddedImg *Ei2 = (EmbeddedImg *)malloc(sizeof(EmbeddedImg));
Ei2->Offset = cq->ActualPos+AccessoryDataLen+sizeof(AccessoryDataLen); /*skip accessory data in the wpg2*/
Ei2->Length = Rec2.RecordLength-AccessoryDataLen-sizeof(AccessoryDataLen);
Ei2->Extension = Ei2->ImgName = NULL;
Ei2->Next = *EmImg;
*EmImg = Ei2;
}
}
}
strcpy(cq->ObjType,"Object Image");
break;
}
case 0x15:{strcpy(cq->ObjType,"Polyline");
float *Points;
WPG_records WPG;
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
Rd_word(cq->wpd,&WPG.Curve.Count);
FixPolySize(cq, &WPG.Curve.Count, (StartWPG.PosSizePrecision==0)?Rec2.RecordLength:(Rec2.RecordLength/2)); //insufficient fix -sizeof(CTM)!!!
Points = LoadPoints(cq, WPG.Curve.Count, bbx, &TRx, StartWPG.PosSizePrecision>0);
if(Points==NULL) break;
if(TRx.Flags & WPG2_Transform::WPG2_FILL) //check Fill flag
{
VectorPolygon *pVecPoly = new VectorPolygon(Points, WPG.Curve.Count);
Points = NULL;
pVecPoly->AttribFromPSS(PSS);
pVecPoly->Close = true;
pVecPoly->Outline = TRx.Flags&WPG2_Transform::WPG2_FRM;
if((TRx.Flags & WPG2_Transform::WPG2_FRM) == 0) pVecPoly->LineStyle=0; // Disable object fill.
else
{if(pVecPoly->LineStyle==0) pVecPoly->LineStyle=1;}
pVecPoly->Transform(vecResizeXY(WPGu2PSu(1)));
VectList.AddObject(pVecPoly);
}
else
{
VectorLine *pVecLine = new VectorLine(Points, WPG.Curve.Count);
Points = NULL;
pVecLine->AttribFromPSS(PSS);
pVecLine->Close = TRx.Flags&WPG2_Transform::WPG2_CLS;
pVecLine->Transform(vecResizeXY(WPGu2PSu(1)));
VectList.AddObject(pVecLine);
}
break;
}
case 0x16:strcpy(cq->ObjType,"!Polyspline");break;
case 0x17:{strcpy(cq->ObjType,"Polycurve");
float *Points;
WPG_records WPG;
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
//!!RotAngle Ignored!!!
Rd_word(cq->wpd,&WPG.Curve.Count);
WPG.Curve.Count *= 3;
FixPolySize(cq, &WPG.Curve.Count, (StartWPG.PosSizePrecision==0)?Rec2.RecordLength:(Rec2.RecordLength/2)); //insufficient fix -sizeof(CTM)!!!
Points = LoadPoints(cq,WPG.Curve.Count,bbx,NULL,StartWPG.PosSizePrecision>0);
if(Points==NULL) break;
VectorCurve *pVecCurve = new VectorCurve(Points, WPG.Curve.Count);
pVecCurve->AttribFromPSS(PSS);
pVecCurve->Transform(vecResizeXY(WPGu2PSu(1)));
if(TRx.Flags&WPG2_Transform::WPG2_FILL) pVecCurve->Filled=true; // check Fill
if(TRx.Flags&WPG2_Transform::WPG2_FRM) pVecCurve->LineStyle=0; // Frame flags
VectList.AddObject(pVecCurve);
break;
}
case 0x18:{ WPG_records WPG;
strcpy(cq->ObjType,"Rectangle");
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
ImgSts.RotAngle = TRx.RotAngle;
LoadWPG2Rectangle(cq->wpd,WPG._2Rect);
UpdateBBox(bbx, 0, WPG._2Rect.X_ur,WPG._2Rect.Y_ll,WPG._2Rect.X_ll-WPG._2Rect.X_ur,WPG._2Rect.Y_ur-WPG._2Rect.Y_ll);
VectorRectangleArc *pRectArc = new VectorRectangleArc(
WPGu2PSu(WPG._2Rect.X_ll), WPGu2PSu(WPG._2Rect.Y_ll), WPGu2PSu(WPG._2Rect.X_ur), WPGu2PSu(WPG._2Rect.Y_ur),
WPGu2PSu(WPG._2Rect.H_radius), WPGu2PSu(WPG._2Rect.V_radius));
pRectArc->AttribFromPSS(PSS);
VectList.AddObject(pRectArc);
break;
}
case 0x19:{
WPG_records WPG;
strcpy(cq->ObjType,"Arc");
//CrackObject(cq,NewObject);
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
LoadWPG2Arc(cq->wpd,WPG._2Arc);
float Sx = WPG._2Arc.Sx;
float Sy = WPG._2Arc.Sy;
TRx.ApplyTransform(Sx,Sy);
float LeftX = WPG._2Arc.Sx - WPG._2Arc.rx;
float LeftY = WPG._2Arc.Sy;
TRx.ApplyTransform(LeftX,LeftY);
float TopX = WPG._2Arc.Sx;
float TopY = WPG._2Arc.Sy + WPG._2Arc.ry;
TRx.ApplyTransform(TopX,TopY);
float rx = sqrt((Sx-LeftX)*(Sx-LeftX) + (Sy-LeftY)*(Sy-LeftY));
float ry = sqrt((Sx-TopX)*(Sx-TopX) + (Sy-TopY)*(Sy-TopY));
VectorEllipse *pVecEllipse = new VectorEllipse(Sy-ry, Sy+ry, Sx-rx, Sx+rx);
if(fabs(TRx.RotAngle) > 1e-3)
{
pVecEllipse->Tx = new vecTransform;
pVecEllipse->Tx->RotAngle = TRx.RotAngle;
pVecEllipse->Tx->CenterX = Sx;
pVecEllipse->Tx->CenterY = Sy;
}
if((WPG._2Arc.Xi!=WPG._2Arc.Xt || WPG._2Arc.Yi!=WPG._2Arc.Yt) &&
WPG._2Arc.rx!=0 && WPG._2Arc.ry!=0)
{
pVecEllipse->bAngle = 180*atan2(WPG._2Arc.Yi/(float)WPG._2Arc.ry, WPG._2Arc.Xi/(float)WPG._2Arc.rx)/M_PI;
pVecEllipse->eAngle = 180*atan2(WPG._2Arc.Yt/(float)WPG._2Arc.ry, WPG._2Arc.Xt/(float)WPG._2Arc.rx)/M_PI;
if(pVecEllipse->bAngle<0) pVecEllipse->bAngle+=360;
if(pVecEllipse->eAngle<0) pVecEllipse->eAngle+=360;
}
UpdateBBox(bbx, TRx.RotAngle, Sx-rx, Sy-ry, 2*rx, 2*ry);
pVecEllipse->Transform(vecResizeXY(WPGu2PSu(1)));
pVecEllipse->AttribFromPSS(PSS);
if((TRx.Flags & WPG2_Transform::WPG2_FILL) == 0) pVecEllipse->BrushStyle=0; // Disable object fill.
if((TRx.Flags & WPG2_Transform::WPG2_FRM) == 0) pVecEllipse->LineStyle=0; // Disable object fill.
else
{if(pVecEllipse->LineStyle==0) pVecEllipse->LineStyle=1;}
//if(b) {pVecEllipse->FillColor.Red=0x80;b=false;}
VectList.AddObject(pVecEllipse);
break;
}
case 0x1A:strcpy(cq->ObjType,"!Compound Polygon");break;
case 0x1B:{
WPG_records WPG;
strcpy(cq->ObjType,"Bitmap position");
//CrackObject(cq,NewObject);//!!!!
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
//printf("\n Rot angle = %f ", RotAngle);
float Sx, Sy;
float RightX, RightY;
float TopX, TopY;
if(StartWPG.PosSizePrecision==0)
{
LoadWPG2BitmapRectangle(cq->wpd,WPG._2BitmapRectangle);
Sx = (WPG._2BitmapRectangle.LowLeftX + WPG._2BitmapRectangle.UpRightX) / 2;
Sy = (WPG._2BitmapRectangle.LowLeftY + WPG._2BitmapRectangle.UpRightY) / 2;
RightX = WPG._2BitmapRectangle.UpRightX;
TopY = WPG._2BitmapRectangle.UpRightY;
}
if(StartWPG.PosSizePrecision==1)
{
LoadWPG2DblBitmapRectangle(cq->wpd,WPG._2DblBitmapRectangle);
Sx = (WPG._2DblBitmapRectangle.LowLeftX + WPG._2DblBitmapRectangle.UpRightX) / (float)0x20000;
Sy = (WPG._2DblBitmapRectangle.LowLeftY + WPG._2DblBitmapRectangle.UpRightY) / (float)0x20000;
RightX = WPG._2DblBitmapRectangle.UpRightX / (float)0x10000;
TopY = WPG._2DblBitmapRectangle.UpRightY / (float)0x10000;
}
RightY = Sy;
TopX = Sx;
TRx.ApplyTransform(Sx,Sy); // Image center is rotation invariant.
TRx.ApplyTransform(RightX,RightY);
TRx.ApplyTransform(TopX,TopY);
ImgSts.dx = 2 * sqrt((RightX-Sx)*(RightX-Sx) + (RightY-Sy)*(RightY-Sy));
ImgSts.dy = 2 * sqrt((TopX-Sx)*(TopX-Sx) + (TopY-Sy)*(TopY-Sy));
if(fabs(RightY-Sy)<1e-5 && fabs(RightX-Sx)<1e-5)
{
ImgSts.RotAngle = TRx.RotAngle;
if(RightX < Sx) ImgSts.dx = -ImgSts.dx;
if(TopY < Sy) ImgSts.dy = -ImgSts.dy;
}
else
{
ImgSts.RotAngle = 180*atan2(RightY-Sy, RightX-Sx)/M_PI; // Direct rot angle calculation according to all transforms.
if((fabs(ImgSts.RotAngle)<90) ^ (TopY>Sy))
ImgSts.dy = -ImgSts.dy;
}
ImgSts.x = Sx - fabs(ImgSts.dx)/2.0;
ImgSts.y = Sy - fabs(ImgSts.dy)/2.0;
ImgSts.x /= 47.0; ImgSts.dx /= 47.0;
ImgSts.y /= 47.0; ImgSts.dy /= 47.0;
break;
}
case 0x1C:{
WPG_records WPG;
strcpy(cq->ObjType,"Text Line");
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
ImgSts.RotAngle = TRx.RotAngle;
LoadWPG2TextLine(cq->wpd,WPG._2TxtLine);
ImgSts.x = WPG._2TxtLine.Xref;
ImgSts.y = WPG._2TxtLine.Yref;
UpdateBBox(bbx, 0, ImgSts.x,ImgSts.y,0,0);
break;
}
case 0x1D:{
WPG_records WPG;
strcpy(cq->ObjType,"Text Block");
TRx.LoadWPG2Flags(cq->wpd,StartWPG.PosSizePrecision);
ImgSts.RotAngle = TRx.RotAngle;
if(StartWPG.PosSizePrecision==0)
{
LoadWPG2TextBlock(cq->wpd, WPG._2TxtBlock);
ImgSts.x = WPG._2TxtBlock.LowLeftX;
ImgSts.y = WPG._2TxtBlock.LowLeftY;
ImgSts.dx = WPG._2TxtBlock.UpRightX - WPG._2TxtBlock.LowLeftX;
ImgSts.dy = WPG._2TxtBlock.UpRightY - WPG._2TxtBlock.LowLeftY;
}
if(StartWPG.PosSizePrecision==1)
{
LoadWPG2TextBlockDbl(cq->wpd, WPG._2TxtBlockDbl);
ImgSts.x = WPG._2TxtBlockDbl.LowLeftX / (float)0x10000;
ImgSts.y = WPG._2TxtBlockDbl.LowLeftY / (float)0x10000;
ImgSts.dx = (WPG._2TxtBlockDbl.UpRightX - WPG._2TxtBlockDbl.LowLeftX) / (float)0x10000;
ImgSts.dy = (WPG._2TxtBlockDbl.UpRightY - WPG._2TxtBlockDbl.LowLeftY) / (float)0x10000;
}
UpdateBBox(bbx, 0, ImgSts.x, ImgSts.y, ImgSts.dy, ImgSts.dy); // box specification is stored for further call
}
break;
case 0x1E:strcpy(cq->ObjType,"!Text Path");break;
case 0x1F:strcpy(cq->ObjType,"!Chart");break;
case 0x20:strcpy(cq->ObjType,"!Group");break;
case 0x21:{strcpy(cq->ObjType,"!Object Capsule");break;
}
case 0x22:strcpy(cq->ObjType,"!Font Settings");break;
case 0x23:strcpy(cq->ObjType,"!Line Cap Definition");break;
case 0x24:strcpy(cq->ObjType,"!Line Join Definition");break;
case 0x25:{strcpy(cq->ObjType,"Pen Fore Color");
PSS.LineColor.Red=fgetc(cq->wpd);
PSS.LineColor.Green=fgetc(cq->wpd);
PSS.LineColor.Blue=fgetc(cq->wpd);
//PSS.LineColor.Transparency=fgetc(cq->wpd);
PSS.dirty |= PSS_LineColor;
break;
}
case 0x26:strcpy(cq->ObjType,"!DP Pen Fore Color");break;
case 0x27:{
RGB_Record Color;
Color.Red = fgetc(cq->wpd);
Color.Green = fgetc(cq->wpd);
Color.Blue = fgetc(cq->wpd);
sprintf(cq->ObjType,"!Pen Back Color %2.2X %2.2X %2.2X", Color.Red, Color.Green, Color.Blue);
break;
}
case 0x28:strcpy(cq->ObjType,"!DP Pen Back Color");break;
case 0x29:{strcpy(cq->ObjType,"Pen Style");
BYTE PenStyle;
static const BYTE ConvertPen[16]={0,1,2,5,7,10,3,19/*11*/,4,6,8,12,13,16,17/*14*/,18/*15*/};
PenStyle=fgetc(cq->wpd);
if(PenStyle<16) PenStyle=ConvertPen[PenStyle];
if(PSS.LineStyle!=PenStyle)
{PSS.LineStyle=PenStyle;PSS.dirty|=PSS_LineStyle;}
break;
}
case 0x2A:strcpy(cq->ObjType,"!Pen Pattern");break;
case 0x2B:{
WORD Width, Height;
float LineWidth;
Rd_word(cq->wpd,(WORD*)&Width);
Rd_word(cq->wpd,(WORD*)&Height);
LineWidth = WPGu2PSu(Width>Height?Width:Height);
if(PSS.LineWidth!=LineWidth)
{
PSS.LineWidth = LineWidth;
PSS.dirty |= PSS_LineWidth;
}
sprintf(cq->ObjType,"Pen Size %d", Width>Height?Width:Height);
break;
}
case 0x2C:strcpy(cq->ObjType,"!DP Pen Size");break;
case 0x2D:strcpy(cq->ObjType,"!Line Cap");break;
case 0x2E:strcpy(cq->ObjType,"!Line Join");break;
case 0x2F:strcpy(cq->ObjType,"!Brush Gradient");break;
case 0x30:strcpy(cq->ObjType,"!DP Brush Gradient");break;
case 0x31:{char GradientType;
GradientType = fgetc(cq->wpd);
WORD BrushColors = 1;
if(GradientType!=0)
Rd_word(cq->wpd, &BrushColors);
if(BrushColors>=1)
{
PSS.FillColor.Red = fgetc(cq->wpd);
PSS.FillColor.Green = fgetc(cq->wpd);
PSS.FillColor.Blue = fgetc(cq->wpd);
char FillTransparency = fgetc(cq->wpd);
/*if(BrushColors>=2)
{
PSS.FillColor.Red = fgetc(cq->wpd);
PSS.FillColor.Green = fgetc(cq->wpd);
PSS.FillColor.Blue = fgetc(cq->wpd);
PSS.FillTransparency = fgetc(cq->wpd);
}*/
sprintf(cq->ObjType,"Brush Fore Color n:%d (%2.2X %2.2X %2.2X; %2.2X)",
(int)BrushColors,
PSS.FillColor.Red, PSS.FillColor.Green, PSS.FillColor.Blue, FillTransparency);
}
else
strcpy(cq->ObjType,"!Brush Fore Color");
break;
}
case 0x32:{
WORD R,G,B,A;
char GradientType;
GradientType = fgetc(cq->wpd);
WORD BrushColors = 1;
if(GradientType!=0)
Rd_word(cq->wpd, &BrushColors);
if(BrushColors>=1)
{
Rd_word(cq->wpd,&R);
Rd_word(cq->wpd,&G);
Rd_word(cq->wpd,&B);
Rd_word(cq->wpd,&A);
PSS.FillColor.Red = R >> 8;
PSS.FillColor.Green = G >> 8;
PSS.FillColor.Blue = B >> 8;
PSS.FillTransparency = A >> 8;
sprintf(cq->ObjType,"DP Brush Fore Color n:%d (%X %X %X; %X)",
(int)BrushColors, R, G, B, A);
}
else
strcpy(cq->ObjType,"!DP Brush Fore Color");
break;
}
case 0x33:{
PSS.FillBackground.Red = fgetc(cq->wpd);
PSS.FillBackground.Green = fgetc(cq->wpd);
PSS.FillBackground.Blue = fgetc(cq->wpd);
sprintf(cq->ObjType,"Brush Back Color (%2.2X %2.2X %2.2X)",
PSS.FillBackground.Red, PSS.FillBackground.Green, PSS.FillBackground.Blue);
break;
}
case 0x34:{
WORD R,G,B;
Rd_word(cq->wpd,&R);
Rd_word(cq->wpd,&G);
Rd_word(cq->wpd,&B);
PSS.FillBackground.Red = R >> 8;
PSS.FillBackground.Green = G >> 8;
PSS.FillBackground.Blue = B >> 8;
sprintf(cq->ObjType,"DP Brush Back Color (%2X %2X %2X)", R,G,B);
break;
}
case 0x35:{WORD Pattern;
Rd_word(cq->wpd,&Pattern);
sprintf(cq->ObjType,"Brush Pattern %u", Pattern);
switch(Pattern)
{
case 0: PSS.FillPattern=1; break; // Solid pattern.
case 1: PSS.FillPattern=15; break; // 50% Gray
case 2: PSS.FillPattern=14; break; // 25% Gray
case 3: PSS.FillPattern=13; break; // 12% Gray
case 4: PSS.FillPattern=104; break; // CrossHatch
case 5: PSS.FillPattern=105; break; // CrossHatch2
case 6: PSS.FillPattern=5; break; // Diagonal CrossHatch
case 7: PSS.FillPattern=6; break; // Diagonal CrossHatch7
case 8: PSS.FillPattern=102; break; // Horizontal
case 9: PSS.FillPattern=103; break; // Horizontal2
case 10: PSS.FillPattern=8; break; // Vertical
case 11: PSS.FillPattern=9; break; // Vertical
case 12: PSS.FillPattern=2; break; // Diagonal up
case 13: PSS.FillPattern=3; break; // Diagonal2 up
case 14: PSS.FillPattern=100; break; // Diagonal down
case 15: PSS.FillPattern=101; break; // Diagonal2 down
case 16: PSS.FillPattern=106; break; // Small squares
case 17: PSS.FillPattern=107; break; // Bigger squares
case 25: PSS.FillPattern=110; break; // Plaid (Tartan)
case 26: PSS.FillPattern=109; break; // Balls
case 27: PSS.FillPattern=112; break;
case 28: PSS.FillPattern=108; break; // Plus
case 29: PSS.FillPattern=111; break; // Triangles
//case 30: // Waves
//case 31: // Arch
default:if(cq->err && Pattern>=32)
{
cq->perc.Hide();
fprintf(cq->err,_("Warning: Unexpected hatch pattern %d."),Pattern);
}
PSS.FillPattern=1;
break;
}
break;}
case 0x36:{
strcpy(cq->ObjType,"Horizontal Line");
VectorLine *pVecl = new VectorLine(2);
SWORD val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[1] = pVecl->Points[3] = val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[0] = val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[2] = val;
VectList.AddObject(pVecl);
break;
}
case 0x37:{
strcpy(cq->ObjType,"Vertical Line");
VectorLine *pVecl = new VectorLine(2);
SWORD val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[0] = pVecl->Points[2] = val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[1] = val;
Rd_word(cq->wpd, (WORD*)&val);
pVecl->Points[3] = val;
VectList.AddObject(pVecl);
break;
}
case 0x38:strcpy(cq->ObjType,"!Poster Settings");break;
case 0x39:strcpy(cq->ObjType,"!Image State");
PSS.FillColor.Red = 0; // I have absolutelly no clue, but it looks like "Image state" RESETs fill foreground color??
PSS.FillColor.Green = 0;
PSS.FillColor.Blue = 0;
PSS.FillTransparency = 0;
PSS.FirstTimeFix = false;
break;
case 0x3A:strcpy(cq->ObjType,"!Envelope Definition");break;
case 0x3B:strcpy(cq->ObjType,"!Envelope");break;
case 0x3C:{WORD TextureId;
Rd_word(cq->wpd,&TextureId);
sprintf(cq->ObjType,"!Texture %u Definition",TextureId);
break;
}
case 0x3D:strcpy(cq->ObjType,"!Brush Texture");break;
case 0x3E:strcpy(cq->ObjType,"!Texture Alignment");break;
case 0x3F:strcpy(cq->ObjType,"!Pen Texture");break;
default: sprintf(cq->ObjType,"?%d?",(int)Rec2.Type); break;
}
//Log a graphical image object into report
if(cq->log!=NULL)
{
fprintf(cq->log,"\n%*s{GRtyp#%X;len:%lXh;%s}", cq->recursion*2, "",
(int)Rec2.Type, (long)Rec2.RecordLength, cq->ObjType);
//fprintf(cq->log,"MaxY= %2.2f",MaxY);
fprintf(cq->log," Pos= %lX", (long)cq->ActualPos);
}
if(*cq->ObjType=='!' || *cq->ObjType=='?')
{UnknownObjects++;*cq->ObjType=0;}
}
/** This procedure reads both embedded and WPG files.
* See https://www.fileformat.info/format/wpg/egff.htm
* @param[in] Filename Original name of image. It is used to help generating EPS.
* No file with this name could exist.
* @param[in] Box Image type 0: external; 1: WPG1; 2: WPG2. */
Image LoadEmbeddedPictureWPG(TconvertedPass1 *cq, const char *Filename, TBox & Box, EmbeddedImg **EmImg)
{
#ifdef DEBUG
fprintf(cq->log,"\n#LoadEmbeddedPictureWPG(%s) ",(Filename==NULL)?"":Filename);fflush(cq->log);
#endif
long ldblk;
char ch, NumFormat;
WPGHeader Hdr;
WPGRecord Rec;
WPG2Record Rec2;
WPG_records WPG;
FILE *SrcImage;
string NewFilename;
Image Img, *CurrImg;
DWORD ResourceEnd, i;
Raster2DAbstract *Raster=NULL;
APalette *Palette=NULL;
PS_State PSS;
FloatBBox bbx;
VectorList VectList;
TImgConvStatus ImgSts;
bbx.MinX=65537; bbx.MaxX=-1; bbx.MinY=65537; bbx.MaxY=-1;
CurrImg = &Img;
if(Box.Image_type==1 && Box.Image_size>0) //WPG level 1
{
TryWPG1:
string PSData;
if(Filename==NULL) Filename=GetSomeImgName(".wpg");
if(*Filename==0) Filename=GetSomeImgName(".wpg");
NewFilename = MergePaths(OutputDir,RelativeFigDir)+GetFullFileName(Filename);
SrcImage=NULL;
if(SaveWPG>=1) // make an attempt to extract resource
{
/* SrcImage=fopen(NewFilename.ch,"r");
if(SrcImage!=NULL)
{
fclose(SrcImage);
goto NoCopyImage;
}*/
if((SrcImage=OpenWrChk(NewFilename,"wb",cq->err))==NULL) goto NoCopyImage;
Hdr.FileId=0x435057FF;
Hdr.DataOffset=0x10;
Hdr.ProductType=0x1601;
Hdr.FileType=0x1;
Hdr.MajorVersion=0;
Hdr.MinorVersion=0;
Hdr.EncryptKey=0;
savestruct(SrcImage,"ddwwbbw",
Hdr.FileId,Hdr.DataOffset,Hdr.ProductType,Hdr.FileType,
Hdr.MajorVersion,Hdr.MinorVersion,Hdr.EncryptKey);
}
fseek(cq->wpd,Box.Image_offset,SEEK_SET);
cq->ActualPos = Box.Image_offset;
ResourceEnd = Box.Image_offset+Box.Image_size; //end of resource
Palette = BuildPalette(256,8);
if(Palette!=NULL)
for(i=0; i<256; i++)
{
Palette->R(i,WPG_Palette[i].Red);
Palette->G(i,WPG_Palette[i].Green);
Palette->B(i,WPG_Palette[i].Blue);
}
while(cq->ActualPos<ResourceEnd)
{
Rec.RecType=fgetc(cq->wpd);
Rd_WP_DWORD(cq->wpd,&Rec.RecordLength);
if(feof(cq->wpd)) break;
cq->ActualPos=ftell(cq->wpd);
DWORD NewObject = cq->ActualPos+Rec.RecordLength;
NumFormat=0;
switch(Rec.RecType)
{
case 0x1:{strcpy(cq->ObjType,"Fill Attributes");
// CrackObject(cq,NewObject);//!!!!
PSS.FillPattern=fgetc(cq->wpd);
BYTE index=fgetc(cq->wpd);
PSS.FillColor=WPG_Palette[index];
if(Palette!=NULL)
{
if(index<Palette->Size1D)
{
PSS.FillColor.Red = Palette->R(index);
PSS.FillColor.Green = Palette->G(index);
PSS.FillColor.Blue = Palette->B(index);
}
}
break;
}
case 0x2:{strcpy(cq->ObjType,"Line Attributes");
// CrackObject(cq,NewObject);
BYTE LineColor,c;
WORD LineWidth;
c = fgetc(cq->wpd);
if(PSS.LineStyle!=c) {PSS.LineStyle=c;PSS.dirty|=PSS_LineStyle;}
LineColor = fgetc(cq->wpd);
PSS.LineColor = WPG_Palette[LineColor];
if(Palette!=NULL)
{
if(LineColor<Palette->Size1D)
{
PSS.LineColor.Red=Palette->R(LineColor);
PSS.LineColor.Green=Palette->G(LineColor);
PSS.LineColor.Blue=Palette->B(LineColor);
}
}
PSS.dirty|=PSS_LineColor;
Rd_word(cq->wpd,&LineWidth);
if(fabs(PSS.LineWidth-WPGu2PSu(LineWidth)) > 1e-5)
{
PSS.LineWidth = WPGu2PSu(LineWidth);
PSS.dirty |= PSS_LineWidth;
}
if(Verbosing>=2 && cq->log!=NULL)
{
fprintf(cq->log, "\nStyle:%u, Color:%u, Width: %u", (unsigned)c, (unsigned)LineColor, (unsigned)LineWidth);
}
break;
}
case 0x3:strcpy(cq->ObjType,"!Symbol Attributes"); break;
case 0x4:strcpy(cq->ObjType,"!Polysymbol"); break;
case 0x5:strcpy(cq->ObjType,"!Line"); break;
case 0x6:{strcpy(cq->ObjType,"Curve");
Rd_word(cq->wpd,&WPG.Curve.Count);
FixPolySize(cq, &WPG.Curve.Count, Rec.RecordLength);
float *Points = LoadPoints(cq,WPG.Curve.Count,bbx);
if(Points==NULL) break;
VectorLine *pVecLine = new VectorLine(Points, WPG.Curve.Count);
Points = NULL;
pVecLine->AttribFromPSS(PSS);
pVecLine->Close = false;
pVecLine->Transform(vecResizeXY(WPGu2PSu(1)));
VectList.AddObject(pVecLine); pVecLine=NULL;
break;
}
case 0x7:strcpy(cq->ObjType,"!Rectangle"); break;
case 0x8:{strcpy(cq->ObjType,"Polygon");
Rd_word(cq->wpd,&WPG.Curve.Count);
FixPolySize(cq,&WPG.Curve.Count,Rec.RecordLength);
float *Points = LoadPoints(cq,WPG.Curve.Count,bbx);
if(Points==NULL) break;
VectorPolygon *pVecPoly = new VectorPolygon(Points, WPG.Curve.Count);
Points = NULL;
pVecPoly->AttribFromPSS(PSS);
pVecPoly->Close = true;
pVecPoly->Transform(vecResizeXY(WPGu2PSu(1)));
VectList.AddObject(pVecPoly); pVecPoly=NULL;
free(Points);
break;
}
case 0x9:{strcpy(cq->ObjType,"Elipsis");
// CrackObject(cq,NewObject);
Rd_word(cq->wpd,(WORD*)&WPG.Ellipse.Sx);
Rd_word(cq->wpd,(WORD*)&WPG.Ellipse.Sy);
Rd_word(cq->wpd,&WPG.Ellipse.rx);
Rd_word(cq->wpd,&WPG.Ellipse.ry);
Rd_word(cq->wpd,&WPG.Ellipse.RotAngle);
Rd_word(cq->wpd,&WPG.Ellipse.bAngle);
Rd_word(cq->wpd,&WPG.Ellipse.eAngle);
WPG.Ellipse.style = fgetc(cq->wpd);
UpdateBBox(bbx, WPG.Ellipse.RotAngle,
WPG.Ellipse.Sx-WPG.Ellipse.rx,WPG.Ellipse.Sy-WPG.Ellipse.ry,2*WPG.Ellipse.rx,2*WPG.Ellipse.ry);
VectorEllipse *pVecEllipse = new VectorEllipse(WPGu2PSu(WPG.Ellipse.Sy-WPG.Ellipse.ry), WPGu2PSu(WPG.Ellipse.Sy+WPG.Ellipse.ry),
WPGu2PSu(WPG.Ellipse.Sx-WPG.Ellipse.rx), WPGu2PSu(WPG.Ellipse.Sx+WPG.Ellipse.rx));
pVecEllipse->bAngle = WPG.Ellipse.bAngle;
pVecEllipse->eAngle = WPG.Ellipse.eAngle;
if(WPG.Ellipse.RotAngle>0)
{
pVecEllipse->Tx = new vecTransform;
pVecEllipse->Tx->RotAngle = WPG.Ellipse.RotAngle;
}
pVecEllipse->AttribFromPSS(PSS);
VectList.AddObject(pVecEllipse);
break;
}
case 0xA:strcpy(cq->ObjType,"!Elipsis"); break;
case 0xB:strcpy(cq->ObjType,"Bitmap l1");
LoadWPGBitmapType1(cq->wpd,WPG.BitmapType1);
if(Raster!=NULL) break;
Raster = CreateRaster2D(WPG.BitmapType1.Width,WPG.BitmapType1.Height,WPG.BitmapType1.Depth);
if(Raster==NULL) {NoImgMemory(cq,WPG.BitmapType1.Width,WPG.BitmapType1.Height);break;}
if(UnpackWPGRaster(Raster,cq->wpd)<0)
{delete Raster;Raster=NULL;break;}
LoadRaster: if(CurrImg->Raster!=NULL)
{
CurrImg->Next=new Image;
CurrImg=CurrImg->Next;
}
ImgSts.RotAngle -= 360*((long)ImgSts.RotAngle/360);
CurrImg->x = ImgSts.x;
CurrImg->y = ImgSts.y;
CurrImg->dx = ImgSts.dx;
CurrImg->dy = ImgSts.dy;
CurrImg->RotAngle = ImgSts.RotAngle;
ImgSts.RotAngle = ImgSts.x = ImgSts.y = ImgSts.dx = ImgSts.dy = 0;
CurrImg->Raster=Raster;CurrImg->Raster->UsageCount++;Raster=NULL;
if(CurrImg->Raster->GetPlanes()>1)
AssignPalette(CurrImg,Palette);
break;
case 0xC:strcpy(cq->ObjType,"!Graphics Text");NumFormat=1; break; //This is a bug fix for Draw Perfect WPG
case 0xD:{strcpy(cq->ObjType,"Text Attributes");
BYTE TextColor;
fseek(cq->wpd, 19, SEEK_CUR);
TextColor = fgetc(cq->wpd);
PSS.TextColor = WPG_Palette[TextColor];
break;
}
case 0xE:strcpy(cq->ObjType,"Color Map");
LoadWPGColormap(cq->wpd,WPG.ColorMapRec);
if(Palette!=NULL && Palette->UsageCount==0) delete Palette;
Palette=BuildPalette(WPG.ColorMapRec.NumOfEntries+WPG.ColorMapRec.StartIndex,8);
if(Palette!=NULL)
{
fread((char *)Palette->Data1D + 3*WPG.ColorMapRec.StartIndex,
3*WPG.ColorMapRec.NumOfEntries,1,cq->wpd);
}
break; // NumFormat=1; // default DR
case 0xF:strcpy(cq->ObjType,"!Start WPG l1"); break;
case 0x10:strcpy(cq->ObjType,"!End WPG l1"); break;
case 0x11:strcpy(cq->ObjType,"Start PS l1");
if(Rec.RecordLength>8)
{
if(EmImg!=NULL)
{
EmbeddedImg *Ei2 = (EmbeddedImg *)malloc(sizeof(EmbeddedImg));
Ei2->Offset=cq->ActualPos+8; /*skip PS header in the wpg*/
Ei2->Length=Rec.RecordLength-8;
Ei2->Extension=Ei2->ImgName=NULL;
Ei2->Next=*EmImg;
*EmImg=Ei2;
}
}
break;
case 0x12:strcpy(cq->ObjType,"!Output Attributes"); break;
case 0x13:{strcpy(cq->ObjType,"Plain Curve");
fseek(cq->wpd, 4, SEEK_CUR);
Rd_word(cq->wpd,&WPG.Curve.Count);
FixPolySize(cq, &WPG.Curve.Count, Rec.RecordLength);
float *Points = LoadPoints(cq, WPG.Curve.Count, bbx);
if(Points==NULL) break;
VectorLine *pVecLine;
if((WPG.Curve.Count-1)%3 == 0)
pVecLine = new VectorCurve(Points, WPG.Curve.Count);
else // Curve is deffective, plot at least polyline.
pVecLine = new VectorLine(Points, WPG.Curve.Count);
pVecLine->AttribFromPSS(PSS);
pVecLine->Transform(vecResizeXY(WPGu2PSu(1)));
VectList.AddObject(pVecLine);
break;
}
case 0x14:{
strcpy(cq->ObjType,"Bitmap l2");
LoadWPGBitmapType2(cq->wpd,WPG.BitmapType2);
if(Raster!=NULL) break;
Raster=CreateRaster2D(WPG.BitmapType2.Width,WPG.BitmapType2.Height,WPG.BitmapType2.Depth);
if(Raster==NULL) {NoImgMemory(cq,WPG.BitmapType2.Width,WPG.BitmapType2.Height);break;}
ImgSts.x = WPG.BitmapType2.LowLeftX/47.0;
ImgSts.y = WPG.BitmapType2.LowLeftY/47.0;
ImgSts.dx = (WPG.BitmapType2.UpRightX-WPG.BitmapType2.LowLeftX)/47.0;
ImgSts.dy = (WPG.BitmapType2.UpRightY-WPG.BitmapType2.LowLeftY)/47.0;
ImgSts.RotAngle = WPG.BitmapType2.RotAngle & 0x0FFF;
if(UnpackWPGRaster(Raster,cq->wpd)<0)
{delete Raster;Raster=NULL;break;}
if(WPG.BitmapType2.RotAngle & 0x8000)
{Flip1D(Raster);ImgSts.RotAngle = 360-ImgSts.RotAngle;}
if(WPG.BitmapType2.RotAngle & 0x2000)
{
Flip2D(Raster);
if((WPG.BitmapType2.RotAngle & 0x8000)==0)
ImgSts.RotAngle = 360-ImgSts.RotAngle;
}
goto LoadRaster;
}
case 0x15:strcpy(cq->ObjType,"!Start Image"); break;
case 0x16:strcpy(cq->ObjType,"!Start Graph"); break;
case 0x17:strcpy(cq->ObjType,"!Plan Perfect"); break;
case 0x18: // NumFormat=1; // default DR
// CrackObject(cq,NewObject);
ldblk = Rec.RecordLength-21;
if(ldblk>0)
{
fseek(cq->wpd,cq->ActualPos+4,SEEK_SET);
Rd_word(cq->wpd,&WPG.TextL2.RotAngle);
WPG.TextL2.RotAngle = WPG.TextL2.RotAngle%360;
fseek(cq->wpd,cq->ActualPos+8,SEEK_SET);
Rd_word(cq->wpd,(WORD *)&WPG.TextL2.LowLeftX);
Rd_word(cq->wpd,(WORD *)&WPG.TextL2.LowLeftY);
Rd_word(cq->wpd,(WORD *)&WPG.TextL2.UpRightX);
Rd_word(cq->wpd,(WORD *)&WPG.TextL2.UpRightY);
// [XScale] [YScale] (Type)
// Debug purpose rectangle
/* VectorRectangle *Vr = new VectorRectangle(WPGu2PSu(WPG.TextL2.LowLeftY), WPGu2PSu(WPG.TextL2.UpRightY), WPGu2PSu(WPG.TextL2.LowLeftX), WPGu2PSu(WPG.TextL2.UpRightX));
Vr->AttribFromPSS(PSS);
VectList.AddObject(Vr); */
UpdateBBox(bbx, WPG.TextL2.RotAngle,
WPG.TextL2.LowLeftX,WPG.TextL2.LowLeftY,WPG.TextL2.UpRightX-WPG.TextL2.LowLeftX,WPG.TextL2.UpRightY-WPG.TextL2.LowLeftY);
Textl2_2PS(cq,VectList,ldblk,PSS,&WPG);
}
strcpy(cq->ObjType,"Graphics Text l2");
break;
case 0x19:strcpy(cq->ObjType,"!Data Start l2"); break;
case 0x1A:strcpy(cq->ObjType,"!Graphics Text l3"); break;
case 0x1B:strcpy(cq->ObjType,"PostScript l2");
if(Rec.RecordLength>0x3B)
if(EmImg!=NULL)
{
EmbeddedImg *Ei2 = (EmbeddedImg *)malloc(sizeof(EmbeddedImg));
Ei2->Offset = cq->ActualPos+0x3C; /*skip PS l2 header in the wpg*/
Ei2->Length = Rec.RecordLength-0x3C;
Ei2->Extension = Ei2->ImgName=NULL;
Ei2->Next = *EmImg;
*EmImg = Ei2;
}
break;
default: sprintf(cq->ObjType,"?%d?",(int)Rec.RecType); break;
}
//Save WPG to the disk file
if(SrcImage)
{
fseek(cq->wpd,cq->ActualPos,SEEK_SET);
fputc(Rec.RecType,SrcImage);
Wr_WP_DWORD(SrcImage, Rec.RecordLength, NumFormat);
for(i=0; i<Rec.RecordLength; i++)
{
ch = fgetc(cq->wpd);
if(feof(cq->wpd)) break;
fputc(ch,SrcImage);
}
}
//Log a graphical image object into report
if(cq->log!=NULL)
{
fprintf(cq->log,"\n%*s{GRtyp#%Xh;len:%lXh;%s}",cq->recursion * 2, "",
(int)Rec.RecType,(long)Rec.RecordLength,cq->ObjType);
#ifdef DEBUG
fflush(cq->log);
#endif //DEBUG
}
if(*cq->ObjType=='!') {UnknownObjects++;*cq->ObjType=0;}
if(NewObject!=ftell(cq->wpd))
fseek(cq->wpd,NewObject,SEEK_SET);
cq->ActualPos=NewObject;
} /**/
if(SrcImage) {fclose(SrcImage);SrcImage=NULL;}
Box.Image_size = 0;
if(PSData.length()>0)
VectList.AddObject(new PsBlob(PSData.ExtractString()));
}
if(Box.Image_type==2 && Box.Image_size>0) //WPG level 2 (might contain l.1 or different content)
{
WPG2Start StartWPG2;
//float_matrix CTM(3,3);
if(Filename==NULL || *Filename==0)
Filename=GetSomeImgName(".wpg");
NewFilename = MergePaths(OutputDir,RelativeFigDir)+GetFullFileName(Filename);
fseek(cq->wpd,Box.Image_offset,SEEK_SET);
ResourceEnd = Box.Image_offset+Box.Image_size; //end of resource
loadstruct(cq->wpd,"ddwwbbw",
&Hdr.FileId,&Hdr.DataOffset,&Hdr.ProductType,&Hdr.FileType,
&Hdr.MajorVersion,&Hdr.MinorVersion,&Hdr.EncryptKey);
if(Hdr.FileId!=0x435057FF || Hdr.EncryptKey!=0) goto NoCopyImage;
if((Hdr.ProductType>>8)==0x30)
{
cq->perc.Hide();
if(SaveWPG>=1)
{
printf("\n!!!! MAC WPG1 detected!!!! %X",Box.Image_offset);
if((SrcImage=OpenWrChk(NewFilename,"wb",cq->err))==NULL)
{
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: Cannot write to the file %s !"),NewFilename());
}
goto NoCopyImage;
}
fseek(cq->wpd,Box.Image_offset,SEEK_SET);
for(i=0;i<Box.Image_size;i++)
{
ch = fgetc(cq->wpd);
//if(feof(cq->wpd)) putchar('!');
fputc(ch,SrcImage);
}
fclose(SrcImage);
//printf("...extracted.%X......",ftell(cq->wpd));
}
cq->ActualPos = Box.Image_offset+0x10;
fseek(cq->wpd, cq->ActualPos, SEEK_SET);
while(cq->ActualPos<ResourceEnd)
{
RdDWORD_HiEnd(&Rec2.RecordLength, cq->wpd);
DWORD NewObject = ftell(cq->wpd) + Rec2.RecordLength;
Rec2.Class = fgetc(cq->wpd);
Rec2.Type = fgetc(cq->wpd);
switch(Rec2.Type)
{
case 0: strcpy(cq->ObjType,"!Start WPG MAC"); break;
case 0x11:strcpy(cq->ObjType,"!Graphics Text"); break;
default: cq->ObjType[0] = 0;
}
if(cq->log!=NULL)
{
fprintf(cq->log,"\n%*s{GRtyp#%Xh;len:%lXh;%s}",cq->recursion * 2, "",
(int)Rec2.Type, (long)Rec2.RecordLength, cq->ObjType);
//fprintf(cq->log,"MaxY= %2.2f",MaxY);
fprintf(cq->log," Pos= %lX", (long)cq->ActualPos);
}
cq->ActualPos = (NewObject+1) & ~1;
fseek(cq->wpd,cq->ActualPos,SEEK_SET);
}
goto NoCopyImage;
}
if((Hdr.ProductType>>8)!=0x16) goto NoCopyImage;
if(Hdr.FileType==1) /*WPG level 1 with header*/
{
Box.Image_offset+=Hdr.DataOffset;
Box.Image_size-=Hdr.DataOffset;
if(Box.Image_size>0) goto TryWPG1;
}
if(Hdr.FileType!=2) goto NoCopyImage;
if(SaveWPG>=1) // Make an attempt to extract resource to the separate file.
{
if((SrcImage=OpenWrChk(NewFilename(),"wb",NULL))==NULL) // the error will be output later.
{
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: Cannot extract image to the file '%s'!"),NewFilename());
}
}
else // SrcImage != NULL
{
fseek(cq->wpd,Box.Image_offset,SEEK_SET);
CopyFile(SrcImage, cq->wpd, Box.Image_size);
fclose(SrcImage);
SrcImage = fopen(NewFilename(),"rb");
if(SrcImage)
{
CheckFileFormat(SrcImage,FilForD);
fclose(SrcImage);
const char *Ext = GetExtension(NewFilename());
if(FilForD.Extension!=NULL && Ext!=NULL)
{
if(*Ext=='.') Ext++;
if(stricmp(Ext,FilForD.Extension))
{
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: File '%s' has wrong extension, should be used '%s'!"), NewFilename(), FilForD.Extension);
}
string FileNameFix(copy(NewFilename(),0,Ext-NewFilename()) + FilForD.Extension);
rename(NewFilename(), FileNameFix());
NewFilename = FileNameFix;
}
}
}
}
}
fseek(cq->wpd,Box.Image_offset+Hdr.DataOffset,SEEK_SET);
cq->ActualPos = Box.Image_offset+Hdr.DataOffset;
StartWPG2.PosSizePrecision = 0;
PSS.LineStyle = 0; // No contour line as default.
PSS.FirstTimeFix = true;
memset(&PSS.FillColor, 0xFF, sizeof(PSS.FillColor));
memset(&PSS.FillBackground, 0xFF, sizeof(PSS.FillBackground));
//VectorList VectList;
string PSData;
while(cq->ActualPos < ResourceEnd)
{
Rec2.Class = fgetc(cq->wpd);
Rec2.Type = fgetc(cq->wpd);
Rd_WP_DWORD(cq->wpd,&Rec2.Extension);
Rd_WP_DWORD(cq->wpd,&Rec2.RecordLength);
cq->ActualPos = ftell(cq->wpd);
DWORD NewObject = cq->ActualPos+Rec2.RecordLength;
if(feof(cq->wpd)) break;
ProcessWPG2Token(cq, Rec2, StartWPG2, Img, &Palette,
PSData, PSS, EmImg, NewObject, ResourceEnd, &CurrImg,
ImgSts, bbx, VectList);
if(NewObject!=ftell(cq->wpd))
fseek(cq->wpd,NewObject,SEEK_SET);
cq->ActualPos = NewObject;
}
if(PSData.length() > 0)
VectList.AddObject(new PsBlob(PSData.ExtractString()));
Box.Image_size=0;
}
if(VectList.VectorObjects > 0) //Transfer PostScript part into Image
{
if(Img.Raster!=NULL || Img.VecImage!=NULL)
{
CurrImg->Next = new Image;
CurrImg = CurrImg->Next;
}
if(CurrImg!=NULL)
{
CurrImg->x = bbx.MinX/47.0;
CurrImg->y = bbx.MinY/47.0;
CurrImg->dx=(bbx.MaxX-bbx.MinX)/47.0;
CurrImg->dy=(bbx.MaxY-bbx.MinY)/47.0;
CurrImg->RotAngle = 0;
CurrImg->AttachVecImg(new VectorImage(VectList,PSS));
}
}
if(Palette!=NULL && Palette->UsageCount==0) {delete Palette;Palette=NULL;}
if(Raster!=NULL && Raster->UsageCount==0) {delete Raster;Raster=NULL;}
NoCopyImage:
return Img;
}
/** This is replacement for LoadPicture for the wp2latex purposes. */
Image WP2L_LoadPictureWPG(TconvertedPass1 *cq, const char *FileName)
{
#ifdef DEBUG
fprintf(cq->log,"\n#WP2L_LoadPictureWPG(%s) ",FileName);fflush(cq->log);
#endif
TBox Box;
FILE *WPD_Backup,*f;
DWORD ActualPos_Backup;
EmbeddedImg *EmImTmp, *EmImg=NULL;
Image Img;
SBYTE Bk_SaveWPG;
if((f=fopen(FileName,"rb"))==NULL) return(NULL);
if(cq->log) fprintf(cq->log,_("\nOpening external image %s "),FileName);
WPD_Backup = cq->wpd;
ActualPos_Backup = cq->ActualPos;
cq->wpd = f;
cq->ActualPos = 0;
initBox(Box);
Box.HorizontalPos = 3; // 3-Full
Box.Image_offset= 0;
Box.Image_size = filesize(cq->wpd); // -Box.Image_offset
Box.Image_type=2; // WPG l2 embedded parser has also autodetect for WPG l.1
Box.Contents = 3; // content image - every images are internally converted into WPG
Bk_SaveWPG = SaveWPG;
if(SaveWPG>=1) SaveWPG=0; // block save of current WPG.
Img = LoadEmbeddedPictureWPG(cq,FileName,Box,&EmImg);
while(EmImg!=NULL) //embedded PS and other files should be processed here
{
if(EmImg->Length>0)
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: Embedded image on pos %Xh, size %u discarded!"), EmImg->Offset, EmImg->Length);
if(EmImg->Offset>8) /*Try to extract PS part from WPG metafile*/
{
/* fseek(cq->wpd,EmImg->Offset,SEEK_SET);
if(CheckWPG2WithoutPrefix(cq->wpd,EmImg->Length)) //TODO: Detect WPG2 without preffix here.
{
} */
string FragmentFileName = MergePaths(OutputDir,RelativeFigDir);
string NewFilename = FragmentFileName;
FragmentFileName += GetSomeImgName(".tmp");
fseek(cq->wpd,EmImg->Offset,SEEK_SET);
if(CopyFile(FragmentFileName(),cq->wpd,EmImg->Length)>=-1)
{
EmImg->Length = 0; // Invalidate fragment.
FILE *SrcImage;
if((SrcImage=fopen(FragmentFileName(),"rb"))==NULL)
{
if(cq->err)
fprintf(cq->err, _("\nError: Cannot open file %s for reading!"),FragmentFileName());
goto FileIsOK;
}
CheckFileFormat(SrcImage,FilForD);
if(!strcmp(FilForD.Converter,"EPS") || !strcmp(FilForD.Converter,"PS"))
{ //EPS is detected
fclose(SrcImage);
SrcImage = NULL;
NewFilename += GetSomeImgName(".eps");
rename(FragmentFileName(), NewFilename());
goto FileIsOK;
}
if(FilForD.Converter==NULL || *FilForD.Converter==0)
{fclose(SrcImage);SrcImage=NULL;}
else
{
if(*FilForD.Converter==0) {fclose(SrcImage);SrcImage=NULL;}
}
if(SrcImage)
{
TconvertedPass1 *cq1_new = GetConverter(FilForD.Converter);
if(cq1_new!=NULL)
{
/*
if(Verbosing >= 1) printf(_("[nested \"%s\" %s] "),NewFilename(),FilForD.Converter);
cq1_new->InitMe(SrcImage,cq->table,cq->strip,cq->log,cq->err);
cq1_new->recursion = cq->recursion+1;
static const int Value1 = 1;
cq1_new->Dispatch(DISP_NOCONVERTIMAGE,&Value1);
i = cq1_new->Convert_first_pass();
if(Verbosing >= 1) printf(_("\n[continuing] "));
if(cq->log!=NULL) fputs(_("\n--End or nested file.--\n"),cq->log);
cq->perc.displayed = false;
Image *pImg=NULL;
cq1_new->Dispatch(DISP_EXTRACTIMAGE,&pImg);
if(pImg)
{
if(pImg->Raster!=NULL || pImg->VecImage!=NULL) //Convert raster image into the PostScript
{ //here should be called reduction of colors
#ifndef NO_IMG
ReducePalette(pImg,256);
#endif
SavePictureEPS_MT(NewFilename,*pImg,cq->err,&cq->perc);
bFileIsOK = true;
}
delete pImg;
}
*/
delete cq1_new;
}
else
fprintf(cq->err, _("\nError: Conversion module \"%s\" is not available for file %s!"),FilForD.Converter,NewFilename());
fclose(SrcImage);
if(SaveWPG<0)
unlink(FragmentFileName());
else
{
string FixFragmentExtension = copy(FragmentFileName,0,FragmentFileName.length()-3) + FilForD.Extension;
rename(FragmentFileName(), FixFragmentExtension());
}
} // SrcImage==NULL
}
else
fprintf(cq->err, _("\nError: Cannot detect fileformat of file %s!"), FragmentFileName());
} // EmImg->Offset>8
}
FileIsOK:
EmImTmp = EmImg->Next;
free(EmImg);
EmImg = EmImTmp;
}
SaveWPG = Bk_SaveWPG;
fclose(f);
cq->wpd=WPD_Backup;
cq->ActualPos=ActualPos_Backup;
if(Img.Raster==NULL && Img.VecImage==NULL) // last chance - try to load any file format
Img = LoadPicture(FileName);
return Img;
}
/** Patch for LoadPicture that allows to use advanced WPG support. */
inline Image WP2L_LoadPicture(TconvertedPass1 *cq, const char *Name)
{
#ifdef DEBUG
fprintf(cq->log,"\n#WP2L_LoadPicture(%s) ",Name);fflush(cq->log);
#endif
Image Img;
Img = WP2L_LoadPictureWPG(cq,Name);
if(Img.Raster!=NULL || Img.VecImage!=NULL) return(Img);
return LoadPicture(Name);
}
/** Check whether file contains WPG2 stream of objects without header. */
bool CheckWPG2WithoutPrefix(FILE *F, size_t BlobSize)
{
WPG2Record Rec2;
//Rec2.Class = fgetc(F);
Rec2.Type = fgetc(F);
Rd_WP_DWORD(F,&Rec2.Extension);
Rd_WP_DWORD(F,&Rec2.RecordLength);
if(Rec2.RecordLength > BlobSize) return false;
if(Rec2.Type != 1) return false;
fseek(F,Rec2.RecordLength,SEEK_CUR);
Rec2.Type = fgetc(F);
Rd_WP_DWORD(F,&Rec2.Extension);
Rd_WP_DWORD(F,&Rec2.RecordLength);
return true;
}
/** Main procedure that extracts WPG blocks from WP files and also handles external files. */
void ImageWP(TconvertedPass1 *cq, const char *Filename, TBox & Box)
{
#ifdef DEBUG
fprintf(cq->log,"\n#ImageWP(%s) ",Filename);fflush(cq->log);
#endif
int i;
int lines=0;
const char *ss;
string NewFilename;
string FileExtension;
Image Img;
EmbeddedImg *EmImTmp,*EmImg=NULL;
FILE *SrcImage;
bool bFileIsOK = false;
if(InputPS<false) return; /* The PS image feature is disabled */
if(Filename==NULL || *Filename==0)
Filename=GetSomeImgName(".wpg"); //invent some filename if empty
if(Filename)
{
if(!strcmp(Filename,"*OLE*"))
{
Filename = GetSomeImgName(".wpg"); //fix for embedded OLE objects
}
}
Img = LoadEmbeddedPictureWPG(cq,Filename,Box,&EmImg);
NewFilename = MergePaths(OutputDir,RelativeFigDir)+CutFileName(Filename)+".eps";
NewFilename = replacesubstring(NewFilename,"?","Q");
ss = GetExtension(Filename);
if(ss!=NULL) if(*ss!=0) FileExtension=ToUpper(ss+1);
if(NewFilename!="")
for(i=StrLen(OutputDir);i<length(NewFilename);i++)
{
if(NewFilename[i]==' ' || NewFilename[i]=='#' || NewFilename[i]=='%' || NewFilename[i]=='$' || NewFilename[i]=='*')
{
if(cq->err != NULL)
{
cq->perc.Hide();
fprintf(cq->err, _("\nWarning: LaTeX cannot process filenames that contain '%c'-> fixed to '_'!"),NewFilename[i]);
}
NewFilename[i]='_';
}
}
if(FileExtension=="PS" || FileExtension=="EPS")
{ // Chybi verifikace na ps!!!!!!!
if(AbsolutePath(Filename))
{
if(!CopyFile(NewFilename,Filename))
{
bFileIsOK = true;
goto FileIsOK;
}
}
else
{
for(i=0; i<length(ImgInputDirs); i++)
{
if(!CopyFile(NewFilename,(string(ImgInputDirs[i])+Filename)()))
{
bFileIsOK = true;
goto FileIsOK;
}
}
}
}
if(Img.Raster!=NULL || Img.VecImage!=NULL) // Convert raster image into the PostScript
{
SavePS:
#ifndef NO_IMG
ReducePalette(&Img,256);
#endif
SavePictureEPS_MT(NewFilename, Img, cq->err, &cq->perc);
bFileIsOK = true;
}
while(EmImg!=NULL && !bFileIsOK)
{
if(EmImg->Offset>8 && EmImg->Length>0) /*Try to extract PS part from WPG metafile*/
{
/* fseek(cq->wpd,EmImg->Offset,SEEK_SET);
if(CheckWPG2WithoutPrefix(cq->wpd,EmImg->Length)) //TODO: Detect WPG2 without preffix here.
{
} */
string FragmentFileName = MergePaths(OutputDir,RelativeFigDir) + GetSomeImgName(".tmp");
fseek(cq->wpd,EmImg->Offset,SEEK_SET);
if(CopyFile(FragmentFileName(),cq->wpd,EmImg->Length)>=-1)
{
EmImg->Length = 0; // Invalidate fragment.
if((SrcImage=fopen(FragmentFileName(),"rb"))==NULL)
{
if(cq->err)
fprintf(cq->err, _("\nError: Cannot open file %s for reading!"), FragmentFileName());
goto FileIsOK;
}
CheckFileFormat(SrcImage,FilForD);
if(!strcmp(FilForD.Converter,"EPS") || !strcmp(FilForD.Converter,"PS"))
{ //EPS is detected
fclose(SrcImage);
SrcImage = NULL;
rename(FragmentFileName(), NewFilename());
goto FileIsOK;
}
if(FilForD.Converter==NULL || *FilForD.Converter==0)
{fclose(SrcImage);SrcImage=NULL;}
else
{
if(*FilForD.Converter==0) {fclose(SrcImage);SrcImage=NULL;}
}
if(SrcImage)
{
TconvertedPass1 *cq1_new = GetConverter(FilForD.Converter);
if(cq1_new!=NULL)
{
if(Verbosing >= 1) printf(_("[nested \"%s\" %s] "),NewFilename(),FilForD.Converter);
cq1_new->InitMe(SrcImage,cq->table,cq->strip,cq->log,cq->err);
cq1_new->recursion = cq->recursion+1;
static const int Value1 = 1;
cq1_new->Dispatch(DISP_NOCONVERTIMAGE,&Value1);
i = cq1_new->Convert_first_pass();
if(Verbosing >= 1) printf(_("\n[continuing] "));
if(cq->log!=NULL) fputs(_("\n--End or nested file.--\n"),cq->log);
cq->perc.displayed = false;
Image *pImg=NULL;
cq1_new->Dispatch(DISP_EXTRACTIMAGE,&pImg);
if(pImg)
{
if(pImg->Raster!=NULL || pImg->VecImage!=NULL) /*Convert raster image into the PostScript*/
{ //here should be called reduction of colors
#ifndef NO_IMG
ReducePalette(pImg,256);
#endif
SavePictureEPS_MT(NewFilename,*pImg,cq->err,&cq->perc);
bFileIsOK = true;
}
delete pImg;
}
delete cq1_new;
}
else
fprintf(cq->err, _("\nError: Conversion module \"%s\" is not available for file %s!"),FilForD.Converter,NewFilename());
fclose(SrcImage);
if(SaveWPG<0)
unlink(FragmentFileName());
else
{
string FixFragmentExtension = copy(FragmentFileName,0,FragmentFileName.length()-3) + FilForD.Extension;
rename(FragmentFileName(), FixFragmentExtension());
}
}
else
fprintf(cq->err, _("\nError: Cannot detect fileformat of file %s!"),NewFilename());
}
}
EmImTmp = EmImg->Next;
free(EmImg);
EmImg = EmImTmp;
}
/* Try to load image from external file */
if(!bFileIsOK)
{
if(AbsolutePath(Filename))
{
Img = WP2L_LoadPicture(cq,Filename);
if(Img.Raster!=NULL) goto SavePS;
}
else
for(i=0;i<length(ImgInputDirs);i++)
{
string FnamePath = string(ImgInputDirs[i]) + Filename;
#if defined(__MSDOS__) || defined(__WIN32__) || defined(_WIN32) || defined(_WIN64) || defined(__OS2__)
FnamePath = replacesubstring(FnamePath, "/","\\");
#else
FnamePath = replacesubstring(FnamePath, "\\","/");
#endif
Img = WP2L_LoadPicture(cq,FnamePath());
if(Img.Raster!=NULL) goto SavePS;
}
if(!CheckPreviousPS(NewFilename))
{
MakeDummyPS(Filename,Img);
if(Img.VecImage!=NULL) goto SavePS;
}
}
FileIsOK:
while(EmImg!=NULL) // Check for remaining EmImg fragments and erase them.
{
if(EmImg->Length>0)
{
printf(_("\nResource 'embedded image' is lost, no support of multiple scenes, please fix."));
if(SaveWPG>=0)
{
string FragmentFileName = MergePaths(OutputDir,RelativeFigDir) + GetSomeImgName(".tmp");
fseek(cq->wpd,EmImg->Offset,SEEK_SET);
if(CopyFile(FragmentFileName(),cq->wpd,EmImg->Length)>=-1)
{
if((SrcImage=fopen(FragmentFileName(),"rb"))!=NULL)
{
CheckFileFormat(SrcImage,FilForD);
fclose(SrcImage);
if(FilForD.Converter!=NULL && *FilForD.Converter!=0)
{
string FixFragmentExtension = copy(FragmentFileName,0,FragmentFileName.length()-3) + FilForD.Extension;
rename(FragmentFileName(), FixFragmentExtension());
}
}
}
}
}
EmImTmp = EmImg->Next;
free(EmImg);
EmImg = EmImTmp;
}
NewFilename = CutFileName(NewFilename); //New Filename only
if(cq->char_on_line == -20) /* Left one enpty line for new enviroment */
{
fputc('%', cq->strip);
NewLines(cq,2);
}
if(cq->char_on_line==true) /* make new line for leader of minipage */
NewLines(cq,1);
if(cq->flag == HeaderText || cq->envir=='B') Box.AnchorType=2;
//This writes a TeX program for including an image into the document
InputPS|=1;
if(Box.AnchorType!=2)
{
if(!BoxTexHeader(cq, Box))
{
if(Box.CaptionSize>0 && Box.CaptionPos>0)
{
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: Existing caption cannot be inserted into a current order of objects."));
}
}
Box.CaptionSize = 0;
}
putc('\n',cq->strip); lines++;
}
if(InputPS & IMG_graphicx) //graphicx.sty
{
if(Box.AnchorType!=2) fprintf(cq->strip," \\begin{center}");
if(fabs(Box.HScale-1)>1e-4 || fabs(Box.VScale-1)>1e-4)
fprintf(cq->strip," \\scalebox{%2.2f}[%2.2f]{",Box.HScale,Box.VScale);
if(Box.RotAngle!=0)
fprintf(cq->strip," \\rotatebox{%d}{",Box.RotAngle);
fprintf(cq->strip,"\\includegraphics");
switch(Box.HorizontalPos)
{
case 4:if(Box.Width>0)
{
fprintf(cq->strip,"[width=%2.2f\\textwidth]",Box.Width/100);break;
}
case 3:{
bool height_width = (Box.RotAngle>88 && Box.RotAngle<92) ||
(Box.RotAngle>268 && Box.RotAngle<272);
fprintf(cq->strip,"[%s=\\textwidth]", height_width?"height":"width");
break;
}
default:fprintf(cq->strip,"[width=%2.2fcm]",
(Box.Width>0) ? (Box.Width/10.0) : DEFAULT_BOX_WIDTH);
}
fprintf(cq->strip,"{\\FigDir/%s.eps}",NewFilename() );
if(Box.RotAngle!=0) fprintf(cq->strip,"}");
if(fabs(Box.HScale-1)>1e-4 || fabs(Box.VScale-1)>1e-4) fprintf(cq->strip,"}");
if(Box.AnchorType!=2) fprintf(cq->strip," \\end{center}");
putc('\n',cq->strip); lines++;
}
else if(InputPS & 4) //epsfig.sty
{
if(Box.AnchorType!=2) fprintf(cq->strip," \\begin{center}");
fprintf(cq->strip,"\\epsfig{file=\\FigDir/%s.eps,",NewFilename() );
switch(Box.HorizontalPos)
{
case 4:if(Box.Width>0)
{
fprintf(cq->strip,"width=%2.2f\\textwidth",Box.Width/100);break;
}
case 3:fprintf(cq->strip,"width=\\textwidth");break;
default:fprintf(cq->strip,"width=%2.2fcm",
(Box.Width>0) ? (Box.Width/10.0) : DEFAULT_BOX_WIDTH);
}
if(Box.RotAngle!=0) fprintf(cq->strip,",angle=%d",Box.RotAngle);
putc('}',cq->strip);
if(Box.AnchorType!=2) fprintf(cq->strip," \\end{center}");
putc('\n',cq->strip); lines++;
}
else if(InputPS & IMG_graphics) //graphics.sty
{
if(Box.AnchorType!=2) fprintf(cq->strip," \\begin{center}");
if(fabs(Box.HScale-1)>1e-4 || fabs(Box.VScale-1)>1e-4)
fprintf(cq->strip," \\scalebox{%2.2f}[%2.2f]{",Box.HScale,Box.VScale);
else
{
if(Box.Width>0 && Box.HorizontalPos!=3)
fprintf(cq->strip,"\\resizebox{%2.2fcm}{!}{", Box.Width/10.0);
}
if(Box.RotAngle!=0) fprintf(cq->strip," \\rotatebox{%d}{",Box.RotAngle);
fprintf(cq->strip,"\\includegraphics");
fprintf(cq->strip,"{\\FigDir/%s.eps}",NewFilename() );
if(Box.RotAngle!=0) fprintf(cq->strip,"}");
if(fabs(Box.HScale-1)>1e-4 || fabs(Box.VScale-1)>1e-4)
fprintf(cq->strip,"}");
else
{
if(Box.Width>0 && Box.HorizontalPos!=3)
fprintf(cq->strip,"}");
}
if(Box.AnchorType!=2) fprintf(cq->strip," \\end{center}");
putc('\n',cq->strip); lines++;
}
else //InputPS.sty
{
char RotFlag=0;
if(Box.RotAngle!=0)
{
switch(Box.RotAngle)
{
case 90: RotFlag='l';break;
case 180:RotFlag='u';break;
case 270:RotFlag='r';break;
}
if(RotFlag)
{
if(Rotate>=false) Rotate=true;
else RotFlag=0;
}
if(!RotFlag)
if(cq->err!=NULL && Verbosing>=0)
{
cq->perc.Hide();
fprintf(cq->err, _("\nError: InputPS.sty does not support box rotation. Use graphics.sty, graphicx.sty or epsfig.sty instead."));
}
}
fprintf(cq->strip,"\\begin{forcewidth}");
switch(Box.HorizontalPos)
{
case 4:if(Box.Width>0)
{
fprintf(cq->strip,"{%2.2f\\textwidth}\n",Box.Width/100);break;
}
case 3:fprintf(cq->strip,"{\\textwidth}\n");break;
default:fprintf(cq->strip,"{%2.2fcm}\n",
(Box.Width>0) ? (Box.Width/10.0) : DEFAULT_BOX_WIDTH);
}
lines++;
if(Box.AnchorType!=2) fprintf(cq->strip," \\begin{center}");
if(RotFlag)
{
WP2LaTeXsty+=sty_rotate;
fprintf(cq->strip," \\rotate[%c]{",RotFlag);
}
fprintf(cq->strip,"\\InputPS{\\FigDir/%s.eps}",NewFilename() );
if(RotFlag) fprintf(cq->strip,"}");
if(Box.AnchorType!=2) fprintf(cq->strip," \\end{center}");
putc('\n',cq->strip); lines++;
fprintf(cq->strip,"\\end{forcewidth}\n");lines++;
}
if(Box.CaptionSize>0 && Box.CaptionPos>0 && Box.AnchorType!=2)
{
fseek(cq->wpd,Box.CaptionPos,SEEK_SET);
if(lines>0) NewLines(cq,lines,false);
lines = 0;
cq->Dispatch(DISP_DO_CAPTION, &Box.CaptionSize);
}
if(Box.AnchorType!=2)
{
BoxTexFoot(cq, Box);
fprintf(cq->strip,"\n");
lines++;
}
if(lines>0) NewLines(cq,lines,false);
cq->char_on_line = (Box.AnchorType==2)?-1:false;
}
/*----------Converter for external standalone images----------*/
class TconvertedPass1_WPG: public TconvertedPass1
{
public:
virtual int Convert_first_pass(void);
};
int TconvertedPass1_WPG::Convert_first_pass(void)
{
#ifdef DEBUG
fprintf(log,"\n#Convert_pass1_WPG() ");fflush(log);
#endif
DWORD fsize;
TBox Box;
SBYTE Bk_SaveWPG;
DocumentStart = ftell(wpd);
fsize = filesize(wpd);
perc.Init(ftell(wpd), fsize, _("First pass WPG:") );
ActualPos = 0;
initBox(Box);
Box.HorizontalPos=3; /*3-Full */
Box.Image_offset = ActualPos;
Box.Image_size = fsize-Box.Image_offset;
Box.Image_type=2; /*WPG l2 parser has also autodetect for WPG l.1*/
Box.Contents = 3; /*content image - every images are internally converted into WPG*/
Bk_SaveWPG = SaveWPG;
if(SaveWPG>=1) SaveWPG=0;
ImageWP(this, wpd_filename(), Box);
SaveWPG = Bk_SaveWPG;
Finalise_Conversion(this);
return(1);
}
TconvertedPass1 *Factory_WPG(void) {return new TconvertedPass1_WPG;}
FFormatTranslator FormatWPG("WPG",&Factory_WPG);
#ifndef NO_IMG
FFormatTranslator FormatBMP("BMP",&Factory_WPG);
FFormatTranslator FormatPNG("PNG",&Factory_WPG);
#endif
/*-------End of WPG converter--------*/
|