2 font-config-scheme.cc -- implement FontConfig bindings.
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "lily-guile.hh"
11 #include "string-convert.hh"
14 #include <fontconfig/fontconfig.h>
17 display_fontset (FcFontSet *fs)
22 for (j = 0; j < fs->nfont; j++)
27 font = FcNameUnparse (fs->fonts[j]);
28 if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &str) == FcResultMatch)
29 retval += String_convert::form_string ("FILE %s\n", str);
30 if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &str) == FcResultMatch)
31 retval += String_convert::form_string ("family %s\n ", str);
32 if (FcPatternGetString (fs->fonts[j],
33 "designsize", 0, &str) == FcResultMatch)
34 retval += String_convert::form_string ("designsize %s\n ", str);
36 retval += String_convert::form_string ("%s\n", (const char*) font);
44 display_strlist (char const*what, FcStrList *slist)
47 while (FcChar8 *dir = FcStrListNext (slist))
49 retval += String_convert::form_string ("%s: %s\n", what, dir);
55 display_config (FcConfig *fcc)
58 retval += display_strlist ("Config files", FcConfigGetConfigFiles(fcc));
59 retval += display_strlist ("Config dir", FcConfigGetConfigDirs(fcc));
60 retval += display_strlist ("Font dir", FcConfigGetFontDirs(fcc));
65 display_list (FcConfig *fcc)
67 FcPattern*pat = FcPatternCreate ();
71 os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
73 FcFontSet *fs = FcFontList (fcc, pat, os);
74 FcObjectSetDestroy (os);
76 FcPatternDestroy (pat);
81 retval = display_fontset (fs);
82 FcFontSetDestroy (fs);
88 LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0,
90 "Get the file for font @var{name}")
92 SCM_ASSERT_TYPE (scm_is_string (name), name,
93 SCM_ARG1, __FUNCTION__, "string");
96 FcPattern*pat = FcPatternCreate ();
99 val.type = FcTypeString;
100 val.u.s = (const FcChar8*)ly_scm2string (name).c_str (); // FC_SLANT_ITALIC;
101 FcPatternAdd(pat, FC_FAMILY, val, FcFalse);
104 SCM scm_result = SCM_BOOL_F;
106 FcConfigSubstitute (NULL, pat, FcMatchFont);
107 FcDefaultSubstitute (pat);
109 pat = FcFontMatch(NULL, pat, &result);
111 if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
112 scm_result = scm_from_locale_string ((char const*) str);
114 FcPatternDestroy (pat);
119 LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0,
121 "Dump a list of all fonts visible to FontConfig.")
123 string str = display_list (NULL);
124 str += display_config (NULL);
126 progress_indication (str);
128 return SCM_UNSPECIFIED;