GRASS 8 Programmer's Manual
8.6.0dev(2026)-ddeab64dbf
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
= 1
e300
;
96
box.
b
= -1
e300
;
97
box.
l
= 1
e300
;
98
box.
r
= -1
e300
;
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
AMI_STREAM
Definition
ami_stream.h:153
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
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:195
gis.h
X
#define X
Definition
ogsf.h:140
Y
#define Y
Definition
ogsf.h:141
l
double l
Definition
r_raster.c:39
t
double t
Definition
r_raster.c:39
rectangle
Definition
clip.h:14
rectangle::r
double r
Definition
text2.c:8
rectangle::left
double left
Definition
clip.h:15
rectangle::t
double t
Definition
text2.c:8
rectangle::bot
double bot
Definition
clip.h:15
rectangle::b
double b
Definition
text2.c:8
rectangle::l
double l
Definition
text2.c:8
rectangle::rite
double rite
Definition
clip.h:15
rectangle::top
double top
Definition
clip.h:15
transform
Definition
ogsf.h:226
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
lib
driver
text2.c
Generated on Sun Apr 5 2026 06:59:55 for GRASS 8 Programmer's Manual by
1.9.8