23 #if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0) || defined(CAIRO_HAS_FC_FONT)
24 #define USE_FONTCONFIG 1
25 #include <fontconfig/fontconfig.h>
27 #define USE_FONTCONFIG 0
35 static char *convert(
const char *in)
48 char *p1 = (
char *)in;
53 if ((cd = iconv_open(
"UTF-8", encoding)) == (iconv_t)-1)
54 G_fatal_error(
_(
"Unable to convert from <%s> to UTF-8"), encoding);
56 ret = iconv(cd, &p1, &ilen, &p2, &olen);
63 G_warning(
_(
"Some characters could not be converted to UTF-8"));
67 const unsigned char *p1 = (
const unsigned char *)in;
68 unsigned char *p2 = (
unsigned char *)out;
71 for (i = j = 0; i < ilen; i++) {
77 p2[j++] = 0xC0 + (c >> 6);
78 p2[j++] = 0x80 + (c & 0x3F);
89 static void set_matrix(
void)
91 static cairo_matrix_t mat;
96 cairo_matrix_init_identity(&mat);
100 cairo_set_font_matrix(
cairo, &mat);
112 char *utf8 = convert(str);
120 cairo_show_text(
cairo, utf8);
135 char *utf8 = convert(str);
136 cairo_text_extents_t ext;
143 cairo_text_extents(
cairo, utf8, &ext);
147 *
l =
cur_x + ext.x_bearing;
148 *
r =
cur_x + ext.x_bearing + ext.width;
149 *
t =
cur_y + ext.y_bearing;
150 *
b =
cur_y + ext.y_bearing + ext.height;
153 static void set_font_toy(
const char *
name)
156 cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
157 cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
160 char *p = strrchr(font,
'-');
166 weight = CAIRO_FONT_WEIGHT_BOLD;
168 slant = CAIRO_FONT_SLANT_ITALIC;
170 slant = CAIRO_FONT_SLANT_OBLIQUE;
177 cairo_select_font_face(
cairo, font, slant, weight);
184 static void fc_init(
void)
186 static int initialized;
194 static void set_font_fc(
const char *
name)
196 static cairo_font_face_t *face;
203 cairo_font_face_destroy(face);
207 pattern = FcNameParse((FcChar8 *)
name);
208 FcDefaultSubstitute(pattern);
209 FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);
210 pattern = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
211 face = cairo_ft_font_face_create_for_pattern(pattern);
212 cairo_set_font_face(
cairo, face);
215 static void font_list_fc(
char ***
list,
int *
count,
int verbose)
220 char **fonts = *
list;
221 int num_fonts = *
count;
226 pattern = FcPatternCreate();
227 objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (
char *)
NULL);
228 fontset = FcFontList(
NULL, pattern, objset);
230 fonts =
G_realloc(fonts, (num_fonts + fontset->nfont) *
sizeof(
char *));
232 for (i = 0; i < fontset->nfont; i++) {
234 FcPattern *pat = fontset->fonts[i];
235 FcChar8 *family = (FcChar8 *)
"", *style = (FcChar8 *)
"";
237 FcPatternGetString(pat, FC_FAMILY, 0, &family);
238 FcPatternGetString(pat, FC_STYLE, 0, &style);
241 sprintf(buf,
"%s:%s|%s:%s|%d|%s|%d|%s|", family, style, family,
244 sprintf(buf,
"%s:%s", family, style);
246 fonts[num_fonts++] =
G_store(buf);
249 FcObjectSetDestroy(objset);
250 FcPatternDestroy(pattern);
251 FcFontSetDestroy(fontset);
259 static const char *toy_fonts[12] = {
260 "sans",
"sans-italic",
"sans-bold",
"sans-bold-italic",
261 "serif",
"serif-italic",
"serif-bold",
"serif-bold-italic",
262 "mono",
"mono-italic",
"mono-bold",
"mono-bold-italic",
265 static const int num_toy_fonts = 12;
267 static int is_toy_font(
const char *
name)
271 for (i = 0; i < num_toy_fonts; i++)
286 if (is_toy_font(
name))
295 static void font_list_toy(
char ***
list,
int *
count,
int verbose)
297 char **fonts = *
list;
298 int num_fonts = *
count;
301 fonts =
G_realloc(fonts, (num_fonts + num_toy_fonts) *
sizeof(
char *));
303 for (i = 0; i < num_toy_fonts; i++) {
307 sprintf(buf,
"%s|%s|%d|%s|%d|%s|", toy_fonts[i], toy_fonts[i],
310 strcpy(buf, toy_fonts[i]);
311 fonts[num_fonts++] =
G_store(buf);
void Cairo_text_box(const char *str, double *t, double *b, double *l, double *r)
void Cairo_font_info(char ***list, int *count)
Get fonts into.
void Cairo_font_list(char ***list, int *count)
Get list of fonts.
void Cairo_Text(const char *str)
Draw text.
void Cairo_set_font(const char *name)
Set font.
GRASS cairo display driver - header file.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
char * G_store(const char *)
Copy string to allocated memory.
GRASS_DRIVER_EXPORT double text_rotation
GRASS_DRIVER_EXPORT double text_size_x
GRASS_DRIVER_EXPORT double cur_y
GRASS_DRIVER_EXPORT double text_size_y
GRASS_DRIVER_EXPORT double cur_x
GRASS_DRIVER_EXPORT int matrix_valid
const char * font_get_encoding(void)
GRASS_INTERPFL_EXPORT int count