]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-config.cc
cbf77c7944d012c9186e50edb1c1dd7143a1f034
[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 "international.hh"
18 #include "main.hh"
19 #include "warn.hh"
20
21
22 FcConfig *font_config_global = 0;
23
24 void
25 init_fontconfig ()
26 {
27   if (be_verbose_global)
28     message (_ ("Initializing FontConfig..."));
29
30   font_config_global = FcInitLoadConfig ();
31   FcChar8 *cache_file = FcConfigGetCache (font_config_global);
32
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
38   /*
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));
45                         
46   vector<string> dirs;
47
48   dirs.push_back (prefix_directory + "/fonts/otf/");
49   dirs.push_back (prefix_directory + "/fonts/type1/");
50   
51   for (vsize i = 0; i < dirs.size (); i++)
52     {
53       string dir = dirs[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 ()));
58     }
59   
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");
66
67   if (cache_file
68       && !is_file ((char*)cache_file))
69     {
70       /* inhibit future messages. */
71       FILE *f = fopen ((char*)cache_file, "w");
72       if (f)
73         fclose (f);
74     }
75   
76 }
77
78 #else
79
80 void
81 init_fontconfig ()
82 {
83 }
84
85 #endif