]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config.cc
Issue 4441 / 2: Add local fontconfig configuration file loading
[lilypond.git] / lily / font-config.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "config.hh"
21
22 #if HAVE_FONTCONFIG
23
24 #include <cstdio>
25 #include <fontconfig/fontconfig.h>
26 #include <sys/stat.h>
27
28 #include "file-path.hh"
29 #include "international.hh"
30 #include "main.hh"
31 #include "warn.hh"
32
33 FcConfig *font_config_global = 0;
34
35 void
36 init_fontconfig ()
37 {
38   debug_output (_ ("Initializing FontConfig..."));
39
40   /* TODO: Find a way for Fontconfig to update its cache, if needed. */
41   font_config_global = FcInitLoadConfig ();
42
43   /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
44      on windows.  */
45   string dir (lilypond_datadir + "/fonts/otf");
46
47   if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
48     error (_f ("failed adding font directory: %s", dir.c_str ()));
49   else
50     debug_output (_f ("Adding font directory: %s", dir.c_str ()));
51
52   string conf (lilypond_datadir + "/fonts/lilypond-fonts.conf");
53
54   if (!FcConfigParseAndLoad (font_config_global,
55                              (FcChar8 *)conf.c_str (),
56                              FcFalse))
57     error (_f ("failed adding fontconfig configuration file: %s",
58                conf.c_str ()));
59   else
60     debug_output (_f ("Adding fontconfig configuration file: %s",
61                       conf.c_str ()));
62
63   debug_output (_ ("Building font database..."));
64
65   FcConfigBuildFonts (font_config_global);
66   FcConfigSetCurrent (font_config_global);
67
68   debug_output ("\n");
69
70 }
71
72 #else
73
74 void
75 init_fontconfig ()
76 {
77 }
78
79 #endif