GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72999
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends 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 struct rectangle
8 {
9  double t, b, l, r;
10 };
11 
12 static void remember(struct rectangle *box, double x, double y)
13 {
14  if (x > box->r)
15  box->r = x;
16  if (x < box->l)
17  box->l = x;
18  if (y > box->b)
19  box->b = y;
20  if (y < box->t)
21  box->t = y;
22 }
23 
24 static void transform(double *x, double *y,
25  int ix, int iy,
26  double orig_x, double orig_y)
27 {
28  double ax = text_size_x * ix / 25;
29  double ay = text_size_y * iy / 25;
30  double rx = ax * text_cosrot - ay * text_sinrot;
31  double ry = ax * text_sinrot + ay * text_cosrot;
32  *x = orig_x + rx;
33  *y = orig_y - ry;
34 }
35 
36 static void draw_char(double *px, double *py, unsigned char character, struct rectangle *box)
37 {
38  unsigned char *X;
39  unsigned char *Y;
40  int n_vects;
41  int i;
42  void (*func)(double, double);
43 
44  get_char_vects(character, &n_vects, &X, &Y);
45 
46  if (!box)
47  COM_Begin();
48 
49  func = COM_Move;
50 
51  for (i = 1; i < n_vects; i++) {
52  int ix, iy;
53  double x, y;
54 
55  if (X[i] == ' ') {
56  func = COM_Move;
57  continue;
58  }
59 
60  ix = 10 + X[i] - 'R';
61  iy = 10 - Y[i] + 'R';
62 
63  transform(&x, &y, ix, iy, *px, *py);
64 
65  if (box)
66  remember(box, x, y);
67  else {
68  (*func)(x, y);
69  func = COM_Cont;
70  }
71  }
72 
73  transform(px, py, 20, 0, *px, *py);
74 
75  if (box)
76  remember(box, *px, *py);
77  else
78  COM_Stroke();
79 }
80 
81 static void draw_text(const char *string, struct rectangle *box)
82 {
83  double base_x = cur_x;
84  double base_y = cur_y;
85  const unsigned char *p;
86 
87  for (p = (const unsigned char *) string; *p; p++)
88  draw_char(&base_x, &base_y, *p, box);
89 }
90 
91 void get_text_ext(const char *string, double *top, double *bot, double *left, double *rite)
92 {
93  struct rectangle box;
94 
95  box.t = 1e300;
96  box.b = -1e300;
97  box.l = 1e300;
98  box.r = -1e300;
99 
100  draw_text(string, &box);
101 
102  *top = box.t;
103  *bot = box.b;
104  *left = box.l;
105  *rite = box.r;
106 }
107 
108 void soft_text(const char *string)
109 {
110  draw_text(string, NULL);
111 }
112 
double text_size_y
Definition: driver/init.c:36
double b
Definition: text2.c:9
void get_text_ext(const char *, double *, double *, double *, double *)
Definition: text2.c:91
void COM_Cont(double x, double y)
Definition: driver/draw.c:23
double cur_y
Definition: driver/init.c:33
double r
Definition: text2.c:9
double cur_x
Definition: driver/init.c:32
double text_sinrot
Definition: driver/init.c:38
#define NULL
Definition: ccmath.h:32
#define x
double l
Definition: r_raster.c:39
double t
Definition: r_raster.c:39
double text_size_x
Definition: driver/init.c:35
void COM_Stroke(void)
Definition: driver/draw.c:35
void soft_text(const char *)
Definition: text2.c:108
Definition: clip.h:17
#define Y
Definition: ogsf.h:138
double t
Definition: text2.c:9
#define X
Definition: ogsf.h:137
void COM_Move(double x, double y)
Definition: driver/draw.c:17
double l
Definition: text2.c:9
void COM_Begin(void)
Definition: driver/draw.c:11
double text_cosrot
Definition: driver/init.c:39
int get_char_vects(unsigned char, int *, unsigned char **, unsigned char **)
Definition: font2.c:191