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"
20 #include <kpathsea/kpathsea.h>
23 const char * default_font_sz_ = "cmr10";
25 All_font_metrics::All_font_metrics (String path)
27 search_path_.parse_path (path);
31 All_font_metrics::find_afm (String name)
33 SCM sname = ly_symbol2scm (name.ch_C ());
34 if (!afm_p_dict_.elem_b (sname))
39 char * p = kpse_find_file(name.ch_C(), kpse_afm_format, true);
45 path = search_path_.find (name + ".afm");
50 progress_indication ("[" + path);
51 Adobe_font_metric * afm_p = read_afm_file (path);
53 afm_p->name_ = ly_symbol2scm (name.ch_C ());
56 progress_indication ("]");
58 afm_p_dict_.set (sname,afm_p->self_scm_);
61 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_.get (sname)));
65 All_font_metrics::find_scaled (String nm, int m)
67 Scaled_font_metric * s=0;
68 String index = nm + "@" + to_str (m);
69 SCM sname = ly_symbol2scm (index.ch_C ());
72 if (!scaled_p_dict_.elem_b (sname))
74 Font_metric *f = find_font (nm);
75 s = new Scaled_font_metric (f, m);
76 scaled_p_dict_.set (sname, s->self_scm_);
80 fm = unsmob_metrics (scaled_p_dict_.get (sname));
82 return dynamic_cast<Scaled_font_metric*> (fm);
86 All_font_metrics::find_tfm (String name)
88 SCM sname = ly_symbol2scm (name.ch_C ());
89 if (!tfm_p_dict_.elem_b (sname))
95 char * p = kpse_find_tfm(name.ch_C());
99 path = search_path_.find (name + ".tfm");
103 if (verbose_global_b)
104 progress_indication ("[" + path);
105 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
106 tfm_p->name_ = ly_symbol2scm (name.ch_C( ));
108 if (verbose_global_b)
109 progress_indication ("]");
111 tfm_p_dict_.set (sname, tfm_p->self_scm_);
115 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_.get(sname)));
120 All_font_metrics::find_font (String name)
131 warning (_f ("can't find font: `%s'", name.ch_C ()));
132 warning (_ ("Loading default font"));
134 String def_name = default_font_sz_;
135 SCM l = scm_assoc (ly_str02scm ("default"),
136 scm_eval (ly_symbol2scm ("cmr-alist")));
139 def_name = ly_scm2string (gh_cdr (l));
141 f = find_tfm (def_name);
145 f= find_afm (def_name);
149 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
150 error (_f ("(search path: `%s')", search_path_.str ()));
151 error (_ ("Giving up"));
157 All_font_metrics::font_descriptions () const
161 l[0] = afm_p_dict_.to_alist ();
162 l[1] = tfm_p_dict_.to_alist ();
163 l[2] = scaled_p_dict_.to_alist ();
166 for (int i=0; i < 3; i++)
168 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
170 Font_metric * fm = unsmob_metrics (gh_cdar (s));
172 list = gh_cons (fm->description (), list);
181 find_font (String name)
183 return all_fonts_global_p->find_font (name);