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
|
/*
* This file is part of the XForms library package.
*
* XForms is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1, or
* (at your option) any later version.
*
* XForms 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with XForms. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This file is part of the XForms library package.
* Copyright (c) 1996-2002 T.C. Zhao
* All rights reserved.
*
* Supports xyplot PostScript dump. Almost a verbatim copy of
* xyplot.c
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "include/forms.h"
#include "flinternal.h"
#include "private/pxyplot.h"
#include "private/pflps.h"
#include <math.h>
static void ps_draw_xyplot( FL_OBJECT * ob );
/***************************************
***************************************/
static int
auto_orientation( float pw,
float ph,
float obw,
float obh )
{
int plm,
pbm,
llm,
lbm;
plm = ( pw - obw ) / 2;
pbm = ( ph - obh ) / 2;
llm = ( pw - obh ) / 2;
lbm = ( ph - obw ) / 2;
return ( FL_abs( lbm - llm ) < FL_abs( pbm - plm ) ) ?
FLPS_LANDSCAPE : FLPS_PORTRAIT;
}
/***************************************
* find scale factor, in percentage point
***************************************/
static int
auto_scale( float pw,
float ph,
float obw,
float obh )
{
float margin = 0.4 * 72; /* about 1cm */
float gscalex,
gscaley;
int i = 100;
pw -= 2 * margin;
ph -= 2 * margin;
if ( ( flps->orientation == FLPS_PORTRAIT
&& ( pw < obw || ph < obh ) )
|| ( flps->orientation == FLPS_LANDSCAPE
&& ( pw < obh || ph < obw ) ) )
{
if ( flps->orientation == FLPS_PORTRAIT )
{
gscalex = ( pw - 2.0 ) / obw;
gscaley = ( ph - 2.0 ) / obh;
}
else
{
gscalex = ( pw - 2.0 ) / obh;
gscaley = ( ph - 2.0 ) / obw;
}
i = 100.0 * ( ( gscalex < gscaley ) ? gscalex : gscaley );
}
return i;
}
/***************************************
***************************************/
static char *
strip_newline( char * str )
{
static char s[ 64 ];
char *c;
strncpy( s, str, 63 );
s[ 63 ] = '\0';
for ( ; ( c = strchr( s, '\n' ) ); )
*c = ' ';
return s;
}
/***************************************
***************************************/
int
fl_object_ps_dump( FL_OBJECT * ob,
const char * fname )
{
float bxi, /* bounding box */
byi,
bxf,
byf;
float objw,
objh,
pw,
ph;
float fgscale;
int gscale = 100;
int orientation;
if ( ! flps )
{
flps = ( FLPSInfo * ) flps_init( );
if (ob->objclass == FL_XYPLOT)
flps->ps_color = FLPS_BW;;
}
/* try to open the file */
if ( ! fname || ! *fname )
fname = fl_show_fselector( "Output Filename", "", "*ps", "" );
/* cancel */
if ( ! fname )
return 0;
if ( ! *fname )
{
M_err( "PS_dump", "null filename" );
return -1;
}
if ( strcmp( fname, "-" ) == 0 )
flps->fp = stdout;
else
flps->fp = fopen( fname, "w" );
if ( ! flps->fp )
{
M_err( "PS_dump", "can't open %s", fname );
return -1;
}
/* we need to do this to get repeated call right */
flps_reset_cache( );
/* fill in some defaults */
if ( flps->drawbox < 0 )
flps->drawbox = 0;
#if 0
fl_freeze_all_forms( );
fl_set_cursor( ob->form->window, XC_watch );
fl_update_display( 0 );
#endif
flps->s2px = 72.0 / flps->xdpi;
flps->s2py = 72.0 / flps->ydpi;
flps->final_xscale = flps->xscale * flps->s2px;
flps->final_yscale = flps->yscale * flps->s2py;
/* bounding box always in point */
pw = flps->paper_w * 72;
ph = flps->paper_h * 72;
objw = ob->w * flps->final_xscale;
objh = ob->h * flps->final_yscale;
/* handle auto orientation */
if ( ( orientation = flps->orientation ) == FLPS_AUTO )
orientation = auto_orientation( pw, ph, objw, objh );
flps->landscape = orientation == FLPS_LANDSCAPE;
if ( flps->auto_fit )
gscale = auto_scale( pw, ph, objw, objh );
fgscale = gscale * 0.01;
flps->final_xscale *= fgscale;
flps->final_yscale *= fgscale;
if ( flps->landscape )
{
bxi = ( pw - objh * fgscale ) * 0.5;
byi = ( ph - objw * fgscale ) * 0.5;
bxf = bxi + objh * fgscale;
byf = byi + objw * fgscale;
}
else
{
bxi = ( pw - objw * fgscale ) * 0.5;
byi = ( ph - objh * fgscale ) * 0.5;
bxf = bxi + objw * fgscale;
byf = byi + objh * fgscale;
}
flps_emit_header( strip_newline( ob->label ), 1, bxi, byi, bxf, byf );
flps_emit_prolog( );
if ( flps->landscape )
{
/* from now on, we are in pixel unit */
flps_output( "gsave %.1f %.1f translate 90 rotate\n",
bxi + objh, byi );
flps_output( "%.1f %.1f translate\n",
-ob->x * flps->final_yscale, -ob->y * flps->final_xscale );
}
else
flps_output( "gsave %.1f %.1f translate\n",
bxi - ob->x * flps->final_xscale,
byi - ob->y * flps->final_yscale );
flps_output( "SX SY scale\n " );
switch ( ob->objclass )
{
case FL_XYPLOT :
ps_draw_xyplot( ob );
break;
default :
M_err( "PS_dump", "unsupported object class: %d", ob->objclass );
break;
}
fputs( "grestore\nshowpage\n", flps->fp );
fclose( flps->fp );
#if 0
fl_reset_cursor( ob->form->window );
fl_unfreeze_all_forms( );
#endif
return 0;
}
static void flps_draw_text_point(int, int, int, FL_COLOR, int, int, char * );
#define PCOL( c ) ( ( flps->ps_color == FLPS_BW && ! flps->drawbox ) ? \
FL_BLACK : c )
#define SPEC FLI_XYPLOT_SPEC
static int ym1,
ym2;
static float ay,
by;
#define FLIP( ys ) ( ym1 + ( sp->yf - ys ) )
#define FMIN 1.e-25
/***************************************
***************************************/
static void
mapw2s( FLI_XYPLOT_SPEC * sp,
FL_POINT * p,
int n1,
int n2,
float * x,
float * y )
{
int i;
float ax = sp->ax,
bx = sp->bx;
float lbase,
t;
ay = ( sp->yf - sp->yi) / (sp->yscmax - sp->yscmin );
by = ym1 - ay * sp->yscmin;
if ( sp->xscale == FL_LOG )
{
lbase = 1.0 / sp->lxbase;
for ( i = n1; i < n2; i++ )
{
t = x[ i ] > 0 ? x[ i ] : FMIN;
p[ i - n1 ].x = ax * log10( t ) * lbase + bx + 0.4;
}
}
else
{
for ( i = n1; i < n2; i++ )
p[ i - n1 ].x = ax * x[ i ] + bx + 0.4;
}
if ( sp->yscale == FL_LOG )
{
lbase = 1.0 / sp->lybase;
for ( i = n1; i < n2; i++ )
{
t = y[ i ] > 0 ? y[ i ] : FMIN;
p[ i - n1 ].y = ay * log10( t ) * lbase + by + 0.4;
}
}
else
{
for ( i = n1; i < n2; i++ )
p[ i - n1 ].y = ay * y[ i ] + by + 0.4;
}
}
/***************************************
***************************************/
static void
add_border( FL_OBJECT * ob,
FL_COLOR c )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
if ( sp->xtic > 0 && sp->ytic > 0 )
flps_rect( sp->xi, ym1, sp->xf - sp->xi + 1, ym2 - ym1 + 1, c );
else if ( sp->xtic > 0 )
flps_line( sp->xi, ym1, sp->xf, ym1, c );
else if ( sp->ytic > 0 )
flps_line( sp->xi, ym1, sp->xi, ym2, c );
}
/***************************************
***************************************/
static void
w2s( FL_OBJECT * ob,
float wx,
float wy,
float * sx,
float * sy )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
*sx = wx * sp->ax + sp->bx;
*sy = wy * ay + by;
}
/***************************************
***************************************/
static void
draw_inset( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
int i;
float tx,
ty;
for ( i = 0; i < sp->maxoverlay; i++ )
{
if ( sp->text[ i ] )
{
w2s( ob, sp->xt[ i ], sp->yt[ i ], &tx, &ty );
flps_draw_text_point( sp->talign[ i ], tx, ty,
PCOL( sp->tcol[ i ] ),
sp->lstyle, sp->lsize, sp->text[ i ] );
}
}
}
#define XRound( s ) \
( ( s )->xtic > 0 && ! ( s )->axtic[ 0 ] && ( s )->xmajor > 1 )
#define YRound( s ) \
( ( s )->ytic > 0 && ! ( s )->aytic[ 0 ] && ( s )->ymajor > 1 )
/***************************************
***************************************/
static void
add_xtics( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
float tic = sp->xtic;
int xr,
ticl = 6,
yi,
yf,
i;
char buf[ 80 ],
*label,
*p;
if ( tic <= 0 )
return;
yi = ym1;
yf = yi - ticl / 2;
for ( i = 0; i < sp->num_xminor; i++ )
{
xr = sp->xtic_minor[ i ];
flps_line( xr, yi, xr, yf, ob->col2 );
}
yi = ym1;
yf = yi - ticl;
for ( i = 0; i < sp->num_xmajor; i++ )
{
xr = sp->xtic_major[ i ];
flps_line( xr, yi, xr, yf, ob->col2 );
if ( ! sp->axtic[ 0 ] )
fli_xyplot_nice_label( tic, sp->xminor,
sp->xmajor_val[ i ], label = buf );
else
{
if ( ( p = strchr( sp->axtic[ i ], '@' ) ) )
{
label = strcpy( buf, sp->axtic[ i ] );
label[ p - sp->axtic[ i ] ] = '\0';
}
else
label = sp->axtic[ i ];
}
flps_draw_text( FL_ALIGN_TOP, xr, ym1 - ticl + 1, 0, 0,
ob->col2, sp->lstyle, sp->lsize, label );
}
}
/***************************************
***************************************/
static void
add_logxtics( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
float xw;
int xr,
ticl = 6,
yi,
yf,
i;
char label[ 80 ];
if ( sp->xtic < 0 )
return;
yi = ym1;
yf = yi - ticl / 2;
for ( i = 0; i < sp->num_xminor; i++ )
{
xr = sp->xtic_minor[ i ];
flps_line( xr, yi, xr, yf, ob->col2 );
}
yi = ym1;
yf = ym1 - ticl;
for ( i = 0; i < sp->num_xmajor; i++ )
{
xr = sp->xtic_major[ i ];
flps_line( xr, yi, xr, yf, ob->col2 );
xw = sp->xmajor_val[ i ];
if ( sp->xbase == 10.0 )
{
sprintf( label, "%g", pow( 10.0, sp->xmajor_val[ i ] ) );
flps_draw_text( FL_ALIGN_TOP, xr, yf + 1, 1, 1,
ob->col2, sp->lstyle, sp->lsize, label);
}
else
{
int len1,
len2,
ll;
ll = sprintf( label, "%g", sp->xbase );
flps_draw_text( FL_ALIGN_TOP, xr - 3, yf - 1, 0, 0,
ob->col2, sp->lstyle, sp->lsize, label );
len1 = fl_get_string_width( sp->lstyle, sp->lsize, label, ll );
ll = sprintf( label, "%d", ( int ) ceil( xw ) );
len2 = fl_get_string_width( sp->lstyle, sp->lsize - 2, label, ll );
flps_draw_text( FL_ALIGN_TOP, xr - 3 + len1 / 2 + len2 / 2,
yf + 3, 0, 0, ob->col2, sp->lstyle, sp->lsize - 2,
label );
}
}
}
/***************************************
***************************************/
static void
add_ytics( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
float tic = sp->ytic;
int yr,
ticl = 6,
i;
char buf[ 80 ],
*label,
*p;
if ( sp->ytic <= 0 )
return;
for ( i = 0; i < sp->num_yminor; i++ )
{
yr = FLIP( sp->ytic_minor[ i ] );
flps_line( sp->xi, yr, sp->xi - ticl / 2, yr, ob->col2 );
}
for ( i = 0; i < sp->num_ymajor; i++ )
{
yr = FLIP( sp->ytic_major[ i ] );
flps_line( sp->xi - ticl, yr, sp->xi, yr, ob->col2 );
if ( ! sp->aytic[ 0 ] )
fli_xyplot_nice_label( tic, sp->yminor,
sp->ymajor_val[ i ], label = buf );
else
{
if ( ( p = strchr( sp->aytic[ i ], '@' ) ) )
{
label = strcpy( buf, sp->aytic[ i ] );
label[ p - sp->aytic[ i ] ] = '\0';
}
else
label = sp->aytic[ i - 1 ];
}
flps_draw_text( FL_ALIGN_RIGHT, sp->xi - ticl + 1, yr,
0, 0, ob->col2, sp->lstyle, sp->lsize, label );
}
}
/***************************************
***************************************/
static void
add_logytics( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
float yw;
int yr,
ticl = 6,
i;
char label[ 80 ];
if ( sp->ytic <= 0 )
return;
for ( i = 0; i < sp->num_yminor; i++ )
{
yr = FLIP( sp->ytic_minor[ i ] );
flps_line( sp->xi, yr, sp->xi - ticl / 2, yr, ob->col2 );
}
for ( i = 0; i < sp->num_ymajor; i++ )
{
yr = FLIP( sp->ytic_major[ i ] );
flps_line( sp->xi - ticl, yr, sp->xi, yr, ob->col2 );
yw = sp->ymajor_val[ i ];
if ( sp->ybase == 10.0 )
{
sprintf( label, "%g", pow( sp->ybase, yw ) );
flps_draw_text( FL_ALIGN_RIGHT, sp->xi - ticl, yr,
1, 1, ob->col2, sp->lstyle, sp->lsize, label );
}
else
{
int len,
ll;
ll = sprintf( label, "%d", ( int ) ceil( yw ) );
flps_draw_text( FL_ALIGN_RIGHT, sp->xi - ticl, yr + 3,
0, 0, ob->col2, sp->lstyle, sp->lsize - 2, label );
len = fl_get_string_width( sp->lstyle, sp->lsize - 2, label, ll );
sprintf( label, "%g", sp->ybase );
flps_draw_text( FL_ALIGN_RIGHT, sp->xi - ticl - len,
yr, 0, 0, ob->col2, sp->lstyle, sp->lsize, label );
}
}
}
/***************************************
***************************************/
static void
draw_square( FL_POINT * p,
int n,
int w,
int h )
{
int w2 = w / 2,
h2 = h / 2;
FL_POINT *ps = p + n;
for ( ; p < ps; p++ )
flps_rectangle( 0, p->x - w2, p->y - h2, w, h, FL_NoColor );
}
/***************************************
***************************************/
static void
draw_circle( FL_POINT * p,
int n,
int w,
int h )
{
FL_POINT *ps = p + n;
int r = ( w + h ) / 4;
for ( ; p < ps; p++ )
flps_circ( 0, p->x, p->y, r, FL_NoColor ); /* nocolor mean current */
}
/***************************************
***************************************/
static void
draw_point( FL_POINT * p,
int n,
int w,
int h )
{
int w2 = w / 2,
h2 = h / 2;
FL_POINT *ps = p + n;
for ( ; p < ps; p++ )
{
flps_line( p->x, p->y - h2, p->x, p->y + h2, FL_NoColor );
flps_line( p->x - w2, p->y, p->x + w2, p->y, FL_NoColor );
flps_line( p->x - w2, p->y - h2, p->x + w2, p->y + h2, FL_NoColor );
flps_line( p->x + w2, p->y - h2, p->x - w2, p->y + h2, FL_NoColor );
}
}
/***************************************
***************************************/
static void
add_xgrid( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
int xr, i;
int savels = flps_get_linestyle( );
flps_linestyle( sp->grid_linestyle );
for ( i = 0; sp->xgrid == FL_GRID_MINOR && i < sp->num_xminor; i++ )
{
xr = sp->xtic_minor[ i ];
flps_line( xr, ym1, xr, ym2, ob->col2 );
}
for ( i = 0; i < sp->num_xmajor; i++ )
{
xr = sp->xtic_major[ i ];
flps_line( xr, ym1, xr, ym2, ob->col2 );
}
flps_linestyle( savels );
}
/***************************************
***************************************/
static void
add_ygrid( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
int yr,
i,
xi,
xf;
int savels = flps_get_linestyle( );
xi = sp->xi + 1;
xf = sp->xf - 1;
flps_linestyle( sp->grid_linestyle );
for ( i = 0; sp->ygrid == FL_GRID_MINOR && i < sp->num_yminor; i++ )
{
yr = FLIP( sp->ytic_minor[ i ] );
flps_line( xi, yr, xf, yr, ob->col2 );
}
for ( i = 0; i < sp->num_ymajor; i++ )
{
yr = FLIP( sp->ytic_major[ i ] );
flps_line( xi, yr, xf, yr, ob->col2 );
}
flps_linestyle( savels );
}
/***************************************
* Draw xyplot in PostScript device. The driver sets things
* up so the coordinate system is in pixels and the origin
* of the coordinate system is at form's origin
*
* This is an almost verbatim copy of the X xyplot drawing
***************************************/
static void
ps_draw_xyplot( FL_OBJECT * ob )
{
FLI_XYPLOT_SPEC *sp = ob->spec;
float *x,
*y;
FL_POINT *xp;
int i,
nplot,
noline = 0,
n1,
n2,
nxp,
newn;
void ( * drawsymbol )( FL_POINT *, int, int, int );
int savels = flps_get_linestyle( );
int savelw = flps_get_linewidth( );
int key_xs,
key_ys;
int dblbuffer;
FL_COLOR col,
savecol2;
if ( ! ob->visible || ! ob->form->visible )
{
M_err( "PSDrawXYPlot", "object must be visible" );
return;
}
flps_linewidth( 1 );
/* for BW output, always black ink */
savecol2 = ob->col2;
ob->col2 = PCOL( ob->col2 );
/* bounding box and object label */
if ( flps->drawbox )
flps_draw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1,
ob->bw );
flps_draw_text_beside( ob->align, ob->x, ob->y, ob->w, ob->h,
PCOL(ob->lcol), ob->lstyle, ob->lsize, ob->label );
/* if we're in double buffer mode, need to shift the plot. */
dblbuffer = sp->bym - sp->by >= 1.0 || sp->bxm - sp->bx >= 1.0;
if ( dblbuffer )
fprintf( flps->fp, "%d -%d translate\n", sp->objx, sp->objy );
/* ym1 and ym2 are the y-bounds in PostScript system, i.e., ym1<ym2 */
ym1 = ob->y + ( ob->y + ob->h - 1 - sp->yf );
ym2 = ( ob->y + ob->h - 1 ) - ( sp->yi - ob->y );
add_border( ob, ob->col2 );
flps_set_clipping( sp->xi, ym1, sp->xf - sp->xi + 1, ym2 - ym1 + 1 );
if ( sp->xgrid != FL_GRID_NONE && sp->xtic > 0 )
add_xgrid( ob );
if ( sp->ygrid != FL_GRID_NONE && sp->ytic > 0 )
add_ygrid( ob );
/* too lazy to figure out the transformation to map X to PS. brute force */
{
FL_POINT tmpp;
float keyx = sp->key_x,
keyy = sp->key_y;
mapw2s( sp, &tmpp, 0, 1, &keyx, &keyy );
sp->key_xs = tmpp.x;
sp->key_ys = tmpp.y;
}
flps_rectangle( 0, sp->key_xs - sp->key_maxw - 1,
sp->key_ys - sp->key_maxh - 1,
sp->key_maxw, sp->key_maxh, PCOL( sp->col[ 0 ] ) );
key_xs = sp->key_xs - sp->key_maxw + 1;
key_ys = sp->key_ys - sp->key_ascend + sp->key_descend + ( sp->lsize > 12 );
for ( nplot = 0; nplot <= sp->maxoverlay; nplot++ )
{
if ( sp->n[ nplot ] == 0 )
continue;
fli_xyplot_compute_data_bounds( ob, &n1, &n2, nplot );
noline = 0;
drawsymbol = NULL;
col = PCOL( sp->col[ nplot ] );
flps_color( col );
/* for PostScript, we don't want 0, too thin */
flps_linewidth( sp->thickness[ nplot ] ? sp->thickness[ nplot ] : 1 );
if ( sp->interpolate[ nplot ] > 1
&& n2 - n1 > 3
&& ( newn = fli_xyplot_interpolate( ob, nplot, n1, n2 ) ) >= 0 )
{
x = sp->wx;
y = sp->wy;
xp = sp->xpi;
mapw2s( sp, xp, 0, newn, x, y );
nxp = sp->nxpi = newn;
mapw2s( sp, sp->xp, n1, n2, sp->x[ nplot ], sp->y[ nplot ] );
sp->nxp = n2 - n1;
}
else
{
x = sp->x[ nplot ];
y = sp->y[ nplot ];
xp = sp->xp;
mapw2s( sp, xp, n1, n2, x, y );
nxp = sp->nxp = n2 - n1;
}
switch ( sp->type[ nplot ] )
{
case FL_SQUARE_XYPLOT :
case FL_ACTIVE_XYPLOT :
drawsymbol = draw_square;
break;
case FL_CIRCLE_XYPLOT :
drawsymbol = draw_circle;
break;
case FL_POINTS_XYPLOT :
noline = 1;
/* fall through */
case FL_LINEPOINTS_XYPLOT :
drawsymbol = draw_point;
break;
case FL_DOTTED_XYPLOT :
flps_linestyle( FL_DOT );
break;
case FL_DOTDASHED_XYPLOT :
flps_linestyle( FL_DOTDASH );
break;
case FL_DASHED_XYPLOT :
flps_linestyle( FL_DASH );
break;
case FL_LONGDASHED_XYPLOT :
flps_linestyle( FL_LONGDASH );
break;
case FL_FILL_XYPLOT :
xp[ -1 ].x = xp[ 0 ].x;
xp[ -1 ].y = ym1;
xp[ nxp ].x = xp[ nxp - 1 ].x;
xp[ nxp ].y = ym1;
flps_poly( 1, xp - 1, nxp + 2, col );
noline = 1;
break;
case FL_IMPULSE_XYPLOT :
noline = 1;
for ( i = 0; i < sp->n[ nplot ]; i++ )
flps_line( sp->xp[ i ].x, ym1, sp->xp[ i ].x,
sp->xp[ i ].y, col );
break;
case FL_EMPTY_XYPLOT :
noline = 1;
break;
case FL_NORMAL_XYPLOT :
default:
noline = 0;
break;
}
if ( ! noline )
flps_lines( xp, nxp, col );
if ( drawsymbol )
{
xp = sp->xp; /* always use original point for symbol */
nxp = sp->nxp;
drawsymbol( xp, nxp, sp->ssize, sp->ssize );
}
/* do keys */
if ( sp->key[ nplot ] )
{
flps_linewidth( 0 );
if ( ! noline )
flps_line( key_xs, key_ys, key_xs + 20, key_ys, col );
if ( sp->type[ nplot ] == FL_IMPULSE_XYPLOT )
{
flps_line( key_xs + 3, key_ys + 2,
key_xs + 3, key_ys - 3, col );
flps_line( key_xs + 7, key_ys + 2,
key_xs + 7, key_ys - 3, col );
flps_line( key_xs + 11, key_ys + 2,
key_xs + 11, key_ys - 3, col );
flps_line( key_xs + 15, key_ys + 2,
key_xs + 15, key_ys - 3, col );
}
else if ( sp->type[ nplot ] == FL_FILL_XYPLOT )
flps_rectangle( 1, key_xs + 1, key_ys - 3, 19, 6, col );
if ( drawsymbol )
{
FL_POINT p[ 3 ];
p[ 0 ].x = key_xs + 3;
p[ 1 ].x = key_xs + 10;
p[ 2 ].x = key_xs + 17;
p[ 0 ].y = p[ 1 ].y = p[ 2 ].y = key_ys;
drawsymbol( p, 3, 4, 4 );
}
flps_draw_text( FL_ALIGN_LEFT, key_xs + 20, key_ys, 0, 0, col,
sp->key_lstyle, sp->key_lsize, sp->key[ nplot ] );
key_ys -= sp->key_ascend + sp->key_descend;
}
flps_linestyle( savels );
flps_linestyle( savelw );
}
flps_unset_clipping( );
flps_draw_text( FL_ALIGN_BOTTOM, ( sp->xi + sp->xf ) / 2,
ym2 + 1,
1, 1, ob->col2, sp->lstyle,
sp->lsize, sp->title );
( sp->xscale == FL_LOG ? add_logxtics : add_xtics )( ob );
( sp->xscale == FL_LOG ? add_logytics : add_ytics )( ob );
draw_inset( ob );
/* xlabel and y label */
flps_draw_text( FL_ALIGN_BOTTOM, ( sp->xi + sp->xf ) / 2,
ob->y + FL_abs(ob->bw) + ( dblbuffer ? sp->objy : 0 ),
1, 1, ob->col2, sp->lstyle, sp->lsize, sp->xlabel );
flps_draw_text( FL_ALIGN_CENTER | FL_ALIGN_VERT,
sp->xi - sp->maxytic -
fl_get_char_height( sp->lstyle, sp->lsize, 0, 0 ) / 2,
( ym1 + ym2 ) / 2,
1, 1, ob->col2, sp->lstyle, sp->lsize, sp->ylabel );
ob->col2 = savecol2;
}
/***************************************
* Draw a string with alignment given relative to a point.
* Figure out the bounding box etc so symbols can be drawn
***************************************/
static void
flps_draw_text_point( int lalign,
int x,
int y,
FL_COLOR col,
int lstyle,
int lsize,
char * str )
{
int align = lalign & ~ FL_ALIGN_INSIDE;
int bbox = 1.4 * lsize + 6;
int xx = x,
yy = y;
switch ( align )
{
case FL_ALIGN_CENTER :
xx = x - bbox / 2;
yy = y - bbox / 2;
break;
case FL_ALIGN_TOP :
xx = x - bbox / 2;
break;
case FL_ALIGN_BOTTOM :
xx = x - bbox / 2;
yy = y - bbox;
break;
case FL_ALIGN_LEFT :
yy = y - bbox / 2;
break;
case FL_ALIGN_RIGHT :
xx = x - bbox;
yy = y - bbox / 2;
break;
case FL_ALIGN_LEFT_TOP :
xx = x - bbox;
align = FL_ALIGN_RIGHT_TOP;
break;
case FL_ALIGN_RIGHT_TOP :
align = FL_ALIGN_LEFT_TOP;
break;
case FL_ALIGN_RIGHT_BOTTOM :
yy = y - bbox;
align = FL_ALIGN_LEFT_BOTTOM;
break;
case FL_ALIGN_LEFT_BOTTOM :
align = FL_ALIGN_RIGHT_BOTTOM;
yy = y - bbox;
xx = x - bbox;
break;
}
flps_draw_text_beside( align, xx, yy, bbox, bbox, col, lstyle, lsize, str );
}
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|