20 #if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1,10,0) || defined(CAIRO_HAS_FC_FONT) 21 #define USE_FONTCONFIG 1 22 #include <fontconfig/fontconfig.h> 24 #define USE_FONTCONFIG 0 32 static char *convert(
const char *
in)
45 char *p1 = (
char *) in;
50 if ((cd = iconv_open(
"UTF-8", encoding)) == (iconv_t) -1)
54 ret = iconv(cd, &p1, &ilen, &p2, &olen);
61 G_warning(
_(
"Some characters could not be converted to UTF-8"));
65 const unsigned char *p1 = (
const unsigned char *) in;
66 unsigned char *p2 = (
unsigned char *) out;
69 for (i = j = 0; i < ilen; i++) {
74 p2[j++] = 0xC0 + (c >> 6);
75 p2[j++] = 0x80 + (c & 0x3F);
86 static void set_matrix(
void)
88 static cairo_matrix_t mat;
93 cairo_matrix_init_identity(&mat);
97 cairo_set_font_matrix(
cairo, &mat);
109 char *utf8 = convert(str);
117 cairo_show_text(
cairo, utf8);
132 char *utf8 = convert(str);
133 cairo_text_extents_t ext;
140 cairo_text_extents(
cairo, utf8, &ext);
144 *l =
cur_x + ext.x_bearing;
145 *r =
cur_x + ext.x_bearing + ext.width;
146 *t =
cur_y + ext.y_bearing;
147 *b =
cur_y + ext.y_bearing + ext.height;
150 static void set_font_toy(
const char *
name)
153 cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
154 cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
157 char *p = strrchr(font,
'-');
162 weight = CAIRO_FONT_WEIGHT_BOLD;
163 else if (strcasecmp(p,
"-italic") == 0)
164 slant = CAIRO_FONT_SLANT_ITALIC;
166 slant = CAIRO_FONT_SLANT_OBLIQUE;
173 cairo_select_font_face(
cairo, font, slant, weight);
180 static void fc_init(
void)
182 static int initialized;
190 static void set_font_fc(
const char *name)
192 static cairo_font_face_t *face;
199 cairo_font_face_destroy(face);
203 pattern = FcNameParse((FcChar8 *)name);
204 FcDefaultSubstitute(pattern);
205 FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);
206 pattern = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
207 face = cairo_ft_font_face_create_for_pattern(pattern);
208 cairo_set_font_face(
cairo, face);
211 static void font_list_fc(
char ***
list,
int *
count,
int verbose)
216 char **fonts = *
list;
217 int num_fonts = *
count;
222 pattern = FcPatternCreate();
223 objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, (
char *)
NULL);
224 fontset = FcFontList(NULL, pattern, objset);
226 fonts =
G_realloc(fonts, (num_fonts + fontset->nfont) *
sizeof(
char *));
228 for (i = 0; i < fontset->nfont; i++) {
230 FcPattern *pat = fontset->fonts[i];
231 FcChar8 *family = (FcChar8 *)
"", *style = (FcChar8 *)
"";
233 FcPatternGetString(pat, FC_FAMILY, 0, &family);
234 FcPatternGetString(pat, FC_STYLE , 0, &style );
237 sprintf(buf,
"%s:%s|%s:%s|%d|%s|%d|%s|",
238 family, style, family, style,
GFONT_DRIVER,
"", 0,
"utf-8");
240 sprintf(buf,
"%s:%s", family, style);
242 fonts[num_fonts++] =
G_store(buf);
245 FcObjectSetDestroy(objset);
246 FcPatternDestroy(pattern);
247 FcFontSetDestroy (fontset);
255 static const char *toy_fonts[12] = {
269 static const int num_toy_fonts = 12;
271 static int is_toy_font(
const char *name)
275 for (i = 0; i < num_toy_fonts; i++)
290 if (is_toy_font(name))
299 static void font_list_toy(
char ***list,
int *count,
int verbose)
301 char **fonts = *
list;
302 int num_fonts = *
count;
305 fonts =
G_realloc(fonts, (num_fonts + num_toy_fonts) *
sizeof(
char *));
307 for (i = 0; i < num_toy_fonts; i++) {
310 sprintf(buf,
"%s|%s|%d|%s|%d|%s|",
311 toy_fonts[i], toy_fonts[i],
GFONT_DRIVER,
"", 0,
"utf-8");
313 strcpy(buf, toy_fonts[i]);
314 fonts[num_fonts++] =
G_store(buf);
329 font_list_toy(list, count, 0);
331 font_list_fc(list, count, 0);
343 font_list_toy(list, count, 1);
345 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.