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
|
/* Hello, Emacs, this is -*-C-*- */
/* GNUPLOT - pm.trm */
/*[
* Copyright 1992, 1993, 1998, 2004, 2019, 2021
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* pm.trm --- inboard terminal driver for Presentation Manager
* --- after X-11 driver, by R.W.Fearick 31/1/92.
* v1.1 11/8/92 -- speed things up
*
* since March 1998: additions for mouse support implemented by Petr Mikulik
* last change: January 2000
* for mouse support, pm.trm has to be compiled with USE_MOUSE, e.g.
* gcc ... -DUSE_MOUSE ...
* January 1999: terminal entries for PM3D functionality by Petr Mikulik
*/
#include "driver.h"
#ifdef TERM_REGISTER
register_term(pm)
#endif
#ifdef TERM_PROTO
TERM_PUBLIC void PM_init(void);
TERM_PUBLIC void PM_options(void);
TERM_PUBLIC void PM_reset(void);
TERM_PUBLIC void PM_suspend(void);
TERM_PUBLIC void PM_resume(void);
TERM_PUBLIC void PM_text(void);
TERM_PUBLIC void PM_graphics(void);
TERM_PUBLIC void PM_layer(t_termlayer layer);
TERM_PUBLIC void PM_modify_plots(unsigned int operations, int plotno);
TERM_PUBLIC void PM_move(unsigned int x, unsigned int y);
TERM_PUBLIC void PM_vector(unsigned int x, unsigned int y);
TERM_PUBLIC void PM_linetype(int lt);
TERM_PUBLIC void PM_dashtype(int dt, t_dashtype *custom_dash_pattern);
TERM_PUBLIC int PM_text_angle(float ang);
TERM_PUBLIC void PM_put_text(unsigned int x, unsigned int y, const char *str);
TERM_PUBLIC int PM_justify_text(enum JUSTIFY mode);
TERM_PUBLIC int PM_set_font(const char *font);
TERM_PUBLIC void PM_point(unsigned int x, unsigned int y, int number);
TERM_PUBLIC void PM_pointsize(double size);
TERM_PUBLIC void PM_fillbox(int style, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
TERM_PUBLIC void PM_linewidth(double linewidth);
#ifdef USE_MOUSE
TERM_PUBLIC void PM_set_ruler(int, int);
TERM_PUBLIC void PM_set_cursor(int, int, int);
TERM_PUBLIC void PM_put_tmptext(int, const char str[]);
TERM_PUBLIC void PM_set_clipboard(const char[]);
TERM_PUBLIC int PM_waitforinput(int mode);
#endif
TERM_PUBLIC int PM_make_palette (t_sm_palette *);
TERM_PUBLIC void PM_set_color (t_colorspec *);
TERM_PUBLIC void PM_filled_polygon (int, gpiPoint *);
TERM_PUBLIC void PM_image(unsigned int, unsigned int, coordval *, gpiPoint *, t_imagecolor);
#ifndef PM_OLD_ENHANCED_TEXT
/* To support "set term pm enhanced" */
TERM_PUBLIC void PM_enhanced_put_text(unsigned int x, unsigned int y, const char *str);
TERM_PUBLIC void PM_enhanced_open(char * fontname, double fontsize,
double base, TBOOLEAN widthflag, TBOOLEAN showflag,
int overprint);
TERM_PUBLIC void PM_enhanced_flush(void);
#endif
/* define PM world coordinate limits */
#define PM_XMAX 19500
#define PM_YMAX 12500
/* approximations for typical font/screen sizes */
# define PM_VCHAR (550)
# define PM_HCHAR (220)
# define PM_VTIC (125)
# define PM_HTIC (130)
#endif
#ifdef TERM_BODY
#include <stdio.h>
#include <process.h>
#include <io.h>
#define INCL_DOSPROCESS
#define INCL_DOSSEMAPHORES
#define INCL_DOSMISC
#define INCL_DOSMODULEMGR
#define INCL_DOSSESMGR
#include <os2.h>
#include "os2/pm_msgs.h"
/* path for pm program */
static char PM_path[PATH_MAX] = "";
/* track mode to avoid redraw after hitting break */
static int PM_mode = SET_TEXT;
static HEV hev;
static int PM_termmode = 0;
static TBOOLEAN PM_must_reset_opts = FALSE;
static TBOOLEAN PM_must_abort = FALSE;
/* terminal options */
static TBOOLEAN PM_widelines = FALSE;
static TBOOLEAN PM_persist = FALSE;
static TBOOLEAN PM_enhanced = TRUE;
static int PM_plot_number = 0;
static char PM_term_title[128] = "";
static char PM_def_font[128] = "";
static double PM_linewidth_scale = 1.; /* scale factor for linewidth */
static double PM_fontscale = 1.;
static double PM_pointscale = 1.;
static char PM_opts[256] = "";
static TBOOLEAN PM_optargs = FALSE;
static int mouseGnupmdrv = 0; /* PM set to 1 if we are connected to a mouseable gnupmdrv */
static FILE *PM_pipe = NULL;
static FILE *PM_savepipe = NULL;
/* characteristics of the default font */
static int PM_def_hchar;
static int PM_def_vchar;
#ifndef PM_OLD_ENHANCED_TEXT
/* track current state of pm terminal */
/* this is only needed for enhanced text */
static char PM_font[FACESIZE] = "";
static unsigned int PM_fontsize = 12;
static unsigned int PM_x = 0;
static unsigned int PM_y = 0;
static enum JUSTIFY PM_justification = LEFT;
static double PM_angle = 0.; /* unit is radian */
/* state variables for enhanced text processing */
static TBOOLEAN ENHpm_opened_string;
static TBOOLEAN ENHpm_show = TRUE;
static int ENHpm_overprint = 0;
static TBOOLEAN ENHpm_widthflag = TRUE;
static TBOOLEAN ENHpm_sizeonly = FALSE;
static double ENHpm_base;
#endif
static void PM_reset_opts(void);
static void PM_query(void);
static void PM_make_servername(char *);
static void PM_abortplot(void);
static void PM_query_font(void);
/* functions for sending messages to and receiving from gnupmdrv */
#define PM_send_msg(a) PM_send_char(a)
static inline void PM_send_char(char c);
static inline void PM_send_int(int i);
static inline void PM_send_uint(unsigned i);
static void PM_send_str(const char *str);
static inline void PM_send_buf(unsigned len, const void *buf);
static inline void PM_send_data(unsigned len, const void *buf);
static inline void PM_flush(void);
static inline int PM_recv_int(void);
static inline char *PM_recv_str(void);
inline TBOOLEAN
PM_is_connected(void)
{
return (PM_pipe != NULL);
}
static inline void
PM_send_char(char c)
{
if (PM_pipe)
putc(c, PM_pipe);
}
static inline void
PM_send_int(int i)
{
if (PM_pipe)
fwrite(&i, sizeof(int), 1, PM_pipe);
}
static inline void
PM_send_uint(unsigned int i)
{
if (PM_pipe)
fwrite(&i, sizeof(unsigned int), 1, PM_pipe);
}
static void
PM_send_str(const char *str)
{
if (PM_pipe) {
/* distinguish between NULL and empty string */
if (str == NULL)
PM_send_uint(0);
else {
unsigned len = strlen(str) + 1;
PM_send_buf(len, str);
/* pad rest of int with zeros
Note that this was wrong since the very early times of gnuplot. */
for (len = (sizeof(int) - len % sizeof(int)) % sizeof(int); len > 0; len--)
putc(NUL, PM_pipe);
}
}
}
static inline void
PM_send_buf(unsigned len, const void *buf)
{
if (PM_pipe) {
fwrite(&len, sizeof(int), 1, PM_pipe);
fwrite(buf, 1, len, PM_pipe);
}
}
static inline void
PM_send_data(unsigned len, const void *buf)
{
if (PM_pipe)
fwrite(buf, 1, len, PM_pipe);
}
static inline void
PM_flush(void)
{
if (PM_pipe)
fflush(PM_pipe);
}
static inline int
PM_recv_int(void)
{
ULONG cbR, rc;
int n = 0;
rc = DosRead(fileno(PM_pipe), &n, sizeof(int), &cbR);
return n;
}
static char *
PM_recv_str(void)
{
ULONG cbR, rc;
char *str;
unsigned len;
len = PM_recv_int();
str = (char *) malloc(len + 1);
rc = DosRead(fileno(PM_pipe), str, len * sizeof(char), &cbR);
str[len] = NUL;
/* FIXME: need padding?? */
return str;
}
TERM_PUBLIC void
PM_init(void)
{
static char buffer[1024];
int pid;
int rc;
PPIB pib;
PTIB tib;
char semname[32];
char pipename[32];
char tempname[32];
char * s;
term_force_init = TRUE;
if (PM_savepipe != NULL && PM_termmode == 0) {
PM_pipe = PM_savepipe;
}
if ((PM_pipe == NULL) && (PM_termmode & 2)) {
/* check if term is running */
PM_make_servername(tempname);
strcpy(pipename, "\\pipe\\");
strcat(pipename, tempname);
DosGetInfoBlocks(&tib, &pib);
PM_pipe = fopen(pipename, "r+b");
if (PM_pipe != NULL) {
setvbuf(PM_pipe, buffer, _IOFBF, 1024);
pid = pib->pib_ulpid;
PM_send_int(pid);
PM_flush();
/* set new options */
/* PM_reset_opts() ; */
}
}
/* else we start up term here */
if (PM_pipe == NULL) {
if (PM_termmode & 2) {
PM_make_servername(tempname);
} else {
static int gpid = 0;
gpid++;
sprintf(tempname, "gp%X%d", getpid(), gpid);
}
strcpy(semname, "\\sem32\\");
strcpy(pipename, "\\pipe\\");
strcat(semname, tempname);
strcat(pipename, tempname);
/* try to find pm outboard driver; first */
if (1) /* try GNUPLOT_DRIVER_DIR */
rc = DosSearchPath(SEARCH_ENVIRONMENT,
"GNUPLOT_DRIVER_DIR",
"gnupmdrv.exe",
PM_path,
sizeof(PM_path));
if (rc != 0) /* then try GNUPLOT */
rc = DosSearchPath(SEARCH_ENVIRONMENT,
"GNUPLOT",
"gnupmdrv.exe",
PM_path,
sizeof(PM_path));
if (rc != 0) { /* try gnuplot's directory */
_execname(PM_path, sizeof(PM_path));
s = strrchr(PM_path, '\\');
if (s != NULL) *(s + 1) = NUL;
strcat(PM_path, "gnupmdrv.exe");
rc = access(PM_path, 0);
}
if (rc != 0) /* then try current directory & path */
rc = DosSearchPath(SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,
"PATH",
"gnupmdrv.exe",
PM_path,
sizeof(PM_path));
if (rc != 0)
int_error(NO_CARET, "Cannot find gnupmdrv.exe !\n");
rc = DosCreateEventSem(semname, &hev, 1, 0);
if (rc != 0)
int_error(NO_CARET, "Cannot create semaphore !\n");
/* Originally, we used _spawnl() to start gnupmdrv. But with kLIBC this
cannot execute WINAPI applications from WINCOMPAT apps. We use OS/2's
DosStartSession() directly. */
{
STARTDATA sd;
PID pid;
ULONG ulSession;
APIRET rc;
char params[288];
memset(&sd, 0, sizeof(STARTDATA));
sd.Length = sizeof(STARTDATA);
sd.Related = (PM_optargs == 0) ? SSF_RELATED_CHILD : SSF_RELATED_INDEPENDENT;
sd.PgmName = PM_path;
snprintf(params, sizeof(params), "%s %s", tempname, PM_opts);
sd.PgmInputs = params;
sd.InheritOpt = SSF_INHERTOPT_PARENT;
rc = DosStartSession(&sd, &ulSession, &pid);
if (rc != 0)
int_error(NO_CARET, "Cannot start gnupmdrv.exe: rc = %ul\n", rc);
}
DosGetInfoBlocks(&tib, &pib);
/* Wait for gnupmdrv to signal that the pipe is ready... */
rc = DosWaitEventSem(hev, 10000);
DosCloseEventSem(hev);
if (rc != 0)
int_error(NO_CARET, "Cannot wait for semaphore: rc = %x!\n", rc);
PM_pipe = fopen(pipename, "r+b");
if (PM_pipe == NULL)
int_error(NO_CARET, "Cannot open pipe to gnupmdrv!\n");
if (PM_termmode == 0)
PM_savepipe = PM_pipe;
setvbuf(PM_pipe, buffer, _IOFBF, 1024);
pid = pib->pib_ulpid;
fwrite(&pid, 1, 4, PM_pipe);
fflush(PM_pipe);
PM_reset_opts();
} else {
if (PM_must_reset_opts)
PM_reset_opts();
}
#ifdef USE_MOUSE
/* PM: notify gnupmdrv that this is mouse-enhanced terminal */
PM_send_msg(GR_MOUSECAPABLE);
PM_flush();
/* we catch mouseable gnupmdrv's answer in PM_query by 0xABCD */
#endif
PM_query();
PM_def_hchar = term->h_char;
PM_def_vchar = term->v_char;
}
static void
PM_make_servername(char *str)
{
if (PM_term_title[0]) {
int hash = 0;
char *p = PM_term_title + 1;
int match = PM_term_title[0];
while (*p != match) {
hash = (hash << 1) + hash + *p++;
}
hash %= (256 * 256 * 256 - 1);
sprintf(str, "gp%x", hash);
} else {
sprintf(str, "gpServ%d", PM_plot_number);
}
}
enum PM_id { PM_DEFAULT,
PM_TITLE, PM_FONT,
PM_LINEWIDTH, PM_POINTSCALE, PM_FONTSCALE,
PM_SERVER, PM_NOSERVER,
PM_PERSIST, PM_NOPERSIST,
PM_WIDELINES, PM_NOWIDELINES,
PM_ENHANCED, PM_NOENHANCED,
PM_OTHER };
static struct gen_table PM_opt_table[] =
{
{ "d$efault", PM_DEFAULT },
{ "pe$rsist", PM_PERSIST },
{ "nope$rsist", PM_NOPERSIST },
{ "s$erver", PM_SERVER },
{ "w$idelines", PM_WIDELINES },
{ "now$idelines", PM_NOWIDELINES },
{ "nos$erver", PM_NOSERVER },
{ "e$nhanced", PM_ENHANCED },
{ "noe$nhanced", PM_NOENHANCED },
{ "ti$tle", PM_TITLE },
{ "font", PM_FONT },
{ "linew$idth", PM_LINEWIDTH },
{ "lw", PM_LINEWIDTH },
{ "fonts$cale", PM_FONTSCALE },
{ "fs", PM_FONTSCALE },
{ "pointscale", PM_POINTSCALE },
{ "ps", PM_POINTSCALE },
{ NULL, PM_OTHER }
};
TERM_PUBLIC void
PM_options(void)
{
static TBOOLEAN first_init = TRUE;
int old_termmode;
char * s;
// honor command line persist option
if (first_init) {
PM_persist = persist_cl || PM_persist;
first_init = FALSE;
}
while (!END_OF_COMMAND) {
switch (lookup_table(&PM_opt_table[0], c_token)) {
case PM_PERSIST:
c_token++;
PM_persist = TRUE;
break;
case PM_NOPERSIST:
c_token++;
PM_persist = FALSE;
break;
case PM_SERVER:
c_token++;
PM_plot_number = int_expression();
if (PM_plot_number <= 0) {
PM_plot_number = 0;
}
break;
case PM_NOSERVER:
c_token++;
PM_plot_number = 0;
break;
case PM_WIDELINES:
c_token++;
PM_widelines = TRUE;
break;
case PM_NOWIDELINES:
c_token++;
PM_widelines = FALSE;
break;
case PM_LINEWIDTH:
c_token++;
PM_linewidth_scale = real_expression();
if (PM_linewidth_scale <= 0) PM_linewidth_scale = 1.;
break;
case PM_FONTSCALE:
c_token++;
PM_fontscale = real_expression();
if (PM_fontscale <= 0) PM_fontscale = 1.;
break;
case PM_POINTSCALE:
c_token++;
PM_pointscale = real_expression();
if (PM_pointscale <= 0) PM_pointscale = 1.;
break;
case PM_ENHANCED:
c_token++;
PM_enhanced = TRUE;
#ifdef PM_OLD_ENHANCED_TEXT
term->put_text = PM_put_text;
#else
term->put_text = PM_enhanced_put_text;
#endif
term->flags |= TERM_ENHANCED_TEXT;
break;
case PM_NOENHANCED:
c_token++;
PM_enhanced = FALSE;
term->put_text = PM_put_text;
term->flags &= ~TERM_ENHANCED_TEXT;
break;
case PM_FONT:
c_token++;
s = try_to_get_string();
if (s != NULL) {
safe_strncpy(PM_def_font, s, sizeof(PM_def_font));
free(s);
} else {
PM_def_font[0] = NUL;
}
break;
case PM_TITLE:
c_token++;
s = try_to_get_string();
if (s == NULL)
int_error(c_token, "expecting string argument");
safe_strncpy(PM_term_title, s, sizeof(PM_term_title));
free(s);
break;
default:
/* deprecated behaviour */
s = try_to_get_string();
if (s == NULL) {
int_error(c_token, "Unknown terminal option");
PM_term_title[0] = NUL;
} else {
safe_strncpy(PM_term_title, s, sizeof(PM_term_title));
free(s);
}
break;
}
}
// re-init terminal parameters etc.
PM_optargs = FALSE;
old_termmode = PM_termmode;
PM_termmode = 0;
PM_opts[0] = NUL;
if (PM_persist) {
strcat(PM_opts, "-p ");
PM_optargs = TRUE;
PM_termmode |= 1;
if (!(old_termmode & 1))
PM_pipe = NULL;
}
if (PM_plot_number > 0) {
PM_termmode |= 2;
if (!(old_termmode & 2))
PM_pipe = NULL;
sprintf(PM_opts + strlen(PM_opts), "-s %d ", PM_plot_number);
PM_optargs = TRUE;
}
if (PM_widelines) {
strcat(PM_opts, "-w ");
PM_optargs = TRUE;
}
if (PM_enhanced) {
#ifdef PM_OLD_ENHANCED_TEXT
strcat(PM_opts, "-e ");
PM_optargs = TRUE;
#endif
}
if (PM_term_title[0]) {
sprintf(PM_opts + strlen(PM_opts), " \"%s\"", PM_term_title);
}
// recreate option string
term_options[0] = NUL;
sprintf(term_options,
"%swidelines %spersist %senhanced",
PM_widelines? "" : "no",
PM_persist ? "" : "no",
PM_enhanced ? "" : "no");
if (PM_def_font[0] != NUL)
sprintf(term_options + strlen(term_options), " font \"%s\"", PM_def_font);
if (PM_linewidth_scale != 1.)
sprintf(term_options + strlen(term_options), " linewidth %.1f", PM_linewidth_scale);
if (PM_pointscale != 1.)
sprintf(term_options + strlen(term_options), " pointscale %.1f", PM_pointscale);
if (PM_fontscale != 1.)
sprintf(term_options + strlen(term_options), " fontscale %.1f", PM_fontscale);
if (PM_plot_number > 0)
sprintf(term_options + strlen(term_options), " server %d", PM_plot_number);
if (PM_term_title[0])
sprintf(term_options + strlen(term_options), " title \"%s\"", PM_term_title);
PM_must_reset_opts = TRUE;
}
static void
PM_reset_opts(void)
{
PM_send_msg(SET_OPTIONS);
PM_send_str(PM_opts);
PM_flush();
PM_must_reset_opts = FALSE;
}
static void
PM_query(void)
{
PM_send_msg(GR_QUERY);
PM_flush();
term->h_char = PM_recv_int();
if (term->h_char == 0xABCD) {
/* PM we received greetings from a mouseable gnupmdrv */
mouseGnupmdrv = 1; /* thus set mouseGnupmdrv on and reread h_char */
term->h_char = PM_recv_int();
}
term->v_char = PM_recv_int();
}
# ifdef USE_MOUSE
/* update menu items in PM terminal */
void
PM_update_menu_items(void)
{
/* connected to a mouseable gnupmdrv */
if (PM_is_connected() && (mouseGnupmdrv)) {
struct t_gpPMmenu gpPMmenu;
PM_set_gpPMmenu(&gpPMmenu);
PM_send_msg(SET_MENU);
PM_send_data(sizeof(gpPMmenu), &gpPMmenu);
}
}
#endif
TERM_PUBLIC void
PM_reset(void)
{
PM_send_msg(GR_RESET);
PM_flush();
term_force_init = FALSE;
if (PM_termmode > 0) {
fclose(PM_pipe);
PM_pipe = NULL;
}
}
TERM_PUBLIC void
PM_suspend(void)
{
PM_send_msg(GR_SUSPEND);
PM_flush();
}
TERM_PUBLIC void
PM_resume(void)
{
PM_send_msg(GR_RESUME);
PM_flush();
}
TERM_PUBLIC void
PM_text(void)
{
PM_flush();
if (PM_mode != SET_TEXT) {
PM_send_msg(SET_TEXT);
PM_flush();
}
PM_mode = SET_TEXT;
#ifdef USE_MOUSE
exec_event(GE_plotdone, 0, 0, 0, 0, 0);
#endif
}
TERM_PUBLIC void
PM_graphics(void)
{
static int last_encoding = -999;
if (PM_mode == SET_GRAPHICS)
return;
PM_send_msg(SET_GRAPHICS);
PM_flush();
#ifdef USE_MOUSE
PM_update_menu_items();
#endif
{
unsigned int fontscale = PM_fontscale * 100;
putc(SET_SPECIAL, PM_pipe);
putc(SET_SPECIAL_FONTSCALE, PM_pipe); /* set fontscale */
fwrite(&fontscale, sizeof(int), 1, PM_pipe);
fflush(PM_pipe);
}
if (encoding != last_encoding) {
int cp;
/* A complete list of codepages can be found at
* http://www.altsan.org/os2/toolkits/uls/codepages.html
*/
switch (encoding) {
case S_ENC_ISO8859_1: cp = 819; break;
case S_ENC_ISO8859_2: cp = 912; break;
case S_ENC_ISO8859_9: cp = 920; break;
case S_ENC_ISO8859_15:cp = 923; break;
case S_ENC_CP437: cp = 437; break;
case S_ENC_CP850: cp = 850; break;
case S_ENC_CP852: cp = 852; break;
case S_ENC_CP950: cp = 950; break;
case S_ENC_CP1250: cp = 1250; break;
case S_ENC_CP1251: cp = 1251; break;
case S_ENC_CP1252: cp = 1252; break;
case S_ENC_CP1254: cp = 1254; break;
case S_ENC_KOI8_R: cp = 878; break;
case S_ENC_SJIS: cp = 932; break;
case S_ENC_UTF8: cp = 1208; break;
default: /* S_ENC_DEFAULT, ... */
cp = 0; break;
};
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_CODEPAGE); /* set codepage */
PM_send_int(cp);
PM_flush();
last_encoding = encoding;
}
{ /* update the default font */
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_FONT); /* set default font */
PM_send_str(PM_def_font);
PM_flush();
}
#ifdef USE_MOUSE
/* PM: notify gnupmdrv that this is mouse-enhanced terminal */
PM_send_msg(GR_MOUSECAPABLE);
PM_flush();
#endif
PM_query();
PM_def_hchar = term->h_char;
PM_def_vchar = term->v_char;
PM_mode = SET_GRAPHICS;
}
TERM_PUBLIC void
PM_layer(t_termlayer layer)
{
PM_send_msg(SET_LAYER);
PM_send_int(layer);
}
TERM_PUBLIC void
PM_modify_plots(unsigned int operations, int plotno)
{
PM_send_msg(SET_MODIFY_PLOTS);
PM_send_uint(operations);
PM_send_int(plotno);
PM_flush();
}
TERM_PUBLIC void
PM_move(unsigned int x, unsigned int y)
{
if (PM_must_abort)
PM_abortplot();
PM_send_msg(GR_MOVE);
PM_send_uint(x);
PM_send_uint(y);
#ifndef PM_OLD_ENHANCED_TEXT
/* save current position, only needed for enhanced text */
PM_x = x;
PM_y = y;
#endif
}
TERM_PUBLIC void
PM_vector(unsigned int x, unsigned int y)
{
if (PM_must_abort)
PM_abortplot();
PM_send_msg(GR_DRAW);
PM_send_uint(x);
PM_send_uint(y);
}
TERM_PUBLIC void
PM_linetype(int lt)
{
PM_send_msg(SET_LINE);
PM_send_int(lt);
}
TERM_PUBLIC void
PM_dashtype(int dt, t_dashtype *custom_dash_pattern)
{
if (dt != DASHTYPE_CUSTOM) { // cannot handle custom dash patterns
PM_send_msg(SET_DASH);
PM_send_int(dt);
}
}
TERM_PUBLIC int
PM_text_angle(float dang)
{
int ang = dang;
PM_send_msg(SET_ANGLE);
PM_send_int(ang);
#ifndef PM_OLD_ENHANCED_TEXT
/* store text angle, only needed for enhanced text */
PM_angle = ang * DEG2RAD;
#endif
return TRUE;
}
TERM_PUBLIC void
PM_put_text(unsigned int x, unsigned int y, const char *str)
{
if (PM_must_abort)
PM_abortplot();
#ifdef PM_OLD_ENHANCED_TEXT
if (ignore_enhanced_text) {
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_ENHANCED); /* switch the enhanced mode off */
PM_send_char('0');
}
#endif
PM_send_msg(GR_TEXT);
PM_send_uint(x);
PM_send_uint(y);
PM_send_str(str);
#ifdef PM_OLD_ENHANCED_TEXT
if (ignore_enhanced_text) {
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_ENHANCED); /* restore the enhanced mode */
PM_send_char('2');
}
#endif
}
TERM_PUBLIC int
PM_justify_text(enum JUSTIFY mode)
{
#ifdef PM_OLD_ENHANCED_TEXT
if (ignore_enhanced_text) {
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_ENHANCED); /* switch the enhanced mode off */
PM_send_char('0');
}
#endif
PM_send_msg(SET_JUSTIFY);
PM_send_uint(mode);
#ifndef PM_OLD_ENHANCED_TEXT
/* store text justification, only needed for enhanced text */
PM_justification = mode;
#else
if (ignore_enhanced_text) {
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_ENHANCED); /* restore the enhanced mode */
PM_send_char('2');
}
#endif
return TRUE;
}
TERM_PUBLIC int
PM_set_font(const char *font)
{
PM_send_msg(SET_FONT);
PM_send_str(font);
// update hchar/vchar
if (font == NULL || *font == NUL) {
term->h_char = PM_def_hchar;
term->v_char = PM_def_vchar;
} else {
PM_query();
}
return TRUE;
}
#ifndef PM_OLD_ENHANCED_TEXT
/* PM_query_font:
get current font name and size from gnupmdrv and
save them to PM_font and PM_fontsize
*/
static void
PM_query_font(void)
{
char *newfont, *s;
PM_send_msg(GR_QUERY_FONT);
PM_flush();
newfont = PM_recv_str();
s = strchr(newfont, '.');
PM_fontsize = atoi(newfont);
if (s != NULL)
safe_strncpy(PM_font, s + 1, sizeof(PM_font));
else
safe_strncpy(PM_font, "Helvetica", sizeof(PM_font));
free(newfont);
}
#endif
TERM_PUBLIC void
PM_point(unsigned int x, unsigned int y, int number)
/*
** tell the driver we are plotting a point so it can decide whether to
** use colour or not
*/
{
PM_send_msg(SET_POINTMODE);
PM_send_int(1);
do_point(x, y, number);
PM_send_msg(SET_POINTMODE);
PM_send_int(0);
}
TERM_PUBLIC void
PM_pointsize(double size)
{
term_pointsize = size * PM_pointscale;
}
void
PM_abortplot(void)
{
PM_must_abort = FALSE;
term_reset();
(void) putc('\n', stderr);
bail_to_command_line();
}
void
PM_intc_cleanup(void)
{
if (PM_pipe == NULL || PM_mode == SET_TEXT)
PM_abortplot();
PM_must_abort = TRUE;
}
int
PM_pause(char *str)
{
if (!PM_is_connected())
return 2; /* handle pause command internally */
PM_send_msg(GR_PAUSE);
PM_send_str(str);
PM_flush();
return PM_recv_int();
}
TERM_PUBLIC void
PM_fillbox(int style, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
{
PM_send_msg(SET_FILLBOX);
PM_send_int(style);
PM_send_uint(x);
PM_send_uint(y);
PM_send_uint(w);
PM_send_uint(h);
}
TERM_PUBLIC void
PM_linewidth(double linewidth)
{
PM_send_msg(SET_LINEWIDTH);
PM_send_int(PM_linewidth_scale * linewidth * 100);
}
TERM_PUBLIC int
PM_make_palette(t_sm_palette * palette)
{
if (palette == NULL) {
/* query maximum number of colours in palette */
PM_send_msg(GR_MAKE_PALETTE);
PM_send_char(0);
PM_flush();
return PM_recv_int();
}
if (sm_palette.colors > 0) {
ULONG *rgbTable;
unsigned int i;
/* Note: gvpm sources also have a limit of 256. Is it a limit of the PM palette?
I suppose yes, thus let colours passed as unsigned char through the pipe.
Gray interval [0;1] will be mapped to interval [0;255] whose r,g,b
components are mapped by the array below.
*/
PM_send_msg(GR_MAKE_PALETTE);
PM_send_char(1);
rgbTable = (ULONG *) malloc(sizeof(ULONG) * sm_palette.colors);
for (i = 0; i < sm_palette.colors; i++) {
ULONG r, g, b;
r = (ULONG) (palette->color[i].r * 255 + 0.5);
g = (ULONG) (palette->color[i].g * 255 + 0.5);
b = (ULONG) (palette->color[i].b * 255 + 0.5);
rgbTable[i] = (r << 16) + (g << 8) + b; /* PM API likes this form */
}
PM_send_int(sm_palette.colors);
PM_send_data(sizeof(ULONG) * sm_palette.colors, rgbTable);
free(rgbTable);
}
return 0;
}
TERM_PUBLIC void
PM_set_color(t_colorspec *colorspec)
{
switch (colorspec->type) {
case TC_FRAC:
if (sm_palette.colors == 0) {
rgb255_color rgb255;
unsigned int rgb;
rgb255maxcolors_from_gray(colorspec->value, &rgb255);
rgb = (rgb255.r << 16) + (rgb255.g << 8) + rgb255.b;
PM_send_msg(GR_SET_RGBCOLOR);
PM_send_uint(rgb);
} else {
unsigned char colorindex;
/* map [0;1] to interval [0;sm_palette.colors-1] */
colorindex = ((colorspec->value * (sm_palette.colors - 1.)) + 0.5);
PM_send_msg(GR_SET_COLOR);
PM_send_char(colorindex);
}
break;
case TC_LT:
PM_send_msg(GR_LTCOLOR);
PM_send_int(colorspec->lt);
break;
case TC_RGB:
PM_send_msg(GR_SET_RGBCOLOR);
PM_send_int(colorspec->lt);
break;
default:
break;
}
}
TERM_PUBLIC void
PM_filled_polygon(int points, gpiPoint *corners)
{
int i;
PM_send_msg(GR_FILLED_POLYGON);
PM_send_int(corners->style);
PM_send_int(points); /* number of corners */
for (i = 0; i < points; i++) {
PM_send_int(corners[i].x);
PM_send_int(corners[i].y);
}
}
#ifdef USE_MOUSE
TERM_PUBLIC void
PM_put_tmptext(int i, const char str[])
{
PM_send_msg(PUT_TMPTEXT);
PM_send_int(i);
/* NOTE: PM_send_str() would have been more consistent,
but now it's too late. */
PM_send_buf(strlen(str) + 1, str);
PM_flush();
}
TERM_PUBLIC void
PM_set_ruler(int x, int y)
{
PM_send_msg(SET_RULER);
PM_send_int(x);
PM_send_int(y);
PM_flush();
}
TERM_PUBLIC void
PM_set_cursor(int c, int x, int y)
{
PM_send_msg(SET_CURSOR);
PM_send_int(c);
PM_send_int(x);
PM_send_int(y);
PM_flush();
}
TERM_PUBLIC void
PM_set_clipboard(const char s[])
{
PM_send_msg(SET_CLIPBOARD);
/* NOTE: PM_send_str() would have been more consistent,
but now it's too late. */
PM_send_buf(strlen(s), s);
PM_send_char(0);
PM_flush();
}
/* Currently, this is only used for input during a "load"
command and during timed "pause" commands. */
int
PM_waitforinput(int mode)
{
return os2_ipc_waitforinput(mode);
}
#endif /* USE_MOUSE */
TERM_PUBLIC void
PM_image(unsigned int M, unsigned int N, coordval *image, gpiPoint *corner, t_imagecolor color_mode)
{
PBYTE rgb_image, mask = NULL;
unsigned int image_size;
unsigned int mask_size;
unsigned int pad_bytes;
unsigned int pad_mask;
BOOL is_rgba = (color_mode == IC_RGBA);
BYTE is_transparent = 0x00; /* indicator if image actually is transparent */
/* Images are converted to a 24bit RGB format
suitable for OS/2's presentation manager:
- sequence of lines is reversed
- each line starts at a 4 byte boundary
*/
pad_bytes = (4 - (3 * M) % 4) % 4; /* scan lines start on ULONG boundaries */
image_size = (M + pad_bytes) * N * 3;
rgb_image = (PBYTE) gp_alloc(image_size, "PM RGB image");
if (is_rgba) {
pad_mask = (4 - M % 4) % 4;
mask_size = (M + pad_bytes) * N;
mask = (PBYTE) gp_alloc(mask_size, "PM RGBA mask");
}
if (color_mode == IC_PALETTE) {
unsigned int x, y;
rgb_image += N * (3 * M + pad_bytes);
for (y = 0; y < N; y++) {
rgb_image -= 3 * M + pad_bytes;
for (x = 0; x < M; x++) {
rgb255_color rgb255;
rgb255maxcolors_from_gray(*image++, &rgb255);
*(rgb_image++) = rgb255.b;
*(rgb_image++) = rgb255.g;
*(rgb_image++) = rgb255.r;
}
rgb_image -= 3 * M;
}
} else if (color_mode == IC_RGB || color_mode == IC_RGBA) {
unsigned int x, y;
rgb_image += N * (3 * M + pad_bytes);
if (is_rgba)
mask += N * (M + pad_mask);
for (y = 0; y < N; y++) {
rgb_image -= 3 * M + pad_bytes;
if (is_rgba)
mask -= M + pad_mask;
for (x = 0; x < M; x++) {
rgb255_color rgb255;
rgb255.r = (BYTE) (*image++ * 255 + 0.5);
rgb255.g = (BYTE) (*image++ * 255 + 0.5);
rgb255.b = (BYTE) (*image++ * 255 + 0.5);
if (is_rgba) {
*mask = *image++ * 255 + 0.5;
is_transparent |= *mask;
mask++;
}
*(rgb_image++) = rgb255.b;
*(rgb_image++) = rgb255.g;
*(rgb_image++) = rgb255.r;
}
rgb_image -= 3 * M;
if (is_rgba)
mask -= M;
}
}
if (color_mode == IC_PALETTE || color_mode == IC_RGB || color_mode == IC_RGBA) {
unsigned int i;
/* transfer data to gnupmdrv */
PM_send_msg(is_rgba && is_transparent ? GR_RGBA_IMAGE : GR_RGB_IMAGE);
PM_send_uint(M);
PM_send_uint(N);
for (i = 0; i < 4; i++) {
PM_send_int(corner[i].x);
PM_send_int(corner[i].y);
}
if (is_rgba && is_transparent)
PM_send_buf(mask_size, mask);
PM_send_buf(image_size, rgb_image);
}
free(rgb_image);
free(mask);
}
#ifndef PM_OLD_ENHANCED_TEXT
TERM_PUBLIC void
PM_enhanced_open(
char *fontname,
double fontsize, double base,
TBOOLEAN widthflag, TBOOLEAN showflag,
int overprint)
{
static const int pm_scale = 35; /* scaling of base offset */
static unsigned int ENHpm_xsave, ENHpm_ysave;
char *fontstring;
/* There are two special cases:
* overprint = 3 means save current position
* overprint = 4 means restore saved position
*/
if (overprint == 3) {
ENHpm_xsave = PM_x;
ENHpm_ysave = PM_y;
return;
} else if (overprint == 4) {
PM_x = ENHpm_xsave;
PM_y = ENHpm_ysave;
return;
}
if (!ENHpm_opened_string) {
ENHpm_opened_string = TRUE;
/* Start new text fragment */
enhanced_cur_text = &enhanced_text[0];
/* Keep track of whether we are supposed to show this string */
ENHpm_show = showflag;
/* 0/1/2 no overprint / 1st pass / 2nd pass */
ENHpm_overprint = overprint;
/* widthflag FALSE means do not update text position after printing */
ENHpm_widthflag = widthflag;
/* Select font */
/* FIXME: It would be nice to have fractional font sizes
for super- and subscripts. */
if ((fontname != NULL) && strlen(fontname) > 0) {
fontstring = malloc(strlen(fontname) + 16);
sprintf(fontstring, "%s,%i", fontname, (int)fontsize);
} else {
fontstring = malloc(16);
sprintf(fontstring, ",%i", (int)fontsize);
}
PM_set_font(fontstring);
free(fontstring);
/* Scale fractional font height to vertical units of display */
/* FIXME:
Font scaling is not done properly (yet) and will lead to
non-optimal results for most font and size selections.
The old gnupmdrv code used FONTINFO information for super-
and subscripts.
*/
ENHpm_base = pm_scale * base;
}
}
TERM_PUBLIC void
PM_enhanced_flush()
{
static unsigned int ENHpm_xsave, ENHpm_ysave;
if (ENHpm_opened_string) {
int width, height;
unsigned int mode;
unsigned int x, y;
*enhanced_cur_text = NUL;
if (PM_must_abort)
PM_abortplot();
/* print the string fragment, perhaps invisibly */
/* NB: base expresses offset from current y pos */
x = PM_x - ENHpm_base * sin(PM_angle);
y = PM_y + ENHpm_base * cos(PM_angle);
mode = ((ENHpm_show && !ENHpm_sizeonly) ? 0x01 : 0x00);
/* send message to gnupmdrv */
PM_send_msg(GR_ENH_TEXT);
PM_send_uint(x);
PM_send_uint(y);
/* write 'mode indicator' (currently show switch only) */
PM_send_uint(mode);
PM_send_str(enhanced_text);
/* answer from gnupmdrv is length of text */
PM_flush();
width = PM_recv_int();
height = PM_recv_int();
/* update drawing position according to len */
if (!ENHpm_widthflag) {
width = 0;
height = 0;
}
if (ENHpm_sizeonly) {
/* This is the first pass for justified printing. */
/* We just adjust the starting position for second pass. */
if (PM_justification == RIGHT) {
PM_x -= width;
PM_y -= height;
}
else if (PM_justification == CENTRE) {
PM_x -= width / 2;
PM_y -= height / 2;
}
/* nothing to do for LEFT justified text */
}
else if (ENHpm_overprint == 1) {
/* Save current position */
ENHpm_xsave = PM_x + width;
ENHpm_ysave = PM_y + height;
/* First pass of overprint, leave position in center of fragment */
PM_x += width / 2;
PM_y += height / 2;
}
else if (ENHpm_overprint == 2) {
/* Restore current position, */
/* this sets the position behind the overprinted text */
PM_x = ENHpm_xsave;
PM_y = ENHpm_ysave;
}
else {
/* Normal case is to update position to end of fragment */
PM_x += width;
PM_y += height;
}
ENHpm_opened_string = FALSE;
}
}
TERM_PUBLIC void
PM_enhanced_put_text(unsigned int x, unsigned int y, const char *str)
{
char *original_string = (char *)str;
unsigned int pass, num_passes;
char *saved_font;
/* If no enhanced text processing is needed, we can use the plain */
/* vanilla put_text() routine instead of this fancy recursive one. */
if (ignore_enhanced_text ||
(!strpbrk(str, "{}^_@&~") && !contains_unicode(str))) {
PM_put_text(x,y,str);
return;
}
/* Set up global variables needed by enhanced_recursion() */
ENHpm_opened_string = FALSE;
enhanced_fontscale = 1.0;
safe_strncpy(enhanced_escape_format, "%c", sizeof(enhanced_escape_format));
/* Tell the terminal to move the drawing position */
/* we store the current position to PM_x and PM_y */
PM_x = x;
PM_y = y;
/* Text justification requires two passes. During the first pass we */
/* don't draw anything, we just measure the space it will take. */
/* Without justification one pass is enough */
if (PM_justification == LEFT) {
num_passes = 1;
}
else {
num_passes = 2;
ENHpm_sizeonly = TRUE;
}
/* Update PM_font and PM_fontsize:
the font might have been changed from the default. */
PM_query_font();
saved_font = strdup(PM_font);
for (pass = 1; pass <= num_passes; pass++) {
/* Set the recursion going. We say to keep going until a
* closing brace, but we don't really expect to find one.
* If the return value is not the nul-terminator of the
* string, that can only mean that we did find an unmatched
* closing brace in the string. We increment past it (else
* we get stuck in an infinite loop) and try again.
*/
while (*(str = enhanced_recursion((char *)str, TRUE,
saved_font, PM_fontsize,
0.0, TRUE, TRUE, 0))) {
(term->enhanced_flush)();
/* I think we can only get here if *str == '}' */
enh_err_check(str);
if (!*++str)
break; /* end of string */
/* else carry on and process the rest of the string */
}
/* In order to do text justification we need to do a second pass that */
/* uses information stored during the first pass. */
/* see PM_enhanced_flush() */
if (pass == 1) {
/* do the actual printing in the next pass */
ENHpm_sizeonly = FALSE;
str = original_string;
}
}
free(saved_font);
/* restore default font */
PM_set_font(NULL);
}
#endif /* PM_OLD_ENHANCED_TEXT */
/* helper function */
void
pm_raise_terminal_window(void)
{
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_RAISE); /* raise window */
PM_flush();
}
void
pm_lower_terminal_window(void)
{
PM_send_msg(SET_SPECIAL);
PM_send_msg(SET_SPECIAL_LOWER); /* lower window */
PM_flush();
}
#endif /* TERM_BODY */
#ifdef TERM_TABLE
TERM_TABLE_START(PM_driver)
"pm", "OS/2 Presentation Manager",
PM_XMAX, PM_YMAX, PM_VCHAR, PM_HCHAR,
PM_VTIC, PM_HTIC, PM_options, PM_init, PM_reset,
PM_text, null_scale, PM_graphics, PM_move, PM_vector,
PM_linetype,
#ifdef PM_OLD_ENHANCED_TEXT
PM_put_text,
#else
PM_enhanced_put_text,
#endif
PM_text_angle,
PM_justify_text, PM_point, do_arrow, PM_set_font,
PM_pointsize,
TERM_CAN_MULTIPLOT | TERM_NO_OUTPUTFILE | TERM_ENHANCED_TEXT,
PM_suspend, PM_resume,
PM_fillbox, PM_linewidth,
#ifdef USE_MOUSE
PM_waitforinput,
PM_put_tmptext, PM_set_ruler, PM_set_cursor, PM_set_clipboard,
#endif
PM_make_palette,
0, /* PM_previous_palette */
PM_set_color,
PM_filled_polygon,
PM_image,
#ifndef PM_OLD_ENHANCED_TEXT
PM_enhanced_open, PM_enhanced_flush, do_enh_writec,
#else
NULL, NULL, NULL,
#endif
PM_layer,
NULL, /* path */
0.0, /* scale (unused) */
NULL, /* hypertext */
NULL, /* boxed text */
PM_modify_plots,
PM_dashtype
TERM_TABLE_END(PM_driver)
#undef LAST_TERM
#define LAST_TERM PM_driver
#endif /* TERM_TABLE */
#ifdef TERM_HELP
START_HELP(pm)
"1 pm",
"?commands set terminal pm",
"?set terminal pm",
"?set term pm",
"?terminal pm",
"?term pm",
"?pm",
" The `pm` terminal driver provides an OS/2 Presentation Manager window in",
" which the graph is plotted. The window is opened when the first graph is",
" plotted. This window has its own online help as well as facilities for",
" printing and copying to the clipboard.",
"",
" Syntax:",
" set terminal pm {{server} {n} | noserver}",
" {nopersist | persist}",
" {enhanced | noenhanced}",
" {font <fontspec>}",
" {nowidelines | widelines}",
" {fontscale <scale>}",
" {linewidth <scale>}",
" {pointscale <scale>}",
" {{title} \"title\"}",
"",
" If `persist` is specified, each graph appears in its own window and all",
" windows remain open after `gnuplot` exits. If `server` is specified, all",
" graphs appear in the same window, which remains open when `gnuplot` exits.",
" This option takes an optional numerical argument which specifies an instance",
" of the server process. Thus multiple server windows can be in use at the",
" same time.",
"",
" If `widelines` is specified, all plots will be drawn with wide lines. If",
" `enhanced` is specified, sub- and superscripts and multiple fonts are enabled",
" (see `enhanced text` for details). Font names for the core PostScript fonts",
" may be abbreviated to a single letter ",
" (T/H/C/S for Times/Helvetica/Courier/Symbol).",
"",
" `linewidth`, `fontscale`, `pointscale` can be used to scale the width of",
" lines, the size of text, or the size of the point symbols.",
"",
" If `title` is specified, it will be used as the title of the plot window.",
" It will also be used as the name of the server instance, and will override",
" the optional numerical argument.",
"",
" The gnuplot outboard driver, gnupmdrv.exe, is searched in the same directory",
" as gnuplot itself. You can override that by defining one of the environment",
" variables GNUPLOT_DRIVER_DIR or GNUPLOT. As a last resort the current",
" directory and the PATH are tried to locate gnupmdrv.exe."
END_HELP(pm)
#endif /* TERM_HELP */
|