1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/*
This file is part of LilyPond, the GNU music typesetter.
Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LilyPond is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lily-guile.hh"
#include "international.hh"
#include "main.hh"
#include "string-convert.hh"
#include "warn.hh"
#include <fontconfig/fontconfig.h>
string
display_fontset (FcFontSet *fs)
{
string retval;
int j;
for (j = 0; j < fs->nfont; j++)
{
FcChar8 *font;
FcChar8 *str;
font = FcNameUnparse (fs->fonts[j]);
if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &str) == FcResultMatch)
retval += String_convert::form_string ("FILE %s\n", str);
if (FcPatternGetString (fs->fonts[j], FC_INDEX, 0, &str) == FcResultMatch)
retval += String_convert::form_string ("INDEX %s\n", str);
if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &str) == FcResultMatch)
retval += String_convert::form_string ("family %s\n ", str);
if (FcPatternGetString (fs->fonts[j],
"designsize", 0, &str) == FcResultMatch)
retval += String_convert::form_string ("designsize %s\n ", str);
retval += String_convert::form_string ("%s\n", (const char *)font);
free (font);
}
return retval;
}
string
display_strlist (char const *what, FcStrList *slist)
{
string retval;
while (FcChar8 *dir = FcStrListNext (slist))
{
retval += String_convert::form_string ("%s: %s\n", what, dir);
}
return retval;
}
string
display_config (FcConfig *fcc)
{
string retval;
retval += display_strlist ("Config files", FcConfigGetConfigFiles (fcc));
retval += display_strlist ("Config dir", FcConfigGetConfigDirs (fcc));
retval += display_strlist ("Font dir", FcConfigGetFontDirs (fcc));
return retval;
}
string
display_list (FcConfig *fcc)
{
FcPattern *pat = FcPatternCreate ();
FcObjectSet *os = 0;
if (!os)
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *)0);
FcFontSet *fs = FcFontList (fcc, pat, os);
FcObjectSetDestroy (os);
if (pat)
FcPatternDestroy (pat);
string retval;
if (fs)
{
retval = display_fontset (fs);
FcFontSetDestroy (fs);
}
return retval;
}
LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0,
(SCM name),
"Get the file for font @var{name}.")
{
LY_ASSERT_TYPE (scm_is_string, name, 1);
FcPattern *pat = FcPatternCreate ();
FcValue val;
val.type = FcTypeString;
val.u.s = (const FcChar8 *)ly_scm2string (name).c_str (); // FC_SLANT_ITALIC;
FcPatternAdd (pat, FC_FAMILY, val, FcFalse);
FcResult result;
SCM scm_result = SCM_BOOL_F;
FcConfigSubstitute (NULL, pat, FcMatchFont);
FcDefaultSubstitute (pat);
pat = FcFontMatch (NULL, pat, &result);
FcChar8 *str = 0;
if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
scm_result = scm_from_utf8_string ((char const *)str);
FcPatternDestroy (pat);
return scm_result;
}
LY_DEFINE (ly_font_config_display_fonts, "ly:font-config-display-fonts", 0, 0, 0,
(),
"Dump a list of all fonts visible to FontConfig.")
{
string str = display_list (NULL);
str += display_config (NULL);
progress_indication (str);
return SCM_UNSPECIFIED;
}
LY_DEFINE (ly_font_config_add_directory, "ly:font-config-add-directory", 1, 0, 0,
(SCM dir),
"Add directory @var{dir} to FontConfig.")
{
LY_ASSERT_TYPE (scm_is_string, dir, 1);
string d = ly_scm2string (dir);
if (!FcConfigAppFontAddDir (0, (const FcChar8 *)d.c_str ()))
error (_f ("failed adding font directory: %s", d.c_str ()));
else
debug_output (_f ("Adding font directory: %s", d.c_str ()));
return SCM_UNSPECIFIED;
}
LY_DEFINE (ly_font_config_add_font, "ly:font-config-add-font", 1, 0, 0,
(SCM font),
"Add font @var{font} to FontConfig.")
{
LY_ASSERT_TYPE (scm_is_string, font, 1);
string f = ly_scm2string (font);
if (!FcConfigAppFontAddFile (0, (const FcChar8 *)f.c_str ()))
error (_f ("failed adding font file: %s", f.c_str ()));
else
debug_output (_f ("Adding font file: %s", f.c_str ()));
return SCM_UNSPECIFIED;
}
|