GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
text2.c
Go to the documentation of this file.
1 #include <math.h>
2 
3 #include <grass/gis.h>
4 #include "driver.h"
5 #include "driverlib.h"
6 
7 static int am_inside;
8 static int dont_draw;
9 static int t, b, l, r;
10 static double basex, basey;
11 static double curx, cury;
12 
13 static void remember(double x, double y)
14 {
15  if ((int)x > r)
16  r = (int)x;
17  if ((int)x < l)
18  l = (int)x;
19  if ((int)y > b)
20  b = (int)y;
21  if ((int)y < t)
22  t = (int)y;
23 
24  curx = x;
25  cury = y;
26 }
27 
28 static void text_draw(double x, double y)
29 {
30  int X1 = (int)x;
31  int Y1 = (int)y;
32  int X2 = (int)curx;
33  int Y2 = (int)cury;
34 
35  if (am_inside) {
36  COM_Cont_abs(X1, Y1);
37  }
38  else {
39  COM_Move_abs(X2, Y2);
40  COM_Cont_abs(X1, Y1);
41  am_inside = 1;
42  }
43 
44  curx = x;
45  cury = y;
46 }
47 
48 static void text_move(double x, double y)
49 {
50  int X1 = (int)x;
51  int Y1 = (int)y;
52 
53  if (am_inside)
54  COM_Move_abs(X1, Y1);
55 
56  curx = x;
57  cury = y;
58 }
59 
60 void drawchar(double text_size_x, double text_size_y,
61  double sinrot, double cosrot, unsigned char character)
62 {
63  unsigned char *X;
64  unsigned char *Y;
65  int n_vects;
66  int i;
67  int ax, ay;
68  double x, y;
69  void (*Do) (double, double);
70  int ix, iy;
71 
72  x = basex;
73  y = basey;
74 
75  get_char_vects(character, &n_vects, &X, &Y);
76 
77  Do = text_move;
78 
79  for (i = 1; i < n_vects; i++) {
80  if (X[i] == ' ') {
81  Do = text_move;
82  continue;
83  }
84 
85  ix = 10 + X[i] - 'R';
86  iy = 10 - Y[i] + 'R';
87  ax = (int)(text_size_x * (double)ix);
88  ay = (int)(text_size_y * (double)iy);
89 
90  if (dont_draw) {
91  remember(x + (ax * cosrot - ay * sinrot),
92  y - (ax * sinrot + ay * cosrot));
93  }
94  else {
95  (*Do) (x + (ax * cosrot - ay * sinrot),
96  y - (ax * sinrot + ay * cosrot));
97  Do = text_draw;
98  }
99  }
100  /* This seems to do variable spacing
101  ix = 10 + X[i] - 'R';
102  */
103  ix = 20;
104  iy = 0;
105  ax = (int)(text_size_x * (double)ix);
106  ay = (int)(text_size_y * (double)iy);
107  if (!dont_draw)
108  text_move(basex + (ax * cosrot - ay * sinrot),
109  basey - (ax * sinrot + ay * cosrot));
110  else
111  remember(basex + (ax * cosrot - ay * sinrot),
112  basey - (ax * sinrot + ay * cosrot));
113 }
114 
115 void soft_text_ext(int x, int y,
116  double text_size_x, double text_size_y,
117  double text_rotation, const char *string)
118 {
119  t = 999999;
120  b = 0;
121  l = 999999;
122  r = 0;
123  dont_draw = 1;
124  soft_text(x, y, text_size_x, text_size_y, text_rotation, string);
125  dont_draw = 0;
126 }
127 
128 void get_text_ext(int *top, int *bot, int *left, int *rite)
129 {
130  *top = t;
131  *bot = b;
132  *left = l;
133  *rite = r;
134 }
135 
136 # define RpD ((2 * M_PI) / 360.) /* radians/degree */
137 # define D2R(d) (double)(d * RpD) /* degrees->radians */
138 
139 void soft_text(int x, int y,
140  double text_size_x, double text_size_y, double text_rotation,
141  const char *string)
142 {
143  double sinrot = sin(D2R(text_rotation));
144  double cosrot = cos(D2R(text_rotation));
145 
146  am_inside = 0;
147  curx = basex = (double)x;
148  cury = basey = (double)y;
149  while (*string) {
150  drawchar(text_size_x, text_size_y, sinrot, cosrot, *string++);
151  basex = curx;
152  basey = cury;
153  }
154 }
155 
156 void onechar(int x, int y,
157  double text_size_x, double text_size_y, double text_rotation,
158  unsigned char achar)
159 {
160  double sinrot = sin(D2R(text_rotation));
161  double cosrot = cos(D2R(text_rotation));
162 
163  am_inside = 0;
164  curx = basex = (double)x;
165  cury = basey = (double)y;
166  drawchar(text_size_x, text_size_y, sinrot, cosrot, achar);
167 }
void get_text_ext(int *, int *, int *, int *)
Definition: text2.c:128
double text_size_y
Definition: driver/init.c:41
int l
Definition: dataquad.c:292
float b
Definition: named_colr.c:8
void COM_Move_abs(int, int)
Definition: Move.c:4
float r
Definition: named_colr.c:8
#define Y(x)
Definition: display/draw.c:246
#define X(y)
Definition: display/draw.c:248
int y
Definition: plot.c:34
double text_rotation
Definition: driver/init.c:42
double text_size_x
Definition: driver/init.c:40
void soft_text(int, int, double, double, double, const char *)
Definition: text2.c:139
#define D2R(d)
Definition: text2.c:137
int
Definition: g3dcolor.c:48
void soft_text_ext(int x, int, double, double, double, const char *)
Definition: text2.c:115
void onechar(int, int, double, double, double, unsigned char)
Definition: text2.c:156
void COM_Cont_abs(int x, int y)
Definition: Cont.c:4
void drawchar(double, double, double, double, unsigned char)
Definition: text2.c:60
int get_char_vects(unsigned char, int *, unsigned char **, unsigned char **)
Definition: font2.c:191