📄 postscript.c
字号:
maxStrLength = strlen(maxStr);}void PSDrawString(char *str,int hPositionMode,int i,int vPositionMode,int j){ char c; PSClosePathIfOpen(); /* Let us first fix the horizontal position */ switch (hPositionMode) { /* Justify left */ case HPositionLeftStr : fprintf(psStream,"/sx %.1f def\n",i*rx); break; /* Justify right each line separately */ case HPositionRightNStr : fprintf(psStream,"/sx (%s) %.1f rightx def\n",str,i*rx); break; /* Justify right all the lines as a block */ case HPositionRight1Str : c = maxStr[maxStrLength]; maxStr[maxStrLength] = '\0'; fprintf(psStream,"/sx (%s) %.1f rightx def\n",maxStr,i*rx); maxStr[maxStrLength] = c; break; /* Justify middle each line separately */ case HPositionMiddleNStr : fprintf(psStream,"/sx (%s) %.1f midx def\n",str,i*rx); break; /* Justify middle all the lines as a block */ case HPositionMiddle1Str : c = maxStr[maxStrLength]; maxStr[maxStrLength] = '\0'; fprintf(psStream,"/sx (%s) %.1f midx def\n",maxStr,i*rx); maxStr[maxStrLength] = c; break; } /* Let us then fix the vertical position */ switch (vPositionMode) { case VPositionBaseStr: fprintf(psStream,"/sy %.1f def\n",GetY(j)); break; case VPositionUpStr: fprintf(psStream,"/sy %.1f upy def\n",GetY(j)); break; case VPositionDownStr: fprintf(psStream,"/sy %.1f downy def\n",GetY(j)); break; case VPositionMiddleStr: fprintf(psStream,"/sy %.1f midy def\n",GetY(j)); break; case VPositionMiddleUpStr: fprintf(psStream,"/sy %.1f midupy def\n",GetY(j)); break; } fprintf(psStream,"sx sy mt (%s) show \n",str);}void PSSetLineStyle(int flag){ PSClosePathIfOpen(); if (flag == LineDash) fprintf(psStream,"[3] 3 sd\n"); else fprintf(psStream,"[] 3 sd\n");}void PSSetPenSize(int size){ PSClosePathIfOpen(); fprintf(psStream,"%.1f slw\n",(LWFLOAT) size*rx*linewidth);}void PSSetPenMode(int mode){}void PSSetFont(FONT font){ PSClosePathIfOpen(); if (font == currentFont) return; currentFont = font; fprintf(psStream,"/%s",font->fontName); if (font->style == FontItalic) fprintf(psStream,"-Oblique"); if (font->style == FontBold) fprintf(psStream,"-Bold"); if (font->style == FontBold + FontItalic) fprintf(psStream,"-BoldOblique"); fprintf(psStream," %d cf\n",font->size); }void PSDrawEllipse(int x,int y, int w, int h){ w--; h--; PSClosePathIfOpen(); fprintf(psStream,"np\n"); if (rx*w == ry*h) fprintf(psStream,"%.1f %.1f %.1f 0 360 arc\n",GetX(x+w/2.),GetY(y+h/2.),w*rx/2); else { fprintf(psStream,"%g %g tr\n",GetX(x+w/2.),GetY(y+h/2.)); fprintf(psStream,"%g %g sc\n",1.0,ry*h/(rx*w)); fprintf(psStream,"%g %g %g 0 360 arc\n",0.,0.,w*rx/2); fprintf(psStream,"%g %g sc\n",1.0,rx*w/(ry*h)); fprintf(psStream,"%g %g tr\n",-GetX(x+w/2.),-GetY(y+h/2.)); } fprintf(psStream,"cp\n"); fprintf(psStream,"st\n");}void PSFillEllipse(int x,int y, int w, int h){ w--; h--; PSClosePathIfOpen(); fprintf(psStream,"np\n"); if (rx*w == ry*h) fprintf(psStream,"%.1f %.1f %.1f 0 360 arc\n",GetX(x+w/2.),GetY(y+h/2.),w*rx/2); else { fprintf(psStream,"%g %g tr\n",GetX(x+w/2.),GetY(y+h/2.)); fprintf(psStream,"%g %g sc\n",1.0,ry*h/(rx*w)); fprintf(psStream,"%g %g %g 0 360 arc\n",0.,0.,w*rx/2); fprintf(psStream,"%g %g sc\n",1.0,rx*w/(ry*h)); fprintf(psStream,"%g %g tr\n",-GetX(x+w/2.),-GetY(y+h/2.)); } fprintf(psStream,"cp\n"); fprintf(psStream,"fi\n");}void PSDrawPoint(int x,int y){ PSFillEllipse(x,y,1,1);}void PSDrawRect(int x,int y,int dx,int dy){ dy--; dx--; PSDrawLine(x,y,x+dx,y); PSDrawLine(x+dx,y,x+dx,y+dy); PSDrawLine(x+dx,y+dy,x,y+dy); PSDrawLine(x,y+dy,x,y); }void PSFillRect(int x,int y,int dx,int dy){ dy--; dx--; PSClosePathIfOpen(); fprintf(psStream,"np\n"); fprintf(psStream,"%.1f %.1f mt\n",GetX(x),GetY(y)); fprintf(psStream,"%.1f %.1f rlt\n",0.,-dy*ry); fprintf(psStream,"%.1f %.1f rlt\n",dx*rx,0.); fprintf(psStream,"%.1f %.1f rlt\n",0.,dy*ry); fprintf(psStream,"cp\n"); fprintf(psStream,"fi\n");}void PSSetColor(unsigned long color){ unsigned short r1,g1,b1; PSClosePathIfOpen(); Color2RGB(color,&r1,&g1,&b1); fprintf(psStream,"%g %g %g setrgbcolor\n",r1/65535.0,g1/65535.0,b1/65535.0);}void PSSetClipRect(int x, int y, int w,int h){ PSClosePathIfOpen(); y += h; x-=1; y+=1; w+=2; h+=2; fprintf(psStream,"ic\n"); fprintf(psStream,"%.1f %.1f %.1f %.1f rc\n",GetX(x),GetY(y),w*rx,h*ry);}static unsigned char *psPixmapR = NULL;static unsigned char *psPixmapG = NULL;static unsigned char *psPixmapB = NULL;static int nRows;static int nCols;static void PSDeletePixMap(void){ if (psPixmapR != NULL) { Free(psPixmapR); Free(psPixmapG); Free(psPixmapB); psPixmapR = NULL; psPixmapG = NULL; psPixmapB = NULL; }}void PSInitPixMap(int nR,int nC){ PSDeletePixMap(); nRows = nR; nCols = nC; psPixmapR = (unsigned char *) Calloc(nCols*nRows,sizeof(unsigned char)); psPixmapG = (unsigned char *) Calloc(nCols*nRows,sizeof(unsigned char)); psPixmapB = (unsigned char *) Calloc(nCols*nRows,sizeof(unsigned char));}void PSSetPixelPixMap(int i, int j, unsigned long color){ unsigned short r,g,b; if (i < 0 || i >= nRows) { Warningf("PSSetPixelPixMap() : Bad 'i' index %d",i); return; } if (j < 0 || j >= nCols) { Warningf("PSSetPixelPixMap() : Bad 'j' index %d",j); return; } Color2RGB(color, &r,&g,&b); *(psPixmapR+nCols*i+j) = r/256; *(psPixmapG+nCols*i+j) = g/256; *(psPixmapB+nCols*i+j) = b/256;}static void PSDisplayImage_(int winX, int winY){ unsigned char *pm; int i,j; fprintf(psStream,"/chaineR %d string def\n",nCols); fprintf(psStream,"/chaineG %d string def\n",nCols); fprintf(psStream,"/chaineB %d string def\n",nCols); fprintf(psStream,"/setundercolorremoval where{pop{pop 0}setundercolorremoval}{}ifelse\n"); fprintf(psStream,"/setblackoverprint where{pop true setblackoverprint}{}ifelse\n"); fprintf(psStream,"%d %d %d ",nCols,nRows,8); fprintf(psStream,"[%g 0 0 %g %d %d]\n",1/rx,-1/ry,-winX,-winY+psObject->h); fprintf(psStream,"{currentfile chaineR readhexstring pop}\n"); fprintf(psStream,"{currentfile chaineG readhexstring pop}\n"); fprintf(psStream,"{currentfile chaineB readhexstring pop}\n"); fprintf(psStream,"true 3 colorimage\n"); /* Loop on each row */ for(i=0;i<nRows;i++) { /* Loop on each component */ pm = psPixmapR; while (1) { /* Loop on each column */ for(j=0;j<nCols;j++) { fprintf(psStream,"%02x",pm[i*nCols+j]); } if (pm == psPixmapR) pm = psPixmapG; else if (pm == psPixmapG) pm = psPixmapB; else break; fprintf(psStream,"\n\n"); } fprintf(psStream,"\n\n\n"); } } void PSDisplayPixMap(int winX,int winY){ PSDisplayImage_(winX,winY); PSDeletePixMap();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -