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
|
/*
* TransFig: Facility for Translating Fig code
* Copyright (c) 1985 Supoj Sutantavibul
* Copyright (c) 1991 Micah Beck
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* The X Consortium, and any party obtaining a copy of these files from
* the X Consortium, directly or indirectly, is granted, free of charge, a
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
* nonexclusive right and license to deal in this software and
* documentation files (the "Software"), including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons who receive
* copies from any such party to do so, with the only requirement being
* that this copyright notice remain intact. This license includes without
* limitation a license to do the foregoing actions under any patents of
* the party supplying this software to the X Consortium.
*/
/*
* genibmgl.c : IBMGL driver for fig2dev
* IBM 6180 Color Plotter with
* IBM Graphics Enhancement Cartridge
* Author E. Robert Tisdale, University of California, 1/92
* (edwin@cs.ucla.edu)
*
* adapted from:
*
* genpictex.c : PiCTeX driver for fig2dev
*
* Author Micah Beck, Cornell University, 4/88
* Color, rotated text and ISO-chars added by Herbert Bauer 11/91
*/
static set_style();
#if defined(hpux) || defined(SYSV) || defined(SVR4)
#include <sys/types.h>
#endif
#include <sys/file.h>
#if defined(SYSV) || defined(SVR4)
#include <string.h>
#else
#include <strings.h>
#endif
#include <stdio.h>
#include <math.h>
#include "fig2dev.h"
#include "object.h"
#include "pi.h"
#define FONTS 35
#define COLORS 8
#define PATTERNS 21
#define DPR 180.0/M_PI /* degrees/radian */
#define DELTA M_PI/36.0 /* radians */
#define POINT_PER_INCH 72.27 /* points/inch */
#define CMPP 254.0/7227.0 /* centimeters/point */
#define UNITS_PER_INCH 1016.0 /* plotter units/inch */
#define HEIGHT 7650.0 /* plotter units */
#define ISO_A4 10900.0 /* plotter units */
#define ANSI_A 10300.0 /* plotter units */
#define SPEED_LIMIT 128.0 /* centimeters/second */
#ifdef IBMGEC
static int ibmgec = TRUE;
#else
static int ibmgec = FALSE;
#endif
static int reflected = FALSE;
static int fonts = FONTS;
static int colors = COLORS;
static int patterns = PATTERNS;
static int line_color = DEFAULT;
static int line_style = SOLID_LINE;
static int fill_pattern = DEFAULT;
static double dash_length = DEFAULT; /* in pixels */
#ifdef A4
static double pagelength = ISO_A4/UNITS_PER_INCH;
#else
static double pagelength = ANSI_A/UNITS_PER_INCH;
#endif
static double pageheight = HEIGHT/UNITS_PER_INCH;
static double pen_speed = SPEED_LIMIT;
static double xz = 0.0; /* inches */
static double yz = 0.0; /* inches */
static double xl = 0.0; /* inches */
static double yl = 0.0; /* inches */
static double xu = 32.25; /* inches */
static double yu = 32.25; /* inches */
static int pen_number[] = { 1, 2, 3, 4, 5, 6, 7, 8, 1};
static double pen_thickness[] = {.3,.3,.3,.3,.3,.3,.3,.3,.3};
static int line_type[] =
{1, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6,-1,-1,-1,-1,-1,-1,-1,-1};
static double line_space[] =
{.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.3,.3};
static int fill_type[] =
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 1, 2};
static double fill_space[] =
{.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1};
static double fill_angle[] =
{0,-45,0,45,90,-45,0,45,90,-45,0,45,90,-45,0,45,90, 0, 0, 0, 0};
static int standard[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static int alternate[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
static double slant[] = { 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10,
0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0, 0};
static double wide[] = {.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,
.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6};
static double high[] = {.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,
.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8};
static void genibmgl_option(opt, optarg)
char opt, *optarg;
{
switch (opt) {
case 'a': /* paper size */
#ifdef A4
pagelength = ANSI_A/UNITS_PER_INCH;
#else
pagelength = ISO_A4/UNITS_PER_INCH;
#endif
break;
case 'c': /* Graphics Enhancement */
ibmgec = !ibmgec; /* Cartridge emulation */
break;
case 'd': /* position and window */
sscanf(optarg, "%lf,%lf,%lf,%lf", &xl,&yl,&xu,&yu);
/* inches */
break;
case 'f': /* user's characters */
{
FILE *ffp;
int font;
if ((ffp = fopen(optarg, "r")) == NULL)
fprintf(stderr, "Couldn't open %s\n", optarg);
else
for (font = 0; font <= fonts; font++)
fscanf(ffp, "%d%d%lf%lf%lf",
&standard[font], /* 0-4 6-9 30-39*/
&alternate[font], /* 0-4 6-9 30-39*/
&slant[font], /* degrees */
&wide[font], /* ~1.0 */
&high[font]); /* ~1.0 */
fclose(ffp);
}
break;
case 'l': /* user's fill patterns */
{
FILE *ffp;
int pattern;
if ((ffp = fopen(optarg, "r")) == NULL)
fprintf(stderr, "Couldn't open %s\n", optarg);
else
for (pattern = 0; pattern < patterns; pattern++)
fscanf(ffp, "%d%lf%d%lf%lf",
&line_type[pattern], /* -1-6 */
&line_space[pattern], /* inches */
&fill_type[pattern], /* 1-5 */
&fill_space[pattern], /* inches */
&fill_angle[pattern]); /* degrees */
fclose(ffp);
}
break;
case 's':
case 'L': /* language */
break;
case 'm': /* magnify and offset */
sscanf(optarg, "%lf,%lf,%lf", &mag,&xz,&yz);
/* inches */
break;
case 'p': /* user's colors */
{
FILE *ffp;
int color;
if ((ffp = fopen(optarg, "r")) == NULL)
fprintf(stderr, "Couldn't open %s\n", optarg);
else
for (color = 0; color <= colors; color++)
fscanf(ffp, "%d%lf",
&pen_number[color], /* 1-8 */
&pen_thickness[color]); /* millimeters */
fclose(ffp);
}
break;
case 'P': /* portrait mode */
landscape = FALSE;
orientspec = TRUE; /* user-specified */
break;
case 'S': /* select pen velocity */
pen_speed = atof(optarg);
break;
case 'v':
reflected = TRUE; /* mirror image */
break;
default:
put_msg(Err_badarg, opt, "ibmgl");
exit(1);
break;
}
}
static double ppi; /* pixels/inch */
static double cpi; /* cent/inch */
static double cpp; /* cent/pixel */
static double wcmpp = CMPP; /* centimeter/point */
static double hcmpp = CMPP; /* centimeter/point */
static int flipped = FALSE; /* flip Y coordinate */
void genibmgl_start(objects)
F_compound *objects;
{
int P1x, P1y, P2x, P2y;
int Xll, Yll, Xur, Yur;
double Xmin,Xmax,Ymin,Ymax;
double height, length;
if (fabs(mag) < 1.0/2048.0){
fprintf(stderr, "|mag| < 1/2048\n");
exit(1);
}
if (xl < xu)
if (0.0 < xu)
if (xl < pagelength) {
xl = (0.0 < xl) ? xl: 0.0;
xu = (xu < pagelength) ? xu: pagelength;
}
else {
fprintf(stderr, "xll >= %.2f\n", pagelength);
exit(1);
}
else {
fprintf(stderr, "xur <= 0.0\n");
exit(1);
}
else {
fprintf(stderr, "xur <= xll\n");
exit(1);
}
if (yl < yu)
if (0.0 < yu)
if (yl < pageheight) {
yl = (0.0 < yl) ? yl: 0.0;
yu = (yu < pageheight) ? yu: pageheight;
}
else {
fprintf(stderr, "yll >= %.2f\n", pageheight);
exit(1);
}
else {
fprintf(stderr, "yur <= 0.0\n");
exit(1);
}
else {
fprintf(stderr, "yur <= yll\n");
exit(1);
}
ppi = objects->nwcorner.x;
cpi = mag*100.0/sqrt((xu-xl)*(xu-xl) + (yu-yl)*(yu-yl));
cpp = cpi/ppi;
if (objects->nwcorner.y == 2)
flipped = TRUE;
/* IBMGL start */
fprintf(tfp, "IN;\n"); /* initialize plotter */
if (!landscape) { /* portrait mode */
fprintf(tfp, "RO90;\n"); /* rotate 90 degrees */
Xll = yl*UNITS_PER_INCH;
Xur = yu*UNITS_PER_INCH;
Yll = (pagelength - xu)*UNITS_PER_INCH;
Yur = (pagelength - xl)*UNITS_PER_INCH;
length = yu - yl;
height = xu - xl;
P1x = Xll;
P2x = Xur;
if (reflected) /* upside-down text */
hcmpp = -hcmpp;
if (reflected^flipped) { /* reflected or flipped */
P1y = Yur; /* but not both */
P2y = Yll;
}
else { /* normal */
P1y = Yll;
P2y = Yur;
}
Xmin = xz;
Xmax = xz + (yu - yl)/mag;
Ymin = yz;
Ymax = yz + (xu - xl)/mag;
}
else { /* landscape mode */
Xll = xl*UNITS_PER_INCH;
Yll = yl*UNITS_PER_INCH;
Yur = yu*UNITS_PER_INCH;
Xur = xu*UNITS_PER_INCH;
length = xu - xl;
height = yu - yl;
if (reflected) { /* flipped or not */
wcmpp = -wcmpp; /* backward text */
P1x = Xur;
P2x = Xll;
}
else { /* normal */
P1x = Xll;
P2x = Xur;
}
if (flipped) { /* reflected or not */
P1y = Yur;
P2y = Yll;
}
else {
P1y = Yll;
P2y = Yur;
}
}
Xmin = xz;
Ymin = yz;
Xmax = xz + length/mag;
Ymax = yz + height/mag;
fprintf(tfp, "IP%d,%d,%d,%d;\n",
P1x, P1y, P2x, P2y);
fprintf(tfp, "IW%d,%d,%d,%d;\n",
Xll, Yll, Xur, Yur);
fprintf(tfp, "SC%.4f,%.4f,%.4f,%.4f;\n",
Xmin,Xmax,Ymin,Ymax);
if (0.0 < pen_speed && pen_speed < SPEED_LIMIT)
fprintf(tfp, "VS%.2f;\n", pen_speed);
}
static arc_tangent(x1, y1, x2, y2, direction, x, y)
double x1, y1, x2, y2, *x, *y;
int direction;
{
if (direction) { /* counter clockwise */
*x = x2 - (y2 - y1);
*y = y2 + (x2 - x1);
}
else {
*x = x2 + (y2 - y1);
*y = y2 - (x2 - x1);
}
}
/* draw arrow heading from (x1, y1) to (x2, y2) */
static draw_arrow_head(x1, y1, x2, y2, arrowht, arrowwid)
double x1, y1, x2, y2, arrowht, arrowwid;
{
double x, y, xb, yb, dx, dy, l, sina, cosa;
double xc, yc, xd, yd;
int style;
double length;
dx = x2 - x1;
dy = y1 - y2;
l = sqrt(dx*dx+dy*dy);
sina = dy/l;
cosa = dx/l;
xb = x2*cosa - y2*sina;
yb = x2*sina + y2*cosa;
x = xb - arrowht;
y = yb - arrowwid/2.0;
xc = x*cosa + y*sina;
yc = -x*sina + y*cosa;
y = yb + arrowwid/2.0;
xd = x*cosa + y*sina;
yd = -x*sina + y*cosa;
/* save line style and set to solid */
style = line_style;
length = dash_length;
set_style(SOLID_LINE, 0.0);
fprintf(tfp, "PA%.4f,%.4f;PD%.4f,%.4f,%.4f,%.4f;PU\n",
xc, yc, x2, y2, xd, yd);
/* restore line style */
set_style(style, length);
}
/*
* set_style - issue line style commands as appropriate
*/
static set_style(style, length)
int style;
double length;
{
if (style == line_style)
switch (line_style) {
case SOLID_LINE:
break;
case DASH_LINE:
if (dash_length != length && length > 0.0) {
dash_length = length;
fprintf(tfp, "LT2,%.4f;\n", dash_length*2.0*cpp);
}
break;
case DOTTED_LINE:
if (dash_length != length && length > 0.0) {
dash_length = length;
fprintf(tfp, "LT1,%.4f;\n", dash_length*2.0*cpp);
}
break;
}
else {
line_style = style;
switch (line_style) {
case SOLID_LINE:
fprintf(tfp, "LT;\n");
break;
case DASH_LINE:
if (dash_length != length && length > 0.0)
dash_length = length;
if (dash_length > 0.0)
fprintf(tfp, "LT2,%.4f;\n", dash_length*2.0*cpp);
else
fprintf(tfp, "LT2,-1.0;\n");
break;
case DOTTED_LINE:
if (dash_length != length && length > 0.0)
dash_length = length;
if (dash_length > 0.0)
fprintf(tfp, "LT1,%.4f;\n", dash_length*2.0*cpp);
else
fprintf(tfp, "LT1,-1.0;\n");
break;
}
}
}
/*
* set_width - issue line width commands as appropriate
* NOTE: for HP plotters we can't do anything
*/
static set_width(w)
int w;
{
static int line_width = DEFAULT; /* in pixels */
line_width = w;
}
/*
* set_color - issue line color commands as appropriate
*/
static set_color(color)
int color;
{
static int number = 0; /* 1 <= number <= 8 */
static double thickness = 0.3; /* pen thickness in millimeters */
if (line_color != color) {
line_color = color;
color = (colors + color)%colors;
if (number != pen_number[color]) {
number = pen_number[color];
fprintf(tfp, "SP%d;\n", pen_number[color]);
}
if (thickness != pen_thickness[color]) {
thickness = pen_thickness[color];
fprintf(tfp, "PT%.4f;\n", pen_thickness[color]);
}
}
}
static fill_polygon(pattern, color)
int pattern;
int color;
{
if (0 < pattern && pattern < patterns) {
int style;
double length;
set_color(color);
if (fill_pattern != pattern) {
fill_pattern = pattern;
fprintf(tfp, "FT%d,%.4f,%.4f;", fill_type[pattern],
fill_space[pattern],
reflected ? -fill_angle[pattern]: fill_angle[pattern]);
}
/* save line style */
style = line_style;
length = dash_length;
fprintf(tfp, "LT%d,%.4f;FP;\n",
line_type[pattern], line_space[pattern]*cpi);
/* restore line style */
line_style = DEFAULT;
dash_length = DEFAULT;
set_style(style, length);
}
}
void arc(sx, sy, cx, cy, theta, delta)
double sx, sy, cx, cy, theta, delta;
{
if (ibmgec)
if (delta == M_PI/36.0) /* 5 degrees */
fprintf(tfp, "AA%.4f,%.4f,%.4f;",
cx, cy, theta*DPR);
else
fprintf(tfp, "AA%.4f,%.4f,%.4f,%.4f;",
cx, cy, theta*DPR, delta*DPR);
else {
double alpha;
if (theta < 0.0)
delta = -fabs(delta);
else
delta = fabs(delta);
for (alpha = delta; fabs(alpha) < fabs(theta); alpha += delta) {
fprintf(tfp, "PA%.4f,%.4f;\n",
cx + (sx - cx)*cos(alpha) - (sy - cy)*sin(alpha),
cy + (sy - cy)*cos(alpha) + (sx - cx)*sin(alpha));
}
fprintf(tfp, "PA%.4f,%.4f;\n",
cx + (sx - cx)*cos(theta) - (sy - cy)*sin(theta),
cy + (sy - cy)*cos(theta) + (sx - cx)*sin(theta));
}
}
void genibmgl_arc(a)
F_arc *a;
{
if (a->thickness != 0 ||
ibmgec && 0 <= a->fill_style && a->fill_style < patterns) {
double x, y;
double cx, cy, sx, sy, ex, ey;
double dx1, dy1, dx2, dy2, theta;
set_style(a->style, a->style_val);
set_width(a->thickness);
set_color(a->pen_color);
cx = a->center.x/ppi;
cy = a->center.y/ppi;
sx = a->point[0].x/ppi;
sy = a->point[0].y/ppi;
ex = a->point[2].x/ppi;
ey = a->point[2].y/ppi;
dx1 = sx - cx;
dy1 = sy - cy;
dx2 = ex - cx;
dy2 = ey - cy;
theta = atan2(dy2, dx2) - atan2(dy1, dx1);
if (a->direction^flipped) {
if (theta < 0.0)
theta += 2.0*M_PI;
}
else {
if (theta > 0.0)
theta -= 2.0*M_PI;
}
if (a->thickness != 0 && a->back_arrow) {
arc_tangent(cx, cy, sx, sy, a->direction^flipped, &x, &y);
draw_arrow_head(x, y, sx, sy,
a->back_arrow->ht/ppi, a->back_arrow->wid/ppi);
}
fprintf(tfp, "PA%.4f,%.4f;PM;PD;", sx, sy);
arc(sx, sy, cx, cy, theta, DELTA);
fprintf(tfp, "PU;PM2;\n");
if (a->thickness != 0)
fprintf(tfp, "EP;\n");
if (a->thickness != 0 && a->for_arrow) {
arc_tangent(cx, cy, ex, ey, !a->direction^flipped, &x, &y);
draw_arrow_head(x, y, ex, ey,
a->for_arrow->ht/ppi, a->for_arrow->wid/ppi);
}
if (0 < a->fill_style && a->fill_style < patterns)
fill_polygon(a->fill_style, a->fill_color);
}
}
void genibmgl_ellipse(e)
F_ellipse *e;
{
if (e->thickness != 0 ||
ibmgec && 0 <= e->fill_style && e->fill_style < patterns) {
int j;
double alpha = 0.0;
double angle;
double delta;
double x0, y0;
double a, b;
double x, y;
set_style(e->style, e->style_val);
set_width(e->thickness);
set_color(e->pen_color);
a = e->radiuses.x/ppi;
b = e->radiuses.y/ppi;
x0 = e->center.x/ppi;
y0 = e->center.y/ppi;
angle = (flipped ? -e->angle: e->angle);
delta = (flipped ? -DELTA: DELTA);
x = x0 + cos(angle)*a;
y = y0 + sin(angle)*a;
fprintf(tfp, "PA%.4f,%.4f;PM;PD;\n", x, y);
for (j = 1; j <= 72; j++) { alpha = j*delta;
x = x0 + cos(angle)*a*cos(alpha)
- sin(angle)*b*sin(alpha);
y = y0 + sin(angle)*a*cos(alpha)
+ cos(angle)*b*sin(alpha);
fprintf(tfp, "PA%.4f,%.4f;\n", x, y);
}
fprintf(tfp, "PU;PM2;\n");
if (e->thickness != 0)
fprintf(tfp, "EP;\n");
if (0 < e->fill_style && e->fill_style < patterns)
fill_polygon((int)e->fill_style, e->fill_color);
}
}
void swap(i, j)
int *i, *j;
{ int t; t = *i; *i = *j; *j = t; }
void genibmgl_line(l)
F_line *l;
{
if (l->thickness != 0 ||
ibmgec && 0 <= l->fill_style && l->fill_style < patterns) {
F_point *p, *q;
set_style(l->style, l->style_val);
set_width(l->thickness);
set_color(l->pen_color);
p = l->points;
q = p->next;
switch (l->type) {
case T_POLYLINE:
case T_BOX:
case T_POLYGON:
if (q == NULL) /* A single point line */
fprintf(tfp, "PA%.4f,%.4f;PD;PU;\n",
p->x/ppi, p->y/ppi);
else {
if (l->thickness != 0 && l->back_arrow)
draw_arrow_head(q->x/ppi, q->y/ppi,
p->x/ppi, p->y/ppi,
l->back_arrow->ht/ppi,
l->back_arrow->wid/ppi);
fprintf(tfp, "PA%.4f,%.4f;PM;PD%.4f,%.4f;\n",
p->x/ppi, p->y/ppi,
q->x/ppi, q->y/ppi);
while (q->next != NULL) {
p = q;
q = q->next;
fprintf(tfp, "PA%.4f,%.4f;\n",
q->x/ppi, q->y/ppi);
}
fprintf(tfp, "PU;PM2;\n");
if (l->thickness != 0)
fprintf(tfp, "EP;\n");
if (l->thickness != 0 && l->for_arrow)
draw_arrow_head(p->x/ppi, p->y/ppi,
q->x/ppi, q->y/ppi,
l->for_arrow->ht/ppi,
l->for_arrow->wid/ppi);
if (0 < l->fill_style && l->fill_style < patterns)
fill_polygon((int)l->fill_style, l->fill_color);
}
break;
case T_ARC_BOX: {
int llx, lly, urx, ury;
double x0, y0, x1, y1;
double dx, dy, angle;
llx = urx = p->x;
lly = ury = p->y;
while ((p = p->next) != NULL) {
if (llx > p->x)
llx = p->x;
if (urx < p->x)
urx = p->x;
if (lly > p->y)
lly = p->y;
if (ury < p->y)
ury = p->y;
}
x0 = llx/ppi;
x1 = urx/ppi;
dx = l->radius/ppi;
if (flipped) {
y0 = ury/ppi;
y1 = lly/ppi;
dy = -dx;
angle = -M_PI/2.0;
}
else {
y0 = lly/ppi;
y1 = ury/ppi;
dy = dx;
angle = M_PI/2.0;
}
fprintf(tfp, "PA%.4f,%.4f;PM;PD;\n", x0, y0 + dy);
arc(x0, y0 + dy, x0 + dx, y0 + dy, angle, DELTA);
fprintf(tfp, "PA%.4f,%.4f;\n", x1 - dx, y0);
arc(x1 - dx, y0, x1 - dx, y0 + dy, angle, DELTA);
fprintf(tfp, "PA%.4f,%.4f;\n", x1, y1 - dy);
arc(x1, y1 - dy, x1 - dx, y1 - dy, angle, DELTA);
fprintf(tfp, "PA%.4f,%.4f;\n", x0 + dx, y1);
arc(x0 + dx, y1, x0 + dx, y1 - dy, angle, DELTA);
fprintf(tfp, "PA%.4f,%.4f;PU;PM2;\n", x0, y0 + dy);
if (l->thickness != 0)
fprintf(tfp, "EP;\n");
if (0 < l->fill_style && l->fill_style < patterns)
fill_polygon((int)l->fill_style, l->fill_color);
}
break;
case T_PIC_BOX:
break;
}
}
}
#define THRESHOLD .05 /* inch */
static bezier_spline(a0, b0, a1, b1, a2, b2, a3, b3)
double a0, b0, a1, b1, a2, b2, a3, b3;
{
double x0, y0, x3, y3;
double sx1, sy1, sx2, sy2, tx, ty, tx1, ty1, tx2, ty2, xmid, ymid;
x0 = a0; y0 = b0;
x3 = a3; y3 = b3;
if (fabs(x0 - x3) < THRESHOLD && fabs(y0 - y3) < THRESHOLD)
fprintf(tfp, "PA%.4f,%.4f;\n", x3, y3);
else {
tx = (a1 + a2 )/2.0; ty = (b1 + b2 )/2.0;
sx1 = (x0 + a1 )/2.0; sy1 = (y0 + b1 )/2.0;
sx2 = (sx1 + tx )/2.0; sy2 = (sy1 + ty )/2.0;
tx2 = (a2 + x3 )/2.0; ty2 = (b2 + y3 )/2.0;
tx1 = (tx2 + tx )/2.0; ty1 = (ty2 + ty )/2.0;
xmid = (sx2 + tx1)/2.0; ymid = (sy2 + ty1)/2.0;
bezier_spline(x0, y0, sx1, sy1, sx2, sy2, xmid, ymid);
bezier_spline(xmid, ymid, tx1, ty1, tx2, ty2, x3, y3);
}
}
static void genibmgl_itp_spline(s)
F_spline *s;
{
F_point *p1, *p2;
F_control *cp1, *cp2;
double x1, x2, y1, y2;
p1 = s->points;
cp1 = s->controls;
x2 = p1->x/ppi; y2 = p1->y/ppi;
if (s->thickness != 0 && s->back_arrow)
draw_arrow_head(cp1->rx/ppi, cp1->ry/ppi, x2, y2,
s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
fprintf(tfp, "PA%.4f,%.4f;PD;\n", x2, y2);
for (p2 = p1->next, cp2 = cp1->next; p2 != NULL;
p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
x1 = x2;
y1 = y2;
x2 = p2->x/ppi;
y2 = p2->y/ppi;
bezier_spline(x1, y1, (double)cp1->rx/ppi, cp1->ry/ppi,
(double)cp2->lx/ppi, cp2->ly/ppi, x2, y2);
}
fprintf(tfp, "PU;\n");
if (s->thickness != 0 && s->for_arrow)
draw_arrow_head(cp1->lx/ppi, cp1->ly/ppi, x2, y2,
s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
}
static quadratic_spline(a1, b1, a2, b2, a3, b3, a4, b4)
double a1, b1, a2, b2, a3, b3, a4, b4;
{
double x1, y1, x4, y4;
double xmid, ymid;
x1 = a1; y1 = b1;
x4 = a4; y4 = b4;
xmid = (a2 + a3)/2.0;
ymid = (b2 + b3)/2.0;
if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD)
fprintf(tfp, "PA%.4f,%.4f;\n", xmid, ymid);
else {
quadratic_spline(x1, y1, ((x1+a2)/2.0), ((y1+b2)/2.0),
((3.0*a2+a3)/4.0), ((3.0*b2+b3)/4.0), xmid, ymid);
}
if (fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD)
fprintf(tfp, "PA%.4f,%.4f;\n", x4, y4);
else {
quadratic_spline(xmid, ymid, ((a2+3.0*a3)/4.0), ((b2+3.0*b3)/4.0),
((a3+x4)/2.0), ((b3+y4)/2.0), x4, y4);
}
}
static void genibmgl_ctl_spline(s)
F_spline *s;
{
F_point *p;
double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
double x1, y1, x2, y2;
p = s->points;
x1 = p->x/ppi;
y1 = p->y/ppi;
p = p->next;
x2 = p->x/ppi;
y2 = p->y/ppi;
cx1 = (x1 + x2)/2.0;
cy1 = (y1 + y2)/2.0;
cx2 = (x1 + 3.0*x2)/4.0;
cy2 = (y1 + 3.0*y2)/4.0;
if (closed_spline(s))
fprintf(tfp, "PA%.4f,%.4f;PD;\n ", cx1, cy1);
else {
if (s->thickness != 0 && s->back_arrow)
draw_arrow_head(cx1, cy1, x1, y1,
s->back_arrow->ht/ppi, s->back_arrow->wid/ppi);
fprintf(tfp, "PA%.4f,%.4f;PD%.4f,%.4f;\n",
x1, y1, cx1, cy1);
}
for (p = p->next; p != NULL; p = p->next) {
x1 = x2;
y1 = y2;
x2 = p->x/ppi;
y2 = p->y/ppi;
cx3 = (3.0*x1 + x2)/4.0;
cy3 = (3.0*y1 + y2)/4.0;
cx4 = (x1 + x2)/2.0;
cy4 = (y1 + y2)/2.0;
quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
cx1 = cx4;
cy1 = cy4;
cx2 = (x1 + 3.0*x2)/4.0;
cy2 = (y1 + 3.0*y2)/4.0;
}
x1 = x2;
y1 = y2;
p = s->points->next;
x2 = p->x/ppi;
y2 = p->y/ppi;
cx3 = (3.0*x1 + x2)/4.0;
cy3 = (3.0*y1 + y2)/4.0;
cx4 = (x1 + x2)/2.0;
cy4 = (y1 + y2)/2.0;
if (closed_spline(s)) {
quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
fprintf(tfp, "PU;\n");
}
else {
fprintf(tfp, "PA%.4f,%.4f;PU;\n", x1, y1);
if (s->thickness != 0 && s->for_arrow)
draw_arrow_head(cx1, cy1, x1, y1,
s->for_arrow->ht/ppi, s->for_arrow->wid/ppi);
}
}
void genibmgl_spline(s)
F_spline *s;
{
if (s->thickness != 0) {
set_style(s->style, s->style_val);
set_width(s->thickness);
set_color(s->pen_color);
if (int_spline(s))
genibmgl_itp_spline(s);
else
genibmgl_ctl_spline(s);
}
if (0 < s->fill_style && s->fill_style < patterns)
fprintf(stderr, "Spline area fill not implemented\n");
}
#define FONT(T) ((-1 < (T) && (T) < fonts) ? (T): fonts)
void genibmgl_text(t)
F_text *t;
{
static int font = DEFAULT; /* font */
static int size = DEFAULT; /* font size in points */
static int cs = 0; /* standard character set */
static int ca = 0; /* alternate character set */
static double theta = 0.0; /* character slant in degrees */
static double angle = 0.0; /* label direction in radians */
double width; /* character width in centimeters */
double height; /* character height in centimeters */
if (font != FONT(t->font)) {
font = FONT(t->font);
if (cs != standard[font]) {
cs = standard[font];
fprintf(tfp, "CS%d;", cs);
}
if (ca != alternate[font]) {
ca = alternate[font];
fprintf(tfp, "CA%d;", ca);
}
if (theta != slant[font]) {
theta = slant[font];
fprintf(tfp, "SL%.4f;", tan(theta*M_PI/180.0));
}
}
if (size != t->size) {
size = t->size;
width = size*wcmpp*wide[font];
height = size*hcmpp*high[font];
fprintf(tfp, "SI%.4f,%.4f;", width*mag, height*mag);
}
if (angle != t->angle) {
angle = t->angle;
fprintf(tfp, "DI%.4f,%.4f;",
cos(angle), sin(reflected ? -angle: angle));
}
set_color(t->color);
fprintf(tfp, "PA%.4f,%.4f;\n",
t->base_x/ppi, t->base_y/ppi);
switch (t->type) {
case DEFAULT:
case T_LEFT_JUSTIFIED:
break;
case T_CENTER_JUSTIFIED:
fprintf(tfp, "CP%.4f,0.0;", -(double)(strlen(t->cstring)/2.0));
break;
case T_RIGHT_JUSTIFIED:
fprintf(tfp, "CP%.4f,0.0;", -(double)(strlen(t->cstring)));
break;
default:
fprintf(stderr, "unknown text position type\n");
exit(1);
}
fprintf(tfp, "LB%s\003\n", t->cstring);
}
void genibmgl_end()
{
/* IBMGL ending */
fprintf(tfp, "PU;SP;IN;\n");
}
struct driver dev_ibmgl = {
genibmgl_option,
genibmgl_start,
genibmgl_arc,
genibmgl_ellipse,
genibmgl_line,
genibmgl_spline,
genibmgl_text,
genibmgl_end,
EXCLUDE_TEXT
};
|