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 = ly_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 Adobe_font_metric *afm
82 = dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val) );
83 Tex_font_metric * tfm = find_tfm (name);
85 if (tfm->info_.checksum != afm->checksum_)
87 String s = _f ("checksum mismatch for font file: `%s'", path.ch_C ());
89 s += " TFM: " + to_str ((int) tfm->info_.checksum);
90 s += " AFM: " + to_str ((int) afm->checksum_);
92 s += _(" Rebuild all .afm files, and remove all .pk and .tfm files. Rerun with -V to show font paths.");
98 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
103 All_font_metrics::find_tfm (String name)
105 SCM sname = ly_symbol2scm (name.ch_C ());
106 SCM name_str = ly_str02scm (name.ch_C ());
109 if (!tfm_p_dict_->try_retrieve (sname, &val))
115 char * p = ly_find_tfm (name.ch_C());
121 path = search_path_.find (name + ".tfm");
125 if (verbose_global_b)
126 progress_indication ("[" + path);
127 val = Tex_font_metric::make_tfm (path);
128 if (verbose_global_b)
129 progress_indication ("]");
131 unsmob_metrics (val)->description_ = gh_cons (name_str, gh_double2scm (1.0));
132 tfm_p_dict_->set (sname, val);
134 scm_unprotect_object (val);
138 dynamic_cast<Tex_font_metric*> (unsmob_metrics (val));
143 All_font_metrics::find_font (String name)
145 Font_metric * f= find_afm (name);
153 warning (_f ("can't find font: `%s'", name.ch_C ()));
154 warning (_ ("Loading default font"));
156 String def_name = default_font_sz_;
157 SCM l = scm_assoc (ly_str02scm ("default"),
158 scm_eval2 (ly_symbol2scm ("cmr-alist"), SCM_EOL));
161 def_name = ly_scm2string (gh_cdr (l));
163 f= find_afm (def_name);
167 f = find_tfm (def_name);
171 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
172 error (_f ("(search path: `%s')", search_path_.str ()));
173 error (_ ("Giving up"));