00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #define DEBUG
00036
00037 #define NEED_PLDEBUG
00038 #include "plcore.h"
00039
00040 #ifdef ENABLE_DYNDRIVERS
00041 #ifndef LTDL_WIN32
00042 #include <ltdl.h>
00043 #else
00044 #include "ltdl_win32.h"
00045 #endif
00046 #endif
00047
00048 #if HAVE_DIRENT_H
00049
00050
00051
00052 # ifdef NEED_SYS_TYPE_H
00053 # include <sys/types.h>
00054 # endif
00055 # include <dirent.h>
00056 # define NAMLEN(dirent) strlen((dirent)->d_name)
00057 #else
00058 # if defined(_MSC_VER)
00059 # include "dirent_msvc.h"
00060 # else
00061 # define dirent direct
00062 # define NAMLEN(dirent) (dirent)->d_namlen
00063 # if HAVE_SYS_NDIR_H
00064 # include <sys/ndir.h>
00065 # endif
00066 # if HAVE_SYS_DIR_H
00067 # include <sys/dir.h>
00068 # endif
00069 # if HAVE_NDIR_H
00070 # include <ndir.h>
00071 # endif
00072 # endif
00073 #endif
00074
00075
00076
00077
00078
00079
00080
00081 #if defined(_MSC_VER)
00082 # include <direct.h>
00083 # define getcwd _getcwd
00084 # define chdir _chdir
00085 #endif
00086
00087 #define BUFFER_SIZE 80
00088 #define BUFFER2_SIZE 300
00089 #define DRVSPEC_SIZE 400
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 enum {AT_BOP, DRAWING, AT_EOP};
00121
00122
00123
00124
00125
00126
00127
00128
00129 const char plP_greek_mnemonic[] = "ABGDEZYHIKLMNCOPRSTUFXQWabgdezyhiklmncoprstufxqw";
00130
00131 void
00132 plP_init(void)
00133 {
00134 char * save_locale;
00135 plsc->page_status = AT_EOP;
00136
00137 save_locale = plsave_set_locale();
00138 (*plsc->dispatch_table->pl_init) ((struct PLStream_struct *) plsc);
00139 plrestore_locale(save_locale);
00140
00141 if (plsc->plbuf_write)
00142 plbuf_init(plsc);
00143 }
00144
00145
00146
00147
00148
00149 void
00150 plP_eop(void)
00151 {
00152 int skip_driver_eop = 0;
00153
00154 if (plsc->page_status == AT_EOP)
00155 return;
00156
00157 plsc->page_status = AT_EOP;
00158
00159 if (plsc->plbuf_write)
00160 plbuf_eop(plsc);
00161
00162
00163
00164 if (plsc->eop_handler != NULL)
00165 (*plsc->eop_handler) (plsc->eop_data, &skip_driver_eop);
00166
00167 if (!skip_driver_eop) {
00168 char *save_locale = plsave_set_locale();
00169 (*plsc->dispatch_table->pl_eop) ((struct PLStream_struct *) plsc);
00170 plrestore_locale(save_locale);
00171 }
00172 }
00173
00174
00175
00176
00177
00178
00179 void
00180 plP_bop(void)
00181 {
00182 int skip_driver_bop = 0;
00183
00184 plP_subpInit();
00185 if (plsc->page_status == AT_BOP)
00186 return;
00187
00188 plsc->page_status = AT_BOP;
00189 plsc->nplwin = 0;
00190
00191
00192
00193 if (plsc->bop_handler != NULL)
00194 (*plsc->bop_handler) (plsc->bop_data, &skip_driver_bop);
00195
00196 if (!skip_driver_bop) {
00197 char *save_locale = plsave_set_locale();
00198 (*plsc->dispatch_table->pl_bop) ((struct PLStream_struct *) plsc);
00199 plrestore_locale(save_locale);
00200 }
00201
00202 if (plsc->plbuf_write)
00203 plbuf_bop(plsc);
00204 }
00205
00206
00207
00208 void
00209 plP_tidy(void)
00210 {
00211 char * save_locale;
00212 if (plsc->tidy) {
00213 (*plsc->tidy) (plsc->tidy_data);
00214 plsc->tidy = NULL;
00215 plsc->tidy_data = NULL;
00216 }
00217
00218 save_locale = plsave_set_locale();
00219 (*plsc->dispatch_table->pl_tidy) ((struct PLStream_struct *) plsc);
00220 plrestore_locale(save_locale);
00221
00222 if (plsc->plbuf_write) {
00223 plbuf_tidy(plsc);
00224 }
00225
00226 plsc->OutFile = NULL;
00227
00228 }
00229
00230
00231
00232 void
00233 plP_state(PLINT op)
00234 {
00235 char * save_locale;
00236 if (plsc->plbuf_write) plbuf_state(plsc, op);
00237
00238 save_locale = plsave_set_locale();
00239 (*plsc->dispatch_table->pl_state) ((struct PLStream_struct *) plsc, op);
00240 plrestore_locale(save_locale);
00241 }
00242
00243
00244
00245 void
00246 plP_esc(PLINT op, void *ptr)
00247 {
00248 char * save_locale;
00249 PLINT clpxmi, clpxma, clpymi, clpyma;
00250 EscText* args;
00251
00252
00253 if(plsc->plbuf_write) plbuf_esc(plsc, op, ptr);
00254
00255
00256 if((op==PLESC_HAS_TEXT && plsc->dev_unicode)||
00257 (op==PLESC_END_TEXT && plsc->alt_unicode)){
00258
00259
00260 if (plsc->difilt) {
00261 args = (EscText*)ptr;
00262 difilt(&(args->x),&(args->y),1,&clpxmi,&clpxma,&clpymi,&clpyma);
00263 }
00264 }
00265
00266 save_locale = plsave_set_locale();
00267 (*plsc->dispatch_table->pl_esc) ((struct PLStream_struct *) plsc, op, ptr);
00268 plrestore_locale(save_locale);
00269 }
00270
00271
00272
00273
00274
00275 void
00276 plP_swin(PLWindow *plwin)
00277 {
00278 PLWindow *w;
00279 PLINT clpxmi, clpxma, clpymi, clpyma;
00280
00281
00282
00283 if (plsc->plbuf_write)
00284 plbuf_esc(plsc, PLESC_SWIN, (void *) plwin);
00285
00286 w = &plsc->plwin[plsc->nplwin++ % PL_MAXWINDOWS];
00287
00288 w->dxmi = plwin->dxmi;
00289 w->dxma = plwin->dxma;
00290 w->dymi = plwin->dymi;
00291 w->dyma = plwin->dyma;
00292
00293 if (plsc->difilt) {
00294 xscl[0] = plP_dcpcx(w->dxmi);
00295 xscl[1] = plP_dcpcx(w->dxma);
00296 yscl[0] = plP_dcpcy(w->dymi);
00297 yscl[1] = plP_dcpcy(w->dyma);
00298
00299 difilt(xscl, yscl, 2, &clpxmi, &clpxma, &clpymi, &clpyma);
00300
00301 w->dxmi = plP_pcdcx(xscl[0]);
00302 w->dxma = plP_pcdcx(xscl[1]);
00303 w->dymi = plP_pcdcy(yscl[0]);
00304 w->dyma = plP_pcdcy(yscl[1]);
00305 }
00306
00307 w->wxmi = plwin->wxmi;
00308 w->wxma = plwin->wxma;
00309 w->wymi = plwin->wymi;
00310 w->wyma = plwin->wyma;
00311
00312
00313
00314
00315 if (plsc->dev_swin) {
00316 char *save_locale = plsave_set_locale();
00317 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
00318 PLESC_SWIN, NULL );
00319 plrestore_locale(save_locale);
00320 }
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330 void
00331 plP_line(short *x, short *y)
00332 {
00333 PLINT i, npts = 2, clpxmi, clpxma, clpymi, clpyma;
00334
00335 plsc->page_status = DRAWING;
00336
00337 if (plsc->plbuf_write)
00338 plbuf_line(plsc, x[0], y[0], x[1], y[1]);
00339
00340 if (plsc->difilt) {
00341 for (i = 0; i < npts; i++) {
00342 xscl[i] = x[i];
00343 yscl[i] = y[i];
00344 }
00345 difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma);
00346 plP_pllclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, grline);
00347 }
00348 else {
00349 grline(x, y, npts);
00350 }
00351 }
00352
00353
00354
00355
00356 void
00357 plP_polyline(short *x, short *y, PLINT npts)
00358 {
00359 PLINT i, clpxmi, clpxma, clpymi, clpyma;
00360
00361 plsc->page_status = DRAWING;
00362
00363 if (plsc->plbuf_write)
00364 plbuf_polyline(plsc, x, y, npts);
00365
00366 if (plsc->difilt) {
00367 for (i = 0; i < npts; i++) {
00368 xscl[i] = x[i];
00369 yscl[i] = y[i];
00370 }
00371 difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma);
00372 plP_pllclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma,
00373 grpolyline);
00374 }
00375 else {
00376 grpolyline(x, y, npts);
00377 }
00378 }
00379
00380
00381
00382
00383
00384
00385 static int foo;
00386
00387 void
00388 plP_fill(short *x, short *y, PLINT npts)
00389 {
00390 PLINT i, clpxmi, clpxma, clpymi, clpyma;
00391
00392 plsc->page_status = DRAWING;
00393
00394 if (plsc->plbuf_write) {
00395 plsc->dev_npts = npts;
00396 plsc->dev_x = x;
00397 plsc->dev_y = y;
00398 plbuf_esc(plsc, PLESC_FILL, NULL);
00399 }
00400
00401
00402
00403 if (plsc->patt == 0 && ! plsc->dev_fill0) {
00404 if ( ! foo) {
00405 plwarn("Driver does not support hardware solid fills, switching to software fill.\n");
00406 foo = 1;
00407 }
00408 plsc->patt = 8;
00409 plpsty(plsc->patt);
00410 }
00411 if (plsc->dev_fill1) {
00412 plsc->patt = -ABS(plsc->patt);
00413 }
00414
00415
00416
00417
00418
00419
00420 if (plsc->patt > 0)
00421 plfill_soft(x, y, npts);
00422
00423 else {
00424 if (plsc->difilt) {
00425 for (i = 0; i < npts; i++) {
00426 xscl[i] = x[i];
00427 yscl[i] = y[i];
00428 }
00429 difilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma);
00430 plP_plfclp(xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma,
00431 grfill);
00432 }
00433 else {
00434 grfill(x, y, npts);
00435 }
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 int text2num( const char *text, char end, PLUNICODE *num)
00458 {
00459
00460 char *endptr;
00461 char msgbuf[BUFFER_SIZE];
00462
00463 *num = strtoul(text,&endptr,0);
00464
00465 if (end != endptr[0]) {
00466 snprintf(msgbuf,BUFFER_SIZE,"text2num: invalid control string detected - %c expected",end);
00467 plwarn(msgbuf);
00468 }
00469
00470 return (int)(endptr - text);
00471
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 int text2fci( const char *text, unsigned char *hexdigit, unsigned char *hexpower)
00493 {
00494 typedef struct
00495 {
00496 char *ptext;
00497 unsigned char hexdigit;
00498 unsigned char hexpower;
00499 }
00500 TextLookupTable;
00501
00502
00503
00504 #define N_TextLookupTable 10
00505 const TextLookupTable lookup[N_TextLookupTable] = {
00506 {"<sans-serif/>", PL_FCI_SANS, PL_FCI_FAMILY},
00507 {"<serif/>", PL_FCI_SERIF, PL_FCI_FAMILY},
00508 {"<monospace/>", PL_FCI_MONO, PL_FCI_FAMILY},
00509 {"<script/>", PL_FCI_SCRIPT, PL_FCI_FAMILY},
00510 {"<symbol/>", PL_FCI_SYMBOL, PL_FCI_FAMILY},
00511 {"<upright/>", PL_FCI_UPRIGHT, PL_FCI_STYLE},
00512 {"<italic/>", PL_FCI_ITALIC, PL_FCI_STYLE},
00513 {"<oblique/>", PL_FCI_OBLIQUE, PL_FCI_STYLE},
00514 {"<medium/>", PL_FCI_MEDIUM, PL_FCI_WEIGHT},
00515 {"<bold/>", PL_FCI_BOLD, PL_FCI_WEIGHT}
00516 };
00517 int i, length;
00518 for (i=0; i<N_TextLookupTable; i++) {
00519 length = strlen(lookup[i].ptext);
00520 if (! strncmp(text, lookup[i].ptext, length)) {
00521 *hexdigit = lookup[i].hexdigit;
00522 *hexpower = lookup[i].hexpower;
00523 return(length);
00524 }
00525 }
00526 *hexdigit = 0;
00527 *hexpower = PL_FCI_HEXPOWER_IMPOSSIBLE;
00528 return(0);
00529 }
00530
00531 static PLUNICODE unicode_buffer[1024];
00532
00533 void
00534 plP_text(PLINT base, PLFLT just, PLFLT *xform, PLINT x, PLINT y,
00535 PLINT refx, PLINT refy, const char *string)
00536 {
00537
00538 if (plsc->dev_text) {
00539 EscText args;
00540 short len=0;
00541 char skip;
00542 unsigned short i,j;
00543 PLUNICODE code;
00544 char esc;
00545 int idx;
00546
00547 args.base = base;
00548 args.just = just;
00549 args.xform = xform;
00550 args.x = x;
00551 args.y = y;
00552 args.refx = refx;
00553 args.refy = refy;
00554 args.string = string;
00555
00556 if (plsc->dev_unicode) {
00557 PLINT ig;
00558 PLUNICODE fci, fcisave;
00559 unsigned char hexdigit, hexpower;
00560
00561
00562
00563 if (string!=NULL) {
00564
00565
00566
00567 len=strlen(string);
00568
00569
00570 plgesc(&esc);
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 plgfci(&fci);
00583
00584 if(plsc->alt_unicode){
00585 args.n_fci = fci;
00586 plP_esc(PLESC_BEGIN_TEXT, &args);
00587 }
00588 for (j=i=0;i<len;i++) {
00589
00590 skip=0;
00591
00592 if (string[i]==esc) {
00593 switch(string[i+1]) {
00594 case '(':
00595 i+=2+text2num(&string[i+2],')',&code);
00596 idx=plhershey2unicode(code);
00597
00598 fcisave = fci;
00599 plP_hex2fci(PL_FCI_SYMBOL, PL_FCI_FAMILY, &fci);
00600 unicode_buffer[j++]= fci;
00601 unicode_buffer[j++] = \
00602 (PLUNICODE)hershey_to_unicode_lookup_table[idx].Unicode;
00603
00604 if(plsc->alt_unicode){
00605 args.n_fci = fci;
00606 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00607 plP_esc(PLESC_CONTROL_CHAR, &args);
00608 args.n_char = \
00609 (PLUNICODE)hershey_to_unicode_lookup_table[idx].Unicode;
00610 plP_esc(PLESC_TEXT_CHAR, &args);
00611 }
00612
00613
00614
00615
00616
00617
00618
00619
00620 if (unicode_buffer[j-1]==esc) unicode_buffer[j++]=esc;
00621 fci = fcisave;
00622 unicode_buffer[j]= fci;
00623 skip=1;
00624 break;
00625
00626 case '[':
00627 i+=2+text2num(&string[i+2],']',&code);
00628
00629 fcisave = fci;
00630 plP_hex2fci(PL_FCI_SYMBOL, PL_FCI_FAMILY, &fci);
00631 unicode_buffer[j++]= fci;
00632 unicode_buffer[j++]=code;
00633
00634 if(plsc->alt_unicode){
00635 args.n_fci = fci;
00636 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00637 plP_esc(PLESC_CONTROL_CHAR, &args);
00638 args.n_char = code;
00639 plP_esc(PLESC_TEXT_CHAR, &args);
00640 }
00641
00642
00643
00644
00645
00646
00647
00648
00649 if (unicode_buffer[j-1]==esc) unicode_buffer[j++]=esc;
00650 fci = fcisave;
00651 unicode_buffer[j] = fci;
00652 skip=1;
00653 break;
00654
00655 case '<':
00656 if ('0' <= string[i+2] && string[i+2] <= '9' ) {
00657 i+=2+text2num(&string[i+2],'>', &code);
00658 if (code & PL_FCI_MARK) {
00659
00660
00661
00662 fci = code;
00663 unicode_buffer[j]=fci;
00664 skip=1;
00665
00666 if(plsc->alt_unicode){
00667 args.n_fci = fci;
00668 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00669 plP_esc(PLESC_CONTROL_CHAR, &args);
00670 }
00671 }
00672 else {
00673
00674
00675
00676
00677
00678 hexdigit = (code >> 4) & PL_FCI_HEXDIGIT_MASK;
00679 hexpower = code & PL_FCI_HEXPOWER_MASK;
00680 plP_hex2fci(hexdigit, hexpower, &fci);
00681 unicode_buffer[j]=fci;
00682 skip=1;
00683
00684 if(plsc->alt_unicode){
00685 args.n_fci = fci;
00686 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00687 plP_esc(PLESC_CONTROL_CHAR, &args);
00688 }
00689 }
00690 }
00691
00692 else {
00693 i+=text2fci(&string[i+1], &hexdigit, &hexpower);
00694 if (hexpower < 7) {
00695 plP_hex2fci(hexdigit, hexpower, &fci);
00696 unicode_buffer[j]=fci;
00697 skip=1;
00698
00699 if(plsc->alt_unicode){
00700 args.n_fci = fci;
00701 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00702 plP_esc(PLESC_CONTROL_CHAR, &args);
00703 }
00704 }
00705 }
00706 break;
00707
00708 case 'f':
00709 case 'F':
00710
00711
00712
00713
00714
00715
00716 fci = PL_FCI_MARK;
00717 if (string[i+2] == 'n') {
00718
00719 plP_hex2fci(PL_FCI_SANS, PL_FCI_FAMILY, &fci);
00720 } else if (string[i+2] == 'r') {
00721
00722 plP_hex2fci(PL_FCI_SERIF, PL_FCI_FAMILY, &fci);
00723 } else if (string[i+2] == 'i') {
00724
00725 plP_hex2fci(PL_FCI_ITALIC, PL_FCI_STYLE, &fci);
00726 plP_hex2fci(PL_FCI_SERIF, PL_FCI_FAMILY, &fci);
00727 } else if (string[i+2] == 's') {
00728
00729 plP_hex2fci(PL_FCI_SCRIPT, PL_FCI_FAMILY, &fci);
00730 } else
00731 fci = PL_FCI_IMPOSSIBLE;
00732
00733 if (fci != PL_FCI_IMPOSSIBLE){
00734 i+=2;
00735 unicode_buffer[j] = fci;
00736 skip = 1;
00737
00738 if(plsc->alt_unicode){
00739 args.n_fci = fci;
00740 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00741 plP_esc(PLESC_CONTROL_CHAR, &args);
00742 }
00743 }
00744 break;
00745
00746 case 'g':
00747 case 'G':
00748
00749
00750
00751
00752
00753 fcisave = fci;
00754 plP_hex2fci(PL_FCI_SYMBOL, PL_FCI_FAMILY, &fci);
00755 unicode_buffer[j++]= fci;
00756
00757 if(plsc->alt_unicode){
00758 args.n_fci = fci;
00759 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00760 plP_esc(PLESC_CONTROL_CHAR, &args);
00761 }
00762
00763 ig = plP_strpos(plP_greek_mnemonic, string[i+2]);
00764 if (ig >= 0) {
00765 if (ig >= 24)
00766 ig = ig + 100 - 24;
00767 idx=plhershey2unicode(ig+527);
00768 unicode_buffer[j++] = \
00769 (PLUNICODE)hershey_to_unicode_lookup_table[idx].Unicode;
00770 i+=2;
00771 skip=1;
00772
00773
00774 if(plsc->alt_unicode){
00775 args.n_char = \
00776 (PLUNICODE)hershey_to_unicode_lookup_table[idx].Unicode;
00777 plP_esc(PLESC_TEXT_CHAR, &args);
00778 }
00779 }
00780 else {
00781
00782
00783 unicode_buffer[j++]=(PLUNICODE)0x00;
00784 i+=2;
00785 skip=1;
00786
00787
00788 if(plsc->alt_unicode){
00789 args.n_char = \
00790 (PLUNICODE)hershey_to_unicode_lookup_table[idx].Unicode;
00791 plP_esc(PLESC_TEXT_CHAR, &args);
00792 }
00793 }
00794 fci = fcisave;
00795 unicode_buffer[j]= fci;
00796
00797 if(plsc->alt_unicode){
00798 args.n_fci = fci;
00799 args.n_ctrl_char = PLTEXT_FONTCHANGE;
00800 plP_esc(PLESC_CONTROL_CHAR, &args);
00801 }
00802 break;
00803
00804 case 'u':
00805 if(plsc->alt_unicode){
00806 args.n_ctrl_char = PLTEXT_SUPERSCRIPT;
00807 plP_esc(PLESC_CONTROL_CHAR, &args);
00808 i += 1;
00809 skip = 1;
00810 }
00811 break;
00812
00813 case 'd':
00814 if(plsc->alt_unicode){
00815 args.n_ctrl_char = PLTEXT_SUBSCRIPT;
00816 plP_esc(PLESC_CONTROL_CHAR, &args);
00817 i += 1;
00818 skip = 1;
00819 }
00820 break;
00821 }
00822 }
00823
00824 if (skip==0) {
00825 PLUNICODE unichar = 0;
00826 #ifdef HAVE_LIBUNICODE
00827 char* ptr = unicode_get_utf8 (string + i, &unichar);
00828 #else
00829 char* ptr = utf8_to_ucs4 (string + i, &unichar);
00830 #endif
00831 if (ptr == NULL) {
00832 char buf[BUFFER_SIZE];
00833 strncpy (buf, string, 30);
00834 buf[30] = '\0';
00835 snprintf (buf, BUFFER_SIZE, "UTF-8 string is malformed: %s%s",
00836 buf, strlen (string) > 30 ? "[...]" : "");
00837 plabort (buf);
00838 return;
00839 }
00840 unicode_buffer [j] = unichar;
00841 i += ptr - (string + i) - 1;
00842
00843
00844
00845
00846 if (unicode_buffer[j] == esc && string[i+1] == esc) {
00847 i++;
00848 unicode_buffer[++j] = esc;
00849 args.n_char = esc;
00850 } else {
00851 args.n_char = unichar;
00852 }
00853 if(plsc->alt_unicode){
00854 plP_esc(PLESC_TEXT_CHAR, &args);
00855 }
00856 }
00857 j++;
00858 }
00859 if (j > 0) {
00860 args.unicode_array_len=j;
00861
00862 args.unicode_array=&unicode_buffer[0];
00863
00864
00865
00866 } else
00867
00868 return;
00869 }
00870
00871 if(plsc->alt_unicode){
00872 plP_esc(PLESC_END_TEXT, &args);
00873 }
00874 }
00875
00876 if (plsc->dev_unicode) {
00877 args.string=NULL;
00878 }
00879 else {
00880 args.string = string;
00881 }
00882
00883 if (!plsc->alt_unicode){
00884 plP_esc(PLESC_HAS_TEXT, &args);
00885 }
00886 #ifndef DEBUG_TEXT
00887 } else {
00888 #endif
00889 plstr(base, xform, refx, refy, string);
00890 }
00891 }
00892
00893
00894 static char *
00895 utf8_to_ucs4(const char *ptr, PLUNICODE *unichar)
00896 {
00897 char tmp;
00898 int isFirst = 1;
00899 int cnt = 0;
00900
00901 do {
00902
00903 tmp = *ptr++;
00904 if (isFirst) {
00905 isFirst = 0;
00906
00907 if ((unsigned char)(tmp & 0x80) == 0x00) {
00908 *unichar = (unsigned int)tmp & 0x7F;
00909 cnt = 0;
00910 } else if ((unsigned char)(tmp & 0xE0) == 0xC0) {
00911 *unichar = (unsigned int)tmp & 0x1F;
00912 cnt = 1;
00913 } else if ((unsigned char)(tmp & 0xF0) == 0xE0) {
00914 *unichar = (unsigned char)tmp & 0x0F;
00915 cnt = 2;
00916 } else if ((unsigned char)(tmp & 0xF8) == 0xF0) {
00917 *unichar = (unsigned char)tmp & 0x07;
00918 cnt = 3;
00919 } else if ((unsigned char)(tmp & 0xFC) == 0xF8) {
00920 *unichar = (unsigned char)tmp & 0x03;
00921 cnt = 4;
00922 } else if ((unsigned char)(tmp & 0xFE) == 0xFC) {
00923 *unichar = (unsigned char)tmp & 0x01;
00924 cnt = 5;
00925 } else {
00926 ptr = NULL;
00927 cnt = 0;
00928 }
00929 } else {
00930 if ((unsigned char)(tmp & 0xC0) == 0x80) {
00931 *unichar = (*unichar << 6) | ((unsigned int)tmp & 0x3F);
00932 cnt--;
00933 } else {
00934 ptr = NULL;
00935 cnt = 0;
00936 }
00937 }
00938 } while (cnt > 0);
00939 return (char *) ptr;
00940 }
00941
00942
00943 int
00944 ucs4_to_utf8(PLUNICODE unichar, char *ptr)
00945 {
00946 unsigned char *tmp;
00947 int len;
00948
00949 tmp = (unsigned char *)ptr;
00950
00951 if ( (unichar & 0xffff80) == 0 ) {
00952 *tmp = (unsigned char) unichar;
00953 tmp++;
00954 len = 1;
00955 }
00956 else if ( (unichar & 0xfff800) == 0) {
00957 *tmp = (unsigned char) 0xc0 | (unichar >> 6);
00958 tmp++;
00959 *tmp = (unsigned char) 0x80 | (unichar & 0x3f);
00960 tmp++;
00961 len = 2;
00962 }
00963 else if ( (unichar & 0xff0000) == 0) {
00964 *tmp = (unsigned char) 0xe0 | (unichar >> 12);
00965 tmp++;
00966 *tmp = (unsigned char) 0x80 | ((unichar >> 6) & 0x3f);
00967 tmp++;
00968 *tmp = (unsigned char) 0x80 | (unichar & 0x3f);
00969 tmp++;
00970 len = 3;
00971 }
00972 else if ( (unichar & 0xe0000) == 0){
00973 *tmp = (unsigned char) 0xf0 | (unichar >> 18);
00974 tmp++;
00975 *tmp = (unsigned char) 0x80 | ((unichar >> 12) & 0x3f);
00976 tmp++;
00977 *tmp = (unsigned char) 0x80 | ((unichar >> 6) & 0x3f);
00978 tmp++;
00979 *tmp = (unsigned char) 0x80 | (unichar & 0x3f);
00980 tmp++;
00981 len = 4;
00982 }
00983 else {
00984 len = 0;
00985 }
00986 *tmp = '\0';
00987
00988 return len;
00989 }
00990
00991 static void
00992 grline(short *x, short *y, PLINT npts)
00993 {
00994 char *save_locale = plsave_set_locale();
00995 (*plsc->dispatch_table->pl_line) ( (struct PLStream_struct *) plsc,
00996 x[0], y[0], x[1], y[1] );
00997 plrestore_locale(save_locale);
00998 }
00999
01000 static void
01001 grpolyline(short *x, short *y, PLINT npts)
01002 {
01003 char *save_locale = plsave_set_locale();
01004 (*plsc->dispatch_table->pl_polyline) ( (struct PLStream_struct *) plsc,
01005 x, y, npts );
01006 plrestore_locale(save_locale);
01007 }
01008
01009 static void
01010 grfill(short *x, short *y, PLINT npts)
01011 {
01012 char * save_locale;
01013 plsc->dev_npts = npts;
01014 plsc->dev_x = x;
01015 plsc->dev_y = y;
01016
01017 save_locale = plsave_set_locale();
01018 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
01019 PLESC_FILL, NULL );
01020 plrestore_locale(save_locale);
01021 }
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043 void
01044 difilt(PLINT *xscl, PLINT *yscl, PLINT npts,
01045 PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
01046 {
01047 PLINT i, x, y;
01048
01049
01050
01051 if (plsc->difilt & PLDI_MAP) {
01052 for (i = 0; i < npts; i++) {
01053 xscl[i] = (PLINT)(plsc->dimxax * xscl[i] + plsc->dimxb);
01054 yscl[i] = (PLINT)(plsc->dimyay * yscl[i] + plsc->dimyb);
01055 }
01056 }
01057
01058
01059
01060 if (plsc->difilt & PLDI_ORI) {
01061 for (i = 0; i < npts; i++) {
01062 x = (PLINT)(plsc->dioxax * xscl[i] + plsc->dioxay * yscl[i] + plsc->dioxb);
01063 y = (PLINT)(plsc->dioyax * xscl[i] + plsc->dioyay * yscl[i] + plsc->dioyb);
01064 xscl[i] = x;
01065 yscl[i] = y;
01066 }
01067 }
01068
01069
01070
01071 if (plsc->difilt & PLDI_PLT) {
01072 for (i = 0; i < npts; i++) {
01073 xscl[i] = (PLINT)(plsc->dipxax * xscl[i] + plsc->dipxb);
01074 yscl[i] = (PLINT)(plsc->dipyay * yscl[i] + plsc->dipyb);
01075 }
01076 }
01077
01078
01079
01080
01081 if (plsc->difilt & PLDI_DEV) {
01082 for (i = 0; i < npts; i++) {
01083 xscl[i] = (PLINT)(plsc->didxax * xscl[i] + plsc->didxb);
01084 yscl[i] = (PLINT)(plsc->didyay * yscl[i] + plsc->didyb);
01085 }
01086 *clpxmi = plsc->diclpxmi;
01087 *clpxma = plsc->diclpxma;
01088 *clpymi = plsc->diclpymi;
01089 *clpyma = plsc->diclpyma;
01090 }
01091 else {
01092 *clpxmi = plsc->phyxmi;
01093 *clpxma = plsc->phyxma;
01094 *clpymi = plsc->phyymi;
01095 *clpyma = plsc->phyyma;
01096 }
01097 }
01098
01099 void
01100 sdifilt(short *xscl, short *yscl, PLINT npts,
01101 PLINT *clpxmi, PLINT *clpxma, PLINT *clpymi, PLINT *clpyma)
01102 {
01103 int i;
01104 short x, y;
01105
01106
01107
01108 if (plsc->difilt & PLDI_MAP) {
01109 for (i = 0; i < npts; i++) {
01110 xscl[i] = (PLINT)(plsc->dimxax * xscl[i] + plsc->dimxb);
01111 yscl[i] = (PLINT)(plsc->dimyay * yscl[i] + plsc->dimyb);
01112 }
01113 }
01114
01115
01116
01117 if (plsc->difilt & PLDI_ORI) {
01118 for (i = 0; i < npts; i++) {
01119 x = (PLINT)(plsc->dioxax * xscl[i] + plsc->dioxay * yscl[i] + plsc->dioxb);
01120 y = (PLINT)(plsc->dioyax * xscl[i] + plsc->dioyay * yscl[i] + plsc->dioyb);
01121 xscl[i] = x;
01122 yscl[i] = y;
01123 }
01124 }
01125
01126
01127
01128 if (plsc->difilt & PLDI_PLT) {
01129 for (i = 0; i < npts; i++) {
01130 xscl[i] = (PLINT)(plsc->dipxax * xscl[i] + plsc->dipxb);
01131 yscl[i] = (PLINT)(plsc->dipyay * yscl[i] + plsc->dipyb);
01132 }
01133 }
01134
01135
01136
01137
01138 if (plsc->difilt & PLDI_DEV) {
01139 for (i = 0; i < npts; i++) {
01140 xscl[i] = (PLINT)(plsc->didxax * xscl[i] + plsc->didxb);
01141 yscl[i] = (PLINT)(plsc->didyay * yscl[i] + plsc->didyb);
01142 }
01143 *clpxmi = (PLINT)(plsc->diclpxmi);
01144 *clpxma = (PLINT)(plsc->diclpxma);
01145 *clpymi = (PLINT)(plsc->diclpymi);
01146 *clpyma = (PLINT)(plsc->diclpyma);
01147 }
01148 else {
01149 *clpxmi = plsc->phyxmi;
01150 *clpxma = plsc->phyxma;
01151 *clpymi = plsc->phyymi;
01152 *clpyma = plsc->phyyma;
01153 }
01154 }
01155
01156
01157
01158
01159
01160
01161
01162
01163 void
01164 difilt_clip(PLINT *x_coords, PLINT *y_coords)
01165 {
01166 PLINT x1c, x2c, y1c, y2c;
01167
01168 x1c = plsc->clpxmi;
01169 y1c = plsc->clpymi;
01170 x2c = plsc->clpxma;
01171 y2c = plsc->clpyma;
01172 x_coords[0] = x1c;
01173 x_coords[1] = x1c;
01174 x_coords[2] = x2c;
01175 x_coords[3] = x2c;
01176 y_coords[0] = y1c;
01177 y_coords[1] = y2c;
01178 y_coords[2] = y2c;
01179 y_coords[3] = y1c;
01180 difilt(x_coords, y_coords, 4, &x1c, &x2c, &y1c, &y2c);
01181 }
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191 static void
01192 setdef_diplt()
01193 {
01194 plsc->dipxmin = 0.0;
01195 plsc->dipxmax = 1.0;
01196 plsc->dipymin = 0.0;
01197 plsc->dipymax = 1.0;
01198 }
01199
01200 static void
01201 setdef_didev()
01202 {
01203 plsc->mar = 0.0;
01204 plsc->aspect = 0.0;
01205 plsc->jx = 0.0;
01206 plsc->jy = 0.0;
01207 }
01208
01209 static void
01210 setdef_diori()
01211 {
01212 plsc->diorot = 0.;
01213 }
01214
01215 static void
01216 pldi_ini(void)
01217 {
01218 if (plsc->level >= 1) {
01219 if (plsc->difilt & PLDI_MAP)
01220 calc_dimap();
01221
01222 if (plsc->difilt & PLDI_ORI)
01223 calc_diori();
01224 else
01225 setdef_diori();
01226
01227 if (plsc->difilt & PLDI_PLT)
01228 calc_diplt();
01229 else
01230 setdef_diplt();
01231
01232 if (plsc->difilt & PLDI_DEV)
01233 calc_didev();
01234 else
01235 setdef_didev();
01236 }
01237 }
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248 void
01249 pldid2pc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax)
01250 {
01251 PLFLT pxmin, pymin, pxmax, pymax;
01252 PLFLT sxmin, symin, sxmax, symax;
01253 PLFLT rxmin, rymin, rxmax, rymax;
01254
01255 if (plsc->difilt & PLDI_DEV) {
01256
01257 pldebug("pldid2pc",
01258 "Relative device coordinates (in): %f, %f, %f, %f\n",
01259 *xmin, *ymin, *xmax, *ymax);
01260
01261 pxmin = plP_dcpcx(*xmin);
01262 pymin = plP_dcpcy(*ymin);
01263 pxmax = plP_dcpcx(*xmax);
01264 pymax = plP_dcpcy(*ymax);
01265
01266 sxmin = (pxmin - plsc->didxb) / plsc->didxax;
01267 symin = (pymin - plsc->didyb) / plsc->didyay;
01268 sxmax = (pxmax - plsc->didxb) / plsc->didxax;
01269 symax = (pymax - plsc->didyb) / plsc->didyay;
01270
01271 rxmin = plP_pcdcx((PLINT)sxmin);
01272 rymin = plP_pcdcy((PLINT)symin);
01273 rxmax = plP_pcdcx((PLINT)sxmax);
01274 rymax = plP_pcdcy((PLINT)symax);
01275
01276 *xmin = (rxmin < 0) ? 0 : rxmin;
01277 *xmax = (rxmax > 1) ? 1 : rxmax;
01278 *ymin = (rymin < 0) ? 0 : rymin;
01279 *ymax = (rymax > 1) ? 1 : rymax;
01280
01281 pldebug("pldid2pc",
01282 "Relative plot coordinates (out): %f, %f, %f, %f\n",
01283 rxmin, rymin, rxmax, rymax);
01284 }
01285 }
01286
01287
01288
01289
01290
01291
01292
01293
01294 void
01295 pldip2dc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax)
01296 {
01297 PLFLT pxmin, pymin, pxmax, pymax;
01298 PLFLT sxmin, symin, sxmax, symax;
01299 PLFLT rxmin, rymin, rxmax, rymax;
01300
01301 if (plsc->difilt & PLDI_DEV) {
01302
01303 pldebug("pldip2pc",
01304 "Relative plot coordinates (in): %f, %f, %f, %f\n",
01305 *xmin, *ymin, *xmax, *ymax);
01306
01307 pxmin = plP_dcpcx(*xmin);
01308 pymin = plP_dcpcy(*ymin);
01309 pxmax = plP_dcpcx(*xmax);
01310 pymax = plP_dcpcy(*ymax);
01311
01312 sxmin = pxmin * plsc->didxax + plsc->didxb;
01313 symin = pymin * plsc->didyay + plsc->didyb;
01314 sxmax = pxmax * plsc->didxax + plsc->didxb;
01315 symax = pymax * plsc->didyay + plsc->didyb;
01316
01317 rxmin = plP_pcdcx((PLINT)sxmin);
01318 rymin = plP_pcdcy((PLINT)symin);
01319 rxmax = plP_pcdcx((PLINT)sxmax);
01320 rymax = plP_pcdcy((PLINT)symax);
01321
01322 *xmin = (rxmin < 0) ? 0 : rxmin;
01323 *xmax = (rxmax > 1) ? 1 : rxmax;
01324 *ymin = (rymin < 0) ? 0 : rymin;
01325 *ymax = (rymax > 1) ? 1 : rymax;
01326
01327 pldebug("pldip2pc",
01328 "Relative device coordinates (out): %f, %f, %f, %f\n",
01329 rxmin, rymin, rxmax, rymax);
01330 }
01331 }
01332
01333
01334
01335
01336
01337
01338
01339 void
01340 c_plsdiplt(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax)
01341 {
01342 plsc->dipxmin = (xmin < xmax) ? xmin : xmax;
01343 plsc->dipxmax = (xmin < xmax) ? xmax : xmin;
01344 plsc->dipymin = (ymin < ymax) ? ymin : ymax;
01345 plsc->dipymax = (ymin < ymax) ? ymax : ymin;
01346
01347 if (xmin == 0. && xmax == 1. && ymin == 0. && ymax == 1.) {
01348 plsc->difilt &= ~PLDI_PLT;
01349 return;
01350 }
01351
01352 plsc->difilt |= PLDI_PLT;
01353 pldi_ini();
01354 }
01355
01356
01357
01358
01359
01360
01361
01362 void
01363 c_plsdiplz(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax)
01364 {
01365 if (plsc->difilt & PLDI_PLT) {
01366 xmin = plsc->dipxmin + (plsc->dipxmax - plsc->dipxmin) * xmin;
01367 ymin = plsc->dipymin + (plsc->dipymax - plsc->dipymin) * ymin;
01368 xmax = plsc->dipxmin + (plsc->dipxmax - plsc->dipxmin) * xmax;
01369 ymax = plsc->dipymin + (plsc->dipymax - plsc->dipymin) * ymax;
01370 }
01371
01372 plsdiplt(xmin, ymin, xmax, ymax);
01373 }
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386 static void
01387 calc_diplt(void)
01388 {
01389 PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen;
01390
01391 if (plsc->dev_di) {
01392 char *save_locale = plsave_set_locale();
01393 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
01394 PLESC_DI, NULL );
01395 plrestore_locale(save_locale);
01396 }
01397
01398 if ( ! (plsc->difilt & PLDI_PLT))
01399 return;
01400
01401 pxmin = plP_dcpcx(plsc->dipxmin);
01402 pxmax = plP_dcpcx(plsc->dipxmax);
01403 pymin = plP_dcpcy(plsc->dipymin);
01404 pymax = plP_dcpcy(plsc->dipymax);
01405
01406 pxlen = pxmax - pxmin;
01407 pylen = pymax - pymin;
01408 pxlen = MAX(1, pxlen);
01409 pylen = MAX(1, pylen);
01410
01411 plsc->dipxax = plsc->phyxlen / (double) pxlen;
01412 plsc->dipyay = plsc->phyylen / (double) pylen;
01413 plsc->dipxb = plsc->phyxmi - plsc->dipxax * pxmin;
01414 plsc->dipyb = plsc->phyymi - plsc->dipyay * pymin;
01415 }
01416
01417
01418
01419
01420
01421
01422
01423 void
01424 c_plgdiplt(PLFLT *p_xmin, PLFLT *p_ymin, PLFLT *p_xmax, PLFLT *p_ymax)
01425 {
01426 *p_xmin = plsc->dipxmin;
01427 *p_xmax = plsc->dipxmax;
01428 *p_ymin = plsc->dipymin;
01429 *p_ymax = plsc->dipymax;
01430 }
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443 void
01444 c_plsdidev(PLFLT mar, PLFLT aspect, PLFLT jx, PLFLT jy)
01445 {
01446 plsetvar(plsc->mar, mar);
01447 plsetvar(plsc->aspect, aspect);
01448 plsetvar(plsc->jx, jx);
01449 plsetvar(plsc->jy, jy);
01450
01451 if (mar == 0. && aspect == 0. && jx == 0. && jy == 0. &&
01452 ! (plsc->difilt & PLDI_ORI)) {
01453 plsc->difilt &= ~PLDI_DEV;
01454 return;
01455 }
01456
01457 plsc->difilt |= PLDI_DEV;
01458 pldi_ini();
01459 }
01460
01461
01462
01463
01464
01465
01466
01467
01468 static void
01469 calc_didev(void)
01470 {
01471 PLFLT lx, ly, aspect, aspdev;
01472 PLFLT xmin, xmax, xlen, ymin, ymax, ylen;
01473 PLINT pxmin, pxmax, pymin, pymax, pxlen, pylen;
01474
01475 if (plsc->dev_di) {
01476 char *save_locale = plsave_set_locale();
01477 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
01478 PLESC_DI, NULL );
01479 plrestore_locale(save_locale);
01480 }
01481
01482 if ( ! (plsc->difilt & PLDI_DEV))
01483 return;
01484
01485
01486
01487 lx = plsc->phyxlen / plsc->xpmm;
01488 ly = plsc->phyylen / plsc->ypmm;
01489 aspdev = lx / ly;
01490
01491 if (plsc->difilt & PLDI_ORI)
01492 aspect = plsc->aspori;
01493 else
01494 aspect = plsc->aspect;
01495
01496 if (aspect <= 0.)
01497 aspect = plsc->aspdev;
01498
01499
01500
01501 plsc->mar = (plsc->mar > 0.5) ? 0.5 : plsc->mar;
01502 plsc->mar = (plsc->mar < 0.0) ? 0.0 : plsc->mar;
01503 plsc->jx = (plsc->jx > 0.5) ? 0.5 : plsc->jx;
01504 plsc->jx = (plsc->jx < -0.5) ? -0.5 : plsc->jx;
01505 plsc->jy = (plsc->jy > 0.5) ? 0.5 : plsc->jy;
01506 plsc->jy = (plsc->jy < -0.5) ? -0.5 : plsc->jy;
01507
01508
01509
01510 xlen = (aspect < aspdev) ? (aspect / aspdev) : 1.0;
01511 ylen = (aspect < aspdev) ? 1.0 : (aspdev / aspect);
01512
01513 xlen *= (1.0 - 2.*plsc->mar);
01514 ylen *= (1.0 - 2.*plsc->mar);
01515
01516 xmin = (1. - xlen) * (0.5 + plsc->jx);
01517 xmax = xmin + xlen;
01518
01519 ymin = (1. - ylen) * (0.5 + plsc->jy);
01520 ymax = ymin + ylen;
01521
01522
01523
01524 pxmin = plP_dcpcx(xmin);
01525 pxmax = plP_dcpcx(xmax);
01526 pymin = plP_dcpcy(ymin);
01527 pymax = plP_dcpcy(ymax);
01528
01529 pxlen = pxmax - pxmin;
01530 pylen = pymax - pymin;
01531 pxlen = MAX(1, pxlen);
01532 pylen = MAX(1, pylen);
01533
01534 plsc->didxax = pxlen / (double) plsc->phyxlen;
01535 plsc->didyay = pylen / (double) plsc->phyylen;
01536 plsc->didxb = pxmin - plsc->didxax * plsc->phyxmi;
01537 plsc->didyb = pymin - plsc->didyay * plsc->phyymi;
01538
01539
01540
01541 plsc->diclpxmi = (PLINT)(plsc->didxax * plsc->phyxmi + plsc->didxb);
01542 plsc->diclpxma = (PLINT)(plsc->didxax * plsc->phyxma + plsc->didxb);
01543 plsc->diclpymi = (PLINT)(plsc->didyay * plsc->phyymi + plsc->didyb);
01544 plsc->diclpyma = (PLINT)(plsc->didyay * plsc->phyyma + plsc->didyb);
01545 }
01546
01547
01548
01549
01550
01551
01552
01553 void
01554 c_plgdidev(PLFLT *p_mar, PLFLT *p_aspect, PLFLT *p_jx, PLFLT *p_jy)
01555 {
01556 *p_mar = plsc->mar;
01557 *p_aspect = plsc->aspect;
01558 *p_jx = plsc->jx;
01559 *p_jy = plsc->jy;
01560 }
01561
01562
01563
01564
01565
01566
01567
01568 void
01569 c_plsdiori(PLFLT rot)
01570 {
01571 plsc->diorot = rot;
01572 if (rot == 0.) {
01573 plsc->difilt &= ~PLDI_ORI;
01574 pldi_ini();
01575 return;
01576 }
01577
01578 plsc->difilt |= PLDI_ORI;
01579 pldi_ini();
01580 }
01581
01582
01583
01584
01585
01586
01587
01588
01589 static void
01590 calc_diori(void)
01591 {
01592 PLFLT r11, r21, r12, r22, cost, sint;
01593 PLFLT x0, y0, lx, ly, aspect;
01594
01595 if (plsc->dev_di) {
01596 char *save_locale = plsave_set_locale();
01597 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
01598 PLESC_DI, NULL );
01599 plrestore_locale(save_locale);
01600 }
01601
01602 if ( ! (plsc->difilt & PLDI_ORI))
01603 return;
01604
01605
01606
01607 x0 = (plsc->phyxma + plsc->phyxmi) / 2.;
01608 y0 = (plsc->phyyma + plsc->phyymi) / 2.;
01609
01610
01611
01612 r11 = cos(plsc->diorot * PI / 2.);
01613 r21 = sin(plsc->diorot * PI / 2.);
01614 r12 = -r21;
01615 r22 = r11;
01616
01617 cost = ABS(r11);
01618 sint = ABS(r21);
01619
01620
01621
01622 aspect = plsc->aspect;
01623 if (aspect == 0.)
01624 aspect = plsc->aspdev;
01625
01626 if (plsc->freeaspect)
01627 plsc->aspori = aspect;
01628 else
01629 plsc->aspori = (aspect * cost + sint) / (aspect * sint + cost);
01630
01631 if ( ! (plsc->difilt & PLDI_DEV)) {
01632 plsc->difilt |= PLDI_DEV;
01633 setdef_didev();
01634 }
01635 calc_didev();
01636
01637
01638
01639 lx = plsc->phyxlen;
01640 ly = plsc->phyylen;
01641
01642
01643
01644 plsc->dioxax = r11;
01645 plsc->dioxay = r21 * (lx / ly);
01646 plsc->dioxb = (1. - r11) * x0 - r21 * y0 * (lx / ly);
01647
01648 plsc->dioyax = r12 * (ly / lx);
01649 plsc->dioyay = r22;
01650 plsc->dioyb = (1. - r22) * y0 - r12 * x0 * (ly / lx);
01651 }
01652
01653
01654
01655
01656
01657
01658
01659 void
01660 c_plgdiori(PLFLT *p_rot)
01661 {
01662 *p_rot = plsc->diorot;
01663 }
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674 void
01675 c_plsdimap(PLINT dimxmin, PLINT dimxmax, PLINT dimymin, PLINT dimymax,
01676 PLFLT dimxpmm, PLFLT dimypmm)
01677 {
01678 plsetvar(plsc->dimxmin, dimxmin);
01679 plsetvar(plsc->dimxmax, dimxmax);
01680 plsetvar(plsc->dimymin, dimymin);
01681 plsetvar(plsc->dimymax, dimymax);
01682 plsetvar(plsc->dimxpmm, dimxpmm);
01683 plsetvar(plsc->dimypmm, dimypmm);
01684
01685 plsc->difilt |= PLDI_MAP;
01686 pldi_ini();
01687 }
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698 static void
01699 calc_dimap()
01700 {
01701 PLFLT lx, ly;
01702 PLINT pxmin, pxmax, pymin, pymax;
01703 PLFLT dimxlen, dimylen, pxlen, pylen;
01704
01705 if ((plsc->dimxmin == plsc->phyxmi) && (plsc->dimxmax == plsc->phyxma) &&
01706 (plsc->dimymin == plsc->phyymi) && (plsc->dimymax == plsc->phyyma) &&
01707 (plsc->dimxpmm == plsc->xpmm) && (plsc->dimypmm == plsc->ypmm)) {
01708 plsc->difilt &= ~PLDI_MAP;
01709 return;
01710 }
01711
01712
01713
01714 lx = (plsc->dimxmax - plsc->dimxmin + 1) / plsc->dimxpmm;
01715 ly = (plsc->dimymax - plsc->dimymin + 1) / plsc->dimypmm;
01716
01717 plsc->aspdev = lx / ly;
01718
01719
01720
01721 dimxlen = plsc->dimxmax - plsc->dimxmin;
01722 dimylen = plsc->dimymax - plsc->dimymin;
01723
01724 pxmin = plsc->phyxmi;
01725 pxmax = plsc->phyxma;
01726 pymin = plsc->phyymi;
01727 pymax = plsc->phyyma;
01728 pxlen = pxmax - pxmin;
01729 pylen = pymax - pymin;
01730
01731 plsc->dimxax = pxlen / dimxlen;
01732 plsc->dimyay = pylen / dimylen;
01733 plsc->dimxb = pxmin - pxlen * plsc->dimxmin / dimxlen;
01734 plsc->dimyb = pymin - pylen * plsc->dimymin / dimylen;
01735 }
01736
01737
01738
01739
01740
01741
01742
01743 void
01744 c_plflush(void)
01745 {
01746 if (plsc->dev_flush) {
01747 char *save_locale = plsave_set_locale();
01748 (*plsc->dispatch_table->pl_esc) ( (struct PLStream_struct *) plsc,
01749 PLESC_FLUSH, NULL );
01750 plrestore_locale(save_locale);
01751 }
01752 else {
01753 if (plsc->OutFile != NULL)
01754 fflush(plsc->OutFile);
01755 }
01756 }
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770 void
01771 pllib_init()
01772 {
01773 if (lib_initialized) return;
01774 lib_initialized = 1;
01775
01776 #ifdef ENABLE_DYNDRIVERS
01777
01778 lt_dlinit();
01779 #endif
01780
01781
01782
01783
01784 plInitDispatchTable();
01785 }
01786
01787
01788
01789
01790
01791
01792
01793 void
01794 c_plstar(PLINT nx, PLINT ny)
01795 {
01796 pllib_init();
01797
01798 if (plsc->level != 0)
01799 plend1();
01800
01801 plssub(nx, ny);
01802
01803 c_plinit();
01804 }
01805
01806
01807
01808
01809
01810
01811
01812 void
01813 c_plstart(const char *devname, PLINT nx, PLINT ny)
01814 {
01815 pllib_init();
01816
01817 if (plsc->level != 0)
01818 plend1();
01819
01820 plssub(nx, ny);
01821 plsdev(devname);
01822
01823 c_plinit();
01824 }
01825
01826
01827
01828
01829
01830
01831
01832 void
01833 c_plinit(void)
01834 {
01835 PLFLT def_arrow_x[6] = {-0.5, 0.5, 0.3, 0.5, 0.3, 0.5};
01836 PLFLT def_arrow_y[6] = {0.0, 0.0, 0.2, 0.0, -0.2, 0.0};
01837 PLFLT lx, ly, xpmm_loc, ypmm_loc, aspect_old, aspect_new;
01838 PLINT mk = 0, sp = 0, inc = 0, del = 2000;
01839
01840 pllib_init();
01841
01842 if (plsc->level != 0)
01843 plend1();
01844
01845
01846
01847 plsc->ipls = ipls;
01848
01849
01850
01851 pllib_devinit();
01852
01853
01854
01855 plstrm_init();
01856
01857
01858
01859 plP_init();
01860 plP_bop();
01861 plsc->level = 1;
01862
01863
01864
01865
01866
01867
01868
01869
01870 plP_FreeDrvOpts();
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880 if (plsc->aspect > 0.) {
01881 lx = plsc->phyxlen / plsc->xpmm;
01882 ly = plsc->phyylen / plsc->ypmm;
01883 aspect_old = lx / ly;
01884 aspect_new = plsc->aspect;
01885 plsc->caspfactor = sqrt(aspect_old/aspect_new);
01886 }
01887
01888
01889 else if (plsc->freeaspect && ABS(cos(plsc->diorot * PI / 2.)) <= 1.e-5) {
01890 lx = plsc->phyxlen / plsc->xpmm;
01891 ly = plsc->phyylen / plsc->ypmm;
01892 aspect_old = lx / ly;
01893 aspect_new = ly / lx;
01894 plsc->caspfactor = sqrt(aspect_old/aspect_new);
01895 }
01896
01897 else
01898 plsc->caspfactor = 1.;
01899
01900
01901
01902 plsc->cfont = 1;
01903 plfntld(initfont);
01904
01905
01906
01907 plP_subpInit();
01908
01909
01910
01911
01912 if (plsc->xdigmax == 0)
01913 plsc->xdigmax = 4;
01914
01915 if (plsc->ydigmax == 0)
01916 plsc->ydigmax = 4;
01917
01918 if (plsc->zdigmax == 0)
01919 plsc->zdigmax = 3;
01920
01921 if (plsc->timefmt == NULL)
01922 c_pltimefmt("%c");
01923
01924
01925
01926
01927 if (plsc->qsasconfig == NULL)
01928 c_plconfigtime(0., 0., 0., 0x0, 0, 0, 0, 0, 0, 0, 0.);
01929
01930
01931
01932 plgra();
01933 plcol(1);
01934
01935 plstyl(0, &mk, &sp);
01936 plpat(1, &inc, &del);
01937
01938 plsvect(def_arrow_x, def_arrow_y, 6, 0);
01939
01940
01941
01942 plsc->clpxmi = plsc->phyxmi;
01943 plsc->clpxma = plsc->phyxma;
01944 plsc->clpymi = plsc->phyymi;
01945 plsc->clpyma = plsc->phyyma;
01946
01947
01948
01949 lx = plsc->phyxlen / plsc->xpmm;
01950 ly = plsc->phyylen / plsc->ypmm;
01951 plsc->aspdev = lx / ly;
01952
01953
01954
01955 pldi_ini();
01956
01957
01958
01959
01960
01961
01962
01963 plP_gpixmm(&xpmm_loc, &ypmm_loc);
01964 plP_setpxl(xpmm_loc*plsc->caspfactor, ypmm_loc/plsc->caspfactor);
01965 }
01966
01967
01968
01969
01970
01971
01972
01973 void
01974 c_plend(void)
01975 {
01976 PLINT i;
01977
01978 if (lib_initialized == 0) return;
01979
01980 for (i = PL_NSTREAMS-1; i >= 0; i--) {
01981 if (pls[i] != NULL) {
01982 plsstrm(i);
01983 c_plend1();
01984 }
01985 }
01986 plfontrel();
01987 #ifdef ENABLE_DYNDRIVERS
01988
01989 lt_dlexit();
01990
01991 for (i = 0; i < npldynamicdevices; i++) {
01992 free_mem(loadable_device_list[i].devnam);
01993 free_mem(loadable_device_list[i].description);
01994 free_mem(loadable_device_list[i].drvnam);
01995 free_mem(loadable_device_list[i].tag);
01996 }
01997 free_mem(loadable_device_list);
01998 for (i = 0; i < nloadabledrivers; i++) {
01999 free_mem(loadable_driver_list[i].drvnam);
02000 }
02001 free_mem(loadable_driver_list);
02002 for (i = nplstaticdevices; i < npldrivers; i++) {
02003 free_mem(dispatch_table[i]->pl_MenuStr);
02004 free_mem(dispatch_table[i]->pl_DevName);
02005 free_mem(dispatch_table[i]);
02006 }
02007 #endif
02008 for (i = 0; i < nplstaticdevices; i++) {
02009 free_mem(dispatch_table[i]);
02010 }
02011 free_mem(dispatch_table);
02012
02013 lib_initialized = 0;
02014 }
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024 void
02025 c_plend1(void)
02026 {
02027 if (plsc->level > 0) {
02028 plP_eop();
02029 plP_tidy();
02030 plsc->level = 0;
02031 }
02032
02033 if (plsc->FileName)
02034 free_mem(plsc->FileName);
02035
02036
02037
02038 free_mem(plsc->cmap0);
02039 free_mem(plsc->cmap1);
02040 free_mem(plsc->plwindow);
02041 free_mem(plsc->geometry);
02042 free_mem(plsc->dev);
02043 free_mem(plsc->BaseName);
02044 #ifndef BUFFERED_FILE
02045 free_mem(plsc->plbuf_buffer);
02046 #endif
02047 if (plsc->program) free_mem(plsc->program);
02048 if (plsc->server_name) free_mem(plsc->server_name);
02049 if (plsc->server_host) free_mem(plsc->server_host);
02050 if (plsc->server_port) free_mem(plsc->server_port);
02051 if (plsc->user) free_mem(plsc->user);
02052 if (plsc->plserver) free_mem(plsc->plserver);
02053 if (plsc->auto_path) free_mem(plsc->auto_path);
02054
02055 if (plsc->arrow_x) free_mem(plsc->arrow_x);
02056 if (plsc->arrow_y) free_mem(plsc->arrow_y);
02057
02058 if (plsc->timefmt) free_mem(plsc->timefmt);
02059
02060
02061
02062
02063 closeqsas(&(plsc->qsasconfig));
02064
02065
02066
02067 if (ipls > 0) {
02068 free_mem(plsc);
02069 pls[ipls] = NULL;
02070 plsstrm(0);
02071 }
02072 else {
02073 memset((char *) pls[ipls], 0, sizeof(PLStream));
02074 }
02075 }
02076
02077
02078
02079
02080
02081
02082
02083
02084 void
02085 c_plsstrm(PLINT strm)
02086 {
02087 if (strm < 0 || strm >= PL_NSTREAMS) {
02088 fprintf(stderr,
02089 "plsstrm: Illegal stream number %d, must be in [0, %d]\n",
02090 (int) strm, PL_NSTREAMS);
02091 }
02092 else {
02093 ipls = strm;
02094 if (pls[ipls] == NULL) {
02095 pls[ipls] = (PLStream *) malloc((size_t) sizeof(PLStream));
02096 if (pls[ipls] == NULL)
02097 plexit("plsstrm: Out of memory.");
02098
02099 memset((char *) pls[ipls], 0, sizeof(PLStream));
02100 }
02101 plsc = pls[ipls];
02102 plsc->ipls = ipls;
02103 }
02104 }
02105
02106
02107
02108
02109
02110
02111
02112 void
02113 c_plgstrm(PLINT *p_strm)
02114 {
02115 *p_strm = ipls;
02116 }
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131 void
02132 c_plmkstrm(PLINT *p_strm)
02133 {
02134 int i;
02135
02136 for (i = 1; i < PL_NSTREAMS; i++) {
02137 if (pls[i] == NULL)
02138 break;
02139 }
02140
02141 if (i == PL_NSTREAMS) {
02142 fprintf(stderr, "plmkstrm: Cannot create new stream\n");
02143 *p_strm = -1;
02144 }
02145 else {
02146 *p_strm = i;
02147 plsstrm(i);
02148 }
02149 plstrm_init();
02150 }
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168 void
02169 plstrm_init(void)
02170 {
02171 if ( ! plsc->initialized) {
02172 plsc->initialized = 1;
02173
02174 if (plsc->cmap0 == NULL)
02175 plspal0("");
02176
02177 if (plsc->cmap1 == NULL)
02178 plspal1("", TRUE);
02179 }
02180
02181 plsc->psdoc = NULL;
02182 }
02183
02184
02185
02186
02187
02188
02189
02190 void
02191 pl_cpcolor(PLColor *to, PLColor *from)
02192 {
02193 to->r = from->r;
02194 to->g = from->g;
02195 to->b = from->b;
02196 to->a = from->a;
02197 }
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213 void
02214 c_plcpstrm(PLINT iplsr, PLINT flags)
02215 {
02216 int i;
02217 PLStream *plsr;
02218
02219 plsr = pls[iplsr];
02220 if (plsr == NULL) {
02221 fprintf(stderr, "plcpstrm: stream %d not in use\n", (int) iplsr);
02222 return;
02223 }
02224
02225
02226
02227 plsc->debug = plsr->debug;
02228
02229
02230
02231
02232 #ifdef BUFFERED_FILE
02233 plsc->plbufFile = plsr->plbufFile;
02234 #else
02235 plsc->plbuf_buffer_grow = plsr->plbuf_buffer_grow;
02236 plsc->plbuf_buffer_size = plsr->plbuf_buffer_size;
02237 plsc->plbuf_top = plsr->plbuf_top;
02238 plsc->plbuf_readpos = plsr->plbuf_readpos;
02239 if ((plsc->plbuf_buffer = malloc(plsc->plbuf_buffer_size)) == NULL)
02240 plexit("plcpstrm: Error allocating plot buffer.");
02241 memcpy( plsc->plbuf_buffer, plsr->plbuf_buffer, plsr->plbuf_top );
02242 #endif
02243
02244
02245
02246
02247 if (plsr->difilt & PLDI_PLT)
02248 plsdiplt(plsr->dipxmin, plsr->dipymin, plsr->dipxmax, plsr->dipymax);
02249
02250 if (plsr->difilt & PLDI_DEV)
02251 plsdidev(plsr->mar, plsr->aspect, plsr->jx, plsr->jy);
02252
02253 if (plsr->difilt & PLDI_ORI)
02254 plsdiori(plsr->diorot);
02255
02256
02257
02258 if ( ! (flags & 0x01)) {
02259 pldebug("plcpstrm", "mapping parameters: %d %d %d %d %f %f\n",
02260 plsr->phyxmi, plsr->phyxma, plsr->phyymi, plsr->phyyma,
02261 plsr->xpmm, plsr->ypmm);
02262 plsdimap(plsr->phyxmi, plsr->phyxma, plsr->phyymi, plsr->phyyma,
02263 plsr->xpmm, plsr->ypmm);
02264 }
02265
02266
02267
02268 pl_cpcolor(&plsc->curcolor, &plsr->curcolor);
02269
02270
02271
02272 plsc->icol0 = plsr->icol0;
02273 plsc->ncol0 = plsr->ncol0;
02274 if (plsc->cmap0 != NULL)
02275 free((void *) plsc->cmap0);
02276
02277 if ((plsc->cmap0 = (PLColor *) calloc(1, plsc->ncol0 * sizeof(PLColor)))==NULL)
02278 {
02279 plexit("c_plcpstrm: Insufficient memory");
02280 }
02281
02282 for (i = 0; i < plsc->ncol0; i++)
02283 pl_cpcolor(&plsc->cmap0[i], &plsr->cmap0[i]);
02284
02285
02286
02287 plsc->icol1 = plsr->icol1;
02288 plsc->ncol1 = plsr->ncol1;
02289 if (plsc->cmap1 != NULL)
02290 free((void *) plsc->cmap1);
02291
02292 if ((plsc->cmap1 = (PLColor *) calloc(1, plsc->ncol1 * sizeof(PLColor)))==NULL)
02293 {
02294 plexit("c_plcpstrm: Insufficient memory");
02295 }
02296
02297 for (i = 0; i < plsc->ncol1; i++)
02298 pl_cpcolor(&plsc->cmap1[i], &plsr->cmap1[i]);
02299
02300
02301
02302 if (plsc->level == 0)
02303 plinit();
02304 }
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327 void
02328 pllib_devinit()
02329 {
02330 if (plsc->dev_initialized) return;
02331 plsc->dev_initialized = 1;
02332
02333 plSelectDev();
02334
02335 plLoadDriver();
02336
02337
02338 plsc->dispatch_table = dispatch_table[plsc->device - 1];
02339 }
02340
02341 PLDLLIMPEXP int plInBuildTree()
02342 {
02343 static int inited = 0;
02344 static int inBuildTree = 0;
02345
02346 if (inited == 0) {
02347 char currdir[PLPLOT_MAX_PATH];
02348 char builddir[PLPLOT_MAX_PATH];
02349
02350 if (getcwd(currdir, PLPLOT_MAX_PATH) == NULL) {
02351 pldebug("plInBuildTree():", "Not enough buffer space");
02352 } else {
02353
02354
02355
02356 if (chdir(BUILD_DIR) == 0) {
02357 if (getcwd(builddir, PLPLOT_MAX_PATH) == NULL) {
02358 pldebug("plInBuildTree():", "Not enough buffer space");
02359 }
02360 else {
02361 if (strncmp(builddir, currdir, strlen(builddir)) == 0) {
02362 inBuildTree = 1;
02363 }
02364 }
02365 if (chdir(currdir) != 0)
02366 pldebug("plInBuildTree():", "Unable to chdir to current directory");
02367 }
02368 }
02369 inited = 1;
02370 }
02371 return inBuildTree;
02372 }
02373
02374 #ifdef ENABLE_DYNDRIVERS
02375
02376 char*
02377 plGetDrvDir ()
02378 {
02379 char* drvdir;
02380
02381
02382
02383
02384
02385 if (plInBuildTree() == 1) {
02386 drvdir = BUILD_DIR "/drivers";
02387 pldebug("plGetDrvDir", "Using %s as the driver directory.\n", drvdir);
02388 } else {
02389 pldebug("plGetDrvDir", "Trying to read env var PLPLOT_DRV_DIR\n");
02390 drvdir = getenv ("PLPLOT_DRV_DIR");
02391
02392 if (drvdir == NULL) {
02393 pldebug("plGetDrvDir",
02394 "Will use drivers dir: " DRV_DIR "\n");
02395 drvdir = DRV_DIR;
02396 }
02397 }
02398
02399 return drvdir;
02400 }
02401
02402 #endif
02403
02404
02405
02406
02407
02408
02409
02410
02411 static int plDispatchSequencer( const void *p1, const void *p2 )
02412 {
02413 const PLDispatchTable* t1 = *(PLDispatchTable **) p1;
02414 const PLDispatchTable* t2 = *(PLDispatchTable **) p2;
02415
02416
02417
02418
02419 return t1->pl_seq - t2->pl_seq;
02420 }
02421
02422 static void
02423 plInitDispatchTable()
02424 {
02425 int n;
02426
02427 #ifdef ENABLE_DYNDRIVERS
02428 char buf[BUFFER2_SIZE];
02429 char* drvdir;
02430 char *devnam, *devdesc, *devtype, *driver, *tag, *seqstr;
02431 int seq;
02432 int i, j, driver_found, done=0;
02433 FILE *fp_drvdb = NULL;
02434 DIR* dp_drvdir = NULL;
02435 struct dirent* entry;
02436
02437
02438
02439 npldynamicdevices = 0;
02440 nloadabledrivers = 0;
02441
02442
02443
02444 fp_drvdb = tmpfile ();
02445
02446
02447 drvdir = plGetDrvDir ();
02448 dp_drvdir = opendir (drvdir);
02449 if (dp_drvdir == NULL) {
02450 plabort ("plInitDispatchTable: Could not open drivers directory");
02451 return;
02452 }
02453
02454
02455
02456 pldebug ("plInitDispatchTable", "Scanning dyndrivers dir\n");
02457 while ((entry = readdir (dp_drvdir)) != NULL)
02458 {
02459 char* name = entry->d_name;
02460 int len = strlen (name) - 3;
02461
02462 pldebug ("plInitDispatchTable",
02463 "Consider file %s\n", name);
02464
02465
02466 if ((len > 0) && (strcmp (name + len, ".rc") == 0)) {
02467 char path[PLPLOT_MAX_PATH];
02468 FILE* fd;
02469
02470
02471 snprintf (path, PLPLOT_MAX_PATH, "%s/%s", drvdir, name);
02472 fd = fopen (path, "r");
02473 if (fd == NULL) {
02474 snprintf (buf, BUFFER2_SIZE,
02475 "plInitDispatchTable: Could not open driver info file %s\n",
02476 name);
02477 plabort (buf);
02478 return;
02479 }
02480
02481
02482
02483
02484
02485 pldebug ("plInitDispatchTable",
02486 "Opened driver info file %s\n", name);
02487 while (fgets (buf, BUFFER2_SIZE, fd) != NULL)
02488 {
02489 fprintf (fp_drvdb, "%s", buf);
02490 if ( buf [strlen (buf) - 1] != '\n' )
02491 fprintf (fp_drvdb, "\n");
02492 npldynamicdevices++;
02493 }
02494 fclose (fd);
02495 }
02496 }
02497
02498
02499
02500 fflush (fp_drvdb);
02501 closedir (dp_drvdir);
02502
02503 #endif
02504
02505
02506 if ((dispatch_table = (PLDispatchTable **)
02507 malloc( (nplstaticdevices + npldynamicdevices) * sizeof(PLDispatchTable *) ))==NULL)
02508 {
02509 plexit("plInitDispatchTable: Insufficient memory");
02510 }
02511
02512
02513
02514
02515
02516
02517 for( n=0; n < nplstaticdevices; n++ )
02518 {
02519 if ((dispatch_table[n] = (PLDispatchTable *)malloc( sizeof(PLDispatchTable) ))==NULL)
02520 {
02521 plexit("plInitDispatchTable: Insufficient memory");
02522 }
02523
02524 (*static_device_initializers[n])( dispatch_table[n] );
02525 }
02526 npldrivers = nplstaticdevices;
02527
02528 #ifdef ENABLE_DYNDRIVERS
02529
02530
02531
02532
02533 if (((loadable_device_list = malloc( npldynamicdevices * sizeof(PLLoadableDevice) ))==NULL)||
02534 ((loadable_driver_list = malloc( npldynamicdevices * sizeof(PLLoadableDriver) ))==NULL))
02535 {
02536 plexit("plInitDispatchTable: Insufficient memory");
02537 }
02538
02539 rewind( fp_drvdb );
02540
02541 i = 0;
02542 done = !(i < npldynamicdevices);
02543 while( !done ) {
02544 char *p = fgets( buf, BUFFER2_SIZE, fp_drvdb );
02545
02546 if (p == 0) {
02547 done = 1;
02548 continue;
02549 }
02550
02551 devnam = strtok( buf, ":" );
02552 devdesc = strtok( 0, ":" );
02553 devtype = strtok( 0, ":" );
02554 driver = strtok( 0, ":" );
02555 seqstr = strtok( 0, ":" );
02556 tag = strtok( 0, "\n" );
02557
02558 seq = atoi(seqstr);
02559
02560 n = npldrivers++;
02561
02562 if ((dispatch_table[n] = malloc( sizeof(PLDispatchTable) ))==NULL)
02563 {
02564 plexit("plInitDispatchTable: Insufficient memory");
02565 }
02566
02567
02568 dispatch_table[n]->pl_MenuStr = plstrdup(devdesc);
02569 dispatch_table[n]->pl_DevName = plstrdup(devnam);
02570 dispatch_table[n]->pl_type = atoi(devtype);
02571 dispatch_table[n]->pl_seq = seq;
02572 dispatch_table[n]->pl_init = 0;
02573 dispatch_table[n]->pl_line = 0;
02574 dispatch_table[n]->pl_polyline = 0;
02575 dispatch_table[n]->pl_eop = 0;
02576 dispatch_table[n]->pl_bop = 0;
02577 dispatch_table[n]->pl_tidy = 0;
02578 dispatch_table[n]->pl_state = 0;
02579 dispatch_table[n]->pl_esc = 0;
02580
02581
02582 loadable_device_list[i].devnam = plstrdup(devnam);
02583 loadable_device_list[i].description = plstrdup(devdesc);
02584 loadable_device_list[i].drvnam = plstrdup(driver);
02585 loadable_device_list[i].tag = plstrdup(tag);
02586
02587
02588
02589 driver_found = 0;
02590 for( j=0; j < nloadabledrivers; j++ )
02591 if (strcmp( driver, loadable_driver_list[j].drvnam) == 0)
02592 {
02593 driver_found = 1;
02594 break;
02595 }
02596
02597 if (!driver_found)
02598 {
02599 loadable_driver_list[nloadabledrivers].drvnam = plstrdup(driver);
02600 loadable_driver_list[nloadabledrivers].dlhand = 0;
02601 nloadabledrivers++;
02602 }
02603
02604 loadable_device_list[i].drvidx = j;
02605
02606
02607 i++;
02608 }
02609
02610
02611 fclose (fp_drvdb);
02612
02613 #endif
02614
02615
02616
02617
02618 qsort( dispatch_table, npldrivers, sizeof(PLDispatchTable*),
02619 plDispatchSequencer );
02620 }
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633 static void
02634 plSelectDev()
02635 {
02636 int dev, i, count, length;
02637 char response[80];
02638
02639
02640
02641 if (*(plsc->DevName) != '\0' && *(plsc->DevName) != '?') {
02642 length = strlen(plsc->DevName);
02643 for (i = 0; i < npldrivers; i++) {
02644 if ((*plsc->DevName == *dispatch_table[i]->pl_DevName) &&
02645 (strncmp(plsc->DevName,
02646 dispatch_table[i]->pl_DevName, length) == 0))
02647 break;
02648 }
02649 if (i < npldrivers) {
02650 plsc->device = i + 1;
02651 return;
02652 }
02653 else {
02654 fprintf(stderr, "Requested device %s not available\n",
02655 plsc->DevName);
02656 }
02657 }
02658
02659 dev = 0;
02660 count = 0;
02661
02662 if (npldrivers == 1)
02663 dev = 1;
02664
02665
02666
02667 while (dev < 1 || dev > npldrivers) {
02668 fprintf(stdout, "\nPlotting Options:\n");
02669 for (i = 0; i < npldrivers; i++) {
02670 fprintf(stdout, " <%2d> %-10s %s\n", i + 1,
02671 dispatch_table[i]->pl_DevName,
02672 dispatch_table[i]->pl_MenuStr);
02673 }
02674 if (ipls == 0)
02675 fprintf(stdout, "\nEnter device number or keyword: ");
02676 else
02677 fprintf(stdout, "\nEnter device number or keyword (stream %d): ",
02678 (int) ipls);
02679
02680 plio_fgets(response, sizeof(response), stdin);
02681
02682
02683
02684
02685 length = strlen(response);
02686 if (*(response - 1 + length) == '\n')
02687 length--;
02688
02689 for (i = 0; i < npldrivers; i++) {
02690 if ( ! strncmp(response, dispatch_table[i]->pl_DevName,
02691 (unsigned int) length))
02692 break;
02693 }
02694 if (i < npldrivers) {
02695 dev = i + 1;
02696 }
02697 else {
02698 if ((dev = atoi(response)) < 1) {
02699 fprintf(stdout, "\nInvalid device: %s", response);
02700 dev = 0;
02701 }
02702 }
02703 if (count++ > 10)
02704 plexit("plSelectDev: Too many tries.");
02705 }
02706 plsc->device = dev;
02707 strcpy(plsc->DevName, dispatch_table[dev - 1]->pl_DevName);
02708 }
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718 static void
02719 plLoadDriver(void)
02720 {
02721 #ifdef ENABLE_DYNDRIVERS
02722 int i, drvidx;
02723 char sym[BUFFER_SIZE];
02724 char *tag;
02725
02726 int n=plsc->device - 1;
02727 PLDispatchTable *dev = dispatch_table[n];
02728 PLLoadableDriver *driver = 0;
02729
02730
02731
02732
02733 if (dev->pl_init)
02734 return;
02735
02736 pldebug("plLoadDriver", "Device not loaded!\n");
02737
02738
02739
02740 for( i=0; i < npldynamicdevices; i++ )
02741 if (strcmp( dev->pl_DevName, loadable_device_list[i].devnam ) == 0)
02742 break;
02743
02744
02745
02746
02747 if (i == npldynamicdevices) {
02748 fprintf( stderr, "No such device: %s.\n", dev->pl_DevName );
02749 plexit("plLoadDriver detected device logic screwup");
02750 }
02751
02752
02753
02754
02755 tag = loadable_device_list[i].tag;
02756 drvidx = loadable_device_list[i].drvidx;
02757
02758 pldebug("plLoadDriver", "tag=%s, drvidx=%d\n", tag, drvidx );
02759
02760 driver = &loadable_driver_list[drvidx];
02761
02762
02763 if (!driver->dlhand)
02764 {
02765 char drvspec[ DRVSPEC_SIZE ];
02766 #if defined(LTDL_WIN32) || defined(__CYGWIN__)
02767 snprintf( drvspec, DRVSPEC_SIZE, "%s", driver->drvnam );
02768 #else
02769 snprintf( drvspec, DRVSPEC_SIZE, "%s/%s", plGetDrvDir (), driver->drvnam );
02770 #endif
02771
02772 pldebug("plLoadDriver", "Trying to load %s on %s\n",
02773 driver->drvnam, drvspec );
02774
02775 driver->dlhand = lt_dlopenext( drvspec);
02776 }
02777
02778
02779 if (!driver->dlhand)
02780 {
02781 pldebug("plLoadDriver", "lt_dlopenext failed because of "
02782 "the following reason:\n%s\n", lt_dlerror ());
02783 fprintf( stderr, "Unable to load driver: %s.\n", driver->drvnam );
02784 plexit("Unable to load driver");
02785 }
02786
02787
02788
02789
02790 snprintf( sym, BUFFER_SIZE, "plD_dispatch_init_%s", tag );
02791 {
02792 PLDispatchInit dispatch_init = (PLDispatchInit) lt_dlsym( driver->dlhand, sym );
02793 if (!dispatch_init)
02794 {
02795 fprintf( stderr,
02796 "Unable to locate dispatch table initialization function for driver: %s.\n",
02797 driver->drvnam );
02798 return;
02799 }
02800
02801 (*dispatch_init)( dev );
02802 }
02803 #endif
02804 }
02805
02806
02807
02808
02809
02810
02811
02812 void
02813 c_plfontld(PLINT ifont)
02814 {
02815 if (ifont != 0)
02816 ifont = 1;
02817
02818 if (plsc->level > 0)
02819 plfntld(ifont);
02820 else
02821 initfont = ifont;
02822 }
02823
02824
02825
02826
02827
02828
02829
02830 void
02831 c_plreplot(void)
02832 {
02833 #ifdef BUFFERED_FILE
02834 if (plsc->plbufFile != NULL) {
02835 #else
02836 if (plsc->plbuf_buffer != NULL) {
02837 #endif
02838 plRemakePlot(plsc);
02839 }
02840 else {
02841 plwarn("plreplot: plot buffer not available");
02842 }
02843 }
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856 void
02857 plgFileDevs(const char ***p_menustr, const char ***p_devname, int *p_ndev)
02858 {
02859 plgdevlst(*p_menustr, *p_devname, p_ndev, 0);
02860 }
02861
02862
02863
02864
02865
02866
02867
02868 void
02869 plgDevs(const char ***p_menustr, const char ***p_devname, int *p_ndev)
02870 {
02871 plgdevlst(*p_menustr, *p_devname, p_ndev, -1);
02872 }
02873
02874 static void
02875 plgdevlst(const char **p_menustr, const char **p_devname, int *p_ndev, int type)
02876 {
02877 int i, j;
02878
02879 pllib_init();
02880
02881 for (i = j = 0; i < npldrivers; i++) {
02882 if (type < 0 || dispatch_table[i]->pl_type == type) {
02883 p_menustr[j] = dispatch_table[i]->pl_MenuStr;
02884 p_devname[j] = dispatch_table[i]->pl_DevName;
02885 if (++j + 1 >= *p_ndev) {
02886 plwarn("plgdevlst: too many devices");
02887 break;
02888 }
02889 }
02890 }
02891 p_menustr[j] = NULL;
02892 p_devname[j] = NULL;
02893 *p_ndev = j;
02894 }
02895
02896
02897
02898
02899
02900
02901
02902 void
02903 c_plgpage(PLFLT *p_xp, PLFLT *p_yp,
02904 PLINT *p_xleng, PLINT *p_yleng, PLINT *p_xoff, PLINT *p_yoff)
02905 {
02906 *p_xp = plsc->xdpi;
02907 *p_yp = plsc->ydpi;
02908 *p_xleng = plsc->xlength;
02909 *p_yleng = plsc->ylength;
02910 *p_xoff = plsc->xoffset;
02911 *p_yoff = plsc->yoffset;
02912 }
02913
02914
02915
02916 void
02917 c_plspage(PLFLT xp, PLFLT yp, PLINT xleng, PLINT yleng, PLINT xoff, PLINT yoff)
02918 {
02919 if (plsc->level > 0)
02920 plwarn("calling plspage() after plinit() may give unpredictable results");
02921
02922 if (xp)
02923 plsc->xdpi = xp;
02924 if (yp)
02925 plsc->ydpi = yp;
02926
02927 if (xleng)
02928 plsc->xlength = xleng;
02929 if (yleng)
02930 plsc->ylength = yleng;
02931
02932 if (xoff)
02933 plsc->xoffset = xoff;
02934 if (yoff)
02935 plsc->yoffset = yoff;
02936
02937 plsc->pageset = 1;
02938 }
02939
02940
02941
02942 void
02943 c_plssub(PLINT nx, PLINT ny)
02944 {
02945 if (nx > 0)
02946 plsc->nsubx = nx;
02947 if (ny > 0)
02948 plsc->nsuby = ny;
02949
02950
02951
02952 if (plsc->level > 0) {
02953 plP_subpInit();
02954
02955
02956 }
02957 }
02958
02959
02960
02961 void
02962 c_plsdev(const char *devname)
02963 {
02964 if (plsc->level > 0) {
02965 plwarn("plsdev: Must be called before plinit.");
02966 return;
02967 }
02968 if (devname != NULL) {
02969 strncpy(plsc->DevName, devname, sizeof(plsc->DevName) - 1);
02970 plsc->DevName[sizeof(plsc->DevName) - 1] = '\0';
02971 }
02972 }
02973
02974
02975
02976
02977 void
02978 c_plgdev(char *p_dev)
02979 {
02980 strcpy(p_dev, plsc->DevName);
02981 }
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992 void
02993 c_plsmem(PLINT maxx, PLINT maxy, void *plotmem)
02994 {
02995 plsc->dev = plotmem;
02996 plP_setphy (0, maxx, 0, maxy);
02997 }
02998
02999
03000
03001 void
03002 plgpls(PLStream **p_pls)
03003 {
03004 *p_pls = plsc;
03005 }
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015 void
03016 c_plglevel(PLINT *p_level)
03017 {
03018 *p_level = plsc->level;
03019 }
03020
03021
03022
03023 void
03024 plsKeyEH(void (*KeyEH) (PLGraphicsIn *, void *, int *),
03025 void *KeyEH_data)
03026 {
03027 plsc->KeyEH = KeyEH;
03028 plsc->KeyEH_data = KeyEH_data;
03029 }
03030
03031
03032
03033 void
03034 plsButtonEH(void (*ButtonEH) (PLGraphicsIn *, void *, int *),
03035 void *ButtonEH_data)
03036 {
03037 plsc->ButtonEH = ButtonEH;
03038 plsc->ButtonEH_data = ButtonEH_data;
03039 }
03040
03041
03042
03043 void
03044 plsbopH(void (*handler) (void *, int *), void *handler_data)
03045 {
03046 plsc->bop_handler = handler;
03047 plsc->bop_data = handler_data;
03048 }
03049
03050
03051
03052 void
03053 plseopH(void (*handler) (void *, int *), void *handler_data)
03054 {
03055 plsc->eop_handler = handler;
03056 plsc->eop_data = handler_data;
03057 }
03058
03059
03060
03061 void
03062 plsError(PLINT *errcode, char *errmsg)
03063 {
03064 if (errcode != NULL)
03065 plsc->errcode = errcode;
03066
03067 if (errmsg != NULL)
03068 plsc->errmsg = errmsg;
03069 }
03070
03071
03072
03073 void
03074 c_plsori(PLINT ori)
03075 {
03076 plsdiori((PLFLT) ori);
03077 }
03078
03079
03080
03081
03082
03083
03084
03085 void
03086 c_plwid(PLINT width)
03087 {
03088 if (width != plsc->width && width >= 0) {
03089 plsc->width = width;
03090
03091 if (plsc->level > 0) {
03092 if ( ! plsc->widthlock)
03093 plP_state(PLSTATE_WIDTH);
03094 }
03095 }
03096 }
03097
03098
03099
03100 void
03101 plgfile(FILE **p_file)
03102 {
03103 *p_file = plsc->OutFile;
03104 }
03105
03106
03107
03108 void
03109 plsfile(FILE *file)
03110 {
03111 plsc->OutFile = file;
03112 }
03113
03114
03115
03116
03117 void
03118 c_plgfnam(char *fnam)
03119 {
03120 if (fnam == NULL) {
03121 plabort("filename string must be preallocated to >=80 bytes");
03122 return;
03123 }
03124
03125 *fnam = '\0';
03126 if (plsc->FileName != NULL) {
03127 strncpy(fnam, plsc->FileName, 79);
03128 fnam[79] = '\0';
03129 }
03130 }
03131
03132
03133
03134 void
03135 c_plsfnam(const char *fnam)
03136 {
03137 plP_sfnam(plsc, fnam);
03138 }
03139
03140
03141
03142 void
03143 c_plspause(PLINT pause)
03144 {
03145 plsc->nopause = ! pause;
03146 }
03147
03148
03149
03150 void
03151 c_plprec(PLINT setp, PLINT prec)
03152 {
03153 plsc->setpre = setp;
03154 plsc->precis = prec;
03155 }
03156
03157
03158
03159 void
03160 plP_gprec(PLINT *p_setp, PLINT *p_prec)
03161 {
03162 *p_setp = plsc->setpre;
03163 *p_prec = plsc->precis;
03164 }
03165
03166 const char *
03167 plP_gtimefmt()
03168 {
03169 return (const char *) plsc->timefmt;
03170 }
03171
03172
03173
03174
03175
03176
03177
03178
03179
03180 void
03181 c_plsesc(char esc)
03182 {
03183 switch (esc) {
03184 case '!':
03185 case '#':
03186 case '$':
03187 case '%':
03188 case '&':
03189 case '*':
03190 case '@':
03191 case '^':
03192 case '~':
03193 plsc->esc = esc;
03194 break;
03195
03196 default:
03197 plwarn("plsesc: Invalid escape character, ignoring.");
03198 }
03199 }
03200
03201
03202
03203 void
03204 plgesc(char *p_esc)
03205 {
03206 if (plsc->esc == '\0')
03207 plsc->esc = '#';
03208
03209 *p_esc = plsc->esc;
03210 }
03211
03212
03213
03214
03215 void
03216 c_plsfci(PLUNICODE fci)
03217 {
03218
03219 plsc->fci = fci | PL_FCI_MARK;
03220 }
03221
03222
03223
03224
03225 void
03226 c_plgfci(PLUNICODE *pfci)
03227 {
03228
03229 *pfci = plsc->fci | PL_FCI_MARK;
03230 }
03231
03232
03233
03234 void
03235 plP_hex2fci(unsigned char hexdigit, unsigned char hexpower, PLUNICODE *pfci)
03236 {
03237 PLUNICODE mask;
03238 hexpower = hexpower & PL_FCI_HEXPOWER_MASK;
03239 mask = ~ (((PLUNICODE) PL_FCI_HEXDIGIT_MASK) << ((PLUNICODE) 4*hexpower));
03240 *pfci = *pfci & mask;
03241 mask = (((PLUNICODE) (hexdigit & PL_FCI_HEXDIGIT_MASK)) << (4*hexpower));
03242 *pfci = *pfci | mask;
03243 }
03244
03245
03246
03247 void
03248 plP_fci2hex(PLUNICODE fci, unsigned char *phexdigit, unsigned char hexpower)
03249 {
03250 PLUNICODE mask;
03251 hexpower = hexpower & PL_FCI_HEXPOWER_MASK;
03252 mask = (((PLUNICODE) PL_FCI_HEXPOWER_MASK) << ((PLUNICODE) (4*hexpower)));
03253 *phexdigit = (unsigned char) ((fci & mask) >>
03254 ((PLUNICODE) (4*hexpower)));
03255 }
03256
03257
03258
03259 void
03260 c_plgver(char *p_ver)
03261 {
03262 strcpy(p_ver, VERSION);
03263 }
03264
03265
03266
03267 void
03268 plsxwin(PLINT window_id)
03269 {
03270 plsc->window_id = window_id;
03271 }
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284 void
03285 c_plgfam(PLINT *p_fam, PLINT *p_num, PLINT *p_bmax)
03286 {
03287 *p_fam = plsc->family;
03288 *p_num = plsc->member;
03289 *p_bmax = plsc->bytemax;
03290 }
03291
03292
03293
03294 void
03295 c_plsfam(PLINT fam, PLINT num, PLINT bmax)
03296 {
03297 if (plsc->level > 0)
03298 plwarn("plsfam: Must be called before plinit.");
03299
03300 if (fam >= 0)
03301 plsc->family = fam;
03302 if (num >= 0)
03303 plsc->member = num;
03304 if (bmax >= 0)
03305 plsc->bytemax = bmax;
03306 }
03307
03308
03309
03310 void
03311 c_plfamadv(void)
03312 {
03313 plsc->famadv = 1;
03314 }
03315
03316
03317
03318
03319
03320
03321
03322
03323 void
03324 c_plgxax(PLINT *p_digmax, PLINT *p_digits)
03325 {
03326 *p_digmax = plsc->xdigmax;
03327 *p_digits = plsc->xdigits;
03328 }
03329
03330
03331
03332 void
03333 c_plsxax(PLINT digmax, PLINT digits)
03334 {
03335 plsc->xdigmax = digmax;
03336 plsc->xdigits = digits;
03337 }
03338
03339
03340
03341 void
03342 c_plgyax(PLINT *p_digmax, PLINT *p_digits)
03343 {
03344 *p_digmax = plsc->ydigmax;
03345 *p_digits = plsc->ydigits;
03346 }
03347
03348
03349
03350 void
03351 c_plsyax(PLINT digmax, PLINT digits)
03352 {
03353 plsc->ydigmax = digmax;
03354 plsc->ydigits = digits;
03355 }
03356
03357
03358
03359 void
03360 c_plgzax(PLINT *p_digmax, PLINT *p_digits)
03361 {
03362 *p_digmax = plsc->zdigmax;
03363 *p_digits = plsc->zdigits;
03364 }
03365
03366
03367
03368 void
03369 c_plszax(PLINT digmax, PLINT digits)
03370 {
03371 plsc->zdigmax = digmax;
03372 plsc->zdigits = digits;
03373 }
03374
03375
03376
03377 void
03378 c_plgchr(PLFLT *p_def, PLFLT *p_ht)
03379 {
03380 *p_def = plsc->chrdef;
03381 *p_ht = plsc->chrht;
03382 }
03383
03384
03385
03386 void
03387 c_plgvpd(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax)
03388 {
03389 *p_xmin = plsc->vpdxmi;
03390 *p_xmax = plsc->vpdxma;
03391 *p_ymin = plsc->vpdymi;
03392 *p_ymax = plsc->vpdyma;
03393 }
03394
03395
03396
03397 void
03398 c_plgvpw(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax)
03399 {
03400 *p_xmin = plsc->vpwxmi;
03401 *p_xmax = plsc->vpwxma;
03402 *p_ymin = plsc->vpwymi;
03403 *p_ymax = plsc->vpwyma;
03404 }
03405
03406
03407 void
03408 plP_xgvpw(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax)
03409 {
03410 PLFLT dx, dy;
03411
03412 dx = (plsc->vpwxma - plsc->vpwxmi) * 1.0e-5;
03413 dy = (plsc->vpwyma - plsc->vpwymi) * 1.0e-5;
03414
03415
03416
03417
03418 *p_xmin = plsc->vpwxmi - dx;
03419 *p_xmax = plsc->vpwxma + dx;
03420 *p_ymin = plsc->vpwymi - dy;
03421 *p_ymax = plsc->vpwyma + dy;
03422 }
03423
03424
03425
03426
03427
03428
03429
03430 void
03431 plP_gdom(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax)
03432 {
03433 *p_xmin = plsc->domxmi;
03434 *p_xmax = plsc->domxma;
03435 *p_ymin = plsc->domymi;
03436 *p_ymax = plsc->domyma;
03437 }
03438
03439
03440
03441 void
03442 plP_grange(PLFLT *p_zscl, PLFLT *p_zmin, PLFLT *p_zmax)
03443 {
03444 *p_zscl = plsc->zzscl;
03445 *p_zmin = plsc->ranmi;
03446 *p_zmax = plsc->ranma;
03447 }
03448
03449
03450
03451 void
03452 plP_gw3wc(PLFLT *p_dxx, PLFLT *p_dxy, PLFLT *p_dyx, PLFLT *p_dyy, PLFLT *p_dyz)
03453 {
03454 *p_dxx = plsc->cxx;
03455 *p_dxy = plsc->cxy;
03456 *p_dyx = plsc->cyx;
03457 *p_dyy = plsc->cyy;
03458 *p_dyz = plsc->cyz;
03459 }
03460
03461
03462
03463 void
03464 plP_gclp(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax)
03465 {
03466 *p_ixmin = plsc->clpxmi;
03467 *p_ixmax = plsc->clpxma;
03468 *p_iymin = plsc->clpymi;
03469 *p_iymax = plsc->clpyma;
03470 }
03471
03472
03473
03474 void
03475 plP_sclp(PLINT ixmin, PLINT ixmax, PLINT iymin, PLINT iymax)
03476 {
03477 plsc->clpxmi = ixmin;
03478 plsc->clpxma = ixmax;
03479 plsc->clpymi = iymin;
03480 plsc->clpyma = iymax;
03481 }
03482
03483
03484
03485 void
03486 plP_gphy(PLINT *p_ixmin, PLINT *p_ixmax, PLINT *p_iymin, PLINT *p_iymax)
03487 {
03488 *p_ixmin = plsc->phyxmi;
03489 *p_ixmax = plsc->phyxma;
03490 *p_iymin = plsc->phyymi;
03491 *p_iymax = plsc->phyyma;
03492 }
03493
03494
03495
03496 void
03497 plP_gsub(PLINT *p_nx, PLINT *p_ny, PLINT *p_cs)
03498 {
03499 *p_nx = plsc->nsubx;
03500 *p_ny = plsc->nsuby;
03501 *p_cs = plsc->cursub;
03502 }
03503
03504
03505
03506 void
03507 plP_ssub(PLINT nx, PLINT ny, PLINT cs)
03508 {
03509 plsc->nsubx = nx;
03510 plsc->nsuby = ny;
03511 plsc->cursub = cs;
03512 }
03513
03514
03515
03516 void
03517 plP_gpixmm(PLFLT *p_x, PLFLT *p_y)
03518 {
03519 *p_x = plsc->xpmm;
03520 *p_y = plsc->ypmm;
03521 }
03522
03523
03524
03525 void
03526 plP_setpxl(PLFLT xpmm, PLFLT ypmm)
03527 {
03528 plsc->xpmm = xpmm;
03529 plsc->ypmm = ypmm;
03530 plsc->umx = (PLINT)(1000.0 / plsc->xpmm);
03531 plsc->umy = (PLINT)(1000.0 / plsc->ypmm);
03532 }
03533
03534
03535
03536 void
03537 plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
03538 {
03539 if (xmin > xmax || ymin > ymax)
03540 plexit("plP_setphy: device minima must not exceed maxima");
03541
03542 plsc->phyxmi = xmin;
03543 plsc->phyxma = xmax;
03544 plsc->phyymi = ymin;
03545 plsc->phyyma = ymax;
03546 plsc->phyxlen = xmax - xmin;
03547 plsc->phyylen = ymax - ymin;
03548 }
03549
03550
03551
03552
03553
03554
03555
03556
03557 void
03558 c_plscompression(PLINT compression)
03559 {
03560 if (plsc->level <= 0)
03561 {
03562 plsc->dev_compression=compression;
03563 }
03564 }
03565
03566
03567
03568
03569
03570
03571
03572 void
03573 c_plgcompression(PLINT *compression)
03574 {
03575 *compression = plsc->dev_compression;
03576 }
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589 void
03590 plP_getinitdriverlist(char *names)
03591 {
03592 int i;
03593
03594 for (i=0;i<PL_NSTREAMS;++i)
03595 {
03596 if (pls[i]!=NULL)
03597 {
03598 if (i==0)
03599 strcpy(names,pls[i]->DevName);
03600 else
03601 {
03602 strcat(names," ");
03603 strcat(names,pls[i]->DevName);
03604 }
03605 }
03606 else
03607 break;
03608 }
03609 }
03610
03611
03612
03613
03614
03615
03616
03617
03618
03619
03620 PLINT plP_checkdriverinit( char *names)
03621 {
03622 char *buff;
03623 char *tok=NULL;
03624 PLINT ret=0;
03625
03626 buff=(char *)malloc((size_t) PL_NSTREAMS*8);
03627
03628
03629 if (buff!=NULL)
03630 {
03631 memset(buff,0,PL_NSTREAMS*8);
03632 plP_getinitdriverlist(buff);
03633
03634 for (tok = strtok(buff, " ,");
03635 tok; tok=strtok(0, " ,"))
03636 {
03637 if (strstr(names,tok)!=NULL)
03638 {
03639 ret++;
03640 }
03641 }
03642 free(buff);
03643 }
03644 else
03645 ret=-1;
03646
03647 return(ret);
03648 }
03649
03650
03651
03652
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662 void
03663 plP_image(PLFLT *z , PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
03664 void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
03665 {
03666 plsc->page_status = DRAWING;
03667
03668 plimageslow(z, nx, ny, xmin, ymin, dx, dy, pltr, pltr_data);
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679 #if 0
03680 PLINT i, npts;
03681 short *xscl, *yscl;
03682 int plbuf_write;
03683
03684 plsc->page_status = DRAWING;
03685
03686 if (plsc->dev_fastimg == 0) {
03687 plimageslow(x, y, z, nx-1, ny-1,
03688 xmin, ymin, dx, dy, zmin, zmax);
03689 return ;
03690 }
03691
03692 if (plsc->plbuf_write) {
03693 IMG_DT img_dt;
03694
03695 img_dt.xmin=xmin;
03696 img_dt.ymin=ymin;
03697 img_dt.dx=dx;
03698 img_dt.dy=dy;
03699
03700 plsc->dev_ix = x;
03701 plsc->dev_iy = y;
03702 plsc->dev_z = z;
03703 plsc->dev_nptsX = nx;
03704 plsc->dev_nptsY = ny;
03705 plsc->dev_zmin = zmin;
03706 plsc->dev_zmax = zmax;
03707
03708 plbuf_esc(plsc, PLESC_IMAGE, &img_dt);
03709 }
03710
03711
03712 plbuf_write = plsc->plbuf_write;
03713 plsc->plbuf_write = 0;
03714
03715 npts = nx*ny;
03716 if (plsc->difilt) {
03717 PLINT clpxmi, clpxma, clpymi, clpyma;
03718
03719 if (((xscl = (short *) malloc(nx*ny*sizeof(short)))==NULL)||
03720 ((yscl = (short *) malloc(nx*ny*sizeof(short)))==NULL))
03721 {
03722 plexit("plP_image: Insufficient memory");
03723 }
03724
03725 for (i = 0; i < npts; i++) {
03726 xscl[i] = x[i];
03727 yscl[i] = y[i];
03728 }
03729 sdifilt(xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma);
03730 plsc->imclxmin = clpxmi;
03731 plsc->imclymin = clpymi;
03732 plsc->imclxmax = clpxma;
03733 plsc->imclymax = clpyma;
03734 grimage(xscl, yscl, z, nx, ny);
03735 free(xscl);
03736 free(yscl);
03737 } else {
03738 plsc->imclxmin = plsc->phyxmi;
03739 plsc->imclymin = plsc->phyymi;
03740 plsc->imclxmax = plsc->phyxma;
03741 plsc->imclymax = plsc->phyyma;
03742 grimage(x, y, z, nx, ny );
03743 }
03744 plsc->plbuf_write = plbuf_write;
03745 #endif
03746 }