2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
25 #include <fontconfig/fontconfig.h>
28 #include "file-path.hh"
29 #include "international.hh"
33 FcConfig *font_config_global = 0;
38 debug_output (_ ("Initializing FontConfig..."));
40 /* TODO: Find a way for Fontconfig to update its cache, if needed. */
43 /* Create an empty configuration */
44 font_config_global = FcConfigCreate ();
46 /* fontconfig conf files */
49 /* LilyPond local fontconfig conf file 00
50 This file is loaded *before* fontconfig's default conf. */
51 confs.push_back (lilypond_datadir + "/fonts/00-lilypond-fonts.conf");
53 /* fontconfig's default conf file */
54 void *default_conf = FcConfigFilename (NULL);
55 confs.push_back (static_cast<char*>(default_conf));
56 FcStrFree(static_cast<FcChar8*>(default_conf));
58 /* LilyPond local fontconfig conf file 99
59 This file is loaded *after* fontconfig's default conf. */
60 confs.push_back (lilypond_datadir + "/fonts/99-lilypond-fonts.conf");
62 /* Load fontconfig conf files */
63 for (vector<string>::const_iterator it = confs.begin ();
67 if (!FcConfigParseAndLoad (font_config_global,
68 (FcChar8 *)it->c_str (),
70 error (_f ("failed to add fontconfig configuration file `%s'",
73 debug_output (_f ("Adding fontconfig configuration file: %s",
77 /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
79 string dir (lilypond_datadir + "/fonts/otf");
81 if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
82 error (_f ("failed adding font directory: %s", dir.c_str ()));
84 debug_output (_f ("Adding font directory: %s", dir.c_str ()));
86 debug_output (_ ("Building font database..."));
88 FcConfigBuildFonts (font_config_global);
89 FcConfigSetCurrent (font_config_global);