X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ffont-config.cc;h=742887f6846efdb84ec21a2f3d6aa1abc133350f;hb=080fd805ad13008b9cda1dd67488cb8b3b91583a;hp=5c8fa806e503af37ea9488d344c17c791ab79f6f;hpb=46b41fe6cef4d1a9746e21f809c0ee62662aa145;p=lilypond.git diff --git a/lily/font-config.cc b/lily/font-config.cc index 5c8fa806e5..742887f684 100644 --- a/lily/font-config.cc +++ b/lily/font-config.cc @@ -1,41 +1,85 @@ /* - font-config.cc -- implement Font_config related functions + font-config.cc -- implement FontConfig related functions source file of the GNU LilyPond music typesetter - (c) 2005 Han-Wen Nienhuys - + (c) 2005--2007 Han-Wen Nienhuys */ #include "config.hh" -#ifdef HAVE_PANGO_FT2 +#if HAVE_FONTCONFIG + #include +#include +#include "file-path.hh" +#include "international.hh" #include "main.hh" #include "warn.hh" + +FcConfig *font_config_global = 0; + void init_fontconfig () { - if (!FcInit()) + if (be_verbose_global) + message (_ ("Initializing FontConfig...")); + + font_config_global = FcInitLoadConfig (); + FcChar8 *cache_file = FcConfigGetCache (font_config_global); + +#if 0 + // always returns 0 for FC 2.4 + if (!cache_file) + programming_error ("Cannot find file for FontConfig cache."); +#endif + /* + This is a terrible kludge, but there is apparently no way for + FontConfig to signal whether it needs to rescan directories. + */ + if (cache_file + && !is_file ((char const *)cache_file)) + message (_f ("Rebuilding FontConfig cache %s, this may take a while...", cache_file)); + + vector dirs; + + dirs.push_back (lilypond_datadir + "/fonts/otf/"); + dirs.push_back (lilypond_datadir + "/fonts/type1/"); + + for (vsize i = 0; i < dirs.size (); i++) { - error ("FontConfig failed to initialize"); + string dir = dirs[i]; + if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ())) + error (_f ("failed adding font directory: %s", dir.c_str ())); + else if (be_verbose_global) + message (_f ("adding font directory: %s", dir.c_str ())); } + + if (be_verbose_global) + progress_indication ("Building font database.\n"); + FcConfigBuildFonts (font_config_global); + FcConfigSetCurrent (font_config_global); + if (be_verbose_global) + progress_indication ("\n"); - char const **dirs = prefix_directories; - for (; *dirs; dirs++) + if (cache_file + && !is_file ((char*)cache_file)) { - String path = String (*dirs) + "/" + "otf"; - - if (!FcConfigAppFontAddDir (0, (FcChar8*)path.to_str0 ())) - { - error (_f ("Failed to add lilypond directory %s", path.to_str0 ())); - } - } + /* inhibit future messages. */ + FILE *f = fopen ((char*)cache_file, "w"); + if (f) + fclose (f); + } + } #else -void init_fontconfig() {} +void +init_fontconfig () +{ +} + #endif