Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / font-config.cc
blob7737068c2eb1c55f215db09d79cf71d782162261
1 /*
2 font-config.cc -- implement FontConfig related functions
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "config.hh"
11 #if HAVE_FONTCONFIG
13 #include <cstdio>
14 #include <fontconfig/fontconfig.h>
15 #include <sys/stat.h>
17 #include "file-path.hh"
18 #include "international.hh"
19 #include "main.hh"
20 #include "warn.hh"
23 FcConfig *font_config_global = 0;
25 void
26 init_fontconfig ()
28 if (be_verbose_global)
29 message (_ ("Initializing FontConfig..."));
31 font_config_global = FcInitLoadConfig ();
32 FcChar8 *cache_file = FcConfigGetCache (font_config_global);
34 #if 0
35 // always returns 0 for FC 2.4
36 if (!cache_file)
37 programming_error ("Cannot find file for FontConfig cache.");
38 #endif
40 This is a terrible kludge, but there is apparently no way for
41 FontConfig to signal whether it needs to rescan directories.
42 */
43 if (cache_file
44 && !is_file ((char const *)cache_file))
45 message (_f ("Rebuilding FontConfig cache %s, this may take a while...", cache_file));
47 vector<string> dirs;
49 /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
50 on windows. */
51 dirs.push_back (lilypond_datadir + "/fonts/otf");
52 dirs.push_back (lilypond_datadir + "/fonts/type1");
54 for (vsize i = 0; i < dirs.size (); i++)
56 string dir = dirs[i];
57 if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
58 error (_f ("failed adding font directory: %s", dir.c_str ()));
59 else if (be_verbose_global)
60 message (_f ("adding font directory: %s", dir.c_str ()));
63 if (be_verbose_global)
64 message (_ ("Building font database."));
65 FcConfigBuildFonts (font_config_global);
66 FcConfigSetCurrent (font_config_global);
67 if (be_verbose_global)
68 message ("\n");
70 if (cache_file
71 && !is_file ((char*)cache_file))
73 /* inhibit future messages. */
74 FILE *f = fopen ((char*)cache_file, "w");
75 if (f)
76 fclose (f);
81 #else
83 void
84 init_fontconfig ()
88 #endif