Fix flag snippet in NEWS.tely.
[lilypond.git] / lily / font-config.cc
blob39ae3c2a76c7c64d69d7ceebc7d2e08319ad4416
1 /*
2 font-config.cc -- implement FontConfig related functions
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "config.hh"
11 #if HAVE_FONTCONFIG
13 #include <fontconfig/fontconfig.h>
14 #include <sys/stat.h>
16 #include "file-path.hh"
17 #include "international.hh"
18 #include "main.hh"
19 #include "warn.hh"
22 FcConfig *font_config_global = 0;
24 void
25 init_fontconfig ()
27 if (be_verbose_global)
28 message (_ ("Initializing FontConfig..."));
30 font_config_global = FcInitLoadConfig ();
31 FcChar8 *cache_file = FcConfigGetCache (font_config_global);
33 #if 0
34 // always returns 0 for FC 2.4
35 if (!cache_file)
36 programming_error ("Cannot find file for FontConfig cache.");
37 #endif
39 This is a terrible kludge, but there is apparently no way for
40 FontConfig to signal whether it needs to rescan directories.
41 */
42 if (cache_file
43 && !is_file ((char const *)cache_file))
44 message (_f ("Rebuilding FontConfig cache %s, this may take a while...", cache_file));
46 vector<string> dirs;
48 /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
49 on windows. */
50 dirs.push_back (lilypond_datadir + "/fonts/otf");
51 dirs.push_back (lilypond_datadir + "/fonts/type1");
53 for (vsize i = 0; i < dirs.size (); i++)
55 string dir = dirs[i];
56 if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
57 error (_f ("failed adding font directory: %s", dir.c_str ()));
58 else if (be_verbose_global)
59 message (_f ("adding font directory: %s", dir.c_str ()));
62 if (be_verbose_global)
63 progress_indication ("Building font database.\n");
64 FcConfigBuildFonts (font_config_global);
65 FcConfigSetCurrent (font_config_global);
66 if (be_verbose_global)
67 progress_indication ("\n");
69 if (cache_file
70 && !is_file ((char*)cache_file))
72 /* inhibit future messages. */
73 FILE *f = fopen ((char*)cache_file, "w");
74 if (f)
75 fclose (f);
80 #else
82 void
83 init_fontconfig ()
87 #endif