20 #include <fontconfig/fontconfig.h> 27 static char *convert(
const char *
in)
40 char *p1 = (
char *) in;
45 if ((cd = iconv_open(
"UTF-8", encoding)) == (iconv_t) -1)
49 ret = iconv(cd, &p1, &ilen, &p2, &olen);
56 G_warning(
_(
"Some characters could not be converted to UTF-8"));
60 const unsigned char *p1 = (
const unsigned char *) in;
61 unsigned char *p2 = (
unsigned char *) out;
64 for (i = j = 0; i < ilen; i++) {
69 p2[j++] = 0xC0 + (c >> 6);
70 p2[j++] = 0x80 + (c & 0x3F);
81 static void set_matrix(
void)
83 static cairo_matrix_t mat;
88 cairo_matrix_init_identity(&mat);
92 cairo_set_font_matrix(
cairo, &mat);
104 char *utf8 = convert(str);
112 cairo_show_text(
cairo, utf8);
127 char *utf8 = convert(str);
128 cairo_text_extents_t ext;
135 cairo_text_extents(
cairo, utf8, &ext);
139 *l =
cur_x + ext.x_bearing;
140 *r =
cur_x + ext.x_bearing + ext.width;
141 *t =
cur_y + ext.y_bearing;
142 *b =
cur_y + ext.y_bearing + ext.height;
145 static void set_font_toy(
const char *
name)
148 cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
149 cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
152 char *p = strrchr(font,
'-');
157 weight = CAIRO_FONT_WEIGHT_BOLD;
158 else if (strcasecmp(p,
"-italic") == 0)
159 slant = CAIRO_FONT_SLANT_ITALIC;
161 slant = CAIRO_FONT_SLANT_OBLIQUE;
168 cairo_select_font_face(
cairo, font, slant, weight);
173 #if CAIRO_HAS_FT_FONT 175 static void fc_init(
void)
177 static int initialized;
185 static void set_font_fc(
const char *name)
187 static cairo_font_face_t *face;
194 cairo_font_face_destroy(face);
198 pattern = FcNameParse((FcChar8 *)name);
199 FcDefaultSubstitute(pattern);
200 FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);
201 pattern = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
202 face = cairo_ft_font_face_create_for_pattern(pattern);
203 cairo_set_font_face(
cairo, face);
206 static void font_list_fc(
char ***
list,
int *
count,
int verbose)
211 char **fonts = *
list;
212 int num_fonts = *
count;
217 pattern = FcPatternCreate();
218 objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (
char *)
NULL);
219 fontset = FcFontList(NULL, pattern, objset);
221 fonts =
G_realloc(fonts, (num_fonts + fontset->nfont) *
sizeof(
char *));
223 for (i = 0; i < fontset->nfont; i++) {
225 FcPattern *pat = fontset->fonts[i];
226 FcChar8 *family = (FcChar8 *)
"", *style = (FcChar8 *)
"";
228 FcPatternGetString(pat, FC_FAMILY, 0, &family);
229 FcPatternGetString(pat, FC_STYLE , 0, &style );
232 sprintf(buf,
"%s:%s|%s:%s|%d|%s|%d|%s|",
233 family, style, family, style,
GFONT_DRIVER,
"", 0,
"utf-8");
235 sprintf(buf,
"%s:%s", family, style);
237 fonts[num_fonts++] =
G_store(buf);
240 FcObjectSetDestroy(objset);
241 FcPatternDestroy(pattern);
242 FcFontSetDestroy (fontset);
250 static const char *toy_fonts[12] = {
264 static const int num_toy_fonts = 12;
266 static int is_toy_font(
const char *name)
270 for (i = 0; i < num_toy_fonts; i++)
284 #if CAIRO_HAS_FT_FONT 285 if (is_toy_font(name))
294 static void font_list_toy(
char ***list,
int *count,
int verbose)
296 char **fonts = *
list;
297 int num_fonts = *
count;
300 fonts =
G_realloc(fonts, (num_fonts + num_toy_fonts) *
sizeof(
char *));
302 for (i = 0; i < num_toy_fonts; i++) {
305 sprintf(buf,
"%s|%s|%d|%s|%d|%s|",
306 toy_fonts[i], toy_fonts[i],
GFONT_DRIVER,
"", 0,
"utf-8");
308 strcpy(buf, toy_fonts[i]);
309 fonts[num_fonts++] =
G_store(buf);
324 font_list_toy(list, count, 0);
325 #if CAIRO_HAS_FT_FONT 326 font_list_fc(list, count, 0);
338 font_list_toy(list, count, 1);
339 #if CAIRO_HAS_FT_FONT 340 font_list_fc(list, count, 1);
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void Cairo_font_list(char ***list, int *count)
Get list of fonts.
void Cairo_set_font(const char *name)
Set font.
const char * font_get_encoding(void)
void G_free(void *)
Free allocated memory.
void Cairo_Text(const char *str)
Draw text.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
void Cairo_text_box(const char *str, double *t, double *b, double *l, double *r)
GRASS cairo display driver - header file.
void G_warning(const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
void Cairo_font_info(char ***list, int *count)
Get fonts into.