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>
12 #include "all-font-metrics.hh"
17 #include "lily-guile.hh"
18 #include "scm-hash.hh"
25 const char * default_font_sz_ = "cmr10";
27 All_font_metrics::All_font_metrics (String path)
29 afm_p_dict_ = new Scheme_hash_table;
30 tfm_p_dict_ = new Scheme_hash_table;
31 scaled_p_dict_ = new Scheme_hash_table;
33 search_path_.parse_path (path);
36 All_font_metrics::~All_font_metrics ()
38 scm_unprotect_object (afm_p_dict_->self_scm ());
39 scm_unprotect_object (tfm_p_dict_->self_scm ());
40 scm_unprotect_object (scaled_p_dict_->self_scm ());
44 All_font_metrics::find_afm (String name)
46 SCM sname = ly_symbol2scm (name.ch_C ());
47 if (!afm_p_dict_->elem_b (sname))
52 path = search_path_.find (name + ".afm");
56 char * p = ly_find_afm (name.ch_C());
65 progress_indication ("[" + path);
66 SCM afm = read_afm_file (path);
68 unsmob_metrics (afm)->name_ = sname;
71 progress_indication ("]");
73 afm_p_dict_->set (sname,afm);
76 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_->get (sname)));
80 All_font_metrics::find_scaled (String nm, int m)
82 String index = nm + "@" + to_str (m);
83 SCM sname = ly_symbol2scm (index.ch_C ());
86 if (!scaled_p_dict_->elem_b (sname))
88 Font_metric *f = find_font (nm);
89 SCM s = Scaled_font_metric::make_scaled_font_metric (f, m);
90 scaled_p_dict_->set (sname, s);
91 fm = unsmob_metrics (s);
94 fm = unsmob_metrics (scaled_p_dict_->get (sname));
96 return dynamic_cast<Scaled_font_metric*> (fm);
100 All_font_metrics::find_tfm (String name)
102 SCM sname = ly_symbol2scm (name.ch_C ());
103 if (!tfm_p_dict_->elem_b (sname))
109 char * p = ly_find_tfm (name.ch_C());
115 path = search_path_.find (name + ".tfm");
119 if (verbose_global_b)
120 progress_indication ("[" + path);
121 SCM tfm = Tex_font_metric::make_tfm (path);
122 if (verbose_global_b)
123 progress_indication ("]");
125 Font_metric *fm = unsmob_metrics (tfm);
127 tfm_p_dict_->set (sname, tfm);
131 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_->get(sname)));
136 All_font_metrics::find_font (String name)
148 warning (_f ("can't find font: `%s'", name.ch_C ()));
149 warning (_ ("Loading default font"));
151 String def_name = default_font_sz_;
152 SCM l = scm_assoc (ly_str02scm ("default"),
153 scm_eval2 (ly_symbol2scm ("cmr-alist"), SCM_EOL));
156 def_name = ly_scm2string (gh_cdr (l));
158 f= find_afm (def_name);
162 f = find_tfm (def_name);
166 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
167 error (_f ("(search path: `%s')", search_path_.str ()));
168 error (_ ("Giving up"));
174 All_font_metrics::font_descriptions () const
178 l[0] = afm_p_dict_->to_alist ();
179 l[1] = tfm_p_dict_->to_alist ();
180 l[2] = scaled_p_dict_->to_alist ();
183 for (int i=0; i < 3; i++)
185 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
187 Font_metric * fm = unsmob_metrics (gh_cdar (s));
189 list = gh_cons (fm->description (), list);
198 find_font (String name)
200 return all_fonts_global_p->find_font (name);