GRASS GIS 8 Programmer's Manual
8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
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
double
t, b, l, r;
9
};
10
11
static
void
remember(
struct
rectangle *box,
double
x
,
double
y)
12
{
13
if
(
x
> box->r)
14
box->r =
x
;
15
if
(
x < box->
l
)
16
box->l =
x
;
17
if
(y > box->b)
18
box->b = y;
19
if
(y < box->
t
)
20
box->t = y;
21
}
22
23
static
void
transform(
double
*
x
,
double
*y,
int
ix,
int
iy,
double
orig_x,
24
double
orig_y)
25
{
26
double
ax =
text_size_x
* ix / 25;
27
double
ay =
text_size_y
* iy / 25;
28
double
rx = ax *
text_cosrot
- ay *
text_sinrot
;
29
double
ry = ax *
text_sinrot
+ ay *
text_cosrot
;
30
*
x
= orig_x + rx;
31
*y = orig_y - ry;
32
}
33
34
static
void
draw_char(
double
*px,
double
*py,
unsigned
char
character,
35
struct
rectangle *box)
36
{
37
unsigned
char
*
X
;
38
unsigned
char
*
Y
;
39
int
n_vects;
40
int
i;
41
void (*func)(double, double);
42
43
get_char_vects
(character, &n_vects, &
X
, &
Y
);
44
45
if
(!box)
46
COM_Begin
();
47
48
func =
COM_Move
;
49
50
for
(i = 1; i < n_vects; i++) {
51
int
ix, iy;
52
double
x
, y;
53
54
if
(
X
[i] ==
' '
) {
55
func =
COM_Move
;
56
continue
;
57
}
58
59
ix = 10 +
X
[i] -
'R'
;
60
iy = 10 -
Y
[i] +
'R'
;
61
62
transform(&
x
, &y, ix, iy, *px, *py);
63
64
if
(box)
65
remember(box,
x
, y);
66
else
{
67
(*func)(
x
, y);
68
func =
COM_Cont
;
69
}
70
}
71
72
transform(px, py, 20, 0, *px, *py);
73
74
if
(box)
75
remember(box, *px, *py);
76
else
77
COM_Stroke
();
78
}
79
80
static
void
draw_text(
const
char
*
string
,
struct
rectangle *box)
81
{
82
double
base_x =
cur_x
;
83
double
base_y =
cur_y
;
84
const
unsigned
char
*p;
85
86
for
(p = (
const
unsigned
char
*)
string
; *p; p++)
87
draw_char(&base_x, &base_y, *p, box);
88
}
89
90
void
get_text_ext
(
const
char
*
string
,
double
*top,
double
*bot,
double
*left,
91
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
}
NULL
#define NULL
Definition
ccmath.h:32
COM_Cont
void COM_Cont(double x, double y)
Definition
driver/draw.c:22
COM_Stroke
void COM_Stroke(void)
Definition
driver/draw.c:34
COM_Move
void COM_Move(double x, double y)
Definition
driver/draw.c:16
COM_Begin
void COM_Begin(void)
Definition
driver/draw.c:10
l
double l
Definition
driver/set_window.c:5
t
double t
Definition
driver/set_window.c:5
driver.h
text_size_y
double text_size_y
Definition
driver/init.c:36
text_cosrot
double text_cosrot
Definition
driver/init.c:39
text_size_x
double text_size_x
Definition
driver/init.c:35
cur_x
double cur_x
Definition
driver/init.c:32
text_sinrot
double text_sinrot
Definition
driver/init.c:38
cur_y
double cur_y
Definition
driver/init.c:33
driverlib.h
get_char_vects
int get_char_vects(unsigned char, int *, unsigned char **, unsigned char **)
Definition
font2.c:191
get_text_ext
void get_text_ext(const char *string, double *top, double *bot, double *left, double *rite)
Definition
text2.c:90
soft_text
void soft_text(const char *string)
Definition
text2.c:108
X
#define X(j)
x
#define x
Y
#define Y(j)
driver
text2.c
Generated on Sat Jun 21 2025 21:07:27 for GRASS GIS 8 Programmer's Manual by
1.13.2