]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[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 using std::string;
34 using std::vector;
35
36 FcConfig *font_config_global = 0;
37
38 void
39 init_fontconfig ()
40 {
41   debug_output (_ ("Initializing FontConfig..."));
42
43   /* TODO: Find a way for Fontconfig to update its cache, if needed. */
44   FcInitLoadConfig ();
45
46   /* Create an empty configuration */
47   font_config_global = FcConfigCreate ();
48
49   /* fontconfig conf files */
50   vector<string> confs;
51
52   /* LilyPond local fontconfig conf file 00
53      This file is loaded *before* fontconfig's default conf. */
54   confs.push_back (lilypond_datadir + "/fonts/00-lilypond-fonts.conf");
55
56   /* fontconfig's default conf file */
57   void *default_conf = FcConfigFilename (NULL);
58   confs.push_back (static_cast<char*>(default_conf));
59   FcStrFree(static_cast<FcChar8*>(default_conf));
60
61   /* LilyPond local fontconfig conf file 99
62      This file is loaded *after* fontconfig's default conf. */
63   confs.push_back (lilypond_datadir + "/fonts/99-lilypond-fonts.conf");
64
65   /* Load fontconfig conf files */
66   for (vector<string>::const_iterator it = confs.begin ();
67        it != confs.end ();
68        it++)
69     {
70       if (!FcConfigParseAndLoad (font_config_global,
71                                  (FcChar8 *)it->c_str (),
72                                  FcFalse))
73         error (_f ("failed to add fontconfig configuration file `%s'",
74                    it->c_str ()));
75       else
76         debug_output (_f ("Adding fontconfig configuration file: %s",
77                           it->c_str ()));
78     }
79
80   /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
81      on windows.  */
82   string dir (lilypond_datadir + "/fonts/otf");
83
84   if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
85     error (_f ("failed adding font directory: %s", dir.c_str ()));
86   else
87     debug_output (_f ("Adding font directory: %s", dir.c_str ()));
88
89   debug_output (_ ("Building font database..."));
90
91   FcConfigBuildFonts (font_config_global);
92   FcConfigSetCurrent (font_config_global);
93
94   debug_output ("\n");
95
96 }
97
98 #else
99
100 void
101 init_fontconfig ()
102 {
103 }
104
105 #endif