[BACK]Return to glib CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / lib

Annotation of OpenXM_contrib2/asir2018/lib/glib, Revision 1.2

1.2     ! takayama    1: /* $OpenXM: OpenXM_contrib2/asir2018/lib/glib,v 1.1 2018/09/19 05:45:08 noro Exp $ */
1.1       noro        2:
                      3: /* BUG: this library has not yet been adapted to the new automatic launcher
                      4:         of ox_plot. 2002, Aug, 4.  Do not load glib more than twice.
                      5: */
                      6:
                      7: extern Cfep_loaded$
                      8:
                      9: #define DO_NOT_START_SERVER_EXPLICITLY
                     10:
                     11: /* #define CLIP  1 */
                     12: /* #define DEBUG 1 */
                     13: #define LIST  4
                     14:
                     15: def glib_floor(N) {
                     16:   return(pari(floor,N));
                     17: }
                     18:
                     19: /*
                     20: def join(A,B) {
                     21:   if (type(B) == 0) return(A);
                     22:   return(append(A,B));
                     23: }
                     24: def eigenvalues(M) {
                     25:   return(pari(eigen,M));
                     26: }
                     27: def roots(F) {
                     28:   return(pari(roots,F));
                     29: }
                     30: */
                     31:
                     32: /*  ---------------------------------------------- */
                     33: def glib_ox_get_errors(P) {
                     34:   ox_push_cmd(P,276);
                     35:   return(ox_pop_cmo(P));
                     36: }
                     37:
                     38: def reset_plot() {
1.2     ! takayama   39: /* It is no longer used. See, oxrfc103.rr */
1.1       noro       40:   extern Glib_process;
                     41:   if (!Cfep_loaded) {
                     42:     print("  Sending signal to ox_plot",0);
                     43:     ox_reset(Glib_process);
                     44:     print("  Done.");
                     45:   }
                     46: }
                     47: Glib_ps = 0$
                     48: Glib_h = []$
                     49: Glib_canvas_x = 400$
                     50: Glib_canvas_y = 400$
                     51: Glib_xmin=0$  Glib_xmax=Glib_canvas_x$
                     52: Glib_ymin=0$  Glib_ymax=Glib_canvas_y$
                     53: Glib_math_coordinate=0$
                     54:
                     55:
                     56: Glib_canvas = -1$
                     57: Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffset=0$
                     58: Glib_safe_mode = 2 $
                     59: Glib_counter = 100$
                     60:
                     61: extern Glib_ps_sx$
                     62: extern Glib_ps_sy$
                     63: Glib_ps_sx=2$  /* mag=1/2 for PS picture. cf. glib_ps_form, glib_tops */
                     64: Glib_ps_sy=2$  /* mag=1/2 for PS picture */
                     65:
                     66: def open_Canvas(P,S) {
                     67:   extern Glib_process;
                     68:   /* print("open_Canvas: ",0);print(S); */
                     69:   if (!Cfep_loaded) {
                     70:     if (P < 0) P=open_canvas(S); /* BUG, get process No. */
                     71:     else open_canvas(P,S);
                     72:     Glib_process = P;
                     73:     R = ox_pop_cmo(P);
                     74:     /*
                     75:     if (glib_ox_get_errors(P) == []) {
                     76:       R = ox_pop_cmo(P);
                     77:     }else{
                     78:       debug;
                     79:     }
                     80:     */
                     81:   }else{
                     82:     R=cfep.open_canvas(S);
                     83:   }
                     84:   return(R);
                     85: }
                     86:
                     87: /*&usage begin: glib_open()
                     88:   It starts the ox_plot server and opens a canvas.
                     89:   The canvas size is set to {Glib_canvas_x} X {Glib_canvas_y}
                     90:   (the default value is 400).
                     91:   This function is automatically called when the user calls glib
                     92:   functions.
                     93: end: */
                     94:
                     95: def glib_open() {
                     96:   extern Glib_canvas_x, Glib_canvas_y,
                     97:          Glib_process, Glib_canvas,
                     98:          Glib_server_started, Glib_process$
                     99:   if (!Cfep_loaded) return glib_openx11();
                    100:   else {
                    101:     Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$
                    102:     Glib_server_started = 1$
                    103:     return(Glib_canvas);
                    104:   }
                    105: }
                    106: def glib_openx11() {
                    107:   extern Glib_canvas_x, Glib_canvas_y,
                    108:          Glib_process, Glib_canvas,
                    109:          Glib_server_started, Glib_process$
                    110: #ifndef DO_NOT_START_SERVER_EXPLICITLY
                    111:   if (type(Glib_server_started) == 0) {
                    112:     Glib_process = ox_launch_nox(0,"ox_plot")$
1.2     ! takayama  113:     /* register_handler(reset_plot);  */
1.1       noro      114:     Glib_server_started = 1$
                    115:   }$
                    116:   Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
                    117: #else
                    118:   Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$
1.2     ! takayama  119:   /* register_handler(reset_plot);  */
1.1       noro      120:   Glib_server_started = 1$
                    121: #endif
                    122:   glib_check_strict();
                    123:   return(Glib_canvas);
                    124: }
                    125:
                    126: def glib_check() {
                    127:   extern  Glib_process, Glib_canvas, Glib_safe_mode,
                    128:           Glib_canvas_x, Glib_canvas_y, Glib_counter;
                    129:   if (Glib_safe_mode == 0) {
                    130:      return(0);
                    131:   }
                    132:   if (Glib_safe_mode == 2) {
                    133:    if (Glib_counter > 0) {
                    134:      Glib_counter--;
                    135:      return(0);
                    136:    }else{
                    137:      Glib_counter=100;
                    138:    }
                    139:   }
                    140:   glib_check_strict();
                    141: }
                    142: def glib_check_strict() {
                    143:   extern  Glib_process, Glib_canvas, Glib_safe_mode,
                    144:           Glib_canvas_x, Glib_canvas_y, Glib_counter;
                    145:   if (Glib_canvas < 0) {
                    146:     glib_open();
                    147:   }
                    148:   if (Cfep_loaded) return ;
                    149:   E = glib_ox_get_errors(Glib_process);
                    150:   if (E != []) {
                    151:     ox_pops(Glib_process,200);
                    152:     print(E);
                    153:     print("Warning: ",0);
                    154:     print("Drawing canvas seems to be closed.");
                    155:     print("Opening a new canvas.");
                    156:     Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
                    157:     error("Drawing aborted");
                    158:   }
                    159: }
                    160:
                    161: /*&usage begin: glib_clear()
                    162:   Clear the screen.
                    163: end: */
                    164: def glib_clear() {
                    165:   extern Glib_process, Glib_canvas;
                    166:   if (Glib_canvas < 0) glib_open();
                    167:   if (!Cfep_loaded) clear_canvas(Glib_process,Glib_canvas);
                    168:   else cfep.glib_clear();
                    169: }
                    170:
                    171: /*&usage begin: glib_window(Xmin,Ymin,Xmax,Ymax)
                    172:   It generates a window with the left top corner [{Xmin},{Ymin}] and
                    173:   the right bottom corner [{Xmax},{Ymax}].
                    174:   If the global variable {Glib_math_coordinate} is set to 1, mathematical
                    175:   coordinate system will be employed, i.e., the left top
                    176:   corner will have the coordinate [{Xmin},{Ymax}].
                    177:   example: glib_window(-1,-1,10,10);
                    178: end: */
                    179: def glib_window(Xmin,Ymin,Xmax,Ymax) {
                    180:   extern Glib_xmin,  Glib_xmax, Glib_ymin, Glib_ymax,
                    181:          Glib_canvas_x, Glib_canvas_y, Glib_process, Glib_canvas,
                    182:          Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag;
                    183:   if (Xmax <= Xmin) error("glib window: Invalid size");
                    184:   if (Ymax <= Ymin) error("glib window: Invalid size");
                    185:   glib_check_arg(Xmin,Ymin); glib_check_arg(Xmax,Ymax);
                    186:   Glib_xmin = Xmin;  Glib_xmax = Xmax;
                    187:   Glib_ymin = Ymin;  Glib_ymax = Ymax;
                    188:   Glib_xoffset = -Xmin;
                    189:   Glib_yoffset = -Ymin;
                    190:   Glib_xmag    = Glib_canvas_x/(Xmax-Xmin);
                    191:   Glib_ymag    = Glib_canvas_y/(Ymax-Ymin);
                    192:   if (Glib_canvas < 0) glib_open();
                    193: }
                    194:
                    195: def glib_check_arg(X,Y) {
                    196:   if (type(X) <= 1 && type(Y) <= 1) return 1;
                    197:   else {
                    198:     print("Error in glib: arguments ",0);
                    199:     print([X,Y],0);
                    200:     print(" are not numbers.");
                    201:     error("Invalid argument for glib_window, glib_putpixel, glib_line.");
                    202:   }
                    203: }
                    204:
                    205: /*&usage begin: glib_putpixel(X,Y|color)
                    206:   It puts a pixel at [{X},{Y}] with {color}
                    207:   example: glib_putpixel(1,2 | color=0xffff00);
                    208: end: */
                    209: def glib_putpixel(X,Y) {
                    210:   extern Glib_process, Glib_canvas,
                    211:          Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps,
                    212:          Glib_math_coordinate, Glib_canvas_y;
                    213:   if (Glib_canvas < 0) glib_open();
                    214:   glib_check();
                    215:   glib_check_arg(X,Y);
                    216:   C = getopt(color);
                    217:   if (Glib_math_coordinate) {
                    218:     Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    219:            Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    220:     Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    221:            glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    222:   }else{
                    223:     Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    224:            glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    225:     Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    226:            Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    227:   }
                    228:   if ( type(C) != -1 ) {
                    229:     if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos,C);
                    230:     else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,C);
                    231:     if (Glib_ps) glib_history(["putpixel",Pos2,C]);
                    232:   }else{
                    233:     if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos);
                    234:     else cfep.draw_obj(Glib_process,Glib_canvas,Pos);
                    235:     if (Glib_ps) glib_history(["putpixel",Pos2,0]);
                    236:   }
                    237: }
                    238:
                    239: /*&usage begin: glib_line(X0,Y0,X1,Y1|color,shape)
                    240:   It draws the line [{X0},{Y0}]-- [{X1},{Y1}] with {color} and {shape}
                    241:   example: glib_line(0,0,5,3/2 | color=0xff00ff);
                    242:            glib_line(0,0,10,0 | shape=arrow);
                    243: end: */
                    244: def glib_line(X0,Y0,X1,Y1) {
                    245:   extern Glib_xmag, Glib_ymag, Glib_xoffset, Glib_yoffset;
                    246:   C = getopt(color);
                    247:   glib_check_arg(X0,Y0);
                    248:   glib_check_arg(X1,Y1);
                    249:   glib_clip_line(glib_floor(Glib_xmag*(X0+Glib_xoffset)),
                    250:                  glib_floor(Glib_ymag*(Y0+Glib_yoffset)),
                    251:                  glib_floor(Glib_xmag*(X1+Glib_xoffset)),
                    252:                  glib_floor(Glib_ymag*(Y1+Glib_yoffset)),C);
                    253:   Shape = getopt(shape);
                    254:   if (type(Shape) != 2) return;
                    255:   Px = X0+(7/8)*(X1-X0);
                    256:   Py = Y0+(7/8)*(Y1-Y0);
                    257:   Qx = (Y0-Y1)/8;
                    258:   Qy = (X1-X0)/8;
                    259:   if (type(C)>0) glib_line(X1,Y1,Px+Qx,Py+Qy | color=C);
                    260:   else glib_line(X1,Y1,Px+Qx,Py+Qy);
                    261:   if (type(C)>0) glib_line(X1,Y1,Px-Qx,Py-Qy | color=C);
                    262:   else glib_line(X1,Y1,Px-Qx,Py-Qy);
                    263: }
                    264:
                    265: def glib_clip_line(X0,Y0,X1,Y1,Color) {
                    266:   /* X0, Y0, X1, Y1 should be integers.
                    267:      Coordinates are already translated. */
                    268:   extern Glib_process, Glib_canvas, Glib_canvas_x, Glib_canvas_y,
                    269:          Glib_ps,  Glib_math_coordinate;
                    270:   if (Glib_canvas < 0) glib_open();
                    271:
                    272: if (Glib_ps) {
                    273: #ifdef DEBUG
                    274:   print(["clip_line",[X0,Y0,X1,Y1]]);
                    275: #endif
                    276:   /* clip by x = 0 */
                    277:   S = glib_clip0_x(X0,Y0,X1,Y1,0);
                    278: #ifdef DEBUG
                    279:   print(["clip0_x",S]);
                    280: #endif
                    281:   if (type(S) == 0) return;
                    282:   X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
                    283:
                    284:   S = glib_clip1_x(X0,Y0,X1,Y1,Glib_canvas_x-1);
                    285: #ifdef DEBUG
                    286:   print(["clip1_x",S]);
                    287: #endif
                    288:   if (type(S) == 0) return;
                    289:   X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
                    290:
                    291:   S = glib_clip0_y(X0,Y0,X1,Y1,0);
                    292: #ifdef DEBUG
                    293:   print(["clip0_y",S]);
                    294: #endif
                    295:   if (type(S) == 0) return;
                    296:   X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
                    297:
                    298:   S = glib_clip1_y(X0,Y0,X1,Y1,Glib_canvas_y-1);
                    299: #ifdef DEBUG
                    300:   print(["clip1_y",S]);
                    301: #endif
                    302:   if (type(S) == 0) return;
                    303:   X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
                    304:
                    305: #ifdef DEBUG
                    306:   print([X0,Y0,X1,Y1]);
                    307: #endif
                    308: }
                    309:
                    310:   glib_check();
                    311:   if (Glib_math_coordinate) {
                    312:     Pos = [glib_floor(X0),Glib_canvas_y-glib_floor(Y0),
                    313:            glib_floor(X1),Glib_canvas_y-glib_floor(Y1)];
                    314:     Pos2= [glib_floor(X0),glib_floor(Y0),glib_floor(X1),glib_floor(Y1)];
                    315:   }else{
                    316:     Pos = [glib_floor(X0),glib_floor(Y0),glib_floor(X1),glib_floor(Y1)];
                    317:     Pos2 = [glib_floor(X0),Glib_canvas_y-glib_floor(Y0),
                    318:            glib_floor(X1),Glib_canvas_y-glib_floor(Y1)];
                    319:   }
                    320:   if ( type(Color) != -1 ) {
                    321:     if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos,Color);
                    322:     else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,Color);
                    323:     if (Glib_ps) glib_history(["line",Pos2,Color]);
                    324:   }else{
                    325:     if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos);
                    326:     else cfep.draw_obj(Glib_process,Glib_canvas,Pos);
                    327:     if (Glib_ps) glib_history(["line",Pos2,0]);
                    328:   }
                    329: }
                    330:
                    331: def glib_clip0_x(X0,Y0,X1,Y1,Clip) {
                    332:    if (X0 < Clip && X1 < Clip) return(0);
                    333:    if (X0 < Clip && X1 > Clip) {
                    334:      return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
                    335:    }
                    336:    if (X1 > Clip && X1 < Clip) {
                    337:      return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
                    338:    }
                    339:    return([X0,Y0,X1,Y1]);
                    340: }
                    341: def glib_clip0_y(X0,Y0,X1,Y1,Clip) {
                    342:    if (Y0 < Clip && Y1 < Clip) return(0);
                    343:    if (Y0 < Clip && Y1 > Clip) {
                    344:      return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
                    345:    }
                    346:    if (Y1 > Clip && Y1 < Clip) {
                    347:      return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
                    348:    }
                    349:    return([X0,Y0,X1,Y1]);
                    350: }
                    351: def glib_clip1_x(X0,Y0,X1,Y1,Clip) {
                    352:    if (X0 > Clip && X1 > Clip) return(0);
                    353:    if (X0 > Clip && X1 < Clip) {
                    354:      return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
                    355:    }
                    356:    if (X1 < Clip && X1 > Clip) {
                    357:      return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
                    358:    }
                    359:    return([X0,Y0,X1,Y1]);
                    360: }
                    361: def glib_clip1_y(X0,Y0,X1,Y1,Clip) {
                    362:    if (Y0 > Clip && Y1 > Clip) return(0);
                    363:    if (Y0 > Clip && Y1 < Clip) {
                    364:      return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
                    365:    }
                    366:    if (Y0 < Clip && Y1 > Clip) {
                    367:      return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
                    368:    }
                    369:    return([X0,Y0,X1,Y1]);
                    370: }
                    371:
                    372: /*&usage begin: glib_print(X,Y,Text|color)
                    373:   It put a string {Text} at [{X},{Y}] on the glib canvas.
                    374:   example: glib_print(100,100,"Hello Worlds" | color=0xff0000);
                    375: end: */
                    376: def glib_print(X,Y,Text) {
                    377:   extern Glib_process, Glib_canvas,
                    378:          Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps,
                    379:          Glib_math_coordinate, Glib_canvas_y;
                    380:   if (Glib_canvas < 0) glib_open();
                    381:   glib_check();
                    382:   glib_check_arg(X,Y);
                    383:   if (type(Text) != 7) error("glib_print(X,Y,Text): Text must be a string.");
                    384:   C = getopt(color);
                    385:   if (Glib_math_coordinate) {
                    386:     Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    387:            Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    388:     Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    389:            glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    390:   }else{
                    391:     Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    392:            glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    393:     Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
                    394:            Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
                    395:   }
                    396:   if ( type(C) != -1 ) {
                    397:     if (!Cfep_loaded) draw_string(Glib_process,Glib_canvas,Pos,Text,C);
                    398:     else cfep.draw_string2(Glib_process,Glib_canvas,Pos,Text,C);
                    399:     if (Glib_ps) glib_history(["print",Pos2,Text,C]);
                    400:   }else{
                    401:     if (!Cfep_loaded) draw_string(Glib_process,Glib_canvas,Pos,Text);
                    402:     else cfep.draw_string(Glib_process,Glib_canvas,Pos,Text);
                    403:     if (Glib_ps) glib_history(["print",Pos2,Text,0]);
                    404:   }
                    405: }
                    406:
                    407: def glib_history(L) {
                    408:   extern Glib_h, Glib_canvas_x, Glib_canvas_y,
                    409:          Glib_math_coodinate;
                    410:   if (L[0] == "putpixel" || L[0] == "print") {
                    411:     if (L[1][0] <= Glib_canvas_x && L[1][0] >= 0) {
                    412:       if (L[1][1] <= Glib_canvas_x && L[1][1] >= 0)
                    413:          Glib_h = cons(L,Glib_h);
                    414:     }
                    415:   }else {
                    416:     Glib_h = cons(L,Glib_h);
                    417:   }
                    418:   return 0;
                    419: }
                    420:
                    421: #define xxx(x) idiv(x,Glib_ps_sx)
                    422: #define yyy(y) idiv(y,Glib_ps_sy)
                    423:
                    424: /*&usage begin: glib_tops()
                    425:   If Glib_ps is set to 1,
                    426:   it returns a postscript program to draw the picture on the canvas.
                    427:   ref: print_output
                    428: end: */
                    429: def glib_tops() {
                    430:   extern Glib_h;
                    431:   return glib_ps(Glib_h);
                    432: }
                    433: def glib_ps(L) {
                    434:   extern Glib_ps_sx;
                    435:   extern Glib_ps_sy;
                    436:   PS = string_to_tb("");
                    437:   Prev_color = 0;
                    438:   /* Prolog */
                    439:   write_to_tb("%%!PS-Adobe-1.0\n",PS);
                    440:   write_to_tb("%%BoundingBox: 0 0 " +
                    441:           rtostr(xxx(Glib_canvas_x)) + " " + rtostr(yyy(Glib_canvas_y)) + "\n",PS);
                    442:   write_to_tb("%%Creator: This is generated by ifplot\n",PS);
                    443:   write_to_tb("%%Title: ifplot\n",PS);
                    444:   write_to_tb("%%EndComments: \n",PS);
                    445:   write_to_tb("0.1 setlinewidth \n",PS);
                    446:   write_to_tb("2 setlinecap \n",PS);
                    447:   write_to_tb("2 setlinejoin \n",PS);
                    448:   write_to_tb("/ifplot_putpixel {  \n",PS);
                    449:   write_to_tb("    /yyy 2 1 roll def /xxx 2 1 roll def \n",PS);
                    450:   write_to_tb("    gsave newpath xxx yyy .5 0 360 arc \n",PS);
                    451:   write_to_tb("    fill grestore \n",PS);
                    452:   write_to_tb("} def \n",PS);
                    453:
                    454:   L = reverse(L);
                    455:   N = length(L);
                    456:   for (I=0; I<N; I++) {
                    457:     C = L[I];
                    458:     if (C[length(C)-1] != Prev_color) {
                    459:       Prev_color = C[length(C)-1];
                    460:       write_to_tb(rtostr(deval(ishift(Prev_color,16)/256)) + " " +
                    461:             rtostr(deval(iand(ishift(Prev_color,8),0xff)/256)) + " " +
                    462:             rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n",PS);
                    463:     }
                    464:     if (C[0] == "putpixel") {
                    465:        write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " ifplot_putpixel \n",PS);
                    466:     }
                    467:     if (C[0] == "line") {
                    468:        write_to_tb(" newpath ",PS);
                    469:        write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto " +
                    470:              rtostr(xxx(C[1][2])) + " " + rtostr(yyy(C[1][3])) + " lineto stroke \n",PS);
                    471:     }
                    472:     if (C[0] == "print") {
                    473:        write_to_tb("/Times-Roman findfont 10 scalefont setfont \n",PS);
                    474:        write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto ",PS);
                    475:        write_to_tb("(" + C[2] + ")  show \n",PS);
                    476:     }
                    477:   }
                    478:
                    479:   /* Epilog */
                    480:   write_to_tb("0 0 0 setrgbcolor \n",PS);
                    481:   write_to_tb("showpage \n",PS);
                    482:
                    483:   return tb_to_string(PS);
                    484: }
                    485:
                    486: /*&usage begin: glib_ps_form(S)
                    487:   It returns the PS code generated by executing {S}
                    488:   (experimental).
                    489:   example: glib_ps_form(quote( glib_line(0,0,100,100) ));
                    490:   example: glib_ps_form(quote([glib_line(0,0,100,100),glib_line(100,0,0,100)]));
                    491:   ref: glib_tops
                    492: end: */
                    493: /* Todo.  Change the canvas size.  */
                    494: def glib_ps_form(F) {
                    495:   extern Glib_h;
                    496:   extern Glib_ps;
                    497:   H = Glib_h; /* push Glib_h */
                    498:   P = Glib_ps; /* push Glib_ps */
                    499:
                    500:   Glib_ps=1; Glib_h = [];
                    501:   if (type(F) != 17) {
                    502:     return "Error: argument should be quote(...).";
                    503:   }
                    504:   eval_quote(F);
                    505:   /* bug. eval_str causes seg fault for ccurve.rr main(8) */
                    506:   R = glib_tops();
                    507:   Glib_h = H; /* pop Glib_h */
                    508:   Glib_ps = P; /* pop Glib_ps */
                    509:   return R;
                    510: }
                    511:
                    512: /*&usage begin: glib_plot(F)
                    513:   It plots an object {F} on the glib canvas.
                    514:   example: glib_plot([[0,1],[0.1,0.9],[0.2,0.7],[0.3,0.5],[0.4,0.8]]);
                    515:   example: glib_plot(tan(x));
                    516: end: */
                    517: /* bug, xmin, xmax, color should be optional variables. */
                    518: def glib_plot(F) {
                    519:   Opt = getopt();
                    520:   taka_glib_plot(F,Opt);
                    521: }
                    522:
                    523: /*&usage begin: glib_flush();
                    524:   Flush the output.
                    525:  (Cfep only. It also set initGL to 1.).
                    526: end: */
                    527: def glib_flush() {
                    528:   extern Glib_canvas;
                    529:   if (Glib_canvas < 0) glib_open();
                    530:   if (Cfep_loaded) cfep.draw_flush(Glib_canvas);
                    531: }
                    532: /*&usage begin: glib_set_pixel_size(P)
                    533:   Set the size of putpixel to P. 1.0 is the default.
                    534:  (cfep only).
                    535: end: */
                    536: def glib_set_pixel_size(X) {
                    537:   extern  Glib_canvas;
                    538:   if (Glib_canvas < 0) glib_open();
                    539:   if (!Cfep_loaded) /*Not implemented.*/ ;
                    540:   else cfep.glib_set_pixel_size(X);
                    541: }
                    542:
                    543: /*&usage begin: glib_remove_last()
                    544:   Remove the last object.  glib_flush() should also be called to remove
                    545:   the last object.
                    546:  (cfep only).
                    547: end: */
                    548: def glib_remove_last() {
                    549:   extern  Glib_canvas;
                    550:   if (Glib_canvas < 0) glib_open();
                    551:   if (!Cfep_loaded) /*Not implemented.*/ ;
                    552:   else cfep.glib_remove_last();
                    553: }
                    554:
                    555: end$
                    556:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>