2 font-config-scheme.cc -- implement FontConfig bindings.
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "lily-guile.hh"
11 #include "std-string.hh"
13 #include <fontconfig/fontconfig.h>
16 display_fontset (FcFontSet *fs)
19 for (j = 0; j < fs->nfont; j++)
24 font = FcNameUnparse (fs->fonts[j]);
25 if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &str) == FcResultMatch)
26 printf ("FILE %s\n", str);
27 if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &str) == FcResultMatch)
28 printf ("family %s\n ", str);
29 if (FcPatternGetString (fs->fonts[j],
30 "designsize", 0, &str) == FcResultMatch)
31 printf ("designsize %s\n ", str);
33 printf ("%s\n", (const char*) font);
39 display_strlist (char const*what, FcStrList *slist)
41 while (FcChar8 *dir = FcStrListNext (slist))
43 printf("%s: %s\n", what, dir);
48 display_config (FcConfig *fcc)
50 display_strlist ("Config files", FcConfigGetConfigFiles(fcc));
51 display_strlist ("Config dir", FcConfigGetConfigDirs(fcc));
52 display_strlist ("Font dir", FcConfigGetFontDirs(fcc));
56 display_list (FcConfig *fcc)
58 FcPattern*pat = FcPatternCreate ();
62 os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
64 FcFontSet *fs = FcFontList (fcc, pat, os);
65 FcObjectSetDestroy (os);
67 FcPatternDestroy (pat);
72 FcFontSetDestroy (fs);
77 LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0,
79 "Get the file for font @var{name}")
81 SCM_ASSERT_TYPE (scm_is_string (name), name,
82 SCM_ARG1, __FUNCTION__, "string");
85 FcPattern*pat = FcPatternCreate ();
88 val.type = FcTypeString;
89 val.u.s = (const FcChar8*)ly_scm2string (name).c_str (); // FC_SLANT_ITALIC;
90 FcPatternAdd(pat, FC_FAMILY, val, FcFalse);
93 SCM scm_result = SCM_BOOL_F;
95 FcConfigSubstitute (NULL, pat, FcMatchFont);
96 FcDefaultSubstitute (pat);
98 pat = FcFontMatch(NULL, pat, &result);
100 if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
101 scm_result = scm_makfrom0str ((char const*) str);
103 FcPatternDestroy (pat);
108 LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0,
110 "Dump a list of all fonts visible to FontConfig.")
113 display_config (NULL);
115 return SCM_UNSPECIFIED;