~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/src/gist/gtext.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GTEXT.C
 
3
 *
 
4
 * $Id: gtext.c,v 1.1 2003/03/08 15:26:45 travo Exp $
 
5
 *
 
6
 * Define GIST text utilities
 
7
 *
 
8
 */
 
9
/*    Copyright (c) 1994.  The Regents of the University of California.
 
10
                    All rights reserved.  */
 
11
 
 
12
#include "gtext.h"
 
13
 
 
14
extern long strcspn(const char *, const char *);
 
15
 
 
16
int gtDoEscapes= 1;
 
17
 
 
18
/* Return t->alignH, t->alignV, guaranteed not TH_NORMAL or TV_NORMAL */
 
19
void GtGetAlignment(const GpTextAttribs *t, int *alignH, int *alignV)
 
20
{
 
21
  *alignH= t->alignH;
 
22
  *alignV= t->alignV;
 
23
  if (*alignH==TH_NORMAL) *alignH= TH_LEFT;
 
24
  if (*alignV==TV_NORMAL) *alignV= TV_BASE;
 
25
}
 
26
 
 
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)
 
32
{
 
33
  int path= t->orient;
 
34
  GpReal wdest, thisWid;
 
35
  int nLines, nChars;
 
36
 
 
37
  /* Count lines in this text, find widest line */
 
38
  nLines= 0;
 
39
  wdest= 0.0;
 
40
  while ((text= GtNextLine(text, &nChars, path))) {
 
41
    nLines++;
 
42
    if (Width) thisWid= Width(text, nChars, t);
 
43
    else thisWid= (GpReal)nChars;
 
44
    if (thisWid>wdest) wdest= thisWid;
 
45
    text+= nChars;
 
46
  }
 
47
 
 
48
  *widest= wdest;
 
49
  return nLines;
 
50
}
 
51
 
 
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)
 
57
{
 
58
  char first= text[0];
 
59
 
 
60
  if (!first) {
 
61
    *nChars= 0;
 
62
    return 0;
 
63
  }
 
64
 
 
65
  if (first=='\n') text+= 1;
 
66
  *nChars= strcspn(text, "\n");
 
67
 
 
68
  return text;
 
69
}