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

📄 pslegendbox.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* Copyright (c) Colorado School of Mines, 1999.*//* All rights reserved.                       *//*********************** self documentation **********************//*****************************************************************************PSLEGENDBOX - Functions to draw PostScript axes and estimate bounding boxpsLegendBox	Draw an legend box via PostScriptpsLegendBBox	estimate bounding box for an legend box drawn via psLegendBox******************************************************************************Function Prototypes:void psLegendBox(	float x, float y, float width, float height,	float x1Beg, float x1End, float p1Beg, float p1End, 	float d1Num, float f1Num, int n1Tic, int grid1, char *label1,	char *labelFont, float labelSize,	char *axesColor, char *gridColor,	int style);void psLegendBBox(	float x, float y, float width, float height,	char *labelFont, float labelSize,	int style, int bbox[]);******************************************************************************psLegendBox:Input:x		x coordinate of lower left corner of boxy		y coordinate of lower left corner of boxwidth		width of boxheight		height of boxx1Beg  		axis value at beginning of axis 1x1End		axis value at end of axis 1p1Beg  		pad value at beginning of axis 1p1End		pad value at end of axis 1d1Num		numbered tic increment for axis 1 (0.0 for automatic)f1Num		first numbered tic for axis 1n1Tic		number of horizontal tics per numbered tic for axis 1grid1		grid code for axis 1:  NONE, DOT, DASH, or SOLIDlabel1		label for axis 1labelFont	name of font to use for axes labelslabelSize	size of font to use for axes labelsaxesColor	color to use for axes and axes labelsgridColor	color to use for grid linesstyle		VERTLEFT (Vertical, axis label on left side) 		VERTRIGHT (Vertical, axis label on right side) 		HORIBOTTOM (Horizontal, axis label on bottom)*****************************************************************************psLegendBBox:Input:x		x coordinate of lower left corner of boxy		y coordinate of lower left corner of boxwidth		width of boxheight		height of boxlabelFont	name of font to use for axes labelslabelSize	size of font to use for axes labelsstyle		VERTLEFT (Vertical, axis label on left side) 		VERTRIGHT (Vertical, axis label on right side) 		HORIBOTTOM (Horizontal, axis label on bottom)Output:bbox		bounding box (bbox[0:3] = llx, lly, ulx, uly)******************************************************************************Notes:psLegendBox:psLegendBox will determine the numbered tic increment and first numberedtic automatically, if the specified increment is zero.  Axis numberingis in scientific notation, if necessary and is plotted to foursignificant digits.Pad values must be specified in the same units as the correspondingLegend values.  These pads are useful when the contents of the Legend boxrequires more space than implied by the Legend values.  For example, thefirst and last seismic wiggle traces plotted inside an Legend box willtypically extend beyond the Legend values corresponding to the first andlast traces.  However, all tics will lie with the limits specified inthe Legend values (x1Beg, x1End, x2Beg, x2End).psLegendBBox:psLegendBBox uses font sizes to estimate the bounding box foran Legend box drawn with psLegendBox.  To be on the safe side, psLegendBBox overestimates.psLegendBBox assumes that the Legend labels and titles do not extendbeyond the corresponding edges of the Legend box.******************************************************************************References:(see References for basic.c)******************************************************************************Author:   Dave Hale,  Colorado School of Mines, 06/27/89Modified: Ken Larner, Colorado School of Mines, 08/30/90Modified: Dave Hale, Advance Geophysical, 10/18/92	Added color parameters for title, axes, and grid.Modified: Torsten Schoenfelder, Koeln, Germany, 07/06/97        Display a legend for ps file, move axis from left to rightModified: Torsten Schoenfelder, Koeln, Germany, 10/02/98        Corrected width of bbox to include legend title*****************************************************************************//**************** end self doc ********************************/#include "cwp.h"#include "psplot.h"#define RIGHT 0#define LEFT 1#define IROUND(x) (int)((x) > 0 ? (x) + .5 : (x) - .5) #define FMAX(x,y) (float) (x) > (y) ? (x) : (y) #define FMIN(x,y) (float) (x) > (y) ? (y) : (x) void psLegendBox(	float x, float y, float width, float height,	float x1Beg, float x1End, float p1Beg, float p1End, 	float d1Num, float f1Num, int n1Tic, int grid1, char *label1,	char *labelFont, float labelSize,	char *axesColor, char *gridColor,	int style)/*****************************************************************************Draw an legend box via PostScript******************************************************************************Input:x		x coordinate of lower left corner of boxy		y coordinate of lower left corner of boxwidth		width of boxheight		height of boxx1Beg  		axis value at beginning of axis 1x1End		axis value at end of axis 1p1Beg  		pad value at beginning of axis 1p1End		pad value at end of axis 1d1Num		numbered tic increment for axis 1 (0.0 for automatic)f1Num		first numbered tic for axis 1n1Tic		number of horizontal tics per numbered tic for axis 1grid1		grid code for axis 1:  NONE, DOT, DASH, or SOLIDlabel1		label for axis 1labelFont	name of font to use for axes labelslabelSize	size of font to use for axes labelsaxesColor	color to use for axes and axes labelsgridColor	color to use for grid linesstyle		VERTLEFT (Vertical, axis label on left side) 		VERTRIGHT (Vertical, axis label on right side) 		HORIBOTTOM (Horizontal, axis label on bottom)******************************************************************************Notes:psLegendBox will determine the numbered tic increment and first numberedtic automatically, if the specified increment is zero.  Axis numberingis in scientific notation, if necessary and is plotted to foursignificant digits.Pad values must be specified in the same units as the correspondingaxes values.  These pads are useful when the contents of the axes boxrequires more space than implied by the axes values.  For example, thefirst and last seismic wiggle traces plotted inside an axes box willtypically extend beyond the axes values corresponding to the first andlast traces.  However, all tics will lie with the limits specified inthe axes values (x1Beg, x1End, x2Beg, x2End).** This function has to display a box of width and height. It is not changing** both according to vertical or horizontal layout. It is only moving the axis******************************************************************************Author:   Dave Hale,  Colorado School of Mines, 06/27/89Modified: Ken Larner, Colorado School of Mines, 08/30/90Modified: Dave Hale, Colorado School of Mines, 10/18/92	Added color parameters for title, axes, and grid.Modified: Torsten Schoenfelder, Koeln, Germany, 07/06/97        Display a legend for ps file*****************************************************************************/{	int n1num,ntic,ndash=0,grided;	int ndig,ndigits,nexp,nexpmax=0,nexplot1,		nplaces,nplacesmax,nformat;	float xa,ticsize,dnum,fnum,dtic,amin,amax,azero,		base,scale,anum,anumnorm,atic,fnexp,		ticb,numb,labelb,dash[2],		labelCH,labelCW,labelCA,labelCD,		pnorm,fdexp,azeronorm;	char str[256],str2[256],sformat[256];	int ticsside=LEFT;	if (style==VERTRIGHT) ticsside=RIGHT;	/* determine font dimensions */	labelCH = fontheight(labelFont,labelSize);	labelCW = fontwidth(labelFont,labelSize); /* Not accounting for real width 						  ** of every char. A '0' needs labelCW/2,						  ** a '.' needs labelCW/4 */	labelCA = fontascender(labelFont,labelSize);	labelCD = fontdescender(labelFont,labelSize);	/* keep width and height, even if rotating box */	/* determine numbered tic intervals */	if (d1Num==0.0) {	  if ((style==VERTLEFT) || (style==VERTRIGHT)) { /* vertical */	    n1num = IROUND(height/(2.0*labelCH)); /* 4.* is too much for legend */	  } else { /* horizontal */	    n1num = IROUND(width/(3.5*labelCW)); /* 4.* may be OK for legends with large width */	  }	  scaxis(x1Beg,x1End,&n1num,&d1Num,&f1Num);	}	/* save graphics state */	gsave();	/* translate coordinate system, so that origin is at x,y */	translate(x,y);	/* start a new path (just to be safe) */	newpath();	/* set font and character size */	setfont(labelFont,labelSize);	/* determine tic size */	if ((style==VERTLEFT) || (style==VERTRIGHT)) { /* vertical */	  ticsize = 0.3*labelCW;	} else { /* horizontal */	  ticsize = 0.3*labelCH;	}	/* draw axis 1 */	setcolor(axesColor);	amin = (x1Beg<x1End)?x1Beg:x1End;	amax = (x1Beg>x1End)?x1Beg:x1End;	azero = 0.0001*(amax-amin);	dnum = d1Num;  fnum = f1Num;  ntic = n1Tic;	if ((style==VERTLEFT) || (style==VERTRIGHT)) { /* vertical */	  scale = height/(x1End+p1End-x1Beg-p1Beg);	} else { /* horizontal */	  scale = width/(x1End+p1End-x1Beg-p1Beg);	}	base = -scale*(x1Beg+p1Beg);	ticb = -ticsize;	numb = 1.2*ticb-labelCA;	if((style==VERTLEFT) || (style==VERTRIGHT)) numb = 1.2*ticb;	labelb = numb-labelCH;	/* determine axis1 exponent for scientific notation   */	ndigits = 0;	ndig    = 0;	fdexp = log10(1.001*ABS(dnum));	if(fdexp<0.)   fdexp -=1.0;	for (anum=fnum; anum<=amax; anum+=dnum) {		if(anum==fnum && anum==0.)			nexpmax = 0;		nexp    = 0;		if(anum!=0.)   {			fnexp = log10(1.001*ABS(anum));			if(fnexp>0.)   nexp    = (int)fnexp;			else           nexp    = (int)fnexp-1;					if(anum==fnum)				nexpmax = nexp;

⌨️ 快捷键说明

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