⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postscript.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e   K e r n e l   3 . 0                               *//*                                                                          *//*      Copyright (C) 1998-2002 Emmanuel Bacry.                             *//*      email : lastwave@cmap.polytechnique.fr                              *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*//****************************************************************************//*                                                                          *//*  postscript.c      The Postcript window manager                          *//*                                                                          */    /****************************************************************************/#include "lastwave.h"#define INCH 2.54 /* centimeter */char flagPSMode = NO;/* Size of a page in inches */#define Page_X  8.5  #define Page_Y  11   /* Size of the object to be printed (in inches) */static char flagAdaptYSize = YES;static LWFLOAT lx = 6.0; static LWFLOAT ly = -1;static LWFLOAT dx = 0; /* position in inches on the paper of the left corner */static LWFLOAT dy = 0;static LWFLOAT rx;  /* nb of laser points rx per screen pixels */static LWFLOAT ry;static FILE *psStream = NULL; /* current postscript file */static GOBJECT psObject;          /* Object to be printed */static int flagInPath = NO; /* for newpath and closepath commands */static LWFLOAT linewidth = .7;static FONT currentFont = NULL;/* * General Command to handle postcript */ void C_PS(char **argv){  char *action;  LWFLOAT rx,ry,rw,rh;  LISTV lv;    if (PSMode) Errorf("Sorry cannot use 'ps' command while drawing a postcript file");    /* Get the action name */  argv = ParseArgv(argv,tWORD,&action,-1);    /* The 'csize' action  */  if (!strcmp(action,"csize")) {    if (*argv == NULL) {      lv = TNewListv();      SetResultValue(lv);      if (!flagAdaptYSize) {        AppendFloat2Listv(lv,lx*INCH);        AppendFloat2Listv(lv,ly*INCH);      }      else {        AppendFloat2Listv(lv,lx*INCH);        AppendFloat2Listv(lv,-1.);      }      return;    }    argv = ParseArgv(argv,tFLOAT,&rw,tFLOAT_,-1.0,&rh,0);    if (rw <= 0 || (rh <=0 && rh != -1)) Errorf("Sorry the size of the drawing should be strictly positive");    lx = rw/INCH;    if (rh == -1) {      flagAdaptYSize = YES;      ly = -1;    }    else {      flagAdaptYSize = NO;      ly = rh/INCH;    }    return;  }  /* The 'isize' action  */  if (!strcmp(action,"isize")) {    if (*argv == NULL) {      lv = TNewListv();      SetResultValue(lv);      if (!flagAdaptYSize) {        AppendFloat2Listv(lv,lx);        AppendFloat2Listv(lv,ly);      }      else  {        AppendFloat2Listv(lv,lx);        AppendFloat2Listv(lv,-1);      }      return;    }    argv = ParseArgv(argv,tFLOAT,&rw,tFLOAT_,-1.0,&rh,0);    if (rw <= 0 || (rh <=0 && rh != -1)) Errorf("Sorry the size of the drawing should be strictly positive");    lx = rw;    if (rh == -1) {      flagAdaptYSize = YES;      ly = -1;    }    else {      flagAdaptYSize = NO;    ly = rh;    }    return;  }    /* The 'ipos' action  */  if (!strcmp(action,"ipos")) {    if (*argv == NULL) {      lv = TNewListv();      SetResultValue(lv);      AppendFloat2Listv(lv,dx);      AppendFloat2Listv(lv,dy);      return;    }    argv = ParseArgv(argv,tFLOAT,&rx,tFLOAT,&ry,0);    dx = rx;    dy = ry;    return;  }    /* The 'cpos' action  */  if (!strcmp(action,"cpos")) {    if (*argv == NULL) {      lv = TNewListv();      SetResultValue(lv);      AppendFloat2Listv(lv,dx*INCH);      AppendFloat2Listv(lv,dy*INCH);      return;    }    argv = ParseArgv(argv,tFLOAT,&rx,tFLOAT,&ry,0);    dx = rx/INCH;    dy = ry/INCH;    return;  }  /* The 'linewidth' action  */  if (!strcmp(action,"linewidth")) {    if (*argv == NULL) {      SetResultFloat(linewidth);      return;    }    argv = ParseArgv(argv,tFLOAT,&rx,0);    if (rx <= 0) Errorf("The linewidth should be a strictly positive number");    linewidth = rx;    return;  }    Errorf("Unknown action '%s'",action);} static void PSClosePathIfOpen(){  if (flagInPath == YES) {     fprintf(psStream,"st\n");     flagInPath = NO;  }}void PSClose(void){  if (flagPSMode != YES) return;  PSClosePathIfOpen();  fprintf(psStream,"showpage\n");  FClose(psStream);  flagPSMode = NO;}/* Start a session  */void PSOpen(GOBJECT obj,char *filename){  LWFLOAT page_x = Page_X*72;  if (flagPSMode == YES) {    Warningf("PSOpen() : I had to close the former postscript file");    PSClose();  }  psObject = obj;  psStream = FOpen(filename,"w");  if (psStream == NULL) {    flagPSMode = NO;    Errorf("PSOpen() : Failed to open the ps file %s",filename);  }    /* The size in x has been fixed, now we compute the size in y and the corresponding ratios */  rx = 72.0*lx/psObject->w;  if (flagAdaptYSize) {    ry = rx;    ly = ry*psObject->h/72.0;  }  else ry = 72*ly/psObject->h;                 fprintf(psStream,"%%!PS-Adobe-2.0\n");  fprintf(psStream,"%%%%Creator : LastWave Kernel 1.5.1\n");  fprintf(psStream,"%%%%BoundingBox: %d %d %d %d\n",(int) (dx*72-.5),(int) (dy*72-.5),(int) (psObject->w*rx+.5),(int) (psObject->h*ry+.5));  fprintf(psStream,"/mt {/y exch def /x exch def x y moveto} def\n");  fprintf(psStream,"/lt {/y exch def /x exch def x y lineto} def\n");  fprintf(psStream,"/rlt {/y exch def /x exch def x y rlineto} def\n");  fprintf(psStream,"/np {newpath} def\n");  fprintf(psStream,"/cp {closepath} def\n");  fprintf(psStream,"/st {stroke} def\n");  fprintf(psStream,"/sc {scale} def\n");  fprintf(psStream,"/fi {fill} def\n");  fprintf(psStream,"/tr {translate} def\n");  fprintf(psStream,"/slw {setlinewidth} def\n");  fprintf(psStream,"/sd {setdash} def\n");  fprintf(psStream,"/ic {initclip} def\n");  fprintf(psStream,"/rc {rectclip} def\n");  fprintf(psStream,"/rightx {exch stringwidth pop sub} def\n");  fprintf(psStream,"/midx {exch stringwidth pop 2 div sub} def\n");  fprintf(psStream,"/upy {ascent sub} def\n");  fprintf(psStream,"/downy {descent add} def\n");  fprintf(psStream,"/midy {ascent descent sub 2 div sub} def\n");  fprintf(psStream,"/midupy {ascent 2 div sub} def\n");  fprintf(psStream, "/cf {selectfont 0 0 mt (|jg~A) false charpath pathbbox /ascent exch def pop -1 mul /descent exch def pop} def\n");  fprintf(psStream,"%g %g tr\n",dx*72,dy*72);   flagPSMode = YES;    currentFont = NULL;}#define GetX(x) (rx*(x)) #define GetY(y) ((psObject->h-(y))*ry) /*************************************************** * * Postscript version of  the drawing routines      * ***************************************************/void PSDrawLine(int x1,int y1,int x2,int y2){  static LWFLOAT oldX,oldY; /* former coordinates */  if (flagInPath == NO) {    fprintf(psStream,"newpath\n");    fprintf(psStream,"%.1f %.1f mt\n",GetX(x1),GetY(y1));    fprintf(psStream,"%.1f %.1f lt\n",GetX(x2),GetY(y2));    flagInPath = YES;  }  else if (oldX == x1 && oldY == y1)     fprintf(psStream,"%.1f %.1f lt\n",GetX(x2),GetY(y2));  else {    fprintf(psStream,"%.1f %.1f mt\n",GetX(x1),GetY(y1));    fprintf(psStream,"%.1f %.1f lt\n",GetX(x2),GetY(y2));  }  oldX = x2;  oldY = y2;}static char *maxStr = NULL;static int maxStrLength = 0;void PSMaxString(char *str1){  maxStr = str1; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -