2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "all-font-metrics.hh"
16 #include "dictionary-iter.hh"
17 #include "lily-guile.hh"
18 #include "tfm-reader.hh"
20 const char * default_font_sz_ = "cmr10";
22 All_font_metrics::All_font_metrics (String path)
24 search_path_.parse_path (path);
28 All_font_metrics::find_afm (String name)
30 if (!afm_p_dict_.elem_b (name))
32 String path = name + ".afm";
33 path = search_path_.find (path);
39 * afm_p = new Adobe_font_metric (read_afm_file (path));
41 afm_p->name_str_ = name;
43 *mlog << "]" << flush ;
45 afm_p_dict_[name] = afm_p;
47 return afm_p_dict_[name];
51 All_font_metrics::find_scaled (String nm, int m)
53 Scaled_font_metric * s=0;
54 String index = nm + "@" + to_str (m);
55 if (!scaled_p_dict_.elem_b (index))
57 Font_metric *f = find_font (nm);
58 s = new Scaled_font_metric (f, m);
59 scaled_p_dict_[index] = s;
63 return scaled_p_dict_[index];
67 All_font_metrics::find_tfm (String name)
69 if (!tfm_p_dict_.elem_b (name))
71 String path = name + ".tfm";
72 path = search_path_.find (path);
77 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
78 tfm_p->name_str_ = name;
80 *mlog << "]" << flush ;
82 tfm_p_dict_[name] = tfm_p;
84 return tfm_p_dict_[name];
89 All_font_metrics::find_font (String name)
100 warning (_f ("Can't find font: `%s'", name.ch_C ()));
101 warning (_ ("Loading default font"));
103 f = find_tfm (default_font_sz_);
106 error (_f ("Can't find default font: `%s'", default_font_sz_));
107 error (_f ("(search path: `%s'", search_path_.str ()));
108 error (_ ("Giving up"));
112 All_font_metrics::font_descriptions () const
115 for (Dictionary_iter<Adobe_font_metric*> ai(afm_p_dict_); ai.ok (); ai++)
116 l = gh_cons (ai.val ()->description (), l);
117 for (Dictionary_iter<Tex_font_metric*> ai(tfm_p_dict_); ai.ok (); ai++)
118 l = gh_cons(ai.val ()->description (), l);
120 for (Dictionary_iter<Scaled_font_metric*> ai(scaled_p_dict_); ai.ok (); ai++)
121 l = gh_cons (ai.val ()->description (),l);