]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config-scheme.cc
* Documentation/user/notation-appendices.itely (The Feta font):
[lilypond.git] / lily / font-config-scheme.cc
1 /*
2   font-config-scheme.cc -- implement FontConfig bindings.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "lily-guile.hh"
11
12 #include <fontconfig/fontconfig.h>
13
14 void
15 display_fontset (FcFontSet *fs)
16 {
17   int j;
18   for (j = 0; j < fs->nfont; j++)
19     {
20       FcChar8 *font;
21       FcChar8 *str;
22
23       font = FcNameUnparse (fs->fonts[j]);
24       if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &str) == FcResultMatch)
25         printf ("FILE %s\n", str);
26       if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &str) == FcResultMatch)
27         printf ("family %s\n ", str);
28       if (FcPatternGetString (fs->fonts[j],
29                               "designsize", 0, &str) == FcResultMatch)
30         printf ("designsize %s\n ", str);
31       
32       printf ("%s\n", (const char*) font);
33       free (font);
34     }
35 }
36
37 void
38 display_strlist (char const*what, FcStrList *slist)
39 {
40   while (FcChar8 *dir = FcStrListNext (slist))
41     {
42       printf("%s: %s\n", what, dir);
43     }
44 }
45
46 void
47 display_config (FcConfig *fcc)
48 {
49   display_strlist ("Config files", FcConfigGetConfigFiles(fcc));
50   display_strlist ("Config dir", FcConfigGetConfigDirs(fcc));
51   display_strlist ("Font dir", FcConfigGetFontDirs(fcc));
52 }
53
54 void
55 display_list (FcConfig *fcc)
56 {
57   FcPattern*pat = FcPatternCreate ();
58
59   FcObjectSet *os = 0;
60   if (!os)
61     os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
62
63   FcFontSet *fs = FcFontList (fcc, pat, os);
64   FcObjectSetDestroy (os);
65   if (pat)
66     FcPatternDestroy (pat);
67
68   if (fs)
69     {
70       display_fontset (fs);
71       FcFontSetDestroy (fs);
72     }
73 }
74
75
76 LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0,
77            (),
78            "Dump a list of all fonts visible to FontConfig.")
79 {
80   display_list (NULL);
81   display_config (NULL);
82   
83   return SCM_UNSPECIFIED;
84 }