GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
font.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <string.h>
3
4
#include <grass/gis.h>
5
#include "
driver.h
"
6
#include "
driverlib.h
"
7
8
static
int
font_type = GFONT_STROKE;
9
static
char
*encoding;
10
11
static
void
stroke_set(
const
char
*filename)
12
{
13
if
(
font_init
(filename) == 0)
14
font_type = GFONT_STROKE;
15
}
16
17
static
void
freetype_set(
const
char
*filename,
int
index)
18
{
19
if
(
font_init_freetype
(filename, index) == 0)
20
font_type = GFONT_FREETYPE;
21
}
22
23
static
void
driver_set(
const
char
*
name
)
24
{
25
(*
driver
->
Set_font
)(
name
);
26
font_type = GFONT_DRIVER;
27
}
28
29
int
font_get_type
(
void
)
30
{
31
return
font_type;
32
}
33
34
const
char
*
font_get_encoding
(
void
)
35
{
36
if
(!encoding)
37
encoding =
G_store
(
"ISO-8859-1"
);
38
return
encoding;
39
}
40
41
static
void
font_list(
char
***
list
,
int
*
count
,
int
verbose)
42
{
43
char
**fonts;
44
int
num_fonts;
45
int
i;
46
47
for
(i = 0;
ftcap
[i].name; i++)
48
;
49
num_fonts = i;
50
51
G_debug
(2,
"font_list: num_fonts=%d"
, num_fonts);
52
fonts = G_malloc(num_fonts *
sizeof
(
const
char
*));
53
54
for
(i = 0; i < num_fonts; i++) {
55
struct
GFONT_CAP *p = &
ftcap
[i];
56
57
G_debug
(4,
"font: %d (%s)"
, i, p->name);
58
if
(verbose) {
59
char
buf[GPATH_MAX];
60
61
snprintf(buf,
sizeof
(buf),
"%s|%s|%d|%s|%d|%s|"
, p->name,
62
p->longname, p->type, p->path, p->index, p->encoding);
63
64
fonts[i] =
G_store
(buf);
65
}
66
else
67
fonts[i] =
G_store
(p->name);
68
}
69
70
*
list
= fonts;
71
*
count
= num_fonts;
72
}
73
74
static
void
free_font_list(
char
**fonts,
int
count
)
75
{
76
int
i;
77
78
for
(i = 0; i <
count
; i++)
79
G_free
(fonts[i]);
80
81
G_free
(fonts);
82
}
83
84
void
COM_Set_font
(
const
char
*
name
)
85
{
86
int
i;
87
88
if
(
G_is_absolute_path
(
name
)) {
89
if
(
font_exists
(
name
))
90
freetype_set(
name
, 0);
91
return
;
92
}
93
94
for
(i = 0;
ftcap
[i].name; i++) {
95
struct
GFONT_CAP *cap = &
ftcap
[i];
96
97
if
(strcmp(
name
, cap->name) != 0)
98
continue
;
99
100
switch
(cap->type) {
101
case
GFONT_FREETYPE:
102
freetype_set(cap->path, cap->index);
103
COM_Set_encoding
(cap->encoding);
104
break
;
105
case
GFONT_STROKE:
106
stroke_set(cap->name);
107
break
;
108
}
109
return
;
110
}
111
112
if
(
driver
->
Font_info
&&
driver
->
Set_font
) {
113
char
**
list
=
NULL
;
114
int
count
= 0;
115
116
(*
driver
->
Font_info
)(&
list
, &
count
);
117
118
for
(i = 0; i <
count
; i++) {
119
struct
GFONT_CAP cap;
120
121
if
(!
parse_fontcap_entry
(&cap,
list
[i]))
122
continue
;
123
124
if
(cap.type != GFONT_DRIVER || strcmp(
name
, cap.name) != 0)
125
continue
;
126
127
driver_set(cap.name);
128
COM_Set_encoding
(cap.encoding);
129
break
;
130
}
131
132
free_font_list(
list
,
count
);
133
return
;
134
}
135
136
stroke_set(
"romans"
);
137
}
138
139
void
COM_Set_encoding
(
const
char
*enc)
140
{
141
if
(encoding)
142
G_free
(encoding);
143
144
encoding =
G_store
(enc);
145
}
146
147
void
COM_Font_list
(
char
***
list
,
int
*
count
)
148
{
149
font_list(
list
,
count
, 0);
150
if
(
driver
->
Font_list
)
151
(*
driver
->
Font_list
)(
list
,
count
);
152
}
153
154
void
COM_Font_info
(
char
***
list
,
int
*
count
)
155
{
156
font_list(
list
,
count
, 1);
157
if
(
driver
->
Font_info
)
158
(*
driver
->
Font_info
)(
list
,
count
);
159
}
G_free
void G_free(void *buf)
Free allocated memory.
Definition
alloc.c:147
NULL
#define NULL
Definition
ccmath.h:32
G_debug
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition
debug.c:66
driver.h
ftcap
struct GFONT_CAP * ftcap
Definition
driver/init.c:27
driverlib.h
font_exists
int font_exists(const char *)
Check if font exists.
Definition
parse_ftcap.c:27
font_init_freetype
int font_init_freetype(const char *, int)
Definition
font_freetype.c:9
parse_fontcap_entry
int parse_fontcap_entry(struct GFONT_CAP *, const char *)
Parse fontcap entry.
Definition
parse_ftcap.c:41
font_init
int font_init(const char *)
Definition
font2.c:181
COM_Font_list
void COM_Font_list(char ***list, int *count)
Definition
font.c:147
font_get_encoding
const char * font_get_encoding(void)
Definition
font.c:34
font_get_type
int font_get_type(void)
Definition
font.c:29
COM_Set_encoding
void COM_Set_encoding(const char *enc)
Definition
font.c:139
COM_Set_font
void COM_Set_font(const char *name)
Definition
font.c:84
COM_Font_info
void COM_Font_info(char ***list, int *count)
Definition
font.c:154
count
int count
name
const char * name
Definition
named_colr.c:6
G_is_absolute_path
int G_is_absolute_path(const char *path)
Checks if a specified path looks like an absolute path on the host system.
Definition
paths.c:62
list
struct list * list
Definition
read_list.c:24
G_store
char * G_store(const char *s)
Copy string to allocated memory.
Definition
strings.c:87
driver
Definition
driver.h:27
driver::Font_info
void(* Font_info)(char ***, int *)
Definition
driver.h:55
driver::Font_list
void(* Font_list)(char ***, int *)
Definition
driver.h:54
driver::Set_font
void(* Set_font)(const char *)
Definition
driver.h:53
driver
font.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0