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 "scm-hash.hh"
23 #include <kpathsea/kpathsea.h>
26 const char * default_font_sz_ = "cmr10";
28 All_font_metrics::All_font_metrics (String path)
30 afm_p_dict_ = new Scheme_hash_table;
31 tfm_p_dict_ = new Scheme_hash_table;
32 scaled_p_dict_ = new Scheme_hash_table;
34 search_path_.parse_path (path);
37 All_font_metrics::~All_font_metrics ()
39 scm_unprotect_object (afm_p_dict_->self_scm ());
40 scm_unprotect_object (tfm_p_dict_->self_scm ());
41 scm_unprotect_object (scaled_p_dict_->self_scm ());
45 All_font_metrics::find_afm (String name)
47 SCM sname = ly_symbol2scm (name.ch_C ());
48 if (!afm_p_dict_->elem_b (sname))
53 char * p = kpse_find_file(name.ch_C(), kpse_afm_format, true);
59 path = search_path_.find (name + ".afm");
64 progress_indication ("[" + path);
65 SCM afm = read_afm_file (path);
67 unsmob_metrics (afm)->name_ = sname;
70 progress_indication ("]");
72 afm_p_dict_->set (sname,afm);
75 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_->get (sname)));
79 All_font_metrics::find_scaled (String nm, int m)
81 String index = nm + "@" + to_str (m);
82 SCM sname = ly_symbol2scm (index.ch_C ());
85 if (!scaled_p_dict_->elem_b (sname))
87 Font_metric *f = find_font (nm);
88 SCM s = Scaled_font_metric::make_scaled_font_metric (f, m);
89 scaled_p_dict_->set (sname, s);
90 fm = unsmob_metrics (s);
93 fm = unsmob_metrics (scaled_p_dict_->get (sname));
95 return dynamic_cast<Scaled_font_metric*> (fm);
99 All_font_metrics::find_tfm (String name)
101 SCM sname = ly_symbol2scm (name.ch_C ());
102 if (!tfm_p_dict_->elem_b (sname))
108 char * p = kpse_find_tfm(name.ch_C());
112 path = search_path_.find (name + ".tfm");
116 if (verbose_global_b)
117 progress_indication ("[" + path);
118 SCM tfm = Tex_font_metric::make_tfm (path);
119 if (verbose_global_b)
120 progress_indication ("]");
122 Font_metric *fm = unsmob_metrics (tfm);
124 tfm_p_dict_->set (sname, tfm);
128 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_->get(sname)));
133 All_font_metrics::find_font (String name)
144 warning (_f ("can't find font: `%s'", name.ch_C ()));
145 warning (_ ("Loading default font"));
147 String def_name = default_font_sz_;
148 SCM l = scm_assoc (ly_str02scm ("default"),
149 scm_eval (ly_symbol2scm ("cmr-alist")));
152 def_name = ly_scm2string (gh_cdr (l));
154 f = find_tfm (def_name);
158 f= find_afm (def_name);
162 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
163 error (_f ("(search path: `%s')", search_path_.str ()));
164 error (_ ("Giving up"));
170 All_font_metrics::font_descriptions () const
174 l[0] = afm_p_dict_->to_alist ();
175 l[1] = tfm_p_dict_->to_alist ();
176 l[2] = scaled_p_dict_->to_alist ();
179 for (int i=0; i < 3; i++)
181 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
183 Font_metric * fm = unsmob_metrics (gh_cdar (s));
185 list = gh_cons (fm->description (), list);
194 find_font (String name)
196 return all_fonts_global_p->find_font (name);