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

📄 basic.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
	static char hex[513];	/* build table of hex codes if not already built */	if (!hexbuilt) {		for (i=0; i<256; i++)			sprintf(&hex[2*i],"%02x",(unsigned int) i);		hexbuilt = 1;	}	/* determine number of bytes per row and total number of bytes */	rowbytes = 1+(w*bps-1)/8;	nbytes = rowbytes*h;	/* set up the image */	fprintf(stdout,"/picstr %d string def\n",rowbytes);	fprintf(stdout,"%d %d %d [%.4g %.4g %.4g %.4g %.4g %.4g]\n",		w,h,bps,m[0],m[1],m[2],m[3],m[4],m[5]);	fprintf(stdout,"{currentfile picstr readhexstring pop} image\n");	/* encode and write the image in lines of 78 hex characters */	while(nbytes) {		if (nbytes<nline) nline = nbytes;		for (i=0,linei=line; i<nline; i++) {			hexi = hex+2*(*samples++);			*linei++ = *hexi++;			*linei++ = *hexi;		}		*linei++ = '\n';		*linei = '\0';		fputs(line,stdout);		nbytes -= nline;	}}void rgbimage(int w, int h, int bpc, float m[], unsigned char *samples)/*****************************************************************************Write sampled color (rgb) image******************************************************************************Input:w		width of image (in samples)h		height of image (in samples)bpc		number of bits per componentm		array[6] containing image matrixsamples		array[3*w*h] of sample values******************************************************************************Notes:In general, Level 1 PostScript implementations do not support rgbimage.Level 2 supports 1, 2, 4, 8, and 12 bits per color component.  Thesamples array should contain three color components (in R,G,B... order)for each sample value.  Samples are hex-encoded, and output lines arelimited to 78 characters.*****************************************************************************/{	int ncomp=3,nline=39,i,rowbytes,nbytes;	char line[80],*linei,*hexi;	static int hexbuilt=0;	static char hex[513];	/* build table of hex codes if not already built */	if (!hexbuilt) {		for (i=0; i<256; i++)			sprintf(&hex[2*i],"%02x",(unsigned int) i);		hexbuilt = 1;	}	/* determine number of bytes per row and total number of bytes */	rowbytes = 1+(w*bpc*ncomp-1)/8;	nbytes = rowbytes*h;	/* set up the image */	fprintf(stdout,"/picstr %d string def\n",rowbytes);	fprintf(stdout,"%d %d %d [%.4g %.4g %.4g %.4g %.4g %.4g]\n",		w,h,bpc,m[0],m[1],m[2],m[3],m[4],m[5]);	fprintf(stdout,"{currentfile picstr readhexstring pop}\n");	fprintf(stdout,"false %d colorimage\n",ncomp);	/* encode and write the image in lines of 78 hex characters */	while(nbytes) {		if (nbytes<nline) nline = nbytes;		for (i=0,linei=line; i<nline; i++) {			hexi = hex+2*(*samples++);			*linei++ = *hexi++;			*linei++ = *hexi;		}		*linei++ = '\n';		*linei = '\0';		fputs(line,stdout);		nbytes -= nline;	}}void setfont(const char *fontname, float fontsize)/*****************************************************************************Execute findfont, scalefont, and setfont for specified font and size*****************************************************************************/{	fprintf(stdout,"/%s findfont %.4g scalefont setfont\n",fontname,fontsize);}void fontbbox(const char *fontname, float fontsize, float bbox[])/*****************************************************************************Determine font bounding box for specified font and size*****************************************************************************/{	int i = fontindex(fontname);	int *b = FontMetrics[i].fontbbox;	bbox[0] = b[0]*FONTSCALE*fontsize;	bbox[1] = b[1]*FONTSCALE*fontsize;	bbox[2] = b[2]*FONTSCALE*fontsize;	bbox[3] = b[3]*FONTSCALE*fontsize;}float fontheight(const char *fontname, float fontsize)/*****************************************************************************Return maximum height for specified font and size*****************************************************************************/{	int i;	float h;	i = fontindex(fontname);	h = FontMetrics[i].fontbbox[3] - FontMetrics[i].fontbbox[1];	h *= FONTSCALE*fontsize;	return h;}float fontwidth(const char *fontname, float fontsize)/*****************************************************************************Return maximum width for specified font and size*****************************************************************************/{	int i;	float w;	i = fontindex(fontname);	w = FontMetrics[i].fontbbox[2] - FontMetrics[i].fontbbox[0];	w *= FONTSCALE*fontsize;	return w;}float fontcapheight(const char *fontname, float fontsize)/*****************************************************************************Return maximum capheight for specified font and size*****************************************************************************/{	int i = fontindex(fontname);	return FontMetrics[i].capheight*FONTSCALE*fontsize;}float fontxheight(const char *fontname, float fontsize)/*****************************************************************************Return maximum xheight for specified font and size*****************************************************************************/{	int i = fontindex(fontname);	return FontMetrics[i].xheight*FONTSCALE*fontsize;}float fontdescender(const char *fontname, float fontsize)/*****************************************************************************Return maximum descender for specified font and size*****************************************************************************/{	int i = fontindex(fontname);	return FontMetrics[i].descender*FONTSCALE*fontsize;}float fontascender(const char *fontname, float fontsize)/*****************************************************************************Return maximum ascender for specified font and size*****************************************************************************/{	int i = fontindex(fontname);	return FontMetrics[i].ascender*FONTSCALE*fontsize;}void polyline(const float *x, const float *y, int n)/*****************************************************************************Draw a segmented line******************************************************************************Input:x		array[n] of x-coordinatesy		array[n] of y-coordinatesn		number of points******************************************************************************Notes:The path is stroked every 200 points.*****************************************************************************/{	int i;	gsave();	newpath();	moveto(x[0],y[0]);	for (i=1; i<n; i++) {		lineto(x[i],y[i]);		if (i%200==0) {			stroke();			moveto(x[i],y[i]);		}	}	stroke();	grestore();}void markto(float x, float y, int index, float size)/*****************************************************************************Draw a mark at specified location******************************************************************************Input:x		x-coordinate of marky		y-coordinate of markindex		type of mark to drawsize		size of mark*****************************************************************************/{	gsave();	translate(x,y);	scale(size,size);	fprintf(stdout,"CLW %0.4g div SLW\n",size);	newpath();	switch (index%NMARKS) {	case MPLUS: /* plus */		moveto(-0.5,0.0);		rlineto(1.0,0.0);		moveto(0.0,-0.5);		rlineto(0.0,1.0);		stroke();		break;	case MASTERISK: /* asterisk */		moveto(-0.5,0.0);		rlineto(1.0,0.0);		moveto(-0.25,-0.433);		rlineto(0.5,0.866);		moveto(-0.25,0.433);		rlineto(0.5,-0.866);		stroke();		break;	case MCROSS: /* X */		moveto(-0.5,-0.5);		rlineto(1.0,1.0);		moveto(-0.5,0.5);		rlineto(1.0,-1.0);		stroke();		break;	case MTRIANGLE: /* triangle */		moveto(-0.5,-0.25);		rlineto(1.0,0.0);		rlineto(-0.5,0.809);		closepath();		stroke();		break;	case MSQUARE: /* square */		moveto(-0.5,-0.5);		rlineto(1.0,0.0);		rlineto(0.0,1.0);		rlineto(-1.0,0.0);		closepath();		stroke();		break;	case MCIRCLE: /* circle */		arc(0.0,0.0,0.5,0.0,360.0);		stroke();		break;	case MFILLEDTRIANGLE: /* filled triangle */		moveto(-0.5,-0.25);		rlineto(1.0,0.0);		rlineto(-0.5,0.809);		closepath();		fill();		break;	case MFILLEDSQUARE: /* filled square */		moveto(-0.5,-0.5);		rlineto(1.0,0.0);		rlineto(0.0,1.0);		rlineto(-1.0,0.0);		closepath();		fill();		break;	case MFILLEDCIRCLE: /* filled circle */		arc(0.0,0.0,0.5,0.0,360.0);		fill();		break;	}	grestore();}void rectclip(float x, float y, float width, float height)/*****************************************************************************Set a rectangular clipping path******************************************************************************Input:x		x-coordinate of clipping path originy		y-coordinate of clipping path originwidth		width of clipping pathheight		height of clipping path*****************************************************************************/{	newpath();	moveto(x,y);	rlineto(width,0.0);	rlineto(0.0,height);	rlineto(-width,0.0);	closepath();	clip();	newpath();}void rectfill(float x, float y, float width, float height)/*****************************************************************************Draw a filled rectangle******************************************************************************Input:x		x-coordinate of rectangle originy		y-coordinate of rectangle originwidth		width of rectangleheight		height of rectangle*****************************************************************************/{	gsave();	newpath();	moveto(x,y);	rlineto(width,0.0);	rlineto(0.0,height);	rlineto(-width,0.0);	closepath();	fill();	grestore();}void rectstroke(float x, float y, float width, float height)/*****************************************************************************Stroke a rectangle******************************************************************************Input:x		x-coordinate of rectangle originy		y-coordinate of rectangle originwidth		width of rectangleheight		height of rectangle*****************************************************************************/{	gsave();	newpath();	moveto(x,y);	rlineto(width,0.0);	rlineto(0.0,height);	rlineto(-width,0.0);	closepath();	stroke();	grestore();}

⌨️ 快捷键说明

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