periPos.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2001 Enpc/Jean-Philippe Chancelier
00004  *    jpc@cermics.enpc.fr 
00005  *    Copyright INRIA
00006  --------------------------------------------------------------------------*/
00007 
00008 /*----------------------BEGIN----------------------
00009 \def\encadre#1{\paragraph{}\fbox{\begin{minipage}[t]{15cm}#1 \end{minipage}}}
00010 \section{A Postscript Driver}
00011 ---------------------------------------------------*/
00012 
00013 #include <stdio.h>
00014 #include <math.h>
00015 #include <string.h>
00016 
00017 #ifdef __STDC__
00018 #include <stdlib.h>
00019 #endif
00020 
00021 #include "machine.h"
00022 #include "bcg.h"
00023 #include "sciprint.h"
00024 #include "periScreen.h"
00025 
00026 #if defined(_MSC_VER)
00027 #define CoordModePrevious 1
00028 #define CoordModeOrigin 0
00029 #define GXclear 0
00030 #define GXand 1
00031 #define GXandReverse 2
00032 #define GXcopy 3
00033 #define GXandInverted 4
00034 #define GXnoop 5
00035 #define GXxor 6
00036 #define GXor 7
00037 #define GXnor 8
00038 #define GXequiv 9
00039 #define GXinvert 10
00040 #define GXorReverse 11
00041 #define GXcopyInverted 12
00042 #define GXorInverted 13
00043 #define GXnand 14
00044 #define GXset 15
00045 #endif
00046 
00047 struct BCG  ScilabGCPos ;
00048 static BOOL ScilabGCPos_is_initialized = FALSE;
00049 
00050 #include "math_graphics.h"
00051 #include "periPos.h"
00052 #include "color.h"
00053 #include "bcg.h" /* NG */
00054 #include "MALLOC.h" /* MALLOC */
00055 
00056 void C2F(WriteGeneric1Pos)(char *string, integer nobjpos, integer objbeg, integer sizeobj, integer *vx, integer *vy, integer flag, integer *fvect);
00057 void C2F(xgetmarkPos)(integer *verbose, integer *symb, integer *narg, double *dummy);
00058 void C2F(xsetmarkPos)(integer *number, integer *size, integer *v3, integer *v4);
00059 void C2F(xgetfontPos)(integer *verbose, integer *font, integer *nargs, double *dummy);
00060 void C2F(xsetfontPos)(integer *fontid, integer *fontsize, integer *v3, integer *v4);
00061 void C2F(setdashstylePos)(integer *value, integer *xx, integer *n);
00062 void C2F(Write2VectPos)(integer *vx, integer *vy, integer from, integer n, char *string, integer flag, integer fv);
00063 void C2F(WriteGenericPos)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect);
00064 void C2F(InitScilabGCPos)(integer *v1, integer *v2, integer *v3, integer *v4);
00065 void C2F(setforegroundPos)(integer *num, integer *v2, integer *v3, integer *v4);
00066 void C2F(ScilabGCGetorSetPos)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dx1);
00067 void C2F(setbackgroundPos)(integer *num, integer *v2, integer *v3, integer *v4);
00068 void C2F(set_cPos)(integer i);
00069 void C2F(idfromnamePos) (char *name1, integer *num);
00070 void C2F(getdashPos)(integer *verbose, integer *value, integer *narg, double *dummy);
00071 /* NG beg */
00072 void C2F(setscilabFigurePos)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure);
00073 void C2F(getscilabFigurePos)(integer *verbose, integer *x,integer *narg, double *figure);
00074 void C2F(setscilabVersionPos)(integer *vers, integer *v2, integer *v3, integer *v4);
00075 void C2F(getscilabVersionPos)(integer *verbose, integer *vers, integer *narg, double *dummy);
00076 void C2F(setscilabxgcPos)(integer *v1, integer *v2, integer *v3, integer *v4); 
00077 void C2F(getscilabxgcPos)(integer *verbose, integer *x,integer *narg, double *dummy);
00078 void setposfig(integer *i,integer *j);
00079 /* NG end */
00080 
00081 static double ascentPos(void);
00082 static int fontsizePos (void);
00083 static int C2F(PosQueryFont)(char *name);
00084 static void C2F(displaysymbolsPos)(char *str, integer *n, integer *vx, integer *vy);
00085 static void WriteColorRGB(char *str, double *tab, int ind);
00086 static void WriteColorRGBDef(char *str, short unsigned int *tab, int ind);
00087 #define Char2Int(x)   ( x & 0x000000ff )
00088 
00089 static double *vdouble = 0; /* used when a double argument is needed */
00090 
00091 #if defined(__GNUC__) || defined(_MSC_VER) || defined(__EDG__)
00092 static FILE *file= (FILE *) 0;
00093 #define FPRINTF(x) ( file != (FILE*) 0) ?  fprintf x  : 0 
00094 #else 
00095 #define FPRINTF(x) fprintf x  
00096 static FILE *file= stdout ;
00097 #endif
00098 
00099 void FileInit  __PARAMS((void));
00100 void FileInitFromScreenPos  __PARAMS((void));
00101 
00104 /*-----------------------------------------------------
00105 \encadre{General routines}
00106 -----------------------------------------------------*/
00107 
00110 void C2F(xselgraphicPos)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00111 {}
00112 
00115 void C2F(xendgraphicPos)(void)
00116 {
00117   if (file != stdout && file != (FILE*) 0) {
00118     FPRINTF((file,"\n%%Latex:\\end{picture}"));
00119     FPRINTF((file,"\n showpage\n"));
00120     FPRINTF((file,"\n end saved restore \n"));
00121     fclose(file);
00122     file=stdout;}
00123   ScilabGCPos_is_initialized = FALSE;
00124 }
00125 
00126 void C2F(xendPos)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00127 {
00128   C2F(xendgraphicPos)();
00129 }
00130 
00131 
00135 void C2F(clearwindowPos)(char *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00136 {
00137   /* FPRINTF((file,"\n showpage")); */
00139   /* FileInit(file); */
00140 }
00141 
00142 
00145 void C2F(xclickPos)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00146 { }
00147 
00148 void C2F(xclick_anyPos)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00149 { }
00150 
00151 void C2F(xgetmousePos)(char *str, integer *ibutton, integer *xx1, integer *yy1, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00152 { }
00153 
00156 void C2F(clearareaPos)(char *str, integer *x, integer *y, integer *w, integer *h, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
00157 {
00158   
00159   if ( ScilabGCPos_is_initialized == FALSE ) {
00160     sciprint("xinit must be called before any action \r\n");
00161     return;
00162  }
00163   
00164   FPRINTF((file,"\n [ %d %d %d %d ] clearzone",(int)*x,(int)*y,(int)*w,(int)*h));
00165 }
00166 
00167 
00168 
00169 /*---------------------------------------------------------------------
00170 \section{Function for graphic context modification}
00171 ------------------------------------------------------------------------*/
00172 
00175 void C2F(getwindowposPos)(integer *verbose, integer *x, integer *narg, double *dummy)
00176 {
00177   *narg = 2;
00178   x[0]= x[1]=0;
00179   if (*verbose == 1) 
00180     sciprint("\n CWindow position :%d,%d\r\n",(int)x[0],(int)x[1]);
00181  }
00182 
00185 void C2F(setwindowposPos)(integer *x, integer *y, integer *v3, integer *v4)
00186 {
00187 }
00188 
00194 static integer prec_fact =10;
00195 static integer def_width =600;
00196 static integer def_height = 424;
00197 
00198 void setposfig(integer *i,integer *j)
00199 {
00200   def_width =*i;
00201   def_height =*j;
00202   if (def_width*def_height==0){
00203     def_width =600;
00204     def_height =424;
00205   }
00206 }
00207 
00208 
00209 
00210 void C2F(getwindowdimPos)(integer *verbose, integer *x, integer *narg, double *dummy)
00211 {     
00212   *narg = 2;
00213   x[0]= def_width*prec_fact;
00214   x[1]= def_height*prec_fact;
00215   if (*verbose == 1) 
00216     sciprint("\n CWindow dim :%d,%d\r\n",(int)x[0],(int)x[1]);
00217 } 
00218 
00221 void C2F(setwindowdimPos)(integer *x, integer *y, integer *v3, integer *v4)
00222 {
00223 }
00224 
00225 
00228 void C2F(setcurwinPos)(integer *intnum, integer *v2, integer *v3, integer *v4)
00229 { 
00230   if ( ScilabGCPos_is_initialized == FALSE ) {
00231     sciprint("xinit must be called before any action \r\n");
00232     return;
00233   }
00234   
00235   ScilabGCPos.CurWindow = *intnum;
00236 }
00237 
00240 void C2F(getcurwinPos)(integer *verbose, integer *intnum, integer *narg, double *dummy)
00241 {
00242   if ( ScilabGCPos_is_initialized == FALSE ) {
00243     sciprint("xinit must be called before any action \r\n");
00244     return;
00245   }
00246   
00247   *narg =1 ;
00248   *intnum = ScilabGCPos.CurWindow ;
00249   if (*verbose == 1) 
00250     sciprint("\nJust one graphic page at a time ");
00251 }
00252 
00255 void C2F(setclipPos)(integer *x, integer *y, integer *w, integer *h)
00256 {
00257  if ( ScilabGCPos_is_initialized == FALSE ) {
00258    sciprint("xinit must be called before any action \r\n");
00259    return;
00260  }
00261 
00262   ScilabGCPos.ClipRegionSet = 1;
00263   ScilabGCPos.CurClipRegion[0]= *x;
00264   ScilabGCPos.CurClipRegion[1]= *y;
00265   ScilabGCPos.CurClipRegion[2]= *w;
00266   ScilabGCPos.CurClipRegion[3]= *h;
00267   FPRINTF((file,"\n%d %d %d %d setclipzone",(int)*x,(int)*y,(int)*w,(int)*h));
00268 }
00269 
00272 void C2F(unsetclipPos)(integer *v1, integer *v2, integer *v3, integer *v4)
00273 {
00274   if ( ScilabGCPos_is_initialized == FALSE ) {
00275     sciprint("xinit must be called before any action \r\n");
00276     return;
00277   }
00278   
00279   ScilabGCPos.ClipRegionSet = 0;
00280   ScilabGCPos.CurClipRegion[0]= -1;
00281   ScilabGCPos.CurClipRegion[1]= -1;
00282   ScilabGCPos.CurClipRegion[2]= 200000;
00283   ScilabGCPos.CurClipRegion[3]= 200000;
00284   FPRINTF((file,"\n%d %d %d %d setclipzone",-1,-1,200000,200000));
00285 }
00286 
00289 void C2F(getclipPos)(integer *verbose, integer *x, integer *narg, double *dummy)
00290 {
00291   if ( ScilabGCPos_is_initialized == FALSE ) {
00292     sciprint("xinit must be called before any action \r\n");
00293     return;
00294   }
00295 
00296   x[0] = ScilabGCPos.ClipRegionSet;
00297   if ( x[0] == 1)
00298     {
00299       *narg = 5;
00300       x[1] =ScilabGCPos.CurClipRegion[0];
00301       x[2] =ScilabGCPos.CurClipRegion[1];
00302       x[3] =ScilabGCPos.CurClipRegion[2];
00303       x[4] =ScilabGCPos.CurClipRegion[3];
00304     }
00305   else *narg = 1;
00306   if (*verbose == 1)
00307     {
00308       if (ScilabGCPos.ClipRegionSet == 1)
00309         sciprint("\nThere's a Clip Region :x:%d,y:%d,w:%d,h:%d\r\n",
00310                  ScilabGCPos.CurClipRegion[0],
00311                  ScilabGCPos.CurClipRegion[1],
00312                  ScilabGCPos.CurClipRegion[2],
00313                  ScilabGCPos.CurClipRegion[3]);
00314       else 
00315         sciprint("\nNo Clip Region");
00316     }
00317 }
00318 
00319 /*----------------------------------------------------------
00320 \encadre{For the drawing functions dealing with vectors of 
00321  points, the following routine is used to select the mode 
00322  absolute or relative }
00323  Absolute mode if *num==0, relative mode if *num != 0
00324 ------------------------------------------------------------*/
00325 
00326 void C2F(setabsourelPos)(integer *num, integer *v2, integer *v3, integer *v4)
00327 {
00328   if ( ScilabGCPos_is_initialized == FALSE ) {
00329     sciprint("xinit must be called before any action \r\n");
00330     return;
00331   }
00332   
00333   if (*num ==  CoordModeOrigin )
00334     ScilabGCPos.CurVectorStyle =  CoordModeOrigin;
00335   else 
00336     ScilabGCPos.CurVectorStyle =  CoordModePrevious ;
00337 }
00338 
00341 void C2F(getabsourelPos)(integer *verbose, integer *num, integer *narg, double *dummy)
00342 {
00343   if ( ScilabGCPos_is_initialized == FALSE ) {
00344     sciprint("xinit must be called before any action \r\n");
00345     return;
00346   }
00347   
00348   *narg = 1;
00349   *num = ScilabGCPos.CurVectorStyle  ;
00350   if (*verbose == 1) 
00351     {
00352       if (ScilabGCPos.CurVectorStyle == CoordModeOrigin)
00353         sciprint("\nTrace Absolu");
00354       else 
00355         sciprint("\nTrace Relatif");
00356     }
00357 }
00358 
00359 
00363 void C2F(setalufunctionPos)(char *string)
00364 {    
00365   integer value;
00366   
00367   if ( ScilabGCPos_is_initialized == FALSE ) {
00368     sciprint("xinit must be called before any action \r\n");
00369     return;
00370   }
00371   
00372   C2F(idfromnamePos)(string,&value);
00373   if ( value != -1)
00374     {ScilabGCPos.CurDrawFunction = value;
00375      FPRINTF((file,"\n%% %d setalufunction",(int)value));
00376       }
00377 }
00378 
00381 struct alinfo { 
00382   char *name;
00383   char id;
00384   char *info;} AluStrucPos[] = { 
00385   {"GXclear" ,GXclear," 0 "},
00386   {"GXand" ,GXand," src AND dst "},
00387   {"GXandReverse" ,GXandReverse," src AND NOT dst "},
00388   {"GXcopy" ,GXcopy," src "},
00389   {"GXandInverted" ,GXandInverted," NOT src AND dst "},
00390   {"GXnoop" ,GXnoop," dst "},
00391   {"GXxor" ,GXxor," src XOR dst "},
00392   {"GXor" ,GXor," src OR dst "},
00393   {"GXnor" ,GXnor," NOT src AND NOT dst "},
00394   {"GXequiv" ,GXequiv," NOT src XOR dst "},
00395   {"GXinvert" ,GXinvert," NOT dst "},
00396   {"GXorReverse" ,GXorReverse," src OR NOT dst "},
00397   {"GXcopyInverted" ,GXcopyInverted," NOT src "},
00398   {"GXorInverted" ,GXorInverted," NOT src OR dst "},
00399   {"GXnand" ,GXnand," NOT src OR NOT dst "},
00400   {"GXset" ,GXset," 1 "}
00401 };
00402 
00403 void C2F(idfromnamePos)(char *name1, integer *num)
00404 {
00405   integer i;
00406   *num = -1;
00407   for ( i =0 ; i < 16;i++)
00408     if (strcmp(AluStrucPos[i].name,name1)== 0) 
00409       *num=AluStrucPos[i].id;
00410   if (*num == -1 ) 
00411     {
00412       sciprint("\n Use the following keys :");
00413       for ( i=0 ; i < 16 ; i++)
00414         sciprint("\nkey %s -> %s\r\n",AluStrucPos[i].name,
00415                  AluStrucPos[i].info);
00416     }
00417 }
00418 
00419 
00420 void C2F(setalufunction1Pos)(integer *num, integer *v2, integer *v3, integer *v4)
00421 {     
00422   integer value;
00423 
00424   if ( ScilabGCPos_is_initialized == FALSE ) {
00425     sciprint("xinit must be called before any action \r\n");
00426     return;
00427   }
00428   
00429   value=AluStrucPos[Min(15,Max(0,*num))].id;
00430   if ( value != -1)
00431     {
00432       ScilabGCPos.CurDrawFunction = value;
00433       /* to be done */
00434     }
00435 }
00436 
00439 void C2F(getalufunctionPos)(integer *verbose, integer *value, integer *narg, double *dummy)
00440 {
00441   if ( ScilabGCPos_is_initialized == FALSE ) {
00442     sciprint("xinit must be called before any action \r\n");
00443     return;
00444   }
00445   
00446   *narg =1 ;
00447   *value = ScilabGCPos.CurDrawFunction ;
00448    if (*verbose ==1 ) 
00449      { sciprint("\nThe Alufunction is %s -> <%s>\r\n",
00450                AluStrucPos[*value].name,
00451                AluStrucPos[*value].info);}
00452  }
00453 
00457 #define Thick_prec 5
00458 
00459 void C2F(setthicknessPos)(integer *value, integer *v2, integer *v3, integer *v4)
00460 { 
00461   if ( ScilabGCPos_is_initialized == FALSE ) {
00462     sciprint("xinit must be called before any action \r\n");
00463     return;
00464   }
00465 
00466   ScilabGCPos.CurLineWidth =Max(0, *value);
00467   FPRINTF((file,"\n%d Thickness",(int)Max(0,*value*Thick_prec)));
00468 }
00469 
00472 void C2F(getthicknessPos)(integer *verbose, integer *value, integer *narg, double *dummy)
00473 {
00474   if ( ScilabGCPos_is_initialized == FALSE ) {
00475     sciprint("xinit must be called before any action \r\n");
00476     return;
00477   }
00478   
00479   *narg =1 ;
00480   *value = ScilabGCPos.CurLineWidth ;
00481   if (*verbose ==1 ) 
00482     sciprint("\nLine Width:%d\r\n",
00483             ScilabGCPos.CurLineWidth ) ;
00484 }
00485      
00486 
00487 /*-------------------------------------------------
00488 \encadre{To set grey level for filing areas.
00489   from black (*num =0 ) to white 
00490   you must use the get function to get the id of 
00491   the white pattern }
00492 ----------------------------------------------------*/
00493 
00494 void C2F(setpatternPos)(integer *num, integer *v2, integer *v3, integer *v4)
00495 {
00496   integer i ;
00497   
00498   if ( ScilabGCPos_is_initialized == FALSE ) {
00499     sciprint("xinit must be called before any action \r\n");
00500     return;
00501   }
00502   
00503   if ( ScilabGCPos.CurColorStatus ==1) 
00504     {
00505       i= Max(0,Min(*num-1,ScilabGCPos.Numcolors+1));
00506       ScilabGCPos.CurColor = i ;
00507       C2F(set_cPos)(i);
00508     }
00509   else 
00510     {
00511       /* used when printing from color to b&white color after GREYNUMBER 
00512        are translated to black */
00513       if ( *num-1 > GREYNUMBER -1 ) 
00514         i=0;
00515       else 
00516         i= Max(0,Min(*num-1,GREYNUMBER-1));
00517       ScilabGCPos.CurPattern = i;
00518       if (i ==0)
00519         FPRINTF((file,"\nfillsolid"));
00520       else 
00521         FPRINTF((file,"\n%d Setgray",(int)i));
00522     }
00523 }
00524 
00527 void C2F(getpatternPos)(integer *verbose, integer *num, integer *narg, double *dummy)
00528 { 
00529   if ( ScilabGCPos_is_initialized == FALSE ) {
00530     sciprint("xinit must be called before any action \r\n");
00531     return;
00532   }
00533   
00534   *narg=1;
00535   if ( ScilabGCPos.CurColorStatus ==1) 
00536     {
00537       *num = ScilabGCPos.CurColor +1 ;
00538       if (*verbose == 1) 
00539         sciprint("\n Color : %d\r\n",*num);
00540     }
00541   else 
00542     {
00543       *num = ScilabGCPos.CurPattern +1 ;
00544       if (*verbose == 1) 
00545         sciprint("\n Pattern : %d\r\n",*num);
00546     }
00547 }
00548 
00549 
00552 void C2F(getlastPos)(integer *verbose, integer *num, integer *narg, double *dummy)
00553 {
00554   if ( ScilabGCPos_is_initialized == FALSE ) {
00555     sciprint("xinit must be called before any action \r\n");
00556     return;
00557   }
00558   
00559   *num = ScilabGCPos.IDLastPattern +1 ;
00560   if (*verbose==1) 
00561     sciprint("\n Id of White Pattern %d\r\n",(int)*num);
00562   *narg=1;
00563 }
00564 
00572 #define MAXDASH 6
00573 static integer DashTabPos[MAXDASH][4] = {
00574   {2,5,2,5}, {7,2,7,2},  {2,2,2,2}, {7,2,2,2},
00575   {11,3,2,3}, {11,3,5,3}};
00576 
00577 /* old version of setdashPos retained for compatibility */
00578 
00579 void C2F(set_dash_or_color_Pos)(integer *value, integer *v2, integer *v3, integer *v4)
00580 {
00581   static integer  l2=4,l3 ;
00582   
00583   if ( ScilabGCPos_is_initialized == FALSE ) {
00584     sciprint("xinit must be called before any action \r\n");
00585     return;
00586   }
00587   
00588   if ( ScilabGCPos.CurColorStatus == 1) 
00589     {
00590       int i;
00591       i= Max(0,Min(*value-1,ScilabGCPos.Numcolors+1));
00592       ScilabGCPos.CurColor =i;
00593       C2F(set_cPos)(i);
00594     }
00595   else 
00596     {
00597       l3 = Max(0,Min(MAXDASH - 1,*value - 1));
00598       C2F(setdashstylePos)(&l3,DashTabPos[l3],&l2);
00599       ScilabGCPos.CurDashStyle = l3;
00600     }
00601 }
00602 
00603 
00604 void C2F(setdashPos)(integer *value, integer *v2, integer *v3, integer *v4)
00605 {
00606   static integer l2=4,l3 ;
00607   
00608   if ( ScilabGCPos_is_initialized == FALSE ) {
00609     sciprint("xinit must be called before any action \r\n");
00610     return;
00611   }
00612   
00613   l3 = Max(0,Min(MAXDASH - 1,*value - 1));
00614   C2F(setdashstylePos)(&l3,DashTabPos[l3],&l2);
00615   ScilabGCPos.CurDashStyle = l3;
00616 }
00617 
00618 void C2F(set_dash_and_color_Pos)(integer *value, integer *v2, integer *v3, integer *v4)
00619 {
00620   if ( ScilabGCPos_is_initialized == FALSE ) {
00621     sciprint("xinit must be called before any action \r\n");
00622     return;
00623   }
00624   
00625   C2F(setdashPos)(value, v2, v3, v4); 
00626   C2F(setpatternPos)(value+6, v2, v3, v4);
00627 }
00628 
00629 /* style arguments sets either dash style either color */
00630 
00631 void C2F(set_line_style_Pos)(integer *value, integer *v2, integer *v3, integer *v4)
00632 {
00633   integer j;
00634   
00635   if ( ScilabGCPos_is_initialized == FALSE ) {
00636     sciprint("xinit must be called before any action \r\n");
00637     return;
00638   }
00639   
00640   if (ScilabGCPos.CurColorStatus == 0)
00641     C2F(setdashPos)(value,PI0,PI0,PI0);
00642   else {
00643     j= ScilabGCPos.CurDashStyle + 1;
00644     C2F(setdashPos)(&j,PI0,PI0,PI0);
00645     C2F(setpatternPos)(value,PI0,PI0,PI0);
00646   }
00647 }
00648 
00654 void C2F(setdashstylePos)(integer *value, integer *xx, integer *n)
00655 {
00656   integer i ;
00657 
00658   if ( ScilabGCPos_is_initialized == FALSE ) {
00659     sciprint("xinit must be called before any action \r\n");
00660     return;
00661   }
00662   
00663   if ( *value == 0) FPRINTF((file,"\n[] 0 setdash"));
00664   else 
00665     {
00666       FPRINTF((file,"\n["));
00667       for (i=0;i<*n;i++)
00668         FPRINTF((file,"%d ",(int) (xx[i]*prec_fact)));
00669       FPRINTF((file,"] 0 setdash"));
00670     }
00671 }
00672 
00673 
00676 /* old version of getdashPos retained for compatibility */
00677 void C2F(get_dash_or_color_Pos)(integer *verbose, integer *value, integer *narg, double *dummy)
00678 {
00679   integer i ;
00680 
00681   if ( ScilabGCPos_is_initialized == FALSE ) {
00682     sciprint("xinit must be called before any action \r\n");
00683     return;
00684   }
00685   
00686   *narg =1 ;
00687   if ( ScilabGCPos.CurColorStatus ==1) 
00688     {
00689       *value= ScilabGCPos.CurColor + 1;
00690       if (*verbose == 1) sciprint("Color %d",(int)*value);
00691       return;
00692     }
00693   *value=ScilabGCPos.CurDashStyle+1;
00694   if ( *value == 1) 
00695     { if (*verbose == 1) sciprint("\nLine style = Line Solid");}
00696   else 
00697     {
00698       value[1]=4;
00699       *narg = value[1]+2;
00700       for ( i =0 ; i < value[1]; i++) value[i+2]=DashTabPos[*value-1][i];
00701       if (*verbose ==1 ) 
00702         {
00703           sciprint("\nDash Style %d:<",(int)*value);
00704           for ( i =0 ; i < value[1]; i++)
00705             sciprint("%d ",(int)value[i+2]);
00706           sciprint(">\n");
00707         }
00708     }
00709 }
00710 
00711 void C2F(getdashPos)(integer *verbose, integer *value, integer *narg, double *dummy)
00712 {
00713   integer i ;
00714 
00715   if ( ScilabGCPos_is_initialized == FALSE ) {
00716     sciprint("xinit must be called before any action \r\n");
00717     return;
00718   }
00719 
00720   *narg =1 ;
00721   *value=ScilabGCPos.CurDashStyle+1;
00722   if ( *value == 1) 
00723     { if (*verbose == 1) sciprint("\nLine style = Line Solid");}
00724   else 
00725     {
00726       value[1]=4;
00727       *narg = value[1]+2;
00728       for ( i =0 ; i < value[1]; i++) value[i+2]=DashTabPos[*value-1][i];
00729       if (*verbose ==1 ) 
00730         {
00731           sciprint("\nDash Style %d:<",(int)*value);
00732           for ( i =0 ; i < value[1]; i++)
00733             sciprint("%d ",(int)value[i+2]);
00734           sciprint(">\n");
00735         }
00736     }
00737 }
00738 
00739 void C2F(get_dash_and_color_Pos)(integer *verbose, integer *value, integer *narg, double *dummy)
00740 {
00741   if ( ScilabGCPos_is_initialized == FALSE ) {
00742     sciprint("xinit must be called before any action \r\n");
00743     return;
00744   }
00745   
00746   /*may be improved replacing 6 by narg */
00747   C2F(getdashPos)(verbose, value, narg,dummy);
00748   C2F(getpatternPos)(verbose, value+6, narg,dummy);
00749   *narg = 6;
00750 }
00751 
00752 void C2F(usecolorPos)(integer *num, integer *v2, integer *v3, integer *v4)
00753 {
00754   integer i;
00755 
00756   if ( ScilabGCPos_is_initialized == FALSE ) {
00757     sciprint("xinit must be called before any action \r\n");
00758     return;
00759   }
00760   
00761   i =  Min(Max(*num,0),1);
00762   FPRINTF((file,"\n%%--use color %d ",i));
00763   if ( ScilabGCPos.CurColorStatus != (int)i)
00764     {
00765       if (ScilabGCPos.CurColorStatus == 1) 
00766         {
00767           /* je passe de Couleur a n&b */
00768           /* remise des couleurs a vide */
00769           ScilabGCPos.CurColorStatus = 1;
00770           C2F(setpatternPos)((i=1,&i),PI0,PI0,PI0);
00771           /* passage en n&b */
00772           ScilabGCPos.CurColorStatus = 0;
00773           i= ScilabGCPos.CurPattern+1;
00774           C2F(setpatternPos)(&i,PI0,PI0,PI0);
00775           i= ScilabGCPos.CurDashStyle+1;
00776           C2F(setdashPos)(&i,PI0,PI0,PI0);
00777           ScilabGCPos.IDLastPattern = GREYNUMBER - 1;
00778           FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern));
00779           FPRINTF((file,"\n/Setgray { WhiteLev div setgray } def "));
00780           FPRINTF((file,"\n/Setcolor { WhiteLev div setgray } def "));
00781           FPRINTF((file,"\n/usecolor 0  def "));
00782         }
00783       else 
00784         {
00785           /* je passe en couleur */
00786           /* remise a zero des patterns et dash */
00787           /* remise des couleurs a vide */
00788           ScilabGCPos.CurColorStatus = 0;
00789           C2F(setpatternPos)((i=1,&i),PI0,PI0,PI0);
00790           C2F(setdashPos)((i=1,&i),PI0,PI0,PI0);
00791           /* passage en couleur  */
00792           ScilabGCPos.CurColorStatus = 1;
00793           i= ScilabGCPos.CurColor+1;
00794           C2F(setpatternPos)(&i,PI0,PI0,PI0);
00795           ScilabGCPos.IDLastPattern = ScilabGCPos.Numcolors - 1;
00796           FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern));
00797           FPRINTF((file,"\n/Setgray {/i exch def ColorR i get ColorG i get ColorB i get setrgbcolor } def "));
00798           FPRINTF((file,"\n/Setcolor {/i exch def ColorR i get ColorG i get ColorB i get setrgbcolor } def "));
00799           FPRINTF((file,"\n/usecolor 1 def "));
00800         }
00801     }
00802     FPRINTF((file,"\n%%--end use color %d ",ScilabGCPos.CurColorStatus));
00803 }
00804 
00805 
00806 void C2F(getusecolorPos)(integer *verbose, integer *num, integer *narg, double *dummy)
00807 { 
00808 
00809   if ( ScilabGCPos_is_initialized == FALSE ) {
00810     sciprint("xinit must be called before any action \r\n");
00811     return;
00812   }
00813 
00814   *num = ScilabGCPos.CurColorStatus;
00815   if (*verbose == 1) 
00816     sciprint("\n Use color %d\r\n",(int)*num);
00817   *narg=1;
00818 }
00819 
00820 
00821 /*******************************************************
00822  * Setting the colormap 
00823  * WARNING 
00824  * -------
00825  *   This function is only used when the Postscript driver is on 
00826  *   and xset('colormap',..) is used 
00827  *   (i.e driver('Pos');xset('colormap',....) 
00828  *   In the usual case (i.e when someone exports a graphic 
00829  *   which is displayed in a window) only the graphics 
00830  *   recorded commands are replayed and xset('colormap') belongs 
00831  *   to the non-recorded Scilab graphic commands 
00832  *   
00833  *   Only the <<current colormap>> of the window is translated 
00834  *   to Postscript when the Postscript file is opened 
00835  *   ( see  if (  CheckColormap(&m) == 1) in FileInt) 
00836  ******************************************************/
00837 /* add *v3 (OUT) to know if colormap allocation has succeeded: */
00838 /* 0: succeed */
00839 /* 1: failed */
00840 void setcolormapgPos(struct  BCG *Xgc,integer *v1,integer *v2, double *a, integer *v3);/* NG */
00841 
00842 
00843 void C2F(setgccolormapPos)(struct BCG *Xgc,integer m, double *a, integer *v3)
00844 {
00845   int i;
00846   int mm;
00847 
00848   if ( ScilabGCPos_is_initialized == FALSE ) {
00849     sciprint("xinit must be called before any action \r\n");
00850     return;
00851   }
00852   
00853   /* Checking RGB values */
00854   for (i = 0; i < m; i++) {
00855     if (a[i] < 0 || a[i] > 1 || a[i+m] < 0 || a[i+m] > 1 ||
00856         a[i+2*m] < 0 || a[i+2*m]> 1) {
00857       sciprint("RGB values must be between 0 and 1\n");
00858       *v3 = 1;
00859       return;
00860     }
00861   }
00862   Xgc->Numcolors = m;
00863   Xgc->IDLastPattern = m - 1;
00864   Xgc->NumForeground = m;
00865   Xgc->NumBackground = m + 1;
00866   FPRINTF((file,"\n/WhiteLev %d def",Xgc->IDLastPattern));
00867   WriteColorRGB("R",a,0);
00868   WriteColorRGB("G",a,1);
00869   WriteColorRGB("B",a,2);
00870   C2F(usecolorPos)((i=1,&i) ,PI0,PI0,PI0);
00871   C2F(setalufunction1Pos)((i=3,&i),PI0,PI0,PI0);
00872   C2F(setpatternPos)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);  
00873   C2F(setforegroundPos)((i=Xgc->NumForeground+1,&i),PI0,PI0,PI0);
00874   C2F(setbackgroundPos)((i=Xgc->NumForeground+2,&i),PI0,PI0,PI0);
00875 
00876   /* -------------------------------------------------------- */
00877   /* store the colormap for the get command too */
00878   /* F.Leray 04.10.05 */
00879   FREE(Xgc->Red);
00880   FREE(Xgc->Green);
00881   FREE(Xgc->Blue);
00882   
00883   /* don't forget black and white */
00884   mm = m;
00885   if (!(Xgc->Red = (float *) MALLOC(mm*sizeof(float)))) {
00886     sciprint("XgcAllocColors: unable to alloc\n");
00887     return;
00888   }
00889   if (!(Xgc->Green = (float *) MALLOC(mm*sizeof(float)))) {
00890     sciprint("XgcAllocColors: unable to alloc\n");
00891     FREE(Xgc->Red);
00892     return;
00893   }
00894   if (!(Xgc->Blue = (float *) MALLOC(mm*sizeof(float)))) {
00895     sciprint("XgcAllocColors: unable to alloc\n");
00896     FREE(Xgc->Red);
00897     FREE(Xgc->Green);
00898     return;
00899   }
00900 
00901 
00902   for(i=0;i<m;i++){
00903     Xgc->Red[i] = (float)a[i];
00904     Xgc->Green[i] = (float)a[i+m];
00905     Xgc->Blue[i] = (float)a[i+2*m]; 
00906   }
00907   /* -------------------------------------------------------- */
00908 }
00909 
00910 void C2F(getcolormapsizePos)(integer *v1, integer *v2, integer *v3, double *val)
00911 {
00912   if ( ScilabGCPos_is_initialized == FALSE ) {
00913     sciprint("xinit must be called before any action \r\n");
00914     *v3=1;
00915     return;
00916   }
00917 
00918   *v2 = ScilabGCPos.Numcolors;
00919 }
00920 
00921 void C2F(getcolormapPos)(integer *v1, integer *v2, integer *v3, double *val)
00922 {
00923   int m;
00924   int i;
00925   *v3 = 0;
00926 
00927   if ( ScilabGCPos_is_initialized == FALSE ) {
00928     sciprint("xinit must be called before any action \r\n");
00929     *v3=1;
00930     return;
00931   }
00932 
00933   m = ScilabGCPos.Numcolors;
00934 
00935   for (i = 0; i < m; i++) {
00936     val[i] = (double)ScilabGCPos.Red[i];
00937     val[i+m] = (double)ScilabGCPos.Green[i];
00938     val[i+2*m] = (double)ScilabGCPos.Blue[i];
00939   }
00940 
00941 /*   if (*v2 != 3 ||  *v1 < 0) { */
00942 /*     sciprint("Colormap must be a m x 3 array \n"); */
00943 /*     *v3 = 1; */
00944 /*     return; */
00945 /*   } */
00946 /*   m = *v1; */
00947 /*   C2F(setgccolormapPos)(&ScilabGCPos,m, a, v3); */
00948 }
00949 
00950 void C2F(setcolormapPos)(integer *v1, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, double *a)
00951 {
00952   int m;
00953 
00954   *v3 = 0;
00955   
00956   if ( ScilabGCPos_is_initialized == FALSE ) {
00957     sciprint("xinit must be called before any action \r\n");
00958     *v3=1;
00959     return;
00960   }
00961 
00962   if (*v2 != 3 ||  *v1 < 0) {
00963     sciprint("Colormap must be a m x 3 array \n");
00964     *v3 = 1;
00965     return;
00966   }
00967   m = *v1;
00968   C2F(setgccolormapPos)(&ScilabGCPos,m, a, v3);
00969 }
00970 
00971 /* NG beg */
00972 
00973 void setcolormapgPos(struct  BCG *Xgc,integer *m,integer *v2, double *a, integer *v3) /* NG */
00974 {
00975 
00976   C2F(setgccolormapPos)(Xgc,*m, a, v3);
00977 }
00978 
00979 /* NG end */
00980 
00981 static void WriteColorRGB(char *str, double *tab, int ind)
00982 {
00983   /* RGB are the columns of tab */ 
00984   int i;
00985 
00986   if ( ScilabGCPos_is_initialized == FALSE ) {
00987     sciprint("xinit must be called before any action \r\n");
00988     return;
00989   }
00990 
00991   FPRINTF((file,"\n/Color%s [",str));
00992   for ( i=0; i < ScilabGCPos.Numcolors; i++)
00993     {
00994       FPRINTF((file,"%f ",(float) tab[i+ ScilabGCPos.Numcolors*ind]));
00995       if ( (i % 10 ) == 0 ) FPRINTF((file,"\n"));
00996     }
00997   FPRINTF((file,"0.0 1.0] def"));
00998 }
00999 
01004 void ColorInit(void)
01005 {
01006   int   m = DEFAULTNUMCOLORS;
01007 
01008   ScilabGCPos.Numcolors = m;
01009   WriteColorRGBDef("R",default_colors,0);
01010   WriteColorRGBDef("G",default_colors,1);
01011   WriteColorRGBDef("B",default_colors,2);
01012 }
01013 
01014 static void WriteColorRGBDef(char *str, short unsigned int *tab, int ind)
01015 {
01016   int i;
01017 
01018   FPRINTF((file,"\n/Color%s [",str));
01019   for ( i=0; i < ScilabGCPos.Numcolors; i++)
01020     {
01021       FPRINTF((file,"%f ",(float) tab[3*i+ind]/255.0));
01022       if ( (i % 10 ) == 0 ) FPRINTF((file,"\n"));
01023     }
01024   FPRINTF((file,"0.0 1.0] def"));
01025 }
01026 
01027 void C2F(set_cPos)(integer i)
01028 {
01029   integer j;
01030   j=Max(Min(i,ScilabGCPos.Numcolors+1),0);
01031   FPRINTF((file,"\n%d Setcolor",(int)j));
01032 }
01033 
01034 
01037 void C2F(setbackgroundPos)(integer *num, integer *v2, integer *v3, integer *v4)
01038 { 
01039   if ( ScilabGCPos_is_initialized == FALSE ) {
01040     sciprint("xinit must be called before any action \r\n");
01041     return;
01042   }
01043 
01044   if (ScilabGCPos.CurColorStatus == 1) 
01045     {
01046       ScilabGCPos.NumBackground = Max(0,Min(*num - 1,ScilabGCPos.Numcolors + 1));
01047       FPRINTF((file,"\n/background %d def PaintBackground",ScilabGCPos.NumBackground));
01048     }
01049 }
01050 
01051 void C2F(getbackgroundPos)(integer *verbose, integer *num, integer *narg, double *dummy)
01052 { 
01053   *narg=1;
01054 
01055   if ( ScilabGCPos_is_initialized == FALSE ) {
01056     sciprint("xinit must be called before any action \r\n");
01057     return;
01058   }
01059 
01060   if ( ScilabGCPos.CurColorStatus == 1 ) 
01061     {
01062       *num = ScilabGCPos.NumBackground + 1;
01063     }
01064   else 
01065     {
01066       *num = 1;
01067     }
01068   if (*verbose == 1) 
01069     sciprint("\n Background : %d\r\n",*num);
01070 }
01071 
01072 
01075 void C2F(setforegroundPos)(integer *num, integer *v2, integer *v3, integer *v4)
01076 { 
01077   if ( ScilabGCPos_is_initialized == FALSE ) {
01078     sciprint("xinit must be called before any action \r\n");
01079     return;
01080   }
01081   
01082   if (ScilabGCPos.CurColorStatus == 1) 
01083     {
01084       ScilabGCPos.NumForeground = Max(0,Min(*num - 1,ScilabGCPos.Numcolors + 1));
01085     }
01086 }
01087 
01088 void C2F(getforegroundPos)(integer *verbose, integer *num, integer *narg, double *dummy)
01089 { 
01090   if ( ScilabGCPos_is_initialized == FALSE ) {
01091     sciprint("xinit must be called before any action \r\n");
01092     return;
01093   }
01094   
01095   *narg=1;
01096   if ( ScilabGCPos.CurColorStatus == 1 ) 
01097     {
01098       *num = ScilabGCPos.NumForeground + 1;
01099     }
01100   else 
01101     {
01102       *num = 1; 
01103     }
01104   if (*verbose == 1) 
01105     sciprint("\n Foreground : %d\r\n",*num);
01106 }
01107 
01108 
01109 
01112 void C2F(sethidden3dPos)(integer *num, integer *v2, integer *v3, integer *v4)
01113 {   
01114   if ( ScilabGCPos_is_initialized == FALSE ) {
01115     sciprint("xinit must be called before any action \r\n");
01116     return;
01117   }
01118 
01119   if (ScilabGCPos.CurColorStatus == 1) 
01120     {
01121       /* es: Max(0,... -> Max(-1,... */
01122       /* S Mottelet: Max(-1,... -> Max(-2,...  to take into account the value -1 */
01123       ScilabGCPos.NumHidden3d = Max(-2,Min(*num - 1,ScilabGCPos.Numcolors + 1));
01124     }
01125 }
01126 
01127 void C2F(gethidden3dPos)(integer *verbose, integer *num, integer *narg, double *dummy)
01128 { 
01129   if ( ScilabGCPos_is_initialized == FALSE ) {
01130     sciprint("xinit must be called before any action \r\n");
01131     return;
01132   }
01133   
01134   *narg=1;
01135   if ( ScilabGCPos.CurColorStatus == 1 ) 
01136     {
01137       *num = ScilabGCPos.NumHidden3d + 1;
01138     }
01139   else 
01140     {
01141       *num = 1; 
01142     }
01143   if (*verbose == 1) 
01144     sciprint("\n Hidden3d : %d\r\n",*num);
01145 }
01146 
01147 
01148 
01149 /*--------------------------------------------------------
01150 \encadre{general routines accessing the  set<> or get<>
01151  routines } 
01152 -------------------------------------------------------*/
01153 
01154 void C2F(semptyPos)(integer *v1, integer *v2, integer *v3, integer *v4)
01155 {
01156   /* if ( *verbose ==1 ) sciprint("\n No operation "); */
01157 }
01158 
01159 void C2F(setwwhowPos)(integer *verbose, integer *v2, integer *v3, integer *v4)
01160 {
01161   FPRINTF((file,"\n%% SPLIT HERE"));
01162 
01163 }
01164 
01165 void C2F(gemptyPos)(integer *verbose, integer *v2, integer *v3, double *dummy)
01166 {
01167   if ( *verbose ==1 ) sciprint("\n No operation ");
01168 }
01169 
01170 #define NUMSETFONC 32 /* NG */
01171 
01174 struct bgc { char *name ;
01175              void  (*setfonc )() ;
01176              void (*getfonc )() ;}
01177   ScilabGCTabPos[] = {
01178     {"alufunction",C2F(setalufunction1Pos),C2F(getalufunctionPos)},
01179     {"background",C2F(setbackgroundPos),C2F(getbackgroundPos)},
01180     {"clipoff",C2F(unsetclipPos),C2F(getclipPos)},
01181     {"clipping",C2F(setclipPos),C2F(getclipPos)},
01182     {"cmap_size",C2F(semptyPos),C2F(getcolormapsizePos)},
01183     {"color",C2F(setpatternPos),C2F(getpatternPos)},
01184     {"colormap",C2F(setcolormapPos),C2F(getcolormapPos)},
01185     {"dashes",C2F(set_dash_or_color_Pos),C2F(get_dash_or_color_Pos)},
01186     {"default",InitScilabGCPos, C2F(gemptyPos)},
01187     {"figure",C2F(setscilabFigurePos),C2F(getscilabFigurePos)},/* NG */
01188     {"font",C2F(xsetfontPos),C2F(xgetfontPos)},
01189     {"foreground",C2F(setforegroundPos),C2F(getforegroundPos)},
01190     {"gc",C2F(semptyPos),C2F(getscilabxgcPos)},/* NG */
01191     {"gccolormap",C2F(setgccolormapPos),C2F(gemptyPos)},/* NG */
01192     {"hidden3d",C2F(sethidden3dPos),C2F(gethidden3dPos)},
01193     {"lastpattern",C2F(semptyPos),C2F(getlastPos)},
01194     {"line mode",C2F(setabsourelPos),C2F(getabsourelPos)},
01195     {"line style",C2F(setdashPos),C2F(getdashPos)},
01196     {"mark",C2F(xsetmarkPos),C2F(xgetmarkPos)},
01197     {"pattern",C2F(setpatternPos),C2F(getpatternPos)},
01198     {"pixmap",C2F(semptyPos),C2F(gemptyPos)},
01199     {"thickness",C2F(setthicknessPos),C2F(getthicknessPos)},
01200     {"use color",C2F(usecolorPos),C2F(getusecolorPos)},
01201     {"viewport",C2F(semptyPos),C2F(gemptyPos)},
01202     {"wdim",C2F(setwindowdimPos),C2F(getwindowdimPos)},
01203     {"white",C2F(semptyPos),C2F(getlastPos)},
01204     {"window",C2F(setcurwinPos),C2F(getcurwinPos)},
01205     {"wpdim",C2F(semptyPos),C2F(gemptyPos)},
01206     {"wpos",C2F(setwindowposPos),C2F(getwindowposPos)},
01207     {"wresize",C2F(semptyPos),C2F(gemptyPos)},
01208     {"wshow",C2F(setwwhowPos),C2F(gemptyPos)},
01209     {"wwpc",C2F(semptyPos),C2F(gemptyPos)},
01210   };
01211 
01212 #ifdef lint
01213 
01214 /* pour forcer linteger a verifier ca */
01215 
01216 static  test(str,flag,verbose,x1,x2,x3,x4,x5)
01217      char str[];
01218      integer flag ;
01219      integer  *verbose,*x1,*x2,*x3,*x4,*x5;
01220 { 
01221   double *dv;
01222   C2F(setalufunction1Pos)(x1,x2,x3,x4);C2F(getalufunctionPos)(verbose,x1,x2,dv);
01223   C2F(setclipPos)(x1,x2,x3,x4);C2F(getclipPos)(verbose,x1,x2,dv);
01224   C2F(setdashPos)(x1,x2,x3,x4);C2F(getdashPos)(verbose,x1,x2,dv);
01225   ScilabGCPos_is_initialized = TRUE; /* add the flag ScilabGCPos_is_initialized to test if xinit has been called */
01226   InitScilabGCPos(x1,x2,x3,x4); C2F(gemptyPos)(verbose,x1,x2,dv);
01227   C2F(xsetfontPos)(x1,x2,x3,x4);C2F(xgetfontPos)(verbose,x1,x2,dv);
01228   C2F(setabsourelPos)(x1,x2,x3,x4);C2F(getabsourelPos)(verbose,x1,x2,dv);
01229   C2F(xsetmarkPos)(x1,x2,x3,x4);C2F(xgetmarkPos)(verbose,x1,x2,dv);
01230   C2F(setpatternPos)(x1,x2,x3,x4);C2F(getpatternPos)(verbose,x1,x2,dv);
01231   C2F(setthicknessPos)(x1,x2,x3,x4);C2F(getthicknessPos)(verbose,x1,x2,dv);
01232   C2F(usecolorPos)(x1,x2,x3,x4);C2F(gemptyPos)(verbose,x1,x2,dv);
01233   C2F(setwindowdimPos)(x1,x2,x3,x4);C2F(getwindowdimPos)(verbose,x1,x2,dv);
01234   C2F(semptyPos)(x1,x2,x3,x4);C2F(getlastPos)(verbose,x1,x2,dv);
01235   C2F(setcurwinPos)(x1,x2,x3,x4);C2F(getcurwinPos)(verbose,x1,x2,dv);
01236   C2F(setwindowposPos)(x1,x2,x3,x4);getwindowposPos(verbose,x1,x2,dv);
01237 }
01238 
01239 #endif 
01240 
01241 
01242 void C2F(scilabgcgetPos)(char *str, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, double *dv1, double *dv2, double *dv3, double *dv4)
01243 {
01244   int x6=0;
01245   C2F(ScilabGCGetorSetPos)(str,(integer)1L,verbose,x1,x2,x3,x4,x5,&x6,dv1);
01246 }
01247 
01248 void C2F(scilabgcsetPos)(char *str, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1, double *dv2, double *dv3, double *dv4)
01249 {
01250  integer verbose ;
01251  verbose = 0 ;
01252  C2F(ScilabGCGetorSetPos)(str,(integer)0L,&verbose,x1,x2,x3,x4,x5,x6,dv1);}
01253 
01254 void C2F(ScilabGCGetorSetPos)(char *str, integer flag, integer *verbose, integer *x1, integer *x2, integer *x3, integer *x4, integer *x5, integer *x6, double *dv1)
01255 { integer i ;
01256   for (i=0; i < NUMSETFONC ; i++)
01257      {
01258        integer j;
01259        j = strcmp(str,ScilabGCTabPos[i].name);
01260        if ( j == 0 ) 
01261          { if (*verbose == 1)
01262              sciprint("\nGetting Info on %s\r\n",str);
01263            if (flag == 1)
01264              (ScilabGCTabPos[i].getfonc)(verbose,x1,x2,dv1);
01265            else 
01266              (ScilabGCTabPos[i].setfonc)(x1,x2,x3,x4,x5,x6,dv1);
01267            return;}
01268        else 
01269          { if ( j <= 0)
01270              {
01271                sciprint("\nUnknow Postscript operator <%s>\r\n",str);
01272                *x1=1;*x2=0;
01273                return;
01274              }
01275          }
01276      }
01277   sciprint("\n Unknow Postscript operator <%s>\r\n",str);
01278   *x1=1;*x2=0;
01279 }
01280 
01281 /*-----------------------------------------------------------
01282 \encadre{Functions for drawing}
01283 -----------------------------------------------------------*/
01284 
01285 
01286 
01287 /*----------------------------------------------------
01288 \encadre{display of a string
01289  at (x,y) position whith angle (alpha). Angles in degree
01290  positive when clockwise. If *flag ==1 a framed  box is added 
01291  around the string.}
01292 -----------------------------------------------------*/
01293 
01294 void C2F(displaystringPos)(char *string, integer *x, integer *y, integer *v1, integer *flag, integer *v6, integer *v7, double *angle, double *dv2, double *dv3, double *dv4)
01295 {     
01296   integer i,rect[4] ;
01297   int yn_ = (int) (*y + ascentPos());
01298 
01299   if ( ScilabGCPos_is_initialized == FALSE ) {
01300     sciprint("xinit must be called before any action \r\n");
01301     return;
01302   }
01303   
01304   C2F(boundingboxPos)(string,x,&yn_,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01305   FPRINTF((file,"\n("));
01306   for ( i=0; i < (int)strlen(string);i++)
01307     {
01308       if (string[i]== '(' || string[i] == ')' )
01309         FPRINTF((file,"%c%c",'\\',string[i]));
01310       else 
01311         FPRINTF((file,"%c",string[i]));
01312     }
01313   FPRINTF((file,") %d %d %d %5.2f [%d %d %d %d] Show",
01314            (int)*x,yn_ ,
01315            (int)*flag,*angle,(int)rect[0],
01316            (int)rect[1],(int)rect[2],(int)rect[3]));
01317   
01318   FPRINTF((file,"\n%%Latex:\\myput{%d}{%d}{%d}{%s}",
01319            (int)*x,def_height*prec_fact - yn_, 
01320            fontsizePos ()/2,
01321            string));
01322  }
01323 
01324 /*** ajouts q&d en attendant mieux.... Bruno (le 24 Nov 2002) ***/
01325 
01326 struct posfont  /* a data type for handling a postscript font in scilab */
01327 {
01328   char *name;           
01329   int asc;              /* max ascender of all printable ascii char */
01330   int des;              /* min descender of all printable ascii char */
01331   int mean_char_width;  /* the width used for all char if fixed_pitch=1 or for */ 
01332                         /* printable non ascii characters when fixed_pitch=0 */
01333   int fixed_pitch;
01334   int *char_width;      /* NULL if fixed_pitch = 1 (mean_char_width is used instead)  */
01335                         /* else give the width of all printable ascii character (from 32 to 126) */
01336 };
01337 
01338 typedef struct posfont PosFont;
01339 
01341  static PosFont Courier = { "Courier",
01342                              750,         /* Ascender */
01343                             -250,         /* Descender */
01344                              600,         /* Mean Width */
01345                              1,           /* Is Fixed Pitch */
01346                              NULL };
01347    
01348    
01350  static int WidthSymbol[] = { 250 , 333 , 713 , 500 , 549 , 833 , 778 , 439 , 333 , 333 ,
01351                               500 , 549 , 250 , 549 , 250 , 278 , 500 , 500 , 500 , 500 ,
01352                               500 , 500 , 500 , 500 , 500 , 500 , 278 , 278 , 549 , 549 ,
01353                               549 , 444 , 549 , 722 , 667 , 722 , 612 , 611 , 763 , 603 ,
01354                               722 , 333 , 631 , 722 , 686 , 889 , 722 , 722 , 768 , 741 ,
01355                               556 , 592 , 611 , 690 , 439 , 768 , 645 , 795 , 611 , 333 ,
01356                               863 , 333 , 658 , 500 , 500 , 631 , 549 , 549 , 494 , 439 ,
01357                               521 , 411 , 603 , 329 , 603 , 549 , 549 , 576 , 521 , 549 ,
01358                               549 , 521 , 549 , 603 , 439 , 576 , 713 , 686 , 493 , 686 ,
01359                               494 , 480 , 200 , 480 , 549 };
01360  static PosFont Symbol = { "Symbol",
01361                             917,         /* Ascender */
01362                            -252,         /* Descender */
01363                             548,         /* Mean Width */
01364                             0,           /* Is Fixed Pitch */
01365                             WidthSymbol };
01366    
01367    
01369  static int WidthTimesR[] = { 250 , 333 , 408 , 500 , 500 , 833 , 778 , 333 , 333 , 333 ,
01370                               500 , 564 , 250 , 564 , 250 , 278 , 500 , 500 , 500 , 500 ,
01371                               500 , 500 , 500 , 500 , 500 , 500 , 278 , 278 , 564 , 564 ,
01372                               564 , 444 , 921 , 722 , 667 , 667 , 722 , 611 , 556 , 722 ,
01373                               722 , 333 , 389 , 722 , 611 , 889 , 722 , 722 , 556 , 722 ,
01374                               667 , 556 , 611 , 722 , 722 , 944 , 722 , 722 , 611 , 333 ,
01375                               278 , 333 , 469 , 500 , 333 , 444 , 500 , 444 , 500 , 444 ,
01376                               333 , 500 , 500 , 278 , 278 , 500 , 278 , 778 , 500 , 500 ,
01377                               500 , 500 , 333 , 389 , 278 , 500 , 500 , 722 , 500 , 500 ,
01378                               444 , 480 , 200 , 480 , 541 };
01379  static PosFont TimesR = { "Times-Roman",
01380                             727,         /* Ascender */
01381                            -218,         /* Descender */
01382                             512,         /* Mean Width */
01383                             0,           /* Is Fixed Pitch */
01384                             WidthTimesR };
01385    
01386    
01388  static int WidthTimesI[] = { 250 , 333 , 420 , 500 , 500 , 833 , 778 , 333 , 333 , 333 ,
01389                               500 , 675 , 250 , 333 , 250 , 278 , 500 , 500 , 500 , 500 ,
01390                               500 , 500 , 500 , 500 , 500 , 500 , 333 , 333 , 675 , 675 ,
01391                               675 , 500 , 920 , 611 , 611 , 667 , 722 , 611 , 611 , 722 ,
01392                               722 , 333 , 444 , 667 , 556 , 833 , 667 , 722 , 611 , 722 ,
01393                               611 , 500 , 556 , 722 , 611 , 833 , 611 , 556 , 556 , 389 ,
01394                               278 , 389 , 422 , 500 , 333 , 500 , 500 , 444 , 500 , 444 ,
01395                               278 , 500 , 500 , 278 , 278 , 444 , 278 , 722 , 500 , 500 ,
01396                               500 , 500 , 389 , 389 , 278 , 500 , 444 , 667 , 444 , 444 ,
01397                               389 , 400 , 275 , 400 , 541 };
01398  static PosFont TimesI = { "Times-Italic",
01399                             731,         /* Ascender */
01400                            -209,         /* Descender */
01401                             505,         /* Mean Width */
01402                             0,           /* Is Fixed Pitch */
01403                             WidthTimesI };
01404    
01405    
01407  static int WidthTimesB[] = { 250 , 333 , 555 , 500 , 500 ,1000 , 833 , 333 , 333 , 333 ,
01408                               500 , 570 , 250 , 570 , 250 , 278 , 500 , 500 , 500 , 500 ,
01409                               500 , 500 , 500 , 500 , 500 , 500 , 333 , 333 , 570 , 570 ,
01410                               570 , 500 , 930 , 722 , 667 , 722 , 722 , 667 , 611 , 778 ,
01411                               778 , 389 , 500 , 778 , 667 , 944 , 722 , 778 , 611 , 778 ,
01412                               722 , 556 , 667 , 722 , 722 ,1000 , 722 , 722 , 667 , 333 ,
01413                               278 , 333 , 581 , 500 , 333 , 500 , 556 , 444 , 556 , 444 ,
01414                               333 , 500 , 556 , 278 , 333 , 556 , 278 , 833 , 556 , 500 ,
01415                               556 , 556 , 444 , 389 , 333 , 556 , 500 , 722 , 500 , 500 ,
01416                               444 , 394 , 220 , 394 , 520 };
01417  static PosFont TimesB = { "Times-Bold",
01418                             750,         /* Ascender */
01419                            -206,         /* Descender */
01420                             536,         /* Mean Width */
01421                             0,           /* Is Fixed Pitch */
01422                             WidthTimesB };
01423    
01424    
01426  static int WidthTimesBI[] = { 250 , 389 , 555 , 500 , 500 , 833 , 778 , 333 , 333 , 333 ,
01427                                500 , 570 , 250 , 606 , 250 , 278 , 500 , 500 , 500 , 500 ,
01428                                500 , 500 , 500 , 500 , 500 , 500 , 333 , 333 , 570 , 570 ,
01429                                570 , 500 , 832 , 667 , 667 , 667 , 722 , 667 , 667 , 722 ,
01430                                778 , 389 , 500 , 667 , 611 , 889 , 722 , 722 , 611 , 722 ,
01431                                667 , 556 , 611 , 722 , 667 , 889 , 667 , 611 , 611 , 333 ,
01432                                278 , 333 , 570 , 500 , 333 , 500 , 500 , 444 , 500 , 444 ,
01433                                333 , 500 , 556 , 278 , 278 , 500 , 278 , 778 , 556 , 500 ,
01434                                500 , 500 , 389 , 389 , 278 , 556 , 444 , 667 , 500 , 444 ,
01435                                389 , 348 , 220 , 348 , 570 };
01436  static PosFont TimesBI = { "Times-BoldItalic",
01437                              733,         /* Ascender */
01438                             -208,         /* Descender */
01439                              515,         /* Mean Width */
01440                              0,           /* Is Fixed Pitch */
01441                              WidthTimesBI };
01442    
01444  static int WidthHelvetica[] = { 278 , 278 , 355 , 556 , 556 , 889 , 667 , 222 , 333 , 333 ,
01445                                  389 , 584 , 278 , 333 , 278 , 278 , 556 , 556 , 556 , 556 ,
01446                                  556 , 556 , 556 , 556 , 556 , 556 , 278 , 278 , 584 , 584 ,
01447                                  584 , 556 ,1015 , 667 , 667 , 722 , 722 , 667 , 611 , 778 ,
01448                                  722 , 278 , 500 , 667 , 556 , 833 , 722 , 778 , 667 , 778 ,
01449                                  722 , 667 , 611 , 722 , 667 , 944 , 667 , 667 , 611 , 278 ,
01450                                  278 , 278 , 469 , 556 , 222 , 556 , 556 , 500 , 556 , 556 ,
01451                                  278 , 556 , 556 , 222 , 222 , 500 , 222 , 833 , 556 , 556 ,
01452                                  556 , 556 , 333 , 500 , 278 , 556 , 500 , 722 , 500 , 500 ,
01453                                  500 , 334 , 260 , 334 , 584 };
01454  static PosFont Helvetica = { "Helvetica",
01455                                775,         /* Ascender */
01456                               -220,         /* Descender */
01457                                526,         /* Mean Width */
01458                                0,           /* Is Fixed Pitch */
01459                                WidthHelvetica };
01460    
01461    
01463  static int WidthHelveticaB[] = { 278 , 333 , 474 , 556 , 556 , 889 , 722 , 278 , 333 , 333 ,
01464                                   389 , 584 , 278 , 333 , 278 , 278 , 556 , 556 , 556 , 556 ,
01465                                   556 , 556 , 556 , 556 , 556 , 556 , 333 , 333 , 584 , 584 ,
01466                                   584 , 611 , 975 , 722 , 722 , 722 , 722 , 667 , 611 , 778 ,
01467                                   722 , 278 , 556 , 722 , 611 , 833 , 722 , 778 , 667 , 778 ,
01468                                   722 , 667 , 611 , 722 , 667 , 944 , 667 , 667 , 611 , 333 ,
01469                                   278 , 333 , 584 , 556 , 278 , 556 , 611 , 556 , 611 , 556 ,
01470                                   333 , 611 , 611 , 278 , 278 , 556 , 278 , 889 , 611 , 611 ,
01471                                   611 , 611 , 389 , 556 , 333 , 611 , 556 , 778 , 556 , 556 ,
01472                                   500 , 389 , 280 , 389 , 584 };
01473  static PosFont HelveticaB = { "Helvetica-Bold",
01474                                 775,         /* Ascender */
01475                                -217,         /* Descender */
01476                                 551,         /* Mean Width */
01477                                 0,           /* Is Fixed Pitch */
01478                                 WidthHelveticaB };
01479    
01480    
01482  static int WidthHelveticaO[] = { 278 , 278 , 355 , 556 , 556 , 889 , 667 , 222 , 333 , 333 ,
01483                                   389 , 584 , 278 , 333 , 278 , 278 , 556 , 556 , 556 , 556 ,
01484                                   556 , 556 , 556 , 556 , 556 , 556 , 278 , 278 , 584 , 584 ,
01485                                   584 , 556 ,1015 , 667 , 667 , 722 , 722 , 667 , 611 , 778 ,
01486                                   722 , 278 , 500 , 667 , 556 , 833 , 722 , 778 , 667 , 778 ,
01487                                   722 , 667 , 611 , 722 , 667 , 944 , 667 , 667 , 611 , 278 ,
01488                                   278 , 278 , 469 , 556 , 222 , 556 , 556 , 500 , 556 , 556 ,
01489                                   278 , 556 , 556 , 222 , 222 , 500 , 222 , 833 , 556 , 556 ,
01490                                   556 , 556 , 333 , 500 , 278 , 556 , 500 , 722 , 500 , 500 ,
01491                                   500 , 334 , 260 , 334 , 584 };
01492  static PosFont HelveticaO = { "Helvetica-Oblique",
01493                                 775,         /* Ascender */
01494                                -220,         /* Descender */
01495                                 526,         /* Mean Width */
01496                                 0,           /* Is Fixed Pitch */
01497                                 WidthHelveticaO };
01498    
01499    
01501  static int WidthHelveticaBO[] = { 278 , 333 , 474 , 556 , 556 , 889 , 722 , 278 , 333 , 333 ,
01502                                    389 , 584 , 278 , 333 , 278 , 278 , 556 , 556 , 556 , 556 ,
01503                                    556 , 556 , 556 , 556 , 556 , 556 , 333 , 333 , 584 , 584 ,
01504                                    584 , 611 , 975 , 722 , 722 , 722 , 722 , 667 , 611 , 778 ,
01505                                    722 , 278 , 556 , 722 , 611 , 833 , 722 , 778 , 667 , 778 ,
01506                                    722 , 667 , 611 , 722 , 667 , 944 , 667 , 667 , 611 , 333 ,
01507                                    278 , 333 , 584 , 556 , 278 , 556 , 611 , 556 , 611 , 556 ,
01508                                    333 , 611 , 611 , 278 , 278 , 556 , 278 , 889 , 611 , 611 ,
01509                                    611 , 611 , 389 , 556 , 333 , 611 , 556 , 778 , 556 , 556 ,
01510                                    500 , 389 , 280 , 389 , 584 };
01511  static PosFont HelveticaBO = { "Helvetica-BoldOblique",
01512                                  775,         /* Ascender */
01513                                 -217,         /* Descender */
01514                                  551,         /* Mean Width */
01515                                  0,           /* Is Fixed Pitch */
01516                                  WidthHelveticaBO };
01517 
01518    
01519 #define NB_MAX_POS_FONT 10
01520 static PosFont *FontArray[NB_MAX_POS_FONT] = {&Courier, &Symbol, 
01521                                               &TimesR,    &TimesI,     &TimesB,     &TimesBI,
01522                                               &Helvetica, &HelveticaO, &HelveticaB, &HelveticaBO};
01523 
01524 #define NB_MAX_SIZES 6
01525 static int Font_Size_in_pts[NB_MAX_SIZES] = {8, 10, 12, 14, 18, 24};
01526 
01527 
01528 static void PosStrBox(char *str, integer id_font, integer id_size, 
01529                       double *w, double *h)
01530 {
01531   /*
01532    *   PURPOSE : computes the width w and the height h of a string in postscript  
01533    *             
01534    *      NOTE : the computed h is for most cases too large because I use the
01535    *             max ascender and descender of the font (the previus datas
01536    *             font tables contains only the width of all the printable
01537    *             ascii characters).
01538    */
01539   
01540   PosFont *font=FontArray[id_font];
01541   int nb_pts = Font_Size_in_pts[id_size];
01542 
01543   /* computes w */
01544   if ( font->fixed_pitch )
01545     *w =  strlen(str) * font->mean_char_width*0.001*nb_pts;
01546   else
01547     {
01548       int l=0, c = *str;
01549       while (c != '\0')
01550         {
01551           if (32 <= c && c <= 126)
01552             l += font->char_width[c-32];
01553           else
01554             l += font->mean_char_width;
01555           c = *(++str);
01556         }
01557       *w = l*0.001*nb_pts;
01558     }
01559 
01560   /* computes h */
01561   *h = (font->asc - font->des)*0.001*nb_pts;
01562 }
01563 
01564 static double PosStrAsc(integer id_font, integer id_size)
01565 {
01566   /*  correction pour centrer verticalement une chaine postscript il me semble ?
01567    *             a partir de la hauteur de la boite, h (= ascender max - descender max)
01568    *             on calcule  Dy = h/2 pour centrer verticalement mais ceci n'est pas                  
01569    *    -    -   tres precis => il faut une correction (et descender/2 a l'air de
01570    *    |    |                                          fonctionner...)
01571    *    |    | ascender max
01572    *    | h  |
01573    *    |    -
01574    *    |    | descender max (valeur negative)
01575    *    -    -
01576    *
01577    */
01578   PosFont *font=FontArray[id_font];
01579   int nb_pts = Font_Size_in_pts[id_size];
01580 
01581   return ( font->des*0.5*0.001*nb_pts );
01582 }
01583 /*** fin des ajouts de Bruno  ***/
01584 
01585 
01587 void C2F(boundingboxPos)(char *string, integer *x, integer *y, integer *rect, integer *v5, 
01588                          integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01589 {
01590   integer verbose,nargs,font[2];
01591   double h, w;
01592   verbose=0;
01593   C2F(xgetfontPos)(&verbose,font,&nargs,vdouble);
01594   PosStrBox(string, font[0], font[1], &w, &h);
01595   rect[0]= *x;
01596   rect[1]= (integer)(*y-h*prec_fact);
01597   rect[2]= (integer)(w*prec_fact);
01598   rect[3]= (integer)(h*prec_fact);
01599 }
01600 
01601 /* approximation of ascent using (asc + dsc) /2  (modified by bruno) */
01602 static double ascentPos() 
01603 { 
01604   static integer verbose=0,nargs,font[2];
01605   C2F(xgetfontPos)(&verbose,font,&nargs,vdouble);
01606   return (PosStrAsc(font[0], font[1]) * prec_fact);
01607 }
01608 
01609 
01611 void C2F(drawlinePos)(integer *xx1, integer *yy1, integer *x2, integer *y2)
01612 {
01613   if ( ScilabGCPos_is_initialized == FALSE ) {
01614     sciprint("xinit must be called before any action \r\n");
01615     return;
01616   }
01617   
01618   FPRINTF((file,"\n %d %d %d %d L",(int)*xx1,(int)*yy1,(int)*x2,(int)*y2));
01619 }
01620 
01621 
01625 void C2F(drawsegmentsPos)(char *str, integer *vx, integer *vy, integer *n, integer *style, integer *iflag, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01626 {
01627   integer verbose=0,Dnarg,Dvalue[10],NDvalue;
01628   int i;
01629 
01630   if ( ScilabGCPos_is_initialized == FALSE ) {
01631     sciprint("xinit must be called before any action \r\n");
01632     return;
01633   }
01634   
01635   /* store the current values */
01636   C2F(getpatternPos)(&verbose,Dvalue,&Dnarg,vdouble);
01637   if ((int)  *iflag == 0 )
01638     {
01640       NDvalue= (*style < 1) ? Dvalue[0] : *style; 
01641       C2F(WriteGenericPos)("drawsegs",(integer)1L,(*n)*2,vx,vy,*n,(integer)1L,&NDvalue); 
01642     }
01643   else
01644     {
01645       for ( i=0 ; i < *n/2 ; i++) 
01646         {
01647           integer NDvalue_;
01648           NDvalue_ = style[i];
01649           C2F(WriteGenericPos)("drawsegs",(integer)1L,(integer)4L,&vx[2*i],&vy[2*i],(integer)2L,(integer)1L,&NDvalue_);
01650         }
01651     }
01652   /*C2F(set_dash_and_color_Pos)( Dvalue,PI0,PI0,PI0);*/
01653 }
01654 
01657 void C2F(drawarrowsPos)(char *str, integer *vx, integer *vy, integer *n, integer *as, integer *style, integer *iflag, double *dv1, double *dv2, double *dv3, double *dv4)
01658 {
01659   integer verbose=0,Dnarg,Dvalue[10],NDvalue;
01660   int i;
01661   
01662   if ( ScilabGCPos_is_initialized == FALSE ) {
01663     sciprint("xinit must be called before any action \r\n");
01664     return;
01665   }
01666   
01667   C2F(get_dash_and_color_Pos)(&verbose,Dvalue,&Dnarg,vdouble);
01668   /* store the current values */
01669   if ((int)  *iflag == 0 )
01670     {
01672       NDvalue=(*style < 1) ?  Dvalue[0] : *style;
01673       C2F(set_line_style_Pos)(&NDvalue,PI0,PI0,PI0);
01674       C2F(WriteGenericPos)("drawarrows",(integer)1L,(*n)*2,vx,vy,*n,(integer)1L,as); 
01675     }
01676   else
01677     {
01678       for ( i=0 ; i < *n/2 ; i++) 
01679         {
01680           NDvalue = style[i];
01681           C2F(set_line_style_Pos)(&NDvalue,PI0,PI0,PI0);
01682           /*C2F(setpatternPos)(&NDvalue,PI0,PI0,PI0); commented out ss 13/09/00 */
01683           C2F(WriteGenericPos)("drawarrows",(integer)1L,(integer)4L,&vx[2*i],&vy[2*i],(integer)2L,(integer)1L,as);
01684         }
01685     }
01686   C2F(set_dash_and_color_Pos)( Dvalue,PI0,PI0,PI0);
01687 }
01688 
01697 void C2F(drawrectanglesPos)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01698 {
01699   integer cpat,verb=0,num;
01700 
01701   if ( ScilabGCPos_is_initialized == FALSE ) {
01702     sciprint("xinit must be called before any action \r\n");
01703     return;
01704   }
01705   
01706   C2F(getpatternPos)(&verb,&cpat,&num,vdouble);
01707   C2F(WriteGenericPos)("drawbox",*n,(integer)4L,vects,vects,4*(*n),(integer)0L,fillvect);
01708   C2F(setpatternPos)(&(cpat),PI0,PI0,PI0);
01709 }
01710 
01711 void C2F(drawrectanglePos)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01712 { 
01713   integer i = 1;
01714   integer fvect[1] ;
01715   integer vects[4];
01716   
01717   if ( ScilabGCPos_is_initialized == FALSE ) {
01718     sciprint("xinit must be called before any action \r\n");
01719     return;
01720   }
01721 
01722   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01723   vects[3]= *height;
01725   fvect[0] = 0;
01726   C2F(drawrectanglesPos)(str,vects,fvect,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01727 }
01728 
01731 void C2F(fillrectanglePos)(char *str, integer *x, integer *y, integer *width, integer *height, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01732 { 
01733   integer i = 1;
01734   integer vects[4];
01735   integer cpat,verb=0,num;
01736 
01737   if ( ScilabGCPos_is_initialized == FALSE ) {
01738     sciprint("xinit must be called before any action \r\n");
01739     return;
01740   }
01741   
01742   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01743   vects[3]= *height ; 
01744   C2F(getpatternPos)(&verb,&cpat,&num,vdouble);
01745   C2F(drawrectanglesPos)(str,vects,&cpat,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);    
01746 }
01747 
01753 void C2F(fillarcsPos)(char *str, integer *vects, integer *fillvect, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01754 {
01755   integer cpat,verb,num;
01756   verb=0;
01757   
01758   if ( ScilabGCPos_is_initialized == FALSE ) {
01759     sciprint("xinit must be called before any action \r\n");
01760     return;
01761   }
01762   
01763   C2F(getpatternPos)(&verb,&cpat,&num,vdouble);
01764   C2F(WriteGenericPos)("fillarc",*n,(integer)6L,vects,vects,6*(*n),(integer)0L,fillvect);
01765   C2F(setpatternPos)(&(cpat),PI0,PI0,PI0);
01766 }
01767 
01775 void C2F(drawarcsPos)(char *str, integer *vects, integer *style, integer *n, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01776 {
01777   integer verbose=0,Dnarg,Dvalue[10];
01778   int i;
01779   
01780   if ( ScilabGCPos_is_initialized == FALSE ) {
01781     sciprint("xinit must be called before any action \r\n");
01782     return;
01783   }
01784 
01785   /* store the current values */
01786   C2F(get_dash_and_color_Pos)(&verbose,Dvalue,&Dnarg,vdouble);
01787   for ( i=0 ; i < *n ; i++) 
01788     {
01789       integer fvect,na=1;
01791       C2F(set_line_style_Pos)(&style[i],PI0,PI0,PI0);
01792 
01794       fvect = ScilabGCPos.IDLastPattern + 3 ; /* out of colormap, so don't fill */
01795       C2F(fillarcsPos)(str,&vects[(6)*i],&fvect,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01796     }
01797   C2F(set_dash_and_color_Pos)( Dvalue,PI0,PI0,PI0);
01798 }
01799 
01800 
01804 void C2F(drawarcPos)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01805 { 
01806   integer i =1;
01807   integer fvect[1] ;
01808   integer vects[6];
01809 
01810   if ( ScilabGCPos_is_initialized == FALSE ) {
01811     sciprint("xinit must be called before any action \r\n");
01812     return;
01813   }
01814   
01815   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01816   vects[3]= *height;vects[4]= *angle1;vects[5]= *angle2;
01818   fvect[0] = ScilabGCPos.IDLastPattern + 3  ; /* out of colormap, so don't fill */
01819   C2F(fillarcsPos)(str,vects,fvect,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01820 }
01821 
01825 void C2F(fillarcPos)(char *str, integer *x, integer *y, integer *width, integer *height, integer *angle1, integer *angle2, double *dv1, double *dv2, double *dv3, double *dv4)
01826 { 
01827   integer i =1,vects[6];
01828   integer cpat,verb=0,num;
01829 
01830   if ( ScilabGCPos_is_initialized == FALSE ) {
01831     sciprint("xinit must be called before any action \r\n");
01832     return;
01833   }
01834   
01835   vects[0]= *x;vects[1]= *y;vects[2]= *width;
01836   vects[3]= *height;vects[4]= *angle1;vects[5]= *angle2;
01837   C2F(getpatternPos)(&verb,&cpat,&num,vdouble);
01838   C2F(fillarcsPos)(str,vects,&cpat,&i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01839  }
01840 
01841 /*--------------------------------------------------------------
01842 \encadre{Filling or Drawing Polylines and Polygons}
01843 ---------------------------------------------------------------*/
01844 
01850 void C2F(drawpolylinesPos)(char *str, integer *vectsx, integer *vectsy, integer *drawvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01851 { integer verbose ,symb[2],Mnarg,Dnarg,Dvalue[10],NDvalue,i,close;
01852   verbose =0 ;  
01853   
01854   if ( ScilabGCPos_is_initialized == FALSE ) {
01855     sciprint("xinit must be called before any action \r\n");
01856     return;
01857   }
01858   
01859   /* store the current values */
01860   C2F(xgetmarkPos)(&verbose,symb,&Mnarg,vdouble);
01861   C2F(get_dash_and_color_Pos)(&verbose,Dvalue,&Dnarg,vdouble);
01862   for (i=0 ; i< *n ; i++)
01863     {
01864       if (drawvect[i] <= 0)
01865         { 
01866           NDvalue = - drawvect[i];
01867           C2F(xsetmarkPos)(&NDvalue,symb+1,PI0,PI0);
01868          
01869           C2F(drawpolymarkPos)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
01870         }
01871       else
01872         {
01874           C2F(set_line_style_Pos)(drawvect+i,PI0,PI0,PI0);
01875           close = 0;
01876           C2F(drawpolylinePos)(str,p,vectsx+(*p)*i,vectsy+(*p)*i,&close,PI0,PI0,PD0,PD0,PD0,PD0);
01877         }
01878     }
01880   C2F(set_dash_and_color_Pos)(Dvalue,PI0,PI0,PI0);
01881   C2F(xsetmarkPos)(symb,symb+1,PI0,PI0);
01882 }
01883 
01884 /**************************************************************
01885   fill a set of polygons each of which is defined by 
01886  (*p) points (*n) is the number of polygons 
01887  the polygon is closed by the routine 
01888  fillvect[*n] :         
01889  if fillvect[i] == 0 draw the boundaries with current color 
01890  if fillvect[i] > 0  draw the boundaries with current color 
01891                 then fill with pattern fillvect[i]
01892  if fillvect[i] < 0  fill with pattern - fillvect[i]
01893  **************************************************************/
01894 
01895 void C2F(fillpolylinesPos)(char *str, integer *vectsx, integer *vectsy, integer *fillvect, integer *n, integer *p, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01896 {
01897   integer cpat,verb=0,num;
01898 
01899   if ( ScilabGCPos_is_initialized == FALSE ) {
01900     sciprint("xinit must be called before any action \r\n");
01901     return;
01902   }
01903 
01904   if ( ScilabGCPos.CurVectorStyle !=  CoordModeOrigin)
01905     FPRINTF((file,"\n/absolu false def"));
01906   C2F(getpatternPos)(&verb,&cpat,&num,vdouble);
01907   C2F(WriteGenericPos)("drawpoly",*n,(*p)*2,vectsx,vectsy,(*p)*(*n),(integer)1L,
01908                         fillvect);
01909   C2F(setpatternPos)(&(cpat),PI0,PI0,PI0);
01910   FPRINTF((file,"\n/absolu true def"));
01911 }
01912 
01916 void C2F(drawpolylinePos)(char *str, integer *n, integer *vx, integer *vy, integer *closeflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01917 { integer i =1;
01918   integer fvect[1] ;
01919 
01920   if ( ScilabGCPos_is_initialized == FALSE ) {
01921     sciprint("xinit must be called before any action \r\n");
01922     return;
01923   }
01924 
01926   fvect[0] = 0;
01927   if (*closeflag == 1 )
01928     FPRINTF((file,"\n/closeflag true def"));
01929   else 
01930     FPRINTF((file,"\n/closeflag false def"));
01931   C2F(fillpolylinesPos)(str,vx,vy,fvect,&i,n,PI0,PD0,PD0,PD0,PD0);
01932 }
01933 
01936 void C2F(fillpolylinePos)(char *str, integer *n, integer *vx, integer *vy, integer *closeareaflag, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01937 {
01938   integer i =1;
01939   integer cpat,verb=0,num;
01940 
01941   if ( ScilabGCPos_is_initialized == FALSE ) {
01942     sciprint("xinit must be called before any action \r\n");
01943     return;
01944   }
01945 
01946   C2F(getpatternPos)(&verb,&cpat,&num,vdouble); 
01948   cpat = -cpat;
01949   C2F(fillpolylinesPos)(str,vx,vy,&cpat,&i,n,PI0,PD0,PD0,PD0,PD0);
01950 }
01951 
01955 void C2F(drawpolymarkPos)(char *str, integer *n, integer *vx, integer *vy, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01956 { 
01957   integer keepid,keepsize,i=1,sz;
01958   
01959   if ( ScilabGCPos_is_initialized == FALSE ) {
01960     sciprint("xinit must be called before any action \r\n");
01961     return;
01962   }
01963   
01964   sz=ScilabGCPos.CurHardSymbSize;
01965   keepid =  ScilabGCPos.FontId;
01966   keepsize= ScilabGCPos.FontSize;
01967   C2F(xsetfontPos)(&i,&sz,PI0,PI0);
01968   C2F(displaysymbolsPos)(str,n,vx,vy);
01969   C2F(xsetfontPos)(&keepid,&keepsize,PI0,PI0);
01970 }
01971 
01972 /*-----------------------------------------------------
01973 \encadre{Routine for initialisation}
01974 ------------------------------------------------------*/
01975 
01976 void C2F(initgraphicPos)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
01977 { 
01978   char string1[256];
01979   static integer EntryCounter = 0;
01980   integer fnum;
01981 
01982   *v3 = 0;
01983   if (EntryCounter >= 1) C2F(xendgraphicPos)();
01984   strncpy(string1,string,256);
01985 
01986   /* Not so useful   
01987      sprintf(string2,"%d",(int)EntryCounter);
01988      strcat(string1,string2); */
01989   file=fopen(string1,"w");
01990   if (file == 0) 
01991     {
01992       /*sciprint("Can't open file %s, I'll use stdout\r\n",string1);*/
01993       file =stdout;
01994       *v3 = 1;
01995       return;
01996     }
01997   if (EntryCounter == 0)
01998     { 
01999       fnum=0;      C2F(loadfamilyPos)("Courier",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02000       fnum=1;      C2F(loadfamilyPos)("Symbol",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02001       fnum=2;      C2F(loadfamilyPos)("Times-Roman",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02002       fnum=3;      C2F(loadfamilyPos)("Times-Italic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02003       fnum=4;      C2F(loadfamilyPos)("Times-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02004       fnum=5;      C2F(loadfamilyPos)("Times-BoldItalic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02005       fnum=6;      C2F(loadfamilyPos)("Helvetica",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02006       fnum=7;      C2F(loadfamilyPos)("Helvetica-Oblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02007       fnum=8;      C2F(loadfamilyPos)("Helvetica-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02008       fnum=9;      C2F(loadfamilyPos)("Helvetica-BoldOblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02009 
02010     }
02011   FileInit();
02012   ScilabGCPos.CurWindow =EntryCounter;
02013   EntryCounter =EntryCounter +1;
02014 }
02015 
02016 void FileInit(void)
02017 {
02018 /*   int m, ierr=0; */
02020   integer x[2],verbose,narg;
02021   verbose = 0; 
02022   C2F(getwindowdimPos)(&verbose,x,&narg,vdouble);
02023   ColorInit();
02024   FPRINTF((file,"\n%%scipos_w=%d\n%%scipos_h=%d",(int)x[0]/2,(int)x[1]/2));
02025   FPRINTF((file,"\n%% Dessin en bas a gauche de taille %d,%d",(int)x[0]/2,(int)x[1]/2));
02026   FPRINTF((file,"\n[0.5 %d div 0 0 0.5 %d div neg  0 %d %d div] concat",
02027           (int)prec_fact, (int)prec_fact,(int)x[1]/2,(int) prec_fact ));
02028   FPRINTF((file,"\n%% Init driver "));
02029   FPRINTF((file,"\n/PaintBackground {WhiteLev 2 add background eq {}{ (drawbox) 4 [background 1 add] [0 0 %d %d] dogrey}ifelse } def", x[0],x[1]));
02030 
02031   ScilabGCPos_is_initialized = TRUE; /* add the flag ScilabGCPos_is_initialized to test if xinit has been called */
02032   InitScilabGCPos(PI0,PI0,PI0,PI0);
02033   
02034   FPRINTF((file,"\n%% End init driver "));
02035   FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern));
02036 
02037 
02038 /*   /\** If the X window exists we check its colormap **\/ */
02039 /*   if (  CheckColormap(&m) == 1)  */
02040 /*     {  */
02041 /*       int i; */
02042 /*       float r,g,b; */
02043 /*       ScilabGCPos.Numcolors = m; */
02044 /*       ScilabGCPos.NumForeground = m; */
02045 /*       ScilabGCPos.NumBackground = m + 1; */
02046 /*       if (ScilabGCPos.CurColorStatus == 1)  */
02047 /*      { */
02048 /*        ScilabGCPos.IDLastPattern = ScilabGCPos.Numcolors - 1; */
02049 /*        FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern)); */
02050 /*      } */
02051 /*       FPRINTF((file,"\n/ColorR [")); */
02052 /*       for ( i=0; i < m ; i++) */
02053 /*      { */
02054 /*        get_r(i,&r); */
02055 /*        FPRINTF((file,"%f ",r)); */
02056 /*        if ( (i % 10 ) == 0 ) FPRINTF((file,"\n")); */
02057 /*      } */
02058 /*       FPRINTF((file,"0.0 1.0] def")); */
02059 /*       FPRINTF((file,"\n/ColorG [")); */
02060 /*       for ( i=0; i < m ; i++)  */
02061 /*      { */
02062 /*        get_g(i,&g); */
02063 /*        FPRINTF((file,"%f ",g)); */
02064 /*        if ( (i % 10 ) == 0 ) FPRINTF((file,"\n")); */
02065 /*      } */
02066 /*       FPRINTF((file,"0.0 1.0] def")); */
02067 /*       FPRINTF((file,"\n/ColorB [")); */
02068 /*       for ( i=0; i < m; i++) */
02069 /*      { */
02070 /*        get_b(i,&b); */
02071 /*        FPRINTF((file,"%f ",b)); */
02072 /*        if ( (i % 10 ) == 0 ) FPRINTF((file,"\n")); */
02073 /*      } */
02074 /*       FPRINTF((file,"0.0 1.0] def")); */
02075 /*     } */
02076 
02077 /*   C2F(setgccolormapPos)(&ScilabGCPos,32, default_colors, &ierr); */
02078 
02079 
02080 
02081   FPRINTF((file,"\n%%Latex:\\setlength{\\unitlength}{%4.2fpt}",
02082            1.0/(prec_fact*2)));
02083   FPRINTF((file,"\n%%Latex:\\begin{picture}(%d,%d)(%d,0)",
02084            def_width*prec_fact,
02085            def_height*prec_fact,
02086            def_width/3  /* not so clear XXX */
02087            ));
02088 }
02089 
02090 /*--------------------------------------------------------
02091 \encadre{Initialisation of the graphic context. Used also 
02092 to come back to the default graphic state}
02093 ---------------------------------------------------------*/
02094 
02095 
02096 void InitScilabGCPos(integer *v1, integer *v2, integer *v3, integer *v4)
02097 { integer i,j,col;
02098   ScilabGCPos.IDLastPattern = GREYNUMBER-1;
02099   ScilabGCPos.CurLineWidth=0 ;
02100   i=1;
02101   C2F(setthicknessPos)(&i,PI0,PI0,PI0);
02102   C2F(setalufunctionPos)("GXcopy");
02104   i=j= -1;
02105   C2F(unsetclipPos)(PI0,PI0,PI0,PI0);
02106   C2F(setdashPos)((i=0,&i),PI0,PI0,PI0);
02107   C2F(xsetfontPos)((i=2,&i),(j=1,&j),PI0,PI0);
02108   C2F(xsetmarkPos)((i=0,&i),(j=0,&j),PI0,PI0);
02110   ScilabGCPos.CurVectorStyle = CoordModeOrigin ;
02111   /* initialisation des pattern dash par defaut en n&b */
02112   ScilabGCPos.CurColorStatus =0;
02113   C2F(setpatternPos)((i=1,&i),PI0,PI0,PI0);
02114   C2F(setdashPos)((i=1,&i),PI0,PI0,PI0);
02115   C2F(sethidden3dPos)((i=1,&i),PI0,PI0,PI0);
02116   /* initialisation de la couleur par defaut */ 
02117   ScilabGCPos.Numcolors = DEFAULTNUMCOLORS;
02118   ScilabGCPos.NumForeground = DEFAULTNUMCOLORS;
02119   ScilabGCPos.CurColorStatus = 1 ;
02120   C2F(setpatternPos)((i=1,&i),PI0,PI0,PI0);
02121   C2F(setforegroundPos)((i=ScilabGCPos.NumForeground+1,&i),PI0,PI0,PI0);
02122   C2F(setbackgroundPos)((i=ScilabGCPos.NumForeground+2,&i),PI0,PI0,PI0);
02123   C2F(sethidden3dPos)((i=4,&i),PI0,PI0,PI0);
02124   /* Choix du mode par defaut (decide dans initgraphic_ */
02125   getcolordef(&col);
02129   ScilabGCPos.mafigure = (sciPointObj *)NULL;
02130 
02131   ScilabGCPos.CurColorStatus = (col == 1) ? 0: 1;
02132   C2F(usecolorPos)(&col,PI0,PI0,PI0);
02133   if (col == 1) ScilabGCPos.IDLastPattern = ScilabGCPos.Numcolors - 1;
02134   strcpy(ScilabGCPos.CurNumberDispFormat,"%-5.2g");
02135 }
02136 
02137 /*-----------------------------------------------------
02138 \encadre{Draw an axis whith a slope of alpha degree (clockwise)
02139  . Along the axis marks are set in the direction ( alpha + pi/2), in the 
02140   following way :
02141 \begin{itemize}
02142 \item   $n=<n1,n2>$,
02143 \begin{verbatim}
02144      |            |           |
02145      |----|---|---|---|---|---|
02146      <-----n1---->                 
02147      <-------------n2-------->
02148 \end{verbatim}
02149 $n1$and $n2$ are integer numbers for interval numbers.
02150 \item $size=<dl,r,coeff>$. $dl$ distance in points between 
02151      two marks, $r$ size in points of small mark, $r*coeff$ 
02152      size in points of big marks. (they are doubleing points numbers)
02153 \item $init$. Initial pointeger $<x,y>$. 
02154 \end{itemize}
02155 }
02156 
02157 -------------------------------------------------------------*/
02158 void C2F(drawaxisPos)(char *str, integer *alpha, integer *nsteps, integer *v2, integer *initpoint, integer *v6, integer *v7, double *size, double *dx2, double *dx3, double *dx4)
02159 {
02160   if ( ScilabGCPos_is_initialized == FALSE ) {
02161     sciprint("xinit must be called before any action \r\n");
02162     return;
02163   }
02164 
02165   FPRINTF((file,"\n %d [%d %d] [%f %f %f] [%d %d] drawaxis",
02166           (int)*alpha,(int)nsteps[0],(int)nsteps[1],size[0],size[1],size[2],
02167           (int)initpoint[0],(int)initpoint[1]));
02168 }
02169 
02170 /*-----------------------------------------------------
02171 \encadre{Display numbers z[i] at location (x[i],y[i])
02172   with a slope alpha[i] (see displaystring_), if flag==1
02173   add a box around the string.
02174 -----------------------------------------------------*/
02175 void C2F(displaynumbersPos)(char *str, integer *x, integer *y, integer *v1, integer *v2, integer *n, integer *flag, double *z, double *alpha, double *dx3, double *dx4)
02176 { integer i ;
02177   char buf[20];
02178 
02179   if ( ScilabGCPos_is_initialized == FALSE ) {
02180     sciprint("xinit must be called before any action \r\n");
02181     return;
02182   }
02183   
02184   for (i=0 ; i< *n ; i++)
02185     { 
02186       sprintf(buf,ScilabGCPos.CurNumberDispFormat,z[i]);
02187       C2F(displaystringPos)(buf,&(x[i]),&(y[i]),PI0,flag,PI0,PI0,&(alpha[i]),PD0,PD0,PD0) ;
02188     }
02189 }
02190 
02191 /*-------------------------------------------------------
02192 \encadre{General routine for generating Postscript Code 
02193 to deal with Vectors. The difficulty is that the size 
02194 of vectors is limited by Postscript, so the routine 
02195 must check size and cut into pieces big objects}
02196 \begin{verbatim}
02197   clear (string) sizeobj [fvect[0],...,fvect[nobj]]
02198   (si flag=1)  [ vx[0] vy[0] vx[1] vy[1] ...... vx[sizev] vy[sizev]]
02199   (si flag=0)  [ vx[0] vx[1] ..... vx[sizev] ] dogrey 
02200 \end{verbatim}
02201 ----------------------------------------------------------*/
02202 
02206 #define MAXSIZE 8320
02207 #define PERLINE 20
02208 #define FORMATNUM "%d "
02209 
02210 void C2F(WriteGenericPos)(char *string, integer nobj, integer sizeobj, integer *vx, integer *vy, integer sizev, integer flag, integer *fvect)
02211 {   
02212   integer nobjpos,objbeg;
02213   objbeg= 0 ;
02217   if (nobj ==0 || sizeobj ==0) return;
02218   nobjpos =Min( Max(1,MAXSIZE /sizeobj),nobj);
02219   while ( objbeg < nobj)
02220     {
02221       integer objres;
02222       objres= nobj-objbeg;
02223       C2F(WriteGeneric1Pos)(string,Min(nobjpos,objres),objbeg,sizeobj,vx,vy,flag,fvect);
02224       objbeg = objbeg+nobjpos;
02225    }
02226   
02227 }
02228 
02229 void C2F(WriteGeneric1Pos)(char *string, integer nobjpos, integer objbeg, integer sizeobj, integer *vx, integer *vy, integer flag, integer *fvect)
02230 {
02231   integer from,n,i;
02232   if (flag == 1) 
02233     {  from= (objbeg*sizeobj)/2;
02234        n= (nobjpos*sizeobj)/2;}
02235   else 
02236     {  from= (objbeg*sizeobj);
02237        n= (nobjpos*sizeobj);
02238     }
02239   FPRINTF((file,"\n (%s) %d [",string,(int)Min(sizeobj,MAXSIZE)));
02242   if ( strcmp(string,"drawarrows")== 0 
02243        || strcmp(string,"drawbox")==0
02244        || strcmp(string,"drawpoly")==0)
02245     {
02246       for ( i =objbeg  ; i < (nobjpos+objbeg) ; i++)
02247         {
02248           FPRINTF((file," %d",(int)fvect[i]));
02249         }
02250     }
02251   else
02252     {
02253       for ( i =objbeg  ; i < (nobjpos+objbeg) ; i++)
02254         {
02255           int pat;
02256           pat = Max(0,(int)fvect[i]-1);
02257           FPRINTF((file," %d",pat));
02258         }
02259     }
02260 
02261   FPRINTF((file,"]\n"));
02262   /* Reste un probleme car si un unique objet doit etre dessine
02263      et qu'il est trop gros cet objet est decoupe en bout mais 
02264      il manque alors les raccords eventuels */
02265   C2F(Write2VectPos)(vx,vy,from,n,string,flag,fvect[objbeg]);
02266 }
02267 
02268 /*--------------------------------------------------
02269   [  perline*valeurs de vx et vy 
02270      ......
02271      .....
02272   ] string 
02273   [ 
02274 
02275   ] string 
02276   chaque zone entre [] ne doit pas contenir plus de 
02277   maxsize valeurs.
02278 -------------------------------------------------------*/
02279 
02280 
02281 void C2F(Write2VectPos)(integer *vx, integer *vy, integer from, integer n, char *string, integer flag, integer fv)
02282 { 
02283   integer i,j,k,co,nco;
02284   int fv1;
02285   if ( flag == 1) nco=2*n;else nco=n;
02286   co = 1;
02287   i =0;
02288 
02289   if ( strcmp(string,"drawarrows")== 0)
02290     {
02291       fv1= fv ;
02292     }
02293   else
02294     {
02295       fv1 = Max(0,fv-1);
02296     }
02297 
02298   while( i < n)
02299     {
02300       if ( i > 0) 
02301         FPRINTF((file,"\n (%s) %d [%d]\n",
02302                 string,(int)Min(MAXSIZE,nco-(co-1)*MAXSIZE),fv1));
02303       co = co +1;
02304       j =0;
02305       FPRINTF((file,"["));
02306       while ( j < MAXSIZE && i <n )
02307         {
02308           k=0;
02309           while ( k < PERLINE && i < n && j < MAXSIZE)
02310             {
02311               FPRINTF((file,FORMATNUM,(int)vx[i+from]));
02312               if (flag == 1) 
02313                 { FPRINTF((file,FORMATNUM,(int) vy[i+from]));
02314                   k=k+2;i=i+1;j=j+2;}
02315               else 
02316                 {k=k+1;i=i+1;j=j+1;}}
02317           FPRINTF((file,"\n"));
02318         }
02319       FPRINTF((file,"] dogrey "));
02320     }
02321 }
02322 
02325 #define FONTNUMBER 11
02326 #define FONTMAXSIZE 6
02327 #define SYMBOLNUMBER 10
02328 integer FontsListPos[FONTNUMBER][FONTMAXSIZE];
02329 struct SciFontInfo { integer ok;
02330                   char fname[21];} FontInfoTabPos[FONTNUMBER];
02331 
02332 static char *sizePos[] = { "08" ,"10","12","14","18","24"};
02333 static int  isizePos[] = { 8 ,10,12,14,18,24};
02334 
02337 static int fontsizePos (void)
02338 { 
02339   return isizePos[ScilabGCPos.FontSize];
02340 }
02341          
02342 
02343 void C2F(xsetfontPos)(integer *fontid, integer *fontsize, integer *v3, integer *v4)
02344 /* modified by bruno (Jan 2004) */
02345 { 
02346   integer i,fsiz;
02347 
02348   if ( ScilabGCPos_is_initialized == FALSE ) {
02349     sciprint("xinit must be called before any action \r\n");
02350     return;
02351   }
02352   
02353   i = Min(FONTNUMBER-1,Max(*fontid,0));
02354   fsiz = Min(FONTMAXSIZE-1,Max(*fontsize,0));
02355   if ( FontInfoTabPos[i].ok !=1 )
02356     {
02357       /* currently this case occurs only when i=FONTNUMBER-1 */
02358       sciprint("\n Sorry This Font is Not available: use default font (Times)\n");
02359       i = 2;
02360     }
02361   ScilabGCPos.FontId = i;
02362   ScilabGCPos.FontSize = fsiz;
02363   FPRINTF((file,"\n/%s findfont %d scf mul scalefont setfont",
02364            FontInfoTabPos[i].fname,
02365            (int) (isizePos[fsiz]*prec_fact)));
02366 }
02367 
02370 void C2F(xgetfontPos)(integer *verbose, integer *font, integer *nargs, double *dummy)
02371 {  
02372   if ( ScilabGCPos_is_initialized == FALSE ) {
02373     sciprint("xinit must be called before any action \r\n");
02374     return;
02375   }
02376   
02377   *nargs=2;
02378   font[0]= ScilabGCPos.FontId ;
02379   font[1] =ScilabGCPos.FontSize ;
02380   if (*verbose == 1) 
02381     {
02382       sciprint("\nFontId : %d ",              ScilabGCPos.FontId );
02383       sciprint("--> %s at size %s pts\r\n",
02384              FontInfoTabPos[ScilabGCPos.FontId].fname,
02385              sizePos[ScilabGCPos.FontSize]);
02386     }
02387 }
02388 
02389 
02392 void C2F(xsetmarkPos)(integer *number, integer *size, integer *v3, integer *v4)
02393 {   
02394   if ( ScilabGCPos_is_initialized == FALSE ) {
02395     sciprint("xinit must be called before any action \r\n");
02396     return;
02397   }
02398   
02399   ScilabGCPos.CurHardSymb =     
02400     Max(Min(SYMBOLNUMBER-1,*number),0);
02401   ScilabGCPos.CurHardSymbSize = 
02402     Max(Min(FONTMAXSIZE-1,*size),0);
02403 ;}
02404 
02407 void C2F(xgetmarkPos)(integer *verbose, integer *symb, integer *narg, double *dummy)
02408 {
02409   if ( ScilabGCPos_is_initialized == FALSE ) {
02410     sciprint("xinit must be called before any action \r\n");
02411     return;
02412   }
02413   
02414   *narg =2 ;
02415   symb[0] = ScilabGCPos.CurHardSymb ;
02416   symb[1] = ScilabGCPos.CurHardSymbSize ;
02417   if (*verbose == 1) 
02418   sciprint("\nMark : %d at size %d pts\r\n",
02419           ScilabGCPos.CurHardSymb,
02420           isizePos[ScilabGCPos.CurHardSymbSize]);
02421 }
02422 
02423 char symb_listPos[] = {
02424   /*
02425      0x2e : . alors que 0xb7 est un o plein trop gros 
02426      ., +,X,*,diamond(filled),diamond,triangle up,triangle down,trefle,circle*/
02427   (char)0x2e,(char)0x2b,(char)0xb4,(char)0xc5,(char)0xa8,
02428   (char)0xe0,(char)0x44,(char)0xd1,(char)0xa7,(char)0x4f};
02429 
02430 static void C2F(displaysymbolsPos)(char *str, integer *n, integer *vx, integer *vy)
02431 {
02432   integer fvect[1];
02433   
02434   if ( ScilabGCPos_is_initialized == FALSE ) {
02435     sciprint("xinit must be called before any action \r\n");
02436     return;
02437   }
02438   
02439   fvect[0] =  ( ScilabGCPos.CurColorStatus ==1) ? ScilabGCPos.CurColor : ScilabGCPos.CurPattern ;
02440   if ( ScilabGCPos.CurVectorStyle !=  CoordModeOrigin)
02441     FPRINTF((file,"\n/absolu false def"));
02442   FPRINTF((file,"\nHardMark 0 16#%x put",
02443       Char2Int( symb_listPos[ScilabGCPos.CurHardSymb])));
02444   C2F(WriteGenericPos)("drawpolymark",(integer)1L,(*n)*2,vx,vy,*n,(integer)1L,fvect);
02445   FPRINTF((file,"\n/absolu true def"));
02446 }
02447 
02448 /*------------------------------------------------------------------------------------------*/
02452 void C2F(getFontMaxSizePos)(char *str, integer *sizeMin, integer *sizeMax, integer *v1, integer *v2, integer *v3, integer *v4, double *dx1, double *dx2, double *dx3, double *dx4)
02453 {
02454   *sizeMin = 0 ;
02455   *sizeMax = FONTMAXSIZE ;
02456 }
02457 /*------------------------------------------------------------------------------------------*/
02458 
02459 /*-------------------------------------------------------
02460 \encadre{Check if a specified family of font exist in 
02461 Postscript }
02462 -------------------------------------------------------*/
02463 
02464 void C2F(loadfamilyPos)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02465 {
02466   integer i ;
02467   for ( i = 0; i < FONTMAXSIZE ; i++)
02468     {
02469       FontsListPos[*j][i] = C2F(PosQueryFont)(name);
02470     }
02471   if  (FontsListPos[*j][0] == 0 )
02472           sciprint("\n unknown font family : %s \r\n",name);
02473   else 
02474     {FontInfoTabPos[*j].ok = 1;
02475      strcpy(FontInfoTabPos[*j].fname,name) ;}
02476 }
02477 
02478 /*--------------------------------------------
02479 \encadre{always answer ok. Must be Finished}
02480 ---------------------------------------------*/
02481 
02482 static int C2F(PosQueryFont)(char *name)
02483 { 
02484   return(1);
02485 }
02486 
02487 void C2F(queryfamilyPos)(char *name, integer *j, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02488 { 
02489   integer i ;
02490   name[0]='\0';
02491   for (i=0;i<FONTNUMBER;i++) {
02492     strcat(name,FontInfoTabPos[i].fname);
02493     v3[i]=strlen(FontInfoTabPos[i].fname);
02494   }
02495   *j=FONTNUMBER;
02496 }
02497 
02498 /*------------------------END--------------------*/
02499 /* NG beg */
02500 void C2F(setscilabFigurePos)(integer *v1,integer *v2,integer *v3,integer *v4,integer *v5,integer *v6,double *figure)
02501 {
02502  figure=(double *)ScilabGCPos.mafigure;
02503 }
02504 
02505 void C2F(getscilabFigurePos)(integer *verbose, integer *x,integer *narg, double *figure)
02506 {   
02507   figure=(double *)ScilabGCPos.mafigure;
02508 }
02509 void C2F(setscilabVersionPos)(integer *vers, integer *v2, integer *v3, integer *v4)
02510 {
02511   /*ScilabGCPos.graphicsversion=*vers;*/
02512 }
02513 
02514 void C2F(getscilabVersionPos)(integer *verbose, integer *vers, integer *narg, double *dummy)
02515 {   
02516   *vers = 0 ;
02517 }
02518 void C2F(getscilabxgcPos)(integer *verbose, integer *x,integer *narg, double *dummy)
02519 {   
02520  double **XGC;
02521  XGC=(double **)dummy;
02522  *XGC= (double *)&ScilabGCPos;
02523 }
02524 void C2F(setscilabxgcPos)(integer *v1, integer *v2, integer *v3, integer *v4)
02525 {}
02526 /* NG end */
02527 
02528 
02529 /* 2 routines used only by a call to xinitfromscreen to perform the colormap selection */
02530 /* directly from the screen */
02531 
02532 void C2F(initgraphicfromscreenPos)(char *string, integer *v2, integer *v3, integer *v4, integer *v5, integer *v6, integer *v7, double *dv1, double *dv2, double *dv3, double *dv4)
02533 { 
02534   char string1[256];
02535   static integer EntryCounter = 0;
02536   integer fnum;
02537 
02538   *v3 = 0;
02539   if (EntryCounter >= 1) C2F(xendgraphicPos)();
02540   strncpy(string1,string,256);
02541 
02542   /* Not so useful   
02543      sprintf(string2,"%d",(int)EntryCounter);
02544      strcat(string1,string2); */
02545   file=fopen(string1,"w");
02546   if (file == 0) 
02547     {
02548       /*sciprint("Can't open file %s, I'll use stdout\r\n",string1);*/
02549       file =stdout;
02550       *v3 = 1;
02551       return;
02552     }
02553   if (EntryCounter == 0)
02554     { 
02555       fnum=0;      C2F(loadfamilyPos)("Courier",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02556       fnum=1;      C2F(loadfamilyPos)("Symbol",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02557       fnum=2;      C2F(loadfamilyPos)("Times-Roman",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02558       fnum=3;      C2F(loadfamilyPos)("Times-Italic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02559       fnum=4;      C2F(loadfamilyPos)("Times-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0);
02560       fnum=5;      C2F(loadfamilyPos)("Times-BoldItalic",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02561       fnum=6;      C2F(loadfamilyPos)("Helvetica",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02562       fnum=7;      C2F(loadfamilyPos)("Helvetica-Oblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02563       fnum=8;      C2F(loadfamilyPos)("Helvetica-Bold",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02564       fnum=9;      C2F(loadfamilyPos)("Helvetica-BoldOblique",&fnum,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0); 
02565 
02566     }
02567   FileInitFromScreenPos();
02568   ScilabGCPos.CurWindow =EntryCounter;
02569   EntryCounter =EntryCounter +1;
02570 }
02571 
02572 void FileInitFromScreenPos(void)
02573 {
02574   int m;
02576   integer x[2],verbose,narg;
02577   verbose = 0; 
02578   C2F(getwindowdimPos)(&verbose,x,&narg,vdouble);
02579   ColorInit();
02580   FPRINTF((file,"\n%%scipos_w=%d\n%%scipos_h=%d",(int)x[0]/2,(int)x[1]/2));
02581   FPRINTF((file,"\n%% Dessin en bas a gauche de taille %d,%d",(int)x[0]/2,(int)x[1]/2));
02582   FPRINTF((file,"\n[0.5 %d div 0 0 0.5 %d div neg  0 %d %d div] concat",
02583           (int)prec_fact, (int)prec_fact,(int)x[1]/2,(int) prec_fact ));
02584   FPRINTF((file,"\n%% Init driver "));
02585   FPRINTF((file,"\n/PaintBackground {WhiteLev 2 add background eq {}{ (drawbox) 4 [background 1 add] [0 0 %d %d] dogrey}ifelse } def", x[0],x[1]));
02586 
02587   ScilabGCPos_is_initialized = TRUE; /* add the flag ScilabGCPos_is_initialized to test if xinit has been called */
02588   InitScilabGCPos(PI0,PI0,PI0,PI0);
02589   
02590   FPRINTF((file,"\n%% End init driver "));
02591   FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern));
02593   if (  CheckColormap(&m) == 1) 
02594     { 
02595       int i;
02596       float r,g,b;
02597       ScilabGCPos.Numcolors = m;
02598       ScilabGCPos.NumForeground = m;
02599       ScilabGCPos.NumBackground = m + 1;
02600       if (ScilabGCPos.CurColorStatus == 1) 
02601         {
02602           ScilabGCPos.IDLastPattern = ScilabGCPos.Numcolors - 1;
02603           FPRINTF((file,"\n/WhiteLev %d def",ScilabGCPos.IDLastPattern));
02604         }
02605       FPRINTF((file,"\n/ColorR ["));
02606       for ( i=0; i < m ; i++)
02607         {
02608           get_r(i,&r);
02609           FPRINTF((file,"%f ",r));
02610           if ( (i % 10 ) == 0 ) FPRINTF((file,"\n"));
02611         }
02612       FPRINTF((file,"0.0 1.0] def"));
02613       FPRINTF((file,"\n/ColorG ["));
02614       for ( i=0; i < m ; i++) 
02615         {
02616           get_g(i,&g);
02617           FPRINTF((file,"%f ",g));
02618           if ( (i % 10 ) == 0 ) FPRINTF((file,"\n"));
02619         }
02620       FPRINTF((file,"0.0 1.0] def"));
02621       FPRINTF((file,"\n/ColorB ["));
02622       for ( i=0; i < m; i++)
02623         {
02624           get_b(i,&b);
02625           FPRINTF((file,"%f ",b));
02626           if ( (i % 10 ) == 0 ) FPRINTF((file,"\n"));
02627         }
02628       FPRINTF((file,"0.0 1.0] def"));
02629     }
02630 
02631   FPRINTF((file,"\n%%Latex:\\setlength{\\unitlength}{%4.2fpt}",
02632            1.0/(prec_fact*2)));
02633   FPRINTF((file,"\n%%Latex:\\begin{picture}(%d,%d)(%d,0)",
02634            def_width*prec_fact,
02635            def_height*prec_fact,
02636            def_width/3  /* not so clear XXX */
02637            ));
02638 }

Generated on Sun Mar 4 15:03:52 2007 for Scilab [trunk] by  doxygen 1.5.1