/***********************************************************************/ /* Open Visualization Data Explorer */ /* (C) Copyright IBM Corp. 1989,1999 */ /* ALL RIGHTS RESERVED */ /* This code licensed under the */ /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ /***********************************************************************/ #include /* * $Header: /home/gda/dxcvs/dx/src/exec/dxmods/caption.c,v 1.3 1999/05/10 15:45:22 gda Exp $ */ #include #include #include #define FLAG_VIEWPORT 0 #define FLAG_PIXEL 1 #define ABS(a) ((a)>0.0 ? (a) : -(a)) static Object Caption(char **s, int n, Point p, int flag, Point ref, double align, double h, char *f, Vector x, Vector y) { Matrix m; Vector z; Object a[100], b=NULL, c=NULL, o=NULL, oo=NULL, font; float ascent, descent, widths[100], width, height, lead=.133; Group g=NULL; int i, vertical; float xr, yr, xMin, xMax, yMin, yMax; Vector xlate; /* check vectors */ if (DXLength(x)==0) { DXSetError(ERROR_BAD_PARAMETER, "#11822", "direction"); return ERROR; } if (DXLength(y)==0) { DXSetError(ERROR_BAD_PARAMETER, "#11822","up"); return ERROR; } /* for error recovery */ for (i=0; i width) width = widths[i]; } /* the height is the total letter height */ height = n*(ascent+descent) + (n-1)*lead; x = DXNormalize(x); if (ABS(x.x) < ABS(x.y)) vertical=1; else vertical=0; y = DXNormalize(y); z = DXNormalize(DXCross(x, y)); { float r = sqrt(x.x*x.x + x.y*x.y); xr = x.x / r; yr = x.y / r; } #define MINMAX(a,b) \ { float xx = (a)*xr - (b)*yr; \ float yy = (a)*yr + (b)*xr; \ if (xx > xMax) xMax = xx; \ if (yy > yMax) yMax = yy; \ if (xx < xMin) xMin = xx; \ if (yy < yMin) yMin = yy; \ } xMin = yMin = DXD_MAX_FLOAT; xMax = yMax = -DXD_MAX_FLOAT; MINMAX(0, -descent); MINMAX(width, -descent); MINMAX(width, height-descent); MINMAX(0, height-descent); #undef MINMAX xlate.x = ((xMin + ref.x*(xMax-xMin))*h); xlate.y = ((yMin + ref.y*(yMax-yMin))*h); /* place the captions, put them in the group */ for (i=0; iz = 0; return rc; } Error m_Caption(Object *in, Object *out) { Vector x, y; Point p, ref; Array positionobject=NULL; char *s[100], *f, tmpstring[1000], buf[1000], *s1[100], *newstring; float h, align, *pptr; int flag, n, vertical, horizontal, i, j, k, count=0; /* string(s) */ if (!in[0]) { DXSetError(ERROR_BAD_PARAMETER, "#10000", "string"); goto error; } else { for (n=0; n<100; n++) if (!DXExtractNthString(in[0], n, &s[n])) break; if (!n) { DXSetError(ERROR_BAD_PARAMETER, "#10200","string"); goto error; } } /* look for newlines in the string */ count = 0; for (i=0; i