2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "all-font-metrics.hh"
16 #include "lily-guile.hh"
17 #include "tfm-reader.hh"
19 const char * default_font_sz_ = "cmr10";
21 All_font_metrics::All_font_metrics (String path)
23 search_path_.parse_path (path);
27 All_font_metrics::find_afm (String name)
29 SCM sname = ly_symbol2scm (name.ch_C ());
30 if (!afm_p_dict_.elem_b (sname))
32 String path = name + ".afm";
33 path = search_path_.find (path);
38 progress_indication ("[" + path);
39 Adobe_font_metric * afm_p = read_afm_file (path);
41 afm_p->name_ = ly_symbol2scm (name.ch_C ());
44 progress_indication ("]");
46 afm_p_dict_.set (sname,afm_p->self_scm_);
49 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_.get (sname)));
53 All_font_metrics::find_scaled (String nm, int m)
55 Scaled_font_metric * s=0;
56 String index = nm + "@" + to_str (m);
57 SCM sname = ly_symbol2scm (index.ch_C ());
60 if (!scaled_p_dict_.elem_b (sname))
62 Font_metric *f = find_font (nm);
63 s = new Scaled_font_metric (f, m);
64 scaled_p_dict_.set (sname, s->self_scm_);
68 fm = unsmob_metrics (scaled_p_dict_.get (sname));
70 return dynamic_cast<Scaled_font_metric*> (fm);
74 All_font_metrics::find_tfm (String name)
76 SCM sname = ly_symbol2scm (name.ch_C ());
77 if (!tfm_p_dict_.elem_b (sname))
79 String path = name + ".tfm";
80 path = search_path_.find (path);
84 progress_indication ("[" + path);
85 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
86 tfm_p->name_ = ly_symbol2scm (name.ch_C( ));
89 progress_indication ("]");
91 tfm_p_dict_.set (sname, tfm_p->self_scm_);
95 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_.get(sname)));
100 All_font_metrics::find_font (String name)
111 warning (_f ("can't find font: `%s'", name.ch_C ()));
112 warning (_ ("Loading default font"));
114 String def_name = default_font_sz_;
115 SCM l = scm_assoc (ly_str02scm ("default"),
116 scm_eval (ly_symbol2scm ("cmr-alist")));
119 def_name = ly_scm2string (gh_cdr (l));
121 f = find_tfm (def_name);
125 f= find_afm (def_name);
129 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
130 error (_f ("(search path: `%s')", search_path_.str ()));
131 error (_ ("Giving up"));
137 All_font_metrics::font_descriptions () const
141 l[0] = afm_p_dict_.to_alist ();
142 l[1] = tfm_p_dict_.to_alist ();
143 l[2] = scaled_p_dict_.to_alist ();
146 for (int i=0; i < 3; i++)
148 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
150 Font_metric * fm = unsmob_metrics (gh_cdar (s));
152 list = gh_cons (fm->description (), list);
161 find_font (String name)
163 return all_fonts_global_p->find_font (name);