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;
32 search_path_.parse_path (path);
35 All_font_metrics::~All_font_metrics ()
37 scm_unprotect_object (afm_p_dict_->self_scm ());
38 scm_unprotect_object (tfm_p_dict_->self_scm ());
42 All_font_metrics::find_afm (String name)
44 SCM sname = ly_symbol2scm (name.ch_C ());
46 SCM name_str = gh_str02scm (name.ch_C ());
50 if (!afm_p_dict_->try_retrieve (sname, &val))
55 path = search_path_.find (name + ".afm");
59 char * p = ly_find_afm (name.ch_C());
68 progress_indication ("[" + path);
69 val = read_afm_file (path);
71 unsmob_metrics (val)->description_ = gh_cons (name_str, gh_double2scm (1.0));
74 progress_indication ("]");
76 afm_p_dict_->set (sname,val);
78 scm_unprotect_object (val);
81 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
86 All_font_metrics::find_tfm (String name)
88 SCM sname = ly_symbol2scm (name.ch_C ());
89 SCM name_str = gh_str02scm (name.ch_C ());
92 if (!tfm_p_dict_->try_retrieve (sname, &val))
98 char * p = ly_find_tfm (name.ch_C());
104 path = search_path_.find (name + ".tfm");
108 if (verbose_global_b)
109 progress_indication ("[" + path);
110 val = Tex_font_metric::make_tfm (path);
111 if (verbose_global_b)
112 progress_indication ("]");
114 unsmob_metrics (val)->description_ = gh_cons (name_str, gh_double2scm (1.0));
115 tfm_p_dict_->set (sname, val);
117 scm_unprotect_object (val);
121 dynamic_cast<Tex_font_metric*> (unsmob_metrics (val));
126 All_font_metrics::find_font (String name)
128 Font_metric * f= find_afm (name);
136 warning (_f ("can't find font: `%s'", name.ch_C ()));
137 warning (_ ("Loading default font"));
139 String def_name = default_font_sz_;
140 SCM l = scm_assoc (ly_str02scm ("default"),
141 scm_eval2 (ly_symbol2scm ("cmr-alist"), SCM_EOL));
144 def_name = ly_scm2string (gh_cdr (l));
146 f= find_afm (def_name);
150 f = find_tfm (def_name);
154 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
155 error (_f ("(search path: `%s')", search_path_.str ()));
156 error (_ ("Giving up"));