]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config.cc
* buildscripts/analyse-cxx-log.py: new file. Read compile log to
[lilypond.git] / lily / font-config.cc
1 /*
2   font-config.cc -- implement FontConfig related functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "config.hh"
10
11 #if HAVE_FONTCONFIG
12
13 #include <fontconfig/fontconfig.h>
14 #include <sys/stat.h>
15
16 #include "file-path.hh"
17 #include "main.hh"
18 #include "warn.hh"
19
20
21 FcConfig *font_config_global = 0;
22
23 void
24 init_fontconfig ()
25 {
26   if (be_verbose_global)
27     message (_ ("Initializing FontConfig..."));
28
29   font_config_global = FcInitLoadConfig ();
30   FcChar8 *cache_file = FcConfigGetCache (font_config_global);
31
32   /*
33     This is a terrible kludge, but there is apparently no way for
34     FontConfig to signal whether it needs to rescan directories.
35    */ 
36   if (!is_file ((char*)cache_file))
37     message (_f ("Rebuilding FontConfig cache %s. this may take a while...", cache_file));
38                         
39   Array<String> dirs;
40
41   dirs.push (prefix_directory + "/fonts/otf/");
42   dirs.push (prefix_directory + "/fonts/type1/");
43   
44   for (int i = 0; i < dirs.size (); i++)
45     {
46       String dir = dirs[i];
47       if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
48         error (_f ("adding font directory: %s", dir.c_str ()));
49       else if (be_verbose_global)
50         message (_f ("adding font directory: %s", dir.c_str ()));
51     }
52
53   FcConfigBuildFonts (font_config_global);
54   FcConfigSetCurrent (font_config_global);
55   if (be_verbose_global)
56     progress_indication ("\n");
57
58   if (!is_file ((char*)cache_file))
59     {
60       /* inhibit future messages. */
61       FILE *f = fopen ((char*)cache_file, "w");
62       fclose (f);
63     }
64   
65 }
66
67 #else
68
69 void
70 init_fontconfig ()
71 {
72 }
73
74 #endif