Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!ucsd!ucbvax!parc.xerox.com!janssen From: janssen@parc.xerox.com (Bill Janssen) Newsgroups: comp.soft-sys.andrew Subject: new method for fontdesc? StringBoundingBox. Message-ID: Date: 6 Jun 90 02:48:33 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 39 I find myself using this code over and over, and think something like it might be nice to have in the fontdesc code. It takes a font, graphic, and string, and returns the width and height of that string in that font on that graphic, in pixels. Its return value is the width, in pixels. long fontdesc_StringBoundingBox (font, graphic, string, width, height) struct fontdesc *font; struct graphic *graphic; char *string; int *width; int *height; { int w, a, d, ascent, descent, junk; register short *fwt, *fht; register char *p; static struct fontdesc_charInfo ci; #define MAX(a,b) (((a)>(b))?(a):(b)) fwt = fontdesc_WidthTable (font, graphic); fht = fontdesc_HeightTable (font, graphic); if (fwt == NULL || fht == NULL) return 0; fontdesc_StringSize (font, graphic, string, &w, &junk); for (p = string, a = 0, d = 0; *p != (char) 0; p += 1) { fontdesc_CharSummary (font, graphic, *p, &ci); ascent = ci.yOriginOffset; descent = ci.height - ascent; a = MAX(a,ascent); d = MAX(d,descent); } *width = w; *height = a + d; return (w); } [An Andrew ToolKit view (a raster image) was included here, but could not be displayed.]