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 "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 Adobe_font_metric * afm_p = read_afm_file (path);
40 afm_p->name_str_ = name;
42 *mlog << "]" << flush ;
44 afm_p_dict_[sname] = afm_p->self_scm_;
45 scm_unprotect_object (afm_p->self_scm_);
48 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_[sname]));
52 All_font_metrics::find_scaled (String nm, int m)
54 Scaled_font_metric * s=0;
55 String index = nm + "@" + to_str (m);
56 SCM sname = ly_symbol2scm (index.ch_C ());
59 if (!scaled_p_dict_.elem_b (sname))
61 Font_metric *f = find_font (nm);
62 s = new Scaled_font_metric (f, m);
63 scaled_p_dict_[sname] = s->self_scm_;
65 scm_unprotect_object (s->self_scm_);
68 fm = unsmob_metrics (scaled_p_dict_[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);
85 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
86 tfm_p->name_str_ = name;
88 *mlog << "]" << flush ;
90 tfm_p_dict_[sname] = tfm_p->self_scm_;
91 scm_unprotect_object (tfm_p->self_scm_);
95 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_[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 f = find_tfm (default_font_sz_);
117 error (_f ("Can't find default font: `%s'", default_font_sz_));
118 error (_f ("(search path: `%s'", search_path_.str ()));
119 error (_ ("Giving up"));
125 All_font_metrics::font_descriptions () const
129 l[0] = afm_p_dict_.to_alist ();
130 l[1] = tfm_p_dict_.to_alist ();
131 l[2] = scaled_p_dict_.to_alist ();
134 for (int i=0; i < 3; i++)
136 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
138 Font_metric * fm = unsmob_metrics (gh_cdar (s));
140 list = gh_cons (fm->description (), list);
147 unsmob_metrics( SCM s)
149 if (SMOB_IS_TYPE_B(Font_metric, s))
150 return SMOB_TO_TYPE(Font_metric, s);
155 #include "ly-smobs.icc"
156 IMPLEMENT_SMOBS(Font_metric);