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>
14 #include <fontconfig/fontconfig.h>
17 #include "file-path.hh"
18 #include "international.hh"
23 FcConfig
*font_config_global
= 0;
28 if (be_verbose_global
)
29 message (_ ("Initializing FontConfig..."));
31 font_config_global
= FcInitLoadConfig ();
32 FcChar8
*cache_file
= FcConfigGetCache (font_config_global
);
35 // always returns 0 for FC 2.4
37 programming_error ("Cannot find file for FontConfig cache.");
40 This is a terrible kludge, but there is apparently no way for
41 FontConfig to signal whether it needs to rescan directories.
44 && !is_file ((char const *)cache_file
))
45 message (_f ("Rebuilding FontConfig cache %s, this may take a while...", cache_file
));
49 /* Extra trailing slash suddenly breaks fontconfig (fc-cache 2.5.0)
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
++)
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
)
71 && !is_file ((char*)cache_file
))
73 /* inhibit future messages. */
74 FILE *f
= fopen ((char*)cache_file
, "w");