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

📄 basic.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* PostScript definitions to make output files smaller */static char *Prologue = "\/M {moveto} def\n\/RM {rmoveto} def\n\/L {lineto} def\n\/RL {rlineto} def\n\/S {stroke} def\n\/F {fill} def\n\/GS {gsave} def\n\/GR {grestore} def\n\/SH {show} def\n\/SW {stringwidth} def\n\/NP {newpath} def\n\/CP {closepath} def\n\/SC {scale} def\n\/RO {rotate} def\n\/TR {translate} def\n\/CAT {concat} def\n\/CLW {currentlinewidth} def\n\/SLW {setlinewidth} def\n\";/* private functions (for internal use only) */static int fontindex(const char *fontname)/*****************************************************************************Return index of named font in FontMetrics table*****************************************************************************/{	int i;	/* look for font name in FontMetrics table */	for (i=0; i<NFONTS; i++)		if (0==strcmp(fontname,FontMetrics[i].name))			return i;	/* if font name not found, then return index of unknown font */	return i;}static int colorindex(const char *colorname)/*****************************************************************************Return index of named color in colors table*****************************************************************************/{	int i;	char name[256];    	char *fmt;	unsigned int  r,g,b;	float f=0.0;		/* convert color name to lower case */	strncpy(name,colorname,255);	for (i=0; i<256 && name[i]!='\0'; ++i)		name[i] = tolower(name[i]);	/* look for color name in colors table */	for (i=0; i<NCOLOR; ++i)		if (0==strcmp(name,colors[i].name))			return i;	/* try to decode RGB color definition with X11 syntax	   rkr-31jul98 */		if (name[0] == '#') {	    fmt = NULL;	    switch (strlen(name+1)) {	    case 12:	/* Format: RRRRGGGGBBBB */		fmt = "%4x%4x%4x";	    	f = 65535;		break;	    case 9:	/* Format: RRRGGGBBB */		fmt = "%3x%3x%3x";		f = 4095;		break;	    case 6:	/* Format: RRGGBB */		fmt = "%2x%2x%2x";		f = 255;		break;	    case 3:	/* Format: RGB */		fmt = "%1x%1x%1x";		f = 15;		break;	    }	    /* get RGB values and store them in free table slot */	    if (fmt && sscanf (name+1, fmt, &r, &g, &b) == 3) {    		colors[NCOLOR].rgb[0] = r / f;		colors[NCOLOR].rgb[1] = g / f;		colors[NCOLOR].rgb[2] = b / f;		return (NCOLOR);	    }    	}		/* if color name not found, then return index of last color */	return NCOLOR-1;}/* public functions */void beginps(void)/*****************************************************************************Write PostScript prolog (including %%Pages comment)*****************************************************************************/{	fprintf(stdout,"%%!PS-Adobe-2.0 EPSF-1.2\n");	fprintf(stdout,"%%%%DocumentFonts:\n");	if (BBoxSet) {		fprintf(stdout,"%%%%BoundingBox: %d %d %d %d\n",			BBox.llx,BBox.lly,BBox.urx,BBox.ury);		BBoxOut = 1;	} else {		fprintf(stdout,"%%%%BoundingBox: (atend)\n");	}	fprintf(stdout,"%%%%Pages: (atend)\n");	fprintf(stdout,"%%%%EndComments\n");	fprintf(stdout,"%s\n",Prologue);	fprintf(stdout,"%%%%EndProlog\n");	fprintf(stdout,"GS\n");}void endps(void)/*****************************************************************************Write PostScript trailer (including %%Pages comment)*****************************************************************************/{	fprintf(stdout,"GR\n");	fprintf(stdout,"%%%%Trailer\n");	if (!BBoxOut) {		fprintf(stdout,"%%%%BoundingBox: %d %d %d %d\n",			BBox.llx,BBox.lly,BBox.urx,BBox.ury);		BBoxOut = 1;	}	fprintf(stdout,"%%%%Pages: %d\n",nPages);}void begineps(void)/*****************************************************************************Write encapsulated PostScript prolog (no %%Pages comment)*****************************************************************************/{	fprintf(stdout,"%%!PS-Adobe-2.0 EPSF-1.2\n");	fprintf(stdout,"%%%%DocumentFonts:\n");	if (BBoxSet) {		fprintf(stdout,"%%%%BoundingBox: %d %d %d %d\n",			BBox.llx,BBox.lly,BBox.urx,BBox.ury);		BBoxOut = 1;	} else {		fprintf(stdout,"%%%%BoundingBox: (atend)\n");	}	fprintf(stdout,"%%%%EndComments\n");	fprintf(stdout,"%s\n",Prologue);	fprintf(stdout,"%%%%EndProlog\n");	fprintf(stdout,"GS\n");}void endeps(void)/*****************************************************************************Write encapsulated PostScript trailer (no %%Pages comment)*****************************************************************************/{	fprintf(stdout,"GR\n");	fprintf(stdout,"%%%%Trailer\n");	if (!BBoxOut) {		fprintf(stdout,"%%%%BoundingBox: %d %d %d %d\n",			BBox.llx,BBox.lly,BBox.urx,BBox.ury);		BBoxOut = 1;	}}void boundingbox(int llx, int lly, int urx, int ury)/*****************************************************************************Set BoundingBox to llx lly urx ury*****************************************************************************/{	BBox.llx = llx;	BBox.lly = lly;	BBox.urx = urx;	BBox.ury = ury;	BBoxSet = 1;}void newpage(const char *label, int ordinal){	fprintf(stdout,"%%%%Page: %s %d\n",label,ordinal);	nPages++;}void showpage(void){	fprintf(stdout,"showpage\n"); }void gsave(void){	fprintf(stdout,"GS\n");}void grestore(void){	fprintf(stdout,"GR\n");}void newpath(void){	fprintf(stdout,"NP\n");}void closepath(void){	fprintf(stdout,"CP\n");}void clip(void){	fprintf(stdout,"clip\n");}void translate(float tx, float ty){	fprintf(stdout,"%.7g %.7g TR\n",tx,ty);}void scale(float sx, float sy){	fprintf(stdout,"%.4g %.4g SC\n",sx,sy);}void rotate(float angle){	fprintf(stdout,"%.4g RO\n",angle);}void concat(float m[]){	fprintf(stdout,"[%.4g %.4g %.4g %.4g %.4g %.4g] CAT\n",		m[0],m[1],m[2],m[3],m[4],m[5]);}void setgray(float gray){	fprintf(stdout,"%.4g setgray\n",gray);}void setrgbcolor(float red, float green, float blue){	fprintf(stdout,"%.4g %.4g %.4g setrgbcolor\n",red,green,blue);}void setcolor(const char *name){	int i=colorindex(name);	setrgbcolor(colors[i].rgb[0],colors[i].rgb[1],colors[i].rgb[2]);}void setlinewidth(float width){	fprintf(stdout,"%.4g SLW\n",width);}void setlinejoin(int code){	fprintf(stdout,"%d setlinejoin\n",code);}void setdash(float dash[], int ndash, float offset){	int i;	fprintf(stdout,"[ ");	for (i=0; i<ndash; i++)		fprintf(stdout,"%.4g ",dash[i]);	fprintf(stdout,"] %.4g setdash\n",offset);}void moveto(float x, float y){	fprintf(stdout,"%.4g %.4g M\n",x,y); }void rmoveto(float x, float y){	fprintf(stdout,"%.4g %.4g RM\n",x,y); }void lineto(float x, float y){	fprintf(stdout,"%.4g %.4g L\n",x,y); }void rlineto(float x, float y){	fprintf(stdout,"%.4g %.4g RL\n",x,y); }void arc(float x, float y, float r, float ang1, float ang2){	fprintf(stdout,"%.4g %.4g %.4g %.4g %.4g arc\n",x,y,r,ang1,ang2);}void stroke(void){	fprintf(stdout,"S\n"); }void fill(void){	fprintf(stdout,"F\n");}void show(const char *str){	fprintf(stdout,"(%s) SH\n",str);}void justshow(float just, const char *str)/*****************************************************************************Justify and show a string******************************************************************************Input:just		justification factorstr		string******************************************************************************Notes:The justification factor positions the string relative to the current point."just" may assume any value, but the common uses are:	-1.0	right-justify the string	-0.5	center the string on the current point	 0.0	left-justify the string (like using "show")*****************************************************************************/{	fprintf(stdout,"(%s) SW exch %.4g mul\n",str,just);	fprintf(stdout,"exch %.4g mul RM (%s) SH\n",just,str);}void image(int w, int h, int bps, float m[], unsigned char *samples)/*****************************************************************************Write sampled gray-scale image******************************************************************************Input:w		width of image (in samples)h		height of image (in samples)bps		number of bits per samplem		array[6] containing image matrixsamples		array[w*h] of sample values******************************************************************************Notes:Level 1 PostScript implementations support 1, 2, 4, and 8 bits persample.  Level 2 adds support for 12 bits per sample.Samples are hex-encoded, and output lines are limited to 78 characters.*****************************************************************************/{	int nline=39,i,rowbytes,nbytes;	char line[80],*linei,*hexi;	static int hexbuilt=0;

⌨️ 快捷键说明

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