]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config.cc
641192b12c7566d5bdd3056291a551ff22b3779f
[lilypond.git] / lily / font-config.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2012 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   vector<string> dirs;
44
45   /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
46      on windows.  */
47   dirs.push_back (lilypond_datadir + "/fonts/otf");
48
49   for (vsize i = 0; i < dirs.size (); i++)
50     {
51       string dir = dirs[i];
52       if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
53         error (_f ("failed adding font directory: %s", dir.c_str ()));
54       else
55         debug_output (_f ("Adding font directory: %s", dir.c_str ()));
56     }
57
58   debug_output (_ ("Building font database..."));
59
60   FcConfigBuildFonts (font_config_global);
61   FcConfigSetCurrent (font_config_global);
62
63   debug_output ("\n");
64
65 }
66
67 #else
68
69 void
70 init_fontconfig ()
71 {
72 }
73
74 #endif