4
* $Id: gtext.c,v 1.1 2003/03/08 15:26:45 travo Exp $
6
* Define GIST text utilities
9
/* Copyright (c) 1994. The Regents of the University of California.
10
All rights reserved. */
14
extern long strcspn(const char *, const char *);
18
/* Return t->alignH, t->alignV, guaranteed not TH_NORMAL or TV_NORMAL */
19
void GtGetAlignment(const GpTextAttribs *t, int *alignH, int *alignV)
23
if (*alignH==TH_NORMAL) *alignH= TH_LEFT;
24
if (*alignV==TV_NORMAL) *alignV= TV_BASE;
27
/* Get shape of text input to GdText, given a function Width which can
28
compute the width of a simple text string (no imbedded \n). Returns
29
largest value of Width for any line, and a line count. */
30
int GtTextShape(const char *text, const GpTextAttribs *t,
31
WidthFunction Width, GpReal *widest)
34
GpReal wdest, thisWid;
37
/* Count lines in this text, find widest line */
40
while ((text= GtNextLine(text, &nChars, path))) {
42
if (Width) thisWid= Width(text, nChars, t);
43
else thisWid= (GpReal)nChars;
44
if (thisWid>wdest) wdest= thisWid;
52
/* Return the next line of text--
53
returns text and a count of the characters in the
54
line, nChars. If text is '\0', or '\n', returns text+1 and
55
a count of the number of characters to the next '\n' or '\0'. */
56
const char *GtNextLine(const char *text, int *nChars, int path)
65
if (first=='\n') text+= 1;
66
*nChars= strcspn(text, "\n");