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>
13 #include <fontconfig/fontconfig.h>
16 #include "file-path.hh"
17 #include "international.hh"
22 FcConfig *font_config_global = 0;
27 if (be_verbose_global)
28 message (_ ("Initializing FontConfig..."));
30 font_config_global = FcInitLoadConfig ();
31 FcChar8 *cache_file = FcConfigGetCache (font_config_global);
34 // always returns 0 for FC 2.4
36 programming_error ("Cannot find file for FontConfig cache.");
39 This is a terrible kludge, but there is apparently no way for
40 FontConfig to signal whether it needs to rescan directories.
43 && !is_file ((char const *)cache_file))
44 message (_f ("Rebuilding FontConfig cache %s, this may take a while...", cache_file));
48 dirs.push_back (prefix_directory + "/fonts/otf/");
49 dirs.push_back (prefix_directory + "/fonts/type1/");
51 for (vsize i = 0; i < dirs.size (); i++)
54 if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
55 error (_f ("failed adding font directory: %s", dir.c_str ()));
56 else if (be_verbose_global)
57 message (_f ("adding font directory: %s", dir.c_str ()));
60 if (be_verbose_global)
61 progress_indication ("Building font database.\n");
62 FcConfigBuildFonts (font_config_global);
63 FcConfigSetCurrent (font_config_global);
64 if (be_verbose_global)
65 progress_indication ("\n");
68 && !is_file ((char*)cache_file))
70 /* inhibit future messages. */
71 FILE *f = fopen ((char*)cache_file, "w");