lilypond-1.1.67
[lilypond.git] / lily / all-font-metrics.cc
blobd3722420116299edcf62cde14efb27b603624686
2 #include "main.hh"
3 #include "all-fonts.hh"
4 #include "debug.hh"
5 #include "warn.hh"
6 #include "afm.hh"
7 #include "tfm.hh"
9 const char * default_font_sz_ = "cmr10";
11 All_font_metrics::All_font_metrics (String path)
13 search_path_.parse_path (path);
16 Adobe_font_metric *
17 All_font_metrics::find_afm (String name)
19 if (!afm_p_dict_.elem_b (name))
21 String path = name + ".afm";
22 path = search_path_.find (path);
23 if (path.empty_b ())
24 return 0;
26 *mlog << "[" << path;
27 Adobe_font_metric
28 * afm_p = new Adobe_font_metric (read_afm_file (path));
29 *mlog << "]" << flush ;
31 afm_p_dict_[name] = afm_p;
33 return afm_p_dict_[name];
36 Tex_font_metric *
37 All_font_metrics::find_tfm (String name)
39 if (!tfm_p_dict_.elem_b (name))
41 String path = name + ".tfm";
42 path = search_path_.find (path);
43 if (path.empty_b ())
44 return 0;
46 *mlog << "[" << path;
47 Tex_font_metric * tfm_p = new Tex_font_metric;
48 tfm_p->read_file (path);
49 *mlog << "]" << flush ;
51 tfm_p_dict_[name] = tfm_p;
53 return tfm_p_dict_[name];
57 Font_metric *
58 All_font_metrics::find_font (String name)
60 Font_metric * f=0;
61 f = find_tfm (name);
62 if (f)
63 return f;
65 f= find_afm (name);
66 if (f)
67 return f;
69 warning (_f("Can't find font `%s', loading default font.", name.ch_C()));
71 f = find_tfm (default_font_sz_);
72 if (f)
73 return f;
74 String s = _f("Can't find default font `%s\', giving up.", default_font_sz_);
75 s += String ("\n") + _f ("search path = %s", search_path_.str ());
76 error (s);