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

📄 basic.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//*********************** self documentation **********************//*****************************************************************************BASIC - Basic C function interface to PostScriptbeginps		write PostScript prolog (including %%Pages comment)endps		write PostScript trailer (including %%Pages comment)begineps	write encapsulated PostScript prolog (no %%Pages comment)endeps		write encapsulated PostScript trailer (no %%Pages comment)boundingbox	set BoundingBox to llx lly urx urynewpage		print "%%%%Page: label ordinal" to stdoutshowpage	print "showpage" to stdoutgsave		print "GS" to stdoutgrestore	print "GR" to stdoutnewpath		print "NP" to stdoutclosepath	print "CP" to stdoutclip		print "clip" to stdouttranslate	print "tx ty TR" to stdout, tx,ty = translation in x,yscale		print "sx sy SC" to stdout, sx,sy = scaling in x,yrotate		print "angle RO" to stdout, angle = rotation angleconcat		print "m[0] m[1] m[2] m[3] m[4] m[5] CAT" to stdoutsetgray		print "gray setgray" to stdout, gray is 0-255 gray levelsetrgbcolor	print "red green blue setrgbcolor" to stdout			red,green,blue = 0-255 red,green,blue levelssetcolor	set color by name based on definition in color structuresetlinewidth	print "width SLW" to stdout, width = desired line widthsetlinejoin	print "code setlinejoin"setdash		print "[ dash ] offset setdash" to stdout			dash = array defining dash, offset = dash offsetmoveto		print "x y M" to stdout,   move to x,yrmoveto		print "x y RM" to stdout,  move to x,ylineto		print "x y L" to stdout, draw a line to x,yrlineto		print "x y RL" to stdout, draw a line to x,yarc		print "x y r ang1 ang2 arc" to stdout, draw an arc			x,y = vertex  r = radius from ang1 to ang2stroke		print "S" to stdoutfill		print "F" to stdoutshow 		print "str SH" to stdout, show a stringjustshow	justify and show a stringimage		write a sampled gray-scale imagergbimage	write sampled color (rgb) imagesetfont		execute findfont, scalefont, and setfont for specified font			 and sizefontbbox	determine font bounding box for specified font and sizefontheight	return maximum height for specified font and sizefontwidth	return maximum width for specified font and sizefontcapheight	return maximum capheight for specified font and sizefontxheight	return maximum xheight for specified font and sizefontdescender	return maximum descender for specified font and sizepolyline	draw a segmented linemarkto		draw a mark at specified locationrectclip	set a rectangular clipping pathrectfill	draw a filled rectanglestrokerect	stroke a rectangle******************************************************************************Function Prototypes:void beginps (void);void endps (void);void begineps (void);void endeps (void);void newpage (const char *label, int ordinal);void boundingbox (int llx, int lly, int urx, int ury);void showpage (void);void gsave (void);void grestore (void);void newpath (void);void closepath (void);void clip(void);void translate (float tx, float ty);void scale (float sx, float sy);void rotate (float angle);void concat (float m[]);void setgray (float gray);void setrgbcolor (float red, float green, float blue);void setcolor (const char *name);void setlinewidth (float width);void setlinejoin (int code);void setdash (float dash[], int ndash, float offset);void moveto (float x, float y);void rmoveto (float x, float y);void lineto (float x, float y);void rlineto (float x, float y);void arc (float x, float y, float r, float ang1, float ang2);void stroke (void);void fill (void);void show (const char *str);void justshow (float just, const char *str);void image (int w, int h, int bps, float m[], unsigned char *samples);void rgbimage (int w, int h, int bpc, float m[], unsigned char *samples);void setfont (const char *fontname, float fontsize);void fontbbox (const char *fontname, float fontsize, float bbox[]);float fontheight (const char *fontname, float fontsize);float fontwidth (const char *fontname, float fontsize);float fontcapheight (const char *fontname, float fontsize);float fontxheight (const char *fontname, float fontsize);float fontdescender (const char *fontname, float fontsize);float fontascender (const char *fontname, float fontsize);void polyline (const float *x, const float *y, int n);void markto (float x, float y, int index, float size);void rectclip (float x, float y, float width, float height);void rectfill (float x, float y, float width, float height);void rectstroke (float x, float y, float width, float height);******************************************************************************justshow:Input:just		justification factorstr		string******************************************************************************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******************************************************************************rgbimage: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******************************************************************************polyline:Input:x		array[n] of x-coordinatesy		array[n] of y-coordinatesn		number of points******************************************************************************markto:Input:x		x-coordinate of marky		y-coordinate of markindex		type of mark to drawsize		size of mark*****************************************************************************rectclip:Input:x		x-coordinate of clipping path originy		y-coordinate of clipping path originwidth		width of clipping pathheight		height of clipping path******************************************************************************rectfill:Input:x		x-coordinate of rectangle originy		y-coordinate of rectangle originwidth		width of rectangleheight		height of rectangle******************************************************************************strokerect:Input:x		x-coordinate of rectangle originy		y-coordinate of rectangle originwidth		width of rectangleheight		height of rectangle******************************************************************************Notes:The majority of these routines are self explanatory. They are justC wrappers that echo PostScript graphics commands.justshow: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")image: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.rgbimage: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.polyline:The path is stroked every 200 points.*****************************************************************************References:*****************************************************************************Author:  Dave Hale, Colorado School of Mines, 1989with modifications by Craig Artley, Colorado School of Mines, 1991, andadditions by Dave Hale, Advance Geophysical, 1992.*****************************************************************************//**************** end self doc ********************************//*AUTHOR:  Dave Hale, Colorado School of Mines, 06/27/89MODIFIED:  Craig Artley, Colorado School of Mines, 08/30/91		Change beginps/endps functions to allow BoundingBox at top.MODIFIED:  Dave Hale, Advance Geophysical, 10/17/92		Added function rgbimage().MODIFIED: Robert Krueger of Terrasys, Germany, 31 July 1998, added X 		Window style colormap decoding. */#include <stdio.h>#include "psplot.h"/* Conforming PostScript defaults */static struct {	int llx,lly,urx,ury;} BBox = {0,0,612,792};static int BBoxSet = 0;static int BBoxOut = 0;static int nPages = 0;/* Font metrics (take from the .afm files in the font library) */#define NFONTS 35#define FONTSCALE 0.001typedef struct {	char *name;	int fontbbox[4];	int capheight;	int xheight;	int descender;	int ascender;} FontMetric;static FontMetric FontMetrics[NFONTS] = {{"AvantGarde-Book",{-113,-222,1148,955},740,547,-192,740},{"AvantGarde-BookOblique",{-113,-222,1279,955},740,547,-192,740},{"AvantGarde-Demi",{-123, -251, 1222,1021},740,555,-185,740},{"AvantGarde-DemiOblique",{-123,-251,1256,1021},740,555,-185,740},{"Bookman-Demi",{-194,-250,1346,934},681,502,-212,725},{"Bookman-DemiItalic",{-231,-250,1333,941},681,515,-213,732},{"Bookman-Light",{-188,-251,1266,908},681,484,-228,717},{"Bookman-LightItalic",{-228,-250,1269,883}, 681,494,-212,717},{"Courier",{-28, -250, 628, 805}, 562, 426, -157, 629},{"Courier-Bold",{-113, -250, 749, 801}, 562, 439, -142, 626},{"Courier-BoldOblique",{-56, -250, 868, 801}, 562, 439, -142, 626},{"Courier-Oblique",{-28, -250, 742, 805}, 562, 426, -157, 629},{"Helvetica", {-166, -225, 1000, 931}, 718, 523, -207, 718},{"Helvetica-Bold",{-170, -228, 1003, 962}, 718, 532, -207, 718},{"Helvetica-BoldOblique",{-174, -228, 1114, 962}, 718, 532, -207, 718},{"Helvetica-Oblique",{-170, -225, 1116, 931}, 718, 523, -207, 718},{"Helvetica-Narrow",{-136,-225,820,931},718,523,-207,718},{"Helvetica-Narrow-Bold",{-139,-228,822,962},718,532,-207,718},{"Helvetica-Narrow-BoldOblique",{-143,-228,913,962},718,532,-207,718},{"Helvetica-Narrow-Oblique",{-139,-225,915,931},718,523,-207,228},{"NewCentrySchlbk-Bold",{-165,-250,1000,988},722,475,-205,737},{"NewCenturySchlbk-BoldItalic",{-205,-250,1147,991},722,477,-204,737},{"NewCenturySchlbk-Roman",{-195,-250,1000,965},722,464,-205,737},{"Palatino-Bold",{-152, -266, 1000, 924}, 681, 471, -258, 720},{"Palatino-BoldItalic",{-170,-271,1073,926}, 681,469,-271,726},{"Palatino-Italics",{-170, -276, 1010, 918}, 692, 482, -276, 733},{"Palatino-Roman",{-166, -283, 1021, 927}, 692, 469, -281, 726},{"Symbol",{-180, -293, 1090, 1010}, 729, 525, -219, 729},{"Times-Bold",{-168, -218, 1000, 935}, 676, 461, -205, 676},{"Times-BoldItalic",{-200, -218, 996, 921}, 669, 462, -205, 699},{"Times-Roman",{-168, -218, 1000, 898}, 662, 450, -217, 683},{"Times-Italic",{-169, -217, 1010, 883}, 653, 441, -205, 683},{"ZapfChancery-MediumItalic",{-181, -314, 1065, 831}, 708, 438, -314, 714},{"Unknown",{-174, -220, 1001, 944}, 729, 525, -219, 729},};/* Colors from box of 64 crayons, with some additions */#define NCOLOR 68static struct {	char *name;	float rgb[3];} colors[NCOLOR+1] = {	{"greenyellow",{0.85,0,0.31}},	{"yellow",{1,1,0}},	{"goldenrod",{1,0.9,0.16}},	{"dandelion",{1,0.71,0.16}},	{"apricot",{1,0.68,0.48}},	{"peach",{1,0.50,0.30}},	{"melon",{1,0.54,0.50}},	{"yelloworange",{1,0.58,0}},	{"orange",{1,0.39,0.13}},	{"burntorange",{1,0.49,0}},	{"bittersweet",{0.76,0.01,0}},	{"redorange",{1,0.23,0.13}},	{"mahogany",{0.65,0,0}},	{"maroon",{0.68,0,0}},	{"brickred",{1,0,0}},	{"red",{1,0,0}},	{"orangered",{1,0,0.50}},	{"rubinered",{1,0,0.87}},	{"wildstrawberry",{1,0.04,0.61}},	{"salmon",{1,0.47,0.62}},	{"carnationpink",{1,0.37,1}},	{"magenta",{1,0,1}},	{"violetred",{1,0.19,1}},	{"rhodamine",{1,0.18,1}},	{"mulberry",{0.64,0.08,0.98}},	{"redviolet",{0.59,0,0.64}},	{"fuchsia",{0.45,0.01,0.92}},	{"lavender",{1,0.52,1}},	{"thistle",{0.88,0.41,1}},	{"orchid",{0.68,0.36,1}},	{"darkorchid",{0.60,0.20,0.80}},	{"purple",{0.55,0.14,1}},	{"plum",{0.50,0,1}},	{"violet",{0.21,0.12,1}},	{"royalpurple",{0.25,0.10,1}},	{"blueviolet",{0.10,0.05,0.96}},	{"periwinkle",{0.43,0.45,1}},	{"cadetblue",{0.38,0.43,0.77}},	{"cornflowerblue",{0.35,0.87,1}},	{"midnightblue",{0,0.44,0.57}},	{"naveblue",{0.06,0.46,1}},	{"royalblue",{0,0.50,1}},	{"blue",{0,0,1}},	{"cerulean",{0.06,0.89,1}},	{"cyan",{0,1,1}},	{"processblue",{0.04,1,1}},	{"skyblue",{0.38,1,0.88}},	{"turquoise",{0.15,1,0.80}},	{"tealblue",{0.12,0.98,0.64}},	{"aquamarine",{0.18,1,0.70}},	{"bluegreen",{0.15,1,0.67}},	{"emerald",{0,1,0.50}},	{"junglegreen",{0.01,1,0.48}},	{"seagreen",{0.31,1,0.50}},	{"green",{0,1,0}},	{"forestgreen",{0,0.88,0}},	{"pinegreen",{0,0.75,0.16}},	{"limegreen",{0.50,1,0}},	{"yellowgreen",{0.56,1,0.26}},	{"springgreen",{0.74,1,0.24}},	{"olivegreen",{0,0.60,0}},	{"rawsienna",{0.55,0,0}},	{"sepia",{0.30,0,0}},	{"brown",{0.40,0,0}},	{"tan",{0.86,0.58,0.44}},	{"white",{1,1,1}},	{"black",{0,0,0}},	{"gray",{0.5,0.5,0.5}},	{"",{0,0,0}} /* spare, for arbitrary RGB definition */};

⌨️ 快捷键说明

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