GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
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
text_size_y
double text_size_y
Definition:
driver/init.c:36
rectangle::b
double b
Definition:
text2.c:9
COM_Cont
void COM_Cont(double x, double y)
Definition:
driver/draw.c:23
cur_y
double cur_y
Definition:
driver/init.c:33
rectangle::r
double r
Definition:
text2.c:9
cur_x
double cur_x
Definition:
driver/init.c:32
driver.h
text_sinrot
double text_sinrot
Definition:
driver/init.c:38
NULL
#define NULL
Definition:
ccmath.h:32
x
#define x
gis.h
rectangle::top
double top
Definition:
clip.h:19
soft_text
void soft_text(const char *string)
Definition:
text2.c:108
text_size_x
double text_size_x
Definition:
driver/init.c:35
rectangle::rite
double rite
Definition:
clip.h:19
COM_Stroke
void COM_Stroke(void)
Definition:
driver/draw.c:35
rectangle
Definition:
clip.h:17
Y
#define Y
Definition:
ogsf.h:138
rectangle::bot
double bot
Definition:
clip.h:19
rectangle::t
double t
Definition:
text2.c:9
X
#define X
Definition:
ogsf.h:137
driverlib.h
transform
Definition:
ogsf.h:223
get_text_ext
void get_text_ext(const char *string, double *top, double *bot, double *left, double *rite)
Definition:
text2.c:91
COM_Move
void COM_Move(double x, double y)
Definition:
driver/draw.c:17
rectangle::l
double l
Definition:
text2.c:9
rectangle::left
double left
Definition:
clip.h:19
COM_Begin
void COM_Begin(void)
Definition:
driver/draw.c:11
text_cosrot
double text_cosrot
Definition:
driver/init.c:39
get_char_vects
int get_char_vects(unsigned char, int *, unsigned char **, unsigned char **)
Definition:
font2.c:191
lib
driver
text2.c
Generated on Mon May 31 2021 05:21:32 for GRASS GIS 7 Programmer's Manual by
1.8.13