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);
36 progress_indication ("[" + path);
37 Adobe_font_metric * afm_p = read_afm_file (path);
39 afm_p->name_ = ly_symbol2scm (name.ch_C ());
40 progress_indication ("]");
42 afm_p_dict_[sname] = afm_p->self_scm_;
43 scm_unprotect_object (afm_p->self_scm_);
46 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (afm_p_dict_[sname]));
50 All_font_metrics::find_scaled (String nm, int m)
52 Scaled_font_metric * s=0;
53 String index = nm + "@" + to_str (m);
54 SCM sname = ly_symbol2scm (index.ch_C ());
57 if (!scaled_p_dict_.elem_b (sname))
59 Font_metric *f = find_font (nm);
60 s = new Scaled_font_metric (f, m);
61 scaled_p_dict_[sname] = s->self_scm_;
63 scm_unprotect_object (s->self_scm_);
66 fm = unsmob_metrics (scaled_p_dict_[sname]);
68 return dynamic_cast<Scaled_font_metric*> (fm);
72 All_font_metrics::find_tfm (String name)
74 SCM sname = ly_symbol2scm (name.ch_C ());
75 if (!tfm_p_dict_.elem_b (sname))
77 String path = name + ".tfm";
78 path = search_path_.find (path);
81 progress_indication ("[" + path);
82 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
83 tfm_p->name_ = ly_symbol2scm (name.ch_C( ));
84 progress_indication ("]");
86 tfm_p_dict_[sname] = tfm_p->self_scm_;
87 scm_unprotect_object (tfm_p->self_scm_);
91 dynamic_cast<Tex_font_metric*> (unsmob_metrics (tfm_p_dict_[sname]));
96 All_font_metrics::find_font (String name)
107 warning (_f ("Can't find font: `%s'", name.ch_C ()));
108 warning (_ ("Loading default font"));
110 String def_name = default_font_sz_;
111 SCM l = ly_eval_str ("(style-to-cmr \"default\")");
113 def_name = ly_scm2string (gh_cdr (l));
115 f = find_tfm (def_name);
119 f= find_afm (def_name);
123 error (_f ("Can't find default font: `%s'", def_name.ch_C ()));
124 error (_f ("(search path: `%s'", search_path_.str ()));
125 error (_ ("Giving up"));
131 All_font_metrics::font_descriptions () const
135 l[0] = afm_p_dict_.to_alist ();
136 l[1] = tfm_p_dict_.to_alist ();
137 l[2] = scaled_p_dict_.to_alist ();
140 for (int i=0; i < 3; i++)
142 for (SCM s = l[i]; gh_pair_p (s); s = gh_cdr (s))
144 Font_metric * fm = unsmob_metrics (gh_cdar (s));
146 list = gh_cons (fm->description (), list);
154 #include "ly-smobs.icc"
155 IMPLEMENT_SMOBS(Font_metric);