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

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

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

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