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
|
// $Id: plsym.c 11973 2011-10-17 21:16:39Z andrewross $
//
// Point, symbol, and string plotting routines.
// Also font management code. See the description of plLibOpen() for
// the search path used in finding the font files.
//
// Copyright (C) 1992 Geoffrey Furnish
// Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002 Maurice LeBrun
// Copyright (C) 2000-2010 Alan W. Irwin
// Copyright (C) 2001, 2003, 2004 Rafael Laboissiere
// Copyright (C) 2002 Vincent Darley
// Copyright (C) 2004 Andrew Ross
// Copyright (C) 2007 Hazen Babcock
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//! @file
//!
//! Point-, symbol-, and string-plotting routines.
//!
#ifndef __PLSYM_H__
#define __PLSYM_H__
#include "plplotP.h"
#include <float.h>
#include <ctype.h>
#include "plhershey-unicode.h"
// Declarations
static short int *fntlkup;
static short int *fntindx;
static signed char *fntbffr;
static short int numberfonts, numberchars;
static short int indxleng;
static short fontloaded = 0;
// moved to plstr.h, plsc->cfont static PLINT font = 1; current font
#define PLMAXSTR 300
#define STLEN 250
static const char font_types[] = "nris";
static short symbol_buffer[PLMAXSTR];
static signed char xygrid[STLEN];
int hershey2unicode( int in );
// Static function prototypes
static void
pldeco( short int **sym, PLINT *length, const char *text );
static void
plchar( signed char *xygrid, PLFLT *xform, PLINT base, PLINT oline, PLINT uline,
PLINT refx, PLINT refy, PLFLT scale, PLFLT xpmm, PLFLT ypmm,
PLFLT *p_xorg, PLFLT *p_yorg, PLFLT *p_width );
static PLINT
plcvec( PLINT ch, signed char **xygr );
static void
plhrsh( PLINT ch, PLINT x, PLINT y );
static void
plhrsh2( PLINT ch, PLINT x, PLINT y );
//--------------------------------------------------------------------------
//! Plot a glyph at the specified points. (This function largely
//! supersedes plpoin and plsym because many[!] more glyphs are
//! accessible with plstring.) The glyph is specified with a PLplot
//! user string. Note that the user string is not actually limited to
//! one glyph so it is possible (but not normally useful) to plot more
//! than one glyph at the specified points with this function. As
//! with plmtex and plptex, the user string can contain FCI escapes to
//! determine the font, UTF-8 code to determine the glyph or else
//! PLplot escapes for Hershey or unicode text to determine the glyph.
//! @param n Number of points in x and y arrays.
//! @param x Array of X coordinates of points.
//! @param y Array of Y coordinates of points.
//! @param string PLplot user string corresponding to the glyph to
//! be plotted at each of the n points.
//--------------------------------------------------------------------------
void
c_plstring( PLINT n, const PLFLT *x, const PLFLT *y, const char *string )
{
PLINT i;
for ( i = 0; i < n; i++ )
{
c_plptex( x[i], y[i], 1., 0., 0.5, string );
}
}
//--------------------------------------------------------------------------
//! Plot a glyph at the specified points. (This function is largely
//! superseded by plstring which gives access to many[!] more glyphs.)
//! @param n Number of points in x and y arrays.
//! @param x Pointer to an array with X coordinates of points.
//! @param y Pointer to an array with Y coordinates of points.
//! @param code Hershey symbol code corresponding to a glyph to be
//! plotted at each of the n points.
//--------------------------------------------------------------------------
void
c_plsym( PLINT n, const PLFLT *x, const PLFLT *y, PLINT code )
{
PLINT i;
PLFLT xt, yt;
if ( plsc->level < 3 )
{
plabort( "plsym: Please set up window first" );
return;
}
if ( code < 0 )
{
plabort( "plsym: Invalid code" );
return;
}
for ( i = 0; i < n; i++ )
{
TRANSFORM( x[i], y[i], &xt, &yt );
plhrsh( code, plP_wcpcx( xt ), plP_wcpcy( yt ) );
}
}
//--------------------------------------------------------------------------
//! Plot a glyph at the specified points. (This function is largely
//! superseded by plstring which gives access to many[!] more glyphs.)
//! code=-1 means try to just draw a point. Right now it's just a
//! move and a draw at the same place. Not ideal, since a
//! sufficiently intelligent output device may optimize it away, or
//! there may be faster ways of doing it. This is OK for now, though,
//! and offers a 4X speedup over drawing a Hershey font "point" (which
//! is actually diamond shaped and and therefore takes 4 strokes to
//! draw). If 0 < code < 32, then a useful (but small subset) of
//! Hershey symbols is plotted. If 32 <= code <= 127 the
//! corresponding printable ASCII character is plotted.
//! @param n Number of points in x and y arrays.
//! @param x Pointer to an array with X coordinates of points.
//! @param y Pointer to an array with Y coordinates of points.
//! @param code Hershey symbol code (in "ascii-indexed" form with
//! -1 <= code <= 127) corresponding to a glyph to be plotted at each
//! of the n points.
//--------------------------------------------------------------------------
void
c_plpoin( PLINT n, const PLFLT *x, const PLFLT *y, PLINT code )
{
PLINT i, sym, ifont = plsc->cfont;
PLFLT xt, yt;
if ( plsc->level < 3 )
{
plabort( "plpoin: Please set up window first" );
return;
}
if ( code < -1 || code > 127 )
{
plabort( "plpoin: Invalid code" );
return;
}
if ( code == -1 )
{
for ( i = 0; i < n; i++ )
{
TRANSFORM( x[i], y[i], &xt, &yt );
pljoin( xt, yt, xt, yt );
}
}
else
{
if ( ifont > numberfonts )
ifont = 1;
sym = *( fntlkup + ( ifont - 1 ) * numberchars + code );
// One-time diagnostic output.
// fprintf(stdout, "plploin code, sym = %d, %d\n", code, sym);
for ( i = 0; i < n; i++ )
{
TRANSFORM( x[i], y[i], &xt, &yt );
plhrsh( sym, plP_wcpcx( xt ), plP_wcpcy( yt ) );
}
}
}
//--------------------------------------------------------------------------
//! Plot a glyph at the specified 3D points. (This function is
//! largely superseded by plstring3 which gives access to many[!] more
//! glyphs.) Set up the call to this function similar to what is done
//! for plline3. code=-1 means try to just draw a point. Right now
//! it's just a move and a draw at the same place. Not ideal, since a
//! sufficiently intelligent output device may optimize it away, or
//! there may be faster ways of doing it. This is OK for now, though,
//! and offers a 4X speedup over drawing a Hershey font "point" (which
//! is actually diamond shaped and therefore takes 4 strokes to draw).
//! If 0 < code < 32, then a useful (but small subset) of Hershey
//! symbols is plotted. If 32 <= code <= 127 the corresponding
//! printable ASCII character is plotted.
//! @param n Number of points in x, y, and z arrays.
//! @param x Pointer to an array with X coordinates of points.
//! @param y Pointer to an array with Y coordinates of points.
//! @param z Pointer to an array with Z coordinates of points.
//! @param code Hershey symbol code (in "ascii-indexed" form with
//! -1 <= code <= 127) corresponding to a glyph to be plotted at each
//! of the n points.
//--------------------------------------------------------------------------
void
c_plpoin3( PLINT n, const PLFLT *x, const PLFLT *y, const PLFLT *z, PLINT code )
{
PLINT i, sym, ifont = plsc->cfont;
PLFLT u, v;
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
if ( plsc->level < 3 )
{
plabort( "plpoin3: Please set up window first" );
return;
}
if ( code < -1 || code > 127 )
{
plabort( "plpoin3: Invalid code" );
return;
}
plP_gdom( &xmin, &xmax, &ymin, &ymax );
plP_grange( &zscale, &zmin, &zmax );
if ( code == -1 )
{
for ( i = 0; i < n; i++ )
{
if ( x[i] >= xmin && x[i] <= xmax &&
y[i] >= ymin && y[i] <= ymax &&
z[i] >= zmin && z[i] <= zmax )
{
u = plP_wcpcx( plP_w3wcx( x[i], y[i], z[i] ) );
v = plP_wcpcy( plP_w3wcy( x[i], y[i], z[i] ) );
plP_movphy( (PLINT) u, (PLINT) v );
plP_draphy( (PLINT) u, (PLINT) v );
}
}
}
else
{
if ( ifont > numberfonts )
ifont = 1;
sym = *( fntlkup + ( ifont - 1 ) * numberchars + code );
for ( i = 0; i < n; i++ )
{
if ( x[i] >= xmin && x[i] <= xmax &&
y[i] >= ymin && y[i] <= ymax &&
z[i] >= zmin && z[i] <= zmax )
{
u = plP_wcpcx( plP_w3wcx( x[i], y[i], z[i] ) );
v = plP_wcpcy( plP_w3wcy( x[i], y[i], z[i] ) );
plhrsh( sym, (PLINT) u, (PLINT) v );
}
}
}
}
//--------------------------------------------------------------------------
//! Plot a glyph at the specified 3D points. (This function
//! largely supersedes plpoin3 because many[!] more glyphs are
//! accessible with plstring3). Set up the call to this function
//! similar to what is done for plline3. The glyph is specified with
//! a PLplot user string. Note that the user string is not actually
//! limited to one glyph so it is possible (but not normally useful)
//! to plot more than one glyph at the specified points with this
//! function. As with plmtex and plptex, the user string can contain
//! FCI escapes to determine the font, UTF-8 code to determine the
//! glyph or else PLplot escapes for Hershey or unicode text to
//! determine the glyph.
//! @param n Number of points in x, y, and z arrays.
//! @param x Array of X coordinates of points.
//! @param y Array of Y coordinates of points.
//! @param z Array of Z coordinates of points.
//! @param string PLplot user string corresponding to the glyph to
//! be plotted at each of the n points.
//--------------------------------------------------------------------------
void
c_plstring3( PLINT n, const PLFLT *x, const PLFLT *y, const PLFLT *z, const char * string )
{
PLINT i;
PLFLT u, v;
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
if ( plsc->level < 3 )
{
plabort( "plstring3: Please set up window first" );
return;
}
plP_gdom( &xmin, &xmax, &ymin, &ymax );
plP_grange( &zscale, &zmin, &zmax );
for ( i = 0; i < n; i++ )
{
if ( x[i] >= xmin && x[i] <= xmax &&
y[i] >= ymin && y[i] <= ymax &&
z[i] >= zmin && z[i] <= zmax )
{
u = plP_w3wcx( x[i], y[i], z[i] );
v = plP_w3wcy( x[i], y[i], z[i] );
c_plptex( u, v, 1., 0., 0.5, string );
}
}
}
//--------------------------------------------------------------------------
// static void plhrsh(PLINT ch, PLINT x, PLINT y)
// PLINT ch - hershey code to plot
// PLINT x - device-world x coordinate of hershey character
// PLINT y - device-world y coordinate of hershey character
//
// Writes the Hershey symbol "ch" centred at the physical coordinate (x,y).
// This function is now just a "spoof" front end to the old plhersh,
// which has now been renamed to plhrsh2(). All this function does is
// decide whether or not we should render natively as unicode, and then
// convert between hershey and unicode.
//
// If the function KNOWS there isn't a unicode equivalent, then it will
// try to render it as a hershey font. Understandably, this might make
// testing out the unicode functions a little tricky, so if you want
// to disable this behaviour, recompile with PL_TEST_FOR_MISSING_GLYPHS
// defined.
//--------------------------------------------------------------------------
static void
plhrsh( PLINT ch, PLINT x, PLINT y )
{
EscText args;
int idx;
PLUNICODE unicode_char;
// Check to see if the device understands unicode and wants to draw
// symbols.
//
if ( ( plsc->dev_text ) && ( plsc->dev_unicode ) && ( !plsc->dev_hrshsym ) )
{
idx = plhershey2unicode( ch ); // Get the index in the lookup table
unicode_char = hershey_to_unicode_lookup_table[idx].Unicode;
//
// Test to see if there is a defined unicode glyph for this hershey code;
// if there isn't, then we pass the glyph to plhersh, and have it
// rendered the old fashioned way.
// Otherwise, we let the driver render it as unicode
//
if ( ( unicode_char == 0 ) || ( idx == -1 ) )
{
#ifndef PL_TEST_FOR_MISSING_GLYPHS
plhrsh2( ch, x, y );
#endif
}
else
{
PLUNICODE plhrsh_unicode_buffer[3], fci;
PLFLT xform[] = { 1.0, 0.0, 0.0, 1.0 };
char esc;
args.unicode_char = unicode_char;
args.font_face = hershey_to_unicode_lookup_table[idx].Font;
// Comment out to fix problem with ps, psttf drivers
//args.base = 1;
args.base = 0;
args.just = .5;
args.xform = 0;
args.x = x;
args.y = y;
args.string = NULL; // Since we are using unicode, we want this to be NULL
// "array method"
plgesc( &esc );
args.xform = xform;
args.unicode_array_len = 1;
plhrsh_unicode_buffer[0] = unicode_char;
// watch out for escape character and unescape it by appending
// one extra.
if ( unicode_char == (PLUNICODE) esc )
{
args.unicode_array_len = 2;
plhrsh_unicode_buffer[1] = unicode_char;
}
// No need to change font back since only one character.
args.unicode_array = &plhrsh_unicode_buffer[0]; // Get address of the unicode buffer (even though it is currently static)
plsc->original_chrht = plsc->chrht;
plsc->original_chrdef = plsc->chrdef;
plsc->chrht = plsc->symht;
plsc->chrdef = plsc->symdef;
if ( plsc->alt_unicode )
{
plgfci( &fci );
args.n_fci = fci;
args.n_char = unicode_char;
plP_esc( PLESC_BEGIN_TEXT, &args );
plP_esc( PLESC_TEXT_CHAR, &args );
plP_esc( PLESC_END_TEXT, &args );
}
else
{
plP_esc( PLESC_HAS_TEXT, &args );
}
plsc->chrht = plsc->original_chrht;
plsc->chrdef = plsc->original_chrdef;
}
}
else
{
plhrsh2( ch, x, y );
}
}
//--------------------------------------------------------------------------
// void plhrsh2()
//
// Writes the Hershey symbol "ch" centred at the physical coordinate (x,y).
//--------------------------------------------------------------------------
static void
plhrsh2( PLINT ch, PLINT x, PLINT y )
{
PLINT cx, cy, k, penup, style;
signed char *vxygrid = 0;
PLFLT scale, xscale, yscale;
PLINT llx[STLEN], lly[STLEN], l = 0;
penup = 1;
scale = 0.05 * plsc->symht;
if ( !plcvec( ch, &vxygrid ) )
{
plP_movphy( x, y );
return;
}
// Line style must be continuous
style = plsc->nms;
plsc->nms = 0;
// Compute how many physical pixels correspond to a character pixel
xscale = scale * plsc->xpmm;
yscale = scale * plsc->ypmm;
k = 4;
for (;; )
{
cx = vxygrid[k++];
cy = vxygrid[k++];
if ( cx == 64 && cy == 64 )
{
if ( l )
{
plP_draphy_poly( llx, lly, l );
l = 0;
}
plP_movphy( x, y );
plsc->nms = style;
return;
}
else if ( cx == 64 && cy == 0 )
penup = 1;
else
{
if ( penup == 1 )
{
if ( l )
{
plP_draphy_poly( llx, lly, l );
l = 0;
}
llx[l] = ROUND( x + xscale * cx );
lly[l++] = ROUND( y + yscale * cy );
plP_movphy( llx[l - 1], lly[l - 1] );
penup = 0;
}
else
{
llx[l] = ROUND( x + xscale * cx );
lly[l++] = ROUND( y + yscale * cy );
}
}
}
}
//--------------------------------------------------------------------------
// void pllab()
//
// Simple routine for labelling graphs.
//--------------------------------------------------------------------------
void
c_pllab( const char *xlabel, const char *ylabel, const char *tlabel )
{
if ( plsc->level < 2 )
{
plabort( "pllab: Please set up viewport first" );
return;
}
plmtex( "t", (PLFLT) 2.0, (PLFLT) 0.5, (PLFLT) 0.5, tlabel );
plmtex( "b", (PLFLT) 3.2, (PLFLT) 0.5, (PLFLT) 0.5, xlabel );
plmtex( "l", (PLFLT) 5.0, (PLFLT) 0.5, (PLFLT) 0.5, ylabel );
}
//--------------------------------------------------------------------------
// void plmtex()
//
// Prints out "text" at specified position relative to viewport
// (may be inside or outside)
//
// side String which is one of the following:
// B or b : Bottom of viewport
// T or t : Top of viewport
// BV or bv : Bottom of viewport, vertical text
// TV or tv : Top of viewport, vertical text
// L or l : Left of viewport
// R or r : Right of viewport
// LV or lv : Left of viewport, vertical text
// RV or rv : Right of viewport, vertical text
//
// disp Displacement from specified edge of viewport, measured outwards from
// the viewport in units of the current character height. The
// centerlines of the characters are aligned with the specified
// position.
//
// pos Position of the reference point of the string relative to the
// viewport edge, ranging from 0.0 (left-hand edge) to 1.0 (right-hand
// edge)
//
// just Justification of string relative to reference point
// just = 0.0 => left hand edge of string is at reference
// just = 1.0 => right hand edge of string is at reference
// just = 0.5 => center of string is at reference
//--------------------------------------------------------------------------
void
c_plmtex( const char *side, PLFLT disp, PLFLT pos, PLFLT just,
const char *text )
{
PLINT clpxmi, clpxma, clpymi, clpyma;
PLINT vert, refx, refy, x, y;
PLFLT xdv, ydv, xmm, ymm, refxmm, refymm, shift, xform[4];
PLFLT chrdef, chrht;
PLFLT dispx, dispy;
if ( plsc->level < 2 )
{
plabort( "plmtex: Please set up viewport first" );
return;
}
// Open clip limits to subpage limits
plP_gclp( &clpxmi, &clpxma, &clpymi, &clpyma ); // get and store current clip limits
plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );
if ( plP_stindex( side, "BV" ) != -1 || plP_stindex( side, "bv" ) != -1 )
{
vert = 1;
xdv = plsc->vpdxmi + ( plsc->vpdxma - plsc->vpdxmi ) * pos;
ydv = plsc->vpdymi;
dispx = 0;
dispy = -disp;
}
else if ( plP_stindex( side, "TV" ) != -1 || plP_stindex( side, "tv" ) != -1 )
{
vert = 1;
xdv = plsc->vpdxmi + ( plsc->vpdxma - plsc->vpdxmi ) * pos;
ydv = plsc->vpdyma;
dispx = 0;
dispy = disp;
}
else if ( plP_stsearch( side, 'b' ) )
{
vert = 0;
xdv = plsc->vpdxmi + ( plsc->vpdxma - plsc->vpdxmi ) * pos;
ydv = plsc->vpdymi;
dispx = 0;
dispy = -disp;
}
else if ( plP_stsearch( side, 't' ) )
{
vert = 0;
xdv = plsc->vpdxmi + ( plsc->vpdxma - plsc->vpdxmi ) * pos;
ydv = plsc->vpdyma;
dispx = 0;
dispy = disp;
}
else if ( plP_stindex( side, "LV" ) != -1 || plP_stindex( side, "lv" ) != -1 )
{
vert = 0;
xdv = plsc->vpdxmi;
ydv = plsc->vpdymi + ( plsc->vpdyma - plsc->vpdymi ) * pos;
dispx = -disp;
dispy = 0;
}
else if ( plP_stindex( side, "RV" ) != -1 || plP_stindex( side, "rv" ) != -1 )
{
vert = 0;
xdv = plsc->vpdxma;
ydv = plsc->vpdymi + ( plsc->vpdyma - plsc->vpdymi ) * pos;
dispx = disp;
dispy = 0;
}
else if ( plP_stsearch( side, 'l' ) )
{
vert = 1;
xdv = plsc->vpdxmi;
ydv = plsc->vpdymi + ( plsc->vpdyma - plsc->vpdymi ) * pos;
dispx = -disp;
dispy = 0;
}
else if ( plP_stsearch( side, 'r' ) )
{
vert = 1;
xdv = plsc->vpdxma;
ydv = plsc->vpdymi + ( plsc->vpdyma - plsc->vpdymi ) * pos;
dispx = disp;
dispy = 0;
}
else
{
plP_sclp( clpxmi, clpxma, clpymi, clpyma ); // restore initial clip limits
return;
}
// Transformation matrix
if ( vert != 0 )
{
xform[0] = 0.0;
xform[1] = -1.0;
xform[2] = 1.0;
xform[3] = 0.0;
}
else
{
xform[0] = 1.0;
xform[1] = 0.0;
xform[2] = 0.0;
xform[3] = 1.0;
}
// Convert to physical units (mm) and compute shifts
plgchr( &chrdef, &chrht );
shift = ( just == 0.0 ) ? 0.0 : plstrl( text ) * just;
xmm = plP_dcmmx( xdv ) + dispx * chrht;
ymm = plP_dcmmy( ydv ) + dispy * chrht;
refxmm = xmm - shift * xform[0];
refymm = ymm - shift * xform[2];
// Convert to device units (pixels) and call text plotter
x = plP_mmpcx( xmm );
y = plP_mmpcy( ymm );
refx = plP_mmpcx( refxmm );
refy = plP_mmpcy( refymm );
plP_text( 0, just, xform, x, y, refx, refy, text );
plP_sclp( clpxmi, clpxma, clpymi, clpyma ); // restore clip limits
}
//--------------------------------------------------------------------------
// void plptex()
//
// Prints out "text" at world cooordinate (wx,wy). The text may be
// at any angle "angle" relative to the horizontal. The parameter
// "just" adjusts the horizontal justification of the string:
// just = 0.0 => left hand edge of string is at (wx,wy)
// just = 1.0 => right hand edge of string is at (wx,wy)
// just = 0.5 => center of string is at (wx,wy) etc.
//--------------------------------------------------------------------------
void
c_plptex( PLFLT wx, PLFLT wy, PLFLT dx, PLFLT dy, PLFLT just, const char *text )
{
PLINT x, y, refx, refy;
PLFLT xdv, ydv, xmm, ymm, refxmm, refymm, shift, cc, ss;
PLFLT xform[4], diag;
PLFLT chrdef, chrht;
PLFLT dispx, dispy;
PLFLT wxt, wyt, dxt, dyt;
if ( plsc->level < 3 )
{
plabort( "plptex: Please set up window first" );
return;
}
// Transform both the origin and offset values
TRANSFORM( wx, wy, &wxt, &wyt );
TRANSFORM( wx + dx, wy + dy, &dxt, &dyt );
dxt = dxt - wxt;
dyt = dyt - wyt;
if ( dxt == 0.0 && dyt == 0.0 )
{
dxt = 1.0;
dyt = 0.0;
}
cc = plsc->wmxscl * dxt;
ss = plsc->wmyscl * dyt;
diag = sqrt( cc * cc + ss * ss );
cc /= diag;
ss /= diag;
xform[0] = cc;
xform[1] = -ss;
xform[2] = ss;
xform[3] = cc;
xdv = plP_wcdcx( wxt );
ydv = plP_wcdcy( wyt );
dispx = 0.;
dispy = 0.;
// Convert to physical units (mm) and compute shifts
plgchr( &chrdef, &chrht );
shift = ( just == 0.0 ) ? 0.0 : plstrl( text ) * just;
xmm = plP_dcmmx( xdv ) + dispx * chrht;
ymm = plP_dcmmy( ydv ) + dispy * chrht;
refxmm = xmm - shift * xform[0];
refymm = ymm - shift * xform[2];
x = plP_mmpcx( xmm );
y = plP_mmpcy( ymm );
refx = plP_mmpcx( refxmm );
refy = plP_mmpcy( refymm );
plP_text( 0, just, xform, x, y, refx, refy, text );
}
//--------------------------------------------------------------------------
// void plstr()
//
// Prints out a "string" at reference position with physical coordinates
// (refx,refy). The coordinates of the vectors defining the string are
// passed through the linear mapping defined by the 2 x 2 matrix xform()
// before being plotted. The reference position is at the left-hand edge of
// the string. If base = 1, it is aligned with the baseline of the string.
// If base = 0, it is aligned with the center of the character box.
//
// Note, all calculations are done in terms of millimetres. These are scaled
// as necessary before plotting the string on the page.
//--------------------------------------------------------------------------
void
plstr( PLINT base, PLFLT *xform, PLINT refx, PLINT refy, const char *string )
{
short int *symbol;
signed char *vxygrid = 0;
PLINT ch, i, length, level = 0, style, oline = 0, uline = 0;
PLFLT width = 0., xorg = 0., yorg = 0., def, ht, dscale, scale;
PLFLT old_sscale, sscale, old_soffset, soffset;
plgchr( &def, &ht );
dscale = 0.05 * ht;
scale = dscale;
// Line style must be continuous
style = plsc->nms;
plsc->nms = 0;
pldeco( &symbol, &length, string );
for ( i = 0; i < length; i++ )
{
ch = symbol[i];
if ( ch == -1 ) // superscript
{
plP_script_scale( TRUE, &level,
&old_sscale, &sscale, &old_soffset, &soffset );
yorg = 16.0 * dscale * soffset;
scale = dscale * sscale;
}
else if ( ch == -2 ) // subscript
{
plP_script_scale( FALSE, &level,
&old_sscale, &sscale, &old_soffset, &soffset );
yorg = -16.0 * dscale * soffset;
scale = dscale * sscale;
}
else if ( ch == -3 ) // back-char
xorg -= width * scale;
else if ( ch == -4 ) // toogle overline
oline = !oline;
else if ( ch == -5 ) // toogle underline
uline = !uline;
else
{
if ( plcvec( ch, &vxygrid ) )
plchar( vxygrid, xform, base, oline, uline, refx, refy, scale,
plsc->xpmm, plsc->ypmm, &xorg, &yorg, &width );
}
}
plsc->nms = style;
}
//--------------------------------------------------------------------------
// plchar()
//
// Plots out a given stroke font character.
//--------------------------------------------------------------------------
static void
plchar( signed char *vxygrid, PLFLT *xform, PLINT base, PLINT oline, PLINT uline,
PLINT refx, PLINT refy, PLFLT scale, PLFLT xpmm, PLFLT ypmm,
PLFLT *p_xorg, PLFLT *p_yorg, PLFLT *p_width )
{
PLINT xbase, ybase, ydisp, lx, ly, cx, cy;
PLINT k, penup;
PLFLT x, y;
PLINT llx[STLEN], lly[STLEN], l = 0;
xbase = vxygrid[2];
*p_width = vxygrid[3] - xbase;
if ( base == 0 )
{
ybase = 0;
ydisp = vxygrid[0];
}
else
{
ybase = vxygrid[0];
ydisp = 0;
}
k = 4;
penup = 1;
for (;; )
{
cx = vxygrid[k++];
cy = vxygrid[k++];
if ( cx == 64 && cy == 64 )
{
if ( l )
{
plP_draphy_poly( llx, lly, l );
l = 0;
}
break;
}
if ( cx == 64 && cy == 0 )
{
if ( l )
{
plP_draphy_poly( llx, lly, l );
l = 0;
}
penup = 1;
}
else
{
x = *p_xorg + ( cx - xbase ) * scale;
y = *p_yorg + ( cy - ybase ) * scale;
lx = refx + ROUND( xpmm * ( xform[0] * x + xform[1] * y ) );
ly = refy + ROUND( ypmm * ( xform[2] * x + xform[3] * y ) );
if ( penup == 1 )
{
if ( l )
{
plP_draphy_poly( llx, lly, l );
l = 0;
}
llx[l] = lx;
lly[l++] = ly; // store 1st point !
plP_movphy( lx, ly );
penup = 0;
}
else
{
llx[l] = lx;
lly[l++] = ly;
}
}
}
if ( oline )
{
x = *p_xorg;
y = *p_yorg + ( 30 + ydisp ) * scale;
lx = refx + ROUND( xpmm * ( xform[0] * x + xform[1] * y ) );
ly = refy + ROUND( ypmm * ( xform[2] * x + xform[3] * y ) );
plP_movphy( lx, ly );
x = *p_xorg + *p_width * scale;
lx = refx + ROUND( xpmm * ( xform[0] * x + xform[1] * y ) );
ly = refy + ROUND( ypmm * ( xform[2] * x + xform[3] * y ) );
plP_draphy( lx, ly );
}
if ( uline )
{
x = *p_xorg;
y = *p_yorg + ( -5 + ydisp ) * scale;
lx = refx + ROUND( xpmm * ( xform[0] * x + xform[1] * y ) );
ly = refy + ROUND( ypmm * ( xform[2] * x + xform[3] * y ) );
plP_movphy( lx, ly );
x = *p_xorg + *p_width * scale;
lx = refx + ROUND( xpmm * ( xform[0] * x + xform[1] * y ) );
ly = refy + ROUND( ypmm * ( xform[2] * x + xform[3] * y ) );
plP_draphy( lx, ly );
}
*p_xorg = *p_xorg + *p_width * scale;
}
//--------------------------------------------------------------------------
// PLFLT plstrl()
//
// Computes the length of a string in mm, including escape sequences.
//--------------------------------------------------------------------------
PLFLT
plstrl( const char *string )
{
short int *symbol;
signed char *vxygrid = 0;
PLINT ch, i, length, level = 0;
PLFLT width = 0., xorg = 0., dscale, scale, def, ht;
// If the driver will compute string lengths for us then we ask
// it do so by setting get_string_length flag. When this is set
// the driver will set the string_length variable instead of
// actually rendering the string.
//
// TODO:
// Is plmtex the best string diplay routine to use?
// Will this work for buffered plots?
if ( plsc->has_string_length )
{
plsc->get_string_length = 1;
c_plmtex( "t", 0.0, 0.0, 0.0, string );
plsc->get_string_length = 0;
return (PLFLT) plsc->string_length;
}
plgchr( &def, &ht );
dscale = 0.05 * ht;
scale = dscale;
pldeco( &symbol, &length, string );
for ( i = 0; i < length; i++ )
{
ch = symbol[i];
if ( ch == -1 )
{
level++;
scale = dscale * pow( 0.75, (double) ABS( level ) );
}
else if ( ch == -2 )
{
level--;
scale = dscale * pow( 0.75, (double) ABS( level ) );
}
else if ( ch == -3 )
xorg -= width * scale;
else if ( ch == -4 || ch == -5 )
;
else
{
if ( plcvec( ch, &vxygrid ) )
{
width = vxygrid[3] - vxygrid[2];
xorg += width * scale;
}
}
}
return (PLFLT) xorg;
}
//--------------------------------------------------------------------------
// PLINT plcvec()
//
// Gets the character digitisation of Hershey table entry "char".
// Returns 1 if there is a valid entry.
//--------------------------------------------------------------------------
static PLINT
plcvec( PLINT ch, signed char **xygr )
{
PLINT k = 0, ib;
signed char x, y;
ch--;
if ( ch < 0 || ch >= indxleng )
return (PLINT) 0;
ib = fntindx[ch] - 2;
if ( ib == -2 )
return (PLINT) 0;
do
{
ib++;
x = fntbffr[2 * ib];
y = fntbffr[2 * ib + 1];
xygrid[k++] = x;
xygrid[k++] = y;
} while ( ( x != 64 || y != 64 ) && k <= ( STLEN - 2 ) );
if ( k == ( STLEN - 1 ) )
{
// This is bad if we get here
xygrid[k] = 64;
xygrid[k] = 64;
}
*xygr = xygrid;
return (PLINT) 1;
}
//--------------------------------------------------------------------------
// void pldeco()
//
// Decode a character string, and return an array of float integer symbol
// numbers. This routine is responsible for interpreting all escape sequences.
// At present the following escape sequences are defined (the letter following
// the <esc> may be either upper or lower case):
//
// <esc>u : up one level (returns -1)
// <esc>d : down one level (returns -2)
// <esc>b : backspace (returns -3)
// <esc>+ : toggles overline mode (returns -4)
// <esc>- : toggles underline mode (returns -5)
// <esc><esc> : <esc>
// <esc>gx : greek letter corresponding to roman letter x
// <esc>fn : switch to Normal font
// <esc>fr : switch to Roman font
// <esc>fi : switch to Italic font
// <esc>fs : switch to Script font
// <esc>(nnn) : Hershey symbol number nnn (any number of digits)
//
// The escape character defaults to '#', but can be changed to any of
// [!#$%&*@^~] via a call to plsesc.
//--------------------------------------------------------------------------
static void
pldeco( short int **symbol, PLINT *length, const char *text )
{
PLINT ch, ifont = plsc->cfont, ig, j = 0, lentxt = (PLINT) strlen( text );
char test, esc;
short int *sym = symbol_buffer;
// Initialize parameters.
*length = 0;
*symbol = symbol_buffer;
plgesc( &esc );
if ( ifont > numberfonts )
ifont = 1;
// Get next character; treat non-printing characters as spaces.
while ( j < lentxt )
{
if ( *length >= PLMAXSTR )
return;
test = text[j++];
ch = test;
if ( ch < 0 || ch > 175 )
ch = 32;
// Test for escape sequence (#)
if ( ch == esc && ( lentxt - j ) >= 1 )
{
test = text[j++];
if ( test == esc )
sym[( *length )++] = *( fntlkup + ( ifont - 1 ) * numberchars + ch );
else if ( test == 'u' || test == 'U' )
sym[( *length )++] = -1;
else if ( test == 'd' || test == 'D' )
sym[( *length )++] = -2;
else if ( test == 'b' || test == 'B' )
sym[( *length )++] = -3;
else if ( test == '+' )
sym[( *length )++] = -4;
else if ( test == '-' )
sym[( *length )++] = -5;
else if ( test == '(' )
{
sym[*length] = 0;
while ( '0' <= text[j] && text[j] <= '9' )
{
sym[*length] = (short) ( (int) sym[*length] * 10 + text[j] - '0' );
j++;
}
( *length )++;
if ( text[j] == ')' )
j++;
}
else if ( test == 'f' || test == 'F' )
{
test = text[j++];
ifont = 1 + plP_strpos( font_types,
isupper( test ) ? tolower( test ) : test );
if ( ifont == 0 || ifont > numberfonts )
ifont = 1;
}
else if ( test == 'g' || test == 'G' )
{
test = text[j++];
ig = plP_strpos( plP_greek_mnemonic, test ) + 1;
// This accesses the Hershey glyphs using the same
// "ascii" index as plpoin. So the order of the Greek
// glyphs in this case depends on the subhersh[0-3]
// indices in fonts/font11.c which for lower-case epsilon,
// theta, and phi substitutes (684, 685, and 686) for
// (631, 634, and 647) in the compact case and (2184,
// 2185, and 2186) for (2131, 2134, and 2147) in the
// extended case.
sym[( *length )++] =
*( fntlkup + ( ifont - 1 ) * numberchars + 127 + ig );
}
else
{
;
}
}
else
{
// Decode character.
// >>PC<< removed increment from following expression to fix
// compiler bug
sym[( *length )] = *( fntlkup + ( ifont - 1 ) * numberchars + ch );
( *length )++;
}
}
}
//--------------------------------------------------------------------------
// PLINT plP_strpos()
//
// Searches string str for first occurence of character chr. If found
// the position of the character in the string is returned (the first
// character has position 0). If the character is not found a -1 is
// returned.
//--------------------------------------------------------------------------
PLINT
plP_strpos( const char *str, int chr )
{
char *temp;
if ( ( temp = strchr( str, chr ) ) )
return (PLINT) ( temp - str );
else
return (PLINT) -1;
}
//--------------------------------------------------------------------------
// PLINT plP_stindex()
//
// Similar to strpos, but searches for occurence of string str2.
//--------------------------------------------------------------------------
PLINT
plP_stindex( const char *str1, const char *str2 )
{
PLINT base, str1ind, str2ind;
for ( base = 0; *( str1 + base ) != '\0'; base++ )
{
for ( str1ind = base, str2ind = 0; *( str2 + str2ind ) != '\0' &&
*( str2 + str2ind ) == *( str1 + str1ind ); str1ind++, str2ind++ )
;
if ( *( str2 + str2ind ) == '\0' )
return (PLINT) base;
}
return (PLINT) -1; // search failed
}
//--------------------------------------------------------------------------
// PLBOOL plP_stsearch()
//
// Searches string str for character chr (case insensitive).
//--------------------------------------------------------------------------
PLBOOL
plP_stsearch( const char *str, int chr )
{
if ( strchr( str, chr ) )
return TRUE;
else if ( strchr( str, toupper( chr ) ) )
return TRUE;
else
return FALSE;
}
//--------------------------------------------------------------------------
//! Calculate scale of font size and scale of magnitude of vertical
//! offset associated with superscripts and subscripts.
//! Notes on arguments: ifupper must be either TRUE or FALSE on every
//! call to plP_script_scale. The contents of the location pointed to
//! by the level pointer must be zero on the first call to
//! plP_script_scale, but not modified externally from then on. The
//! contents of the locations pointed to by all other pointer
//! arguments are initialized internally, and should not be modified
//! externally.
//!
//! @param ifupper Value which is TRUE if superscripting, i.e., if
//! incrementing the previous level, and FALSE if subscripting, i.e.,
//! decrementing the previous level.
//! @param level Pointer to a location which contains the value of the
//! superscript/subscript level. That value is 0, +-1, +-2, etc., for
//! no superscript/subscript, the first level of
//! superscript/subscript, the second level of superscript/subscript,
//! etc. Before the call the value is the old level, and after the
//! call the value will be incremented (ifupper TRUE) or decremented
//! (ifupper FALSE) from the previous value.
//! @param old_scale A pointer to a location that contains after the
//! call the old font size scale value.
//! @param scale A pointer to a location that contains after the call
//! the font size scale value. This value is 0.75^{|level|} where
//! |level| is the magnitude of the value of the superscript/subscript
//! level after the call.
//! @param old_offset A pointer to a location that contains after the
//! call the old value of the magnitude of the superscript/subscript
//! offset.
//! @param offset A pointer to a location that contains after the call
//! the value of the magnitude of the superscript/subscript offset
//! which is zero for |level|=0 and sum_{i=1}^{i=|level|} 0.75^{i-1},
//! otherwise.
void
plP_script_scale( PLBOOL ifupper, PLINT *level,
PLFLT *old_scale, PLFLT *scale,
PLFLT *old_offset, PLFLT *offset )
{
if ( *level == 0 )
{
*old_scale = 1.;
*old_offset = 0.;
}
else
{
*old_scale = *scale;
*old_offset = *offset;
}
if ( ( *level >= 0 && ifupper ) || ( *level <= 0 && !ifupper ) )
{
// If superscript of subscript moves further away from centerline....
*scale = 0.75 * *old_scale;
*offset = *old_offset + *old_scale;
}
else
{
// If superscript of subscript moves closer to centerline....
*scale = *old_scale / 0.75;
*offset = *old_offset - *scale;
}
if ( ifupper )
( *level )++;
else
( *level )--;
}
//--------------------------------------------------------------------------
// void c_plfont(ifont)
//
// Sets the global font flag to 'ifont'.
//--------------------------------------------------------------------------
void
c_plfont( PLINT ifont )
{
PLUNICODE fci = PL_FCI_MARK;
if ( plsc->level < 1 )
{
plabort( "plfont: Please call plinit first" );
return;
}
if ( ifont < 1 || ifont > 4 )
{
plabort( "plfont: Invalid font" );
return;
}
plsc->cfont = ifont;
// Provide some degree of forward compatibility if dealing with
// unicode font. But better procedure is to call plsfci directly rather
// than using this lame Hershey font interface.
//
switch ( ifont )
{
case 1:
// normal = (medium, upright, sans serif)
plP_hex2fci( PL_FCI_SANS, PL_FCI_FAMILY, &fci );
plsfci( fci );
break;
// roman = (medium, upright, serif)
case 2:
plP_hex2fci( PL_FCI_SERIF, PL_FCI_FAMILY, &fci );
plsfci( fci );
break;
// italic = (medium, italic, serif)
case 3:
plP_hex2fci( PL_FCI_ITALIC, PL_FCI_STYLE, &fci );
plP_hex2fci( PL_FCI_SERIF, PL_FCI_FAMILY, &fci );
plsfci( fci );
break;
// script = (medium, upright, script)
case 4:
plP_hex2fci( PL_FCI_SCRIPT, PL_FCI_FAMILY, &fci );
plsfci( fci );
break;
}
}
//--------------------------------------------------------------------------
// void plfntld(fnt)
//
// Loads either the standard or extended font.
//--------------------------------------------------------------------------
void
plfntld( PLINT fnt )
{
static PLINT charset;
short bffrleng;
PDFstrm *pdfs;
if ( fontloaded && ( charset == fnt ) )
return;
plfontrel();
fontloaded = 1;
charset = fnt;
if ( fnt )
pdfs = plLibOpenPdfstrm( PL_XFONT );
else
pdfs = plLibOpenPdfstrm( PL_SFONT );
if ( pdfs == NULL )
plexit( "Unable to either (1) open/find or (2) allocate memory for the font file" );
// Read fntlkup[]
pdf_rd_2bytes( pdfs, (U_SHORT *) &bffrleng );
numberfonts = bffrleng / 256;
numberchars = bffrleng & 0xff;
bffrleng = (short) ( numberfonts * numberchars );
fntlkup = (short int *) malloc( (size_t) bffrleng * sizeof ( short int ) );
if ( !fntlkup )
plexit( "plfntld: Out of memory while allocating font buffer." );
pdf_rd_2nbytes( pdfs, (U_SHORT *) fntlkup, bffrleng );
// Read fntindx[]
pdf_rd_2bytes( pdfs, (U_SHORT *) &indxleng );
fntindx = (short int *) malloc( (size_t) indxleng * sizeof ( short int ) );
if ( !fntindx )
plexit( "plfntld: Out of memory while allocating font buffer." );
pdf_rd_2nbytes( pdfs, (U_SHORT *) fntindx, indxleng );
// Read fntbffr[]
// Since this is an array of char, there are no endian problems
pdf_rd_2bytes( pdfs, (U_SHORT *) &bffrleng );
fntbffr = (signed char *) malloc( 2 * (size_t) bffrleng * sizeof ( signed char ) );
if ( !fntbffr )
plexit( "plfntld: Out of memory while allocating font buffer." );
#if PLPLOT_USE_TCL_CHANNELS
pdf_rdx( fntbffr, sizeof ( signed char ) * (size_t) ( 2 * bffrleng ), pdfs );
#else
plio_fread( (void *) fntbffr, (size_t) sizeof ( signed char ),
(size_t) ( 2 * bffrleng ), pdfs->file );
#endif
// Done
pdf_close( pdfs );
}
//--------------------------------------------------------------------------
// void plfontrel()
//
// Release memory for fonts.
//--------------------------------------------------------------------------
void
plfontrel( void )
{
if ( fontloaded )
{
free_mem( fntindx )
free_mem( fntbffr )
free_mem( fntlkup )
fontloaded = 0;
}
}
//--------------------------------------------------------------------------
// int plhershey2unicode ( int in )
//
// Function searches for in, the input hershey code, in a lookup table and
// returns the corresponding index in that table.
// Using this index you can work out the unicode equivalent as well as
// the closest approximate to the font-face. If the returned index is
// -1 then no match was possible.
//
// Two versions of the function exist, a simple linear search version,
// and a more complex, but significantly faster, binary search version.
// If there seem to be problems with the binary search method, the brain-dead
// linear search can be enabled by defining SIMPLE_BUT_SAFE_HERSHEY_LOOKUP
// at compile time.
//--------------------------------------------------------------------------
int plhershey2unicode( int in )
{
#ifdef SIMPLE_BUT_SAFE_HERSHEY_LOOKUP
int ret = -1;
int i;
for ( i = 0; ( i < number_of_entries_in_hershey_to_unicode_table ) && ( ret == -1 ); i++ )
{
if ( hershey_to_unicode_lookup_table[i].Hershey == in )
ret = i;
}
return ( ret );
#else
int jlo = -1, jmid, jhi = number_of_entries_in_hershey_to_unicode_table;
while ( jhi - jlo > 1 )
{
// Note that although jlo or jhi can be just outside valid
// range (see initialization above) because of while condition
// jlo < jmid < jhi and jmid must be in valid range.
//
jmid = ( jlo + jhi ) / 2;
// convert hershey_to_unicode_lookup_table[jmid].Hershey to signed
// integer since we don't loose information - the number range
// is from 1 and 2932 at the moment
if ( in > (int) ( hershey_to_unicode_lookup_table[jmid].Hershey ) )
jlo = jmid;
else if ( in < (int) ( hershey_to_unicode_lookup_table[jmid].Hershey ) )
jhi = jmid;
else
// We have found it!
// in == hershey_to_unicode_lookup_table[jmid].Hershey
//
return ( jmid );
}
// jlo is invalid or it is valid and in > hershey_to_unicode_lookup_table[jlo].Hershey.
// jhi is invalid or it is valid and in < hershey_to_unicode_lookup_table[jhi].Hershey.
// All these conditions together imply in cannot be found in
// hershey_to_unicode_lookup_table[j].Hershey, for all j.
//
return ( -1 );
#endif
}
//--------------------------------------------------------------------------
// char *
// plP_FCI2FontName ( PLUNICODE fci,
// const FCI_to_FontName_Table lookup[], const int nlookup)
//
// Function takes an input FCI (font characterization integer) index,
// looks through the lookup table (which must be sorted by PLUNICODE fci),
// then returns the corresponding pointer to a valid font name. If the FCI
// index is not present the returned value is NULL.
//--------------------------------------------------------------------------
const char *
plP_FCI2FontName( PLUNICODE fci,
const FCI_to_FontName_Table lookup[], const int nlookup )
{
int jlo = -1, jmid, jhi = nlookup;
while ( jhi - jlo > 1 )
{
// Note that although jlo or jhi can be just outside valid
// range (see initialization above) because of while condition
// jlo < jmid < jhi and jmid must be in valid range.
//
jmid = ( jlo + jhi ) / 2;
if ( fci > lookup[jmid].fci )
jlo = jmid;
else if ( fci < lookup[jmid].fci )
jhi = jmid;
else
// We have found it!
// fci == lookup[jmid].fci
//
return (const char *) ( lookup[jmid].pfont );
}
// jlo is invalid or it is valid and fci > lookup[jlo].Unicode.
// jhi is invalid or it is valid and fci < lookup[jhi].Unicode.
// All these conditions together imply fci index cannot be found in lookup.
// Mark lookup failure with NULL pointer.
//
return ( NULL );
}
//--------------------------------------------------------------------------
// void plmtex3()
//
// This is the 3d equivalent of plmtex(). It prints out "text" at specified
// position relative to viewport (may be inside or outside)
//
// side String contains one or more of the following characters
// x,y,z : Specify which axis is to be labeled
// p,s : Label the "primary" or the "secondary" axis. The "primary" axis
// being somewhat arbitrary, but basically it is the one that you'd
// expect to labeled in a 3d graph of standard orientation. Example:
// for z this would be the left hand axis.
// v : draw the text perpendicular to the axis.
//
// disp Displacement from specified edge of axis, measured outwards from
// the axis in units of the current character height. The
// centerlines of the characters are aligned with the specified
// position.
//
// pos Position of the reference point of the string relative to the
// axis ends, ranging from 0.0 (left-hand end) to 1.0 (right-hand
// end)
//
// just Justification of string relative to reference point
// just = 0.0 => left hand edge of string is at reference
// just = 1.0 => right hand edge of string is at reference
// just = 0.5 => center of string is at reference
//
// All calculations are done in physical coordinates.
//
//--------------------------------------------------------------------------
void
c_plmtex3( const char *side, PLFLT disp, PLFLT pos, PLFLT just, const char *text )
{
// local storage
PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
PLFLT chrdef, chrht;
// calculated
PLFLT xpc, ypc, xrefpc, yrefpc;
PLFLT epx1 = 0.0, epy1 = 0.0, epx2 = 0.0, epy2 = 0.0, epx3 = 0.0, epy3 = 0.0;
PLFLT dispx, dispy, xform[4];
PLFLT shift, theta, temp;
// check that the plotting environment is set up
if ( plsc->level < 3 )
{
plabort( "plmtex3: Please set up window first" );
return;
}
// get plotting environment information
plP_gdom( &xmin, &xmax, &ymin, &ymax );
plP_grange( &zscale, &zmin, &zmax );
plgchr( &chrdef, &chrht );
// handle x/y axises
if ( ( plP_stindex( side, "x" ) != -1 ) || ( plP_stindex( side, "y" ) != -1 ) )
{
// get the locations of the end points of the relevant axis
// x axis label
if ( plP_stindex( side, "x" ) != -1 )
{
// primary
if ( plP_stindex( side, "p" ) != -1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
epx2 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
}
else
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
epx2 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
}
}
else
{
if ( plP_stindex( side, "p" ) != -1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
epx2 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
}
else
{
epx1 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
epx2 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
}
}
// text always goes from left to right
if ( epx1 > epx2 )
{
temp = epx1;
epx1 = epx2;
epx2 = temp;
temp = epy1;
epy1 = epy2;
epy2 = temp;
// recalculate position assuming the user specified
// it in the min -> max direction of the axis.
pos = 1.0 - pos;
}
// calculate location of text center point
// 1. calculate the angle of the axis we are to
// draw the text on relative to the horizontal
if ( ( epx2 - epx1 ) != 0.0 )
{
theta = atan( ( epy2 - epy1 ) / ( epx2 - epx1 ) );
}
else
{
if ( epy2 > epy1 )
{
theta = 0.5 * PI;
}
else
{
theta = -0.5 * PI;
}
}
// 2. calculate the perpendicular vector
dispy = disp * chrht;
// 3. calculate x & y center points
xpc = pos * ( epx2 - epx1 ) + epx1;
ypc = pos * ( epy2 - epy1 ) + epy1;
// 4. compute reference point
// It appears that drivers that cannot handle text justification
// use this as the starting point of the string.
// Calculations must be done in millimeters for this part
// so we convert to mm, do the calculation and convert back.
// The calculation is also dependent of the orientation
// (perpendicular or parallel) of the text.
xpc = plP_dcmmx( plP_pcdcx( (PLINT) xpc ) );
ypc = plP_dcmmy( plP_pcdcy( (PLINT) ypc ) ) - dispy;
shift = plstrl( text ) * just;
if ( plP_stindex( side, "v" ) != -1 )
{
xrefpc = xpc;
yrefpc = ypc - shift;
}
else
{
xrefpc = xpc - cos( theta ) * shift;
yrefpc = ypc - sin( theta ) * shift;
}
xpc = plP_mmpcx( xpc );
ypc = plP_mmpcy( ypc );
xrefpc = plP_mmpcx( xrefpc );
yrefpc = plP_mmpcy( yrefpc );
// 5. compute transform matrix & draw text
// perpendicular, rotate 90 degrees & shear
if ( plP_stindex( side, "v" ) != -1 )
{
xform[0] = 0.0;
xform[1] = -cos( theta );
xform[2] = 1.0;
xform[3] = -sin( theta );
plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text );
}
// parallel, rotate & shear by angle
else
{
xform[0] = cos( theta );
xform[1] = 0.0;
xform[2] = sin( theta );
xform[3] = 1.0;
plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text );
}
}
// handle z axises
if ( plP_stindex( side, "z" ) != -1 )
{
// Find the left most of the 4 z axis options for "primary"
// Also find the location of frontmost point in the graph,
// which will be needed to calculate at what angle to shear
// the text.
if ( plP_stindex( side, "p" ) != -1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
if ( plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) ) < epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
}
if ( plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) ) < epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
}
if ( plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) ) < epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
}
}
// find the right most of the 4 z axis options for "primary"
if ( plP_stindex( side, "s" ) != -1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
if ( plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) ) > epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmin, ymax, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmin, ymax, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
}
if ( plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) ) > epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmin, ymin, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmin, ymin, zmin ) );
}
if ( plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) ) > epx1 )
{
epx1 = plP_wcpcx( plP_w3wcx( xmax, ymax, zmin ) );
epy1 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmin ) );
epy2 = plP_wcpcy( plP_w3wcy( xmax, ymax, zmax ) );
epx3 = plP_wcpcx( plP_w3wcx( xmax, ymin, zmin ) );
epy3 = plP_wcpcy( plP_w3wcy( xmax, ymin, zmin ) );
}
}
// Calculate location of text center point.
// This is very similiar for the z axis.
// primary and secondary have to be handled separately here
if ( plP_stindex( side, "p" ) != -1 )
{
// 1. Calculate the angle of the axis we are to
// draw the text on relative to the horizontal.
if ( ( epx3 - epx1 ) != 0.0 )
{
theta = atan( ( epy3 - epy1 ) / ( epx3 - epx1 ) );
}
else
{
if ( epy3 > epy1 )
{
theta = 0.5 * PI;
}
else
{
theta = -0.5 * PI;
}
}
// 2. Calculate the perpendicular vector.
dispx = -cos( theta ) * disp * chrht;
dispy = -sin( theta ) * disp * chrht;
}
else
{
if ( ( epx1 - epx3 ) != 0.0 )
{
theta = -atan( ( epy3 - epy1 ) / ( epx1 - epx3 ) );
}
else
{
if ( epy3 > epy1 )
{
theta = -0.5 * PI;
}
else
{
theta = 0.5 * PI;
}
}
dispx = cos( theta ) * disp * chrht;
dispy = sin( theta ) * disp * chrht;
}
// 3. Calculate x & y center points.
xpc = epx1;
ypc = pos * ( epy2 - epy1 ) + epy1;
// 4. Compute the reference point.
xpc = plP_dcmmx( plP_pcdcx( (PLINT) xpc ) ) + dispx;
ypc = plP_dcmmy( plP_pcdcy( (PLINT) ypc ) ) + dispy;
shift = plstrl( text ) * just;
if ( plP_stindex( side, "v" ) != -1 )
{
xrefpc = xpc - cos( theta ) * shift;
yrefpc = ypc - sin( theta ) * shift;
}
else
{
xrefpc = xpc;
yrefpc = ypc - shift;
}
xpc = plP_mmpcx( xpc );
ypc = plP_mmpcy( ypc );
xrefpc = plP_mmpcx( xrefpc );
yrefpc = plP_mmpcy( yrefpc );
// 5. Compute transform matrix & draw text.
if ( plP_stindex( side, "v" ) != -1 )
{
xform[0] = cos( theta );
xform[1] = 0.0;
xform[2] = sin( theta );
xform[3] = 1.0;
plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text );
}
else
{
xform[0] = 0.0;
xform[1] = -cos( theta );
xform[2] = 1.0;
xform[3] = -sin( theta );
plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text );
}
}
}
//--------------------------------------------------------------------------
// void plptex3()
//
// Prints out "text" at world cooordinate (wx,wy,wz).
//
// The text is drawn parallel to the line between (wx,wy,wz) and
// (wx+dx,wy+dy,wz+dz).
//
// The text is sheared so that it is "vertically" parallel to the
// line between (wx,wy,wz) and (wx+sx, wy+sy, wz+sz). If sx=sy=sz=0 then
// the text is simply rotated to parallel to the baseline.
//
// "just" adjusts the horizontal justification of the string:
// just = 0.0 => left hand edge of string is at (wx,wy)
// just = 1.0 => right hand edge of string is at (wx,wy)
// just = 0.5 => center of string is at (wx,wy) etc.
//
// Calculations are done in physical coordinates.
//
//--------------------------------------------------------------------------
void
c_plptex3( PLFLT wx, PLFLT wy, PLFLT wz, PLFLT dx, PLFLT dy, PLFLT dz,
PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, const char *text )
{
PLFLT xpc, ypc, xrefpc, yrefpc, xdpc, ydpc, xspc, yspc, ld, ls, cp, shift;
PLFLT x_o, y_o, z_o, x_dx, y_dy, z_dz;
PLFLT theta, phi, stride, xform[6], affineL[6], cosphi;
// check that the plotting environment is set up
if ( plsc->level < 3 )
{
plabort( "plptex3: Please set up window first" );
return;
}
// compute text x,y location in physical coordinates
xpc = plP_wcpcx( plP_w3wcx( wx, wy, wz ) );
ypc = plP_wcpcy( plP_w3wcy( wx, wy, wz ) );
// determine angle to rotate text in the x-y plane
xdpc = plP_wcpcx( plP_w3wcx( wx + dx, wy + dy, wz + dz ) );
ydpc = plP_wcpcy( plP_w3wcy( wx + dx, wy + dy, wz + dz ) );
theta = atan2( ydpc - ypc, xdpc - xpc );
// Determine angle to shear text in the x-y plane. This is a little
// messy, but basically the idea is:
//
// Compute the dot product of the vector d and the vector s to
// determine the angle between them (acos(t) = d . s / |d| |s|).
// Then because acos will return a number from 0.0 to PI, i.e.
// only in quadrants 1 or 2, compute the cross product of the
// two vectors. If this is negative then the angle is adjusted
// 0.0 to -PI.
if ( ( sx == 0.0 ) && ( sy == 0.0 ) && ( sz == 0.0 ) )
{
phi = 0.0;
}
else
{
xspc = plP_wcpcx( plP_w3wcx( wx + sx, wy + sy, wz + sz ) );
yspc = plP_wcpcy( plP_w3wcy( wx + sx, wy + sy, wz + sz ) );
ld = sqrt( ( xpc - xdpc ) * ( xpc - xdpc ) + ( ypc - ydpc ) * ( ypc - ydpc ) );
ls = sqrt( ( xpc - xspc ) * ( xpc - xspc ) + ( ypc - yspc ) * ( ypc - yspc ) );
phi = acos( ( ( xdpc - xpc ) * ( xspc - xpc ) + ( ydpc - ypc ) * ( yspc - ypc ) ) / ( ld * ls ) );
cp = ( xdpc - xpc ) * ( yspc - ypc ) - ( ydpc - ypc ) * ( xspc - xpc );
if ( cp < 0.0 )
{
phi = -phi;
}
phi = 0.5 * PI - phi;
}
// Determine how to adjust the "stride" of the text to make it
// appear that it is going into (or out of) the page. Basically
// scale the x baseline of the text by the normalized length of
// the d vector projected into the x-y plane.
x_o = plP_w3wcx( wx, wy, wz );
y_o = plP_w3wcy( wx, wy, wz );
z_o = plP_w3wcz( wx, wy, wz );
x_dx = x_o - plP_w3wcx( wx + dx, wy + dy, wz + dz );
y_dy = y_o - plP_w3wcy( wx + dx, wy + dy, wz + dz );
z_dz = z_o - plP_w3wcz( wx + dx, wy + dy, wz + dz );
stride = sqrt( x_dx * x_dx + y_dy * y_dy );
stride = stride / sqrt( x_dx * x_dx + y_dy * y_dy + z_dz * z_dz );
// compute the reference point
xpc = plP_dcmmx( plP_pcdcx( (PLINT) xpc ) );
ypc = plP_dcmmy( plP_pcdcy( (PLINT) ypc ) );
shift = plstrl( text ) * just;
xrefpc = xpc - cos( theta ) * shift * stride;
yrefpc = ypc - sin( theta ) * shift * stride;
xpc = plP_mmpcx( xpc );
ypc = plP_mmpcy( ypc );
xrefpc = plP_mmpcx( xrefpc );
yrefpc = plP_mmpcy( yrefpc );
// compute the transform
// This affine transformation corresponds to transforming from old
// coordinates to new coordinates by rotating axes, y shearing
// or (y skewing), and scaling.
// Comment out the explicit xform calculations because we use
// the affine utilities for that calculation instead.
//
// xform[0] = cos( theta ) * stride;
// xform[1] = cos( theta ) * sin( phi ) - sin( theta ) * cos( phi );
// xform[2] = sin( theta ) * stride;
// xform[3] = sin( theta ) * sin( phi ) + cos( theta ) * cos( phi );
//
plP_affine_rotate( xform, 180. * theta / PI );
plP_affine_yskew( affineL, -180. * phi / PI );
plP_affine_multiply( xform, affineL, xform );
cosphi = cos( phi );
if ( fabs( cosphi ) > 1.e-300 )
plP_affine_scale( affineL, 1. / stride, 1. / cosphi );
else
plP_affine_scale( affineL, 1. / stride, 1.e300 );
plP_affine_multiply( xform, affineL, xform );
plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text );
}
//--------------------------------------------------------------------------
// void plsfont()
//
// Set the family, style and weight of the current font.
// This is a user-friendly front-end to plsfci.
// Note: A negative value signifies that this element should not be changed.
//--------------------------------------------------------------------------
void
c_plsfont( PLINT family, PLINT style, PLINT weight )
{
PLUNICODE fci;
plgfci( &fci );
if ( family >= 0 )
{
// Bounds checking assumes symbol is last font
if ( family > PL_FCI_SYMBOL )
plwarn( "plsfont: Value for family is out of range" );
else
plP_hex2fci( (unsigned char) family, PL_FCI_FAMILY, &fci );
}
if ( style >= 0 )
{
// Bounds checking assumes oblique is last style
if ( style > PL_FCI_OBLIQUE )
plwarn( "plsfont: Value for style is out of range" );
else
plP_hex2fci( (unsigned char) style, PL_FCI_STYLE, &fci );
}
if ( weight >= 0 )
{
// Bounds checking assumes bold is last weight
if ( weight > PL_FCI_BOLD )
plwarn( "plsfont: Value for weight is out of range" );
else
plP_hex2fci( (unsigned char) weight, PL_FCI_WEIGHT, &fci );
}
plsfci( fci );
}
//--------------------------------------------------------------------------
// void plgfont()
//
// Get the family, style and weight of the current font.
// This is a user-friendly front-end to plgfci.
// Note: A NULL pointer signifies that this value should not be returned.
//--------------------------------------------------------------------------
void
c_plgfont( PLINT *p_family, PLINT *p_style, PLINT *p_weight )
{
PLUNICODE fci;
unsigned char val;
plgfci( &fci );
if ( p_family )
{
plP_fci2hex( fci, &val, PL_FCI_FAMILY );
*p_family = (PLINT) val;
}
if ( p_style )
{
plP_fci2hex( fci, &val, PL_FCI_STYLE );
*p_style = (PLINT) val;
}
if ( p_weight )
{
plP_fci2hex( fci, &val, PL_FCI_WEIGHT );
*p_weight = (PLINT) val;
}
}
#undef PLSYM_H
#endif
|