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"
21 static const char * default_font_sz_ = "cmr10";
23 All_font_metrics::All_font_metrics (String path)
25 afm_p_dict_ = new Scheme_hash_table;
26 tfm_p_dict_ = new Scheme_hash_table;
28 search_path_.parse_path (path);
31 All_font_metrics::~All_font_metrics ()
33 scm_unprotect_object (afm_p_dict_->self_scm ());
34 scm_unprotect_object (tfm_p_dict_->self_scm ());
38 All_font_metrics::find_afm (String name)
40 SCM sname = ly_symbol2scm (name.ch_C ());
42 SCM name_str = ly_str02scm (name.ch_C ());
46 if (!afm_p_dict_->try_retrieve (sname, &val))
51 path = search_path_.find (name + ".afm");
55 char * p = ly_find_afm (name.ch_C());
64 progress_indication ("[" + path);
65 val = read_afm_file (path);
66 unsmob_metrics (val)->path_ = path;
68 unsmob_metrics (val)->description_ = gh_cons (name_str, gh_double2scm (1.0));
71 progress_indication ("]");
73 afm_p_dict_->set (sname,val);
75 scm_unprotect_object (val);
78 Adobe_font_metric *afm
79 = dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val) );
80 Tex_font_metric * tfm = find_tfm (name);
82 if (tfm->info_.checksum != afm->checksum_)
84 String s = _f ("checksum mismatch for font file:\n`%s'", path.ch_C ());
85 s += " " + _f ("does not match: `%s'", tfm->path_.ch_C()); // FIXME
87 s += " TFM: " + to_str ((int) tfm->info_.checksum);
88 s += " AFM: " + to_str ((int) afm->checksum_);
90 s += _(" Rebuild all .afm files, and remove all .pk and .tfm files. Rerun with -V to show font paths.");
96 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
101 All_font_metrics::find_tfm (String name)
103 SCM sname = ly_symbol2scm (name.ch_C ());
104 SCM name_str = ly_str02scm (name.ch_C ());
107 if (!tfm_p_dict_->try_retrieve (sname, &val))
113 char * p = ly_find_tfm (name.ch_C());
119 path = search_path_.find (name + ".tfm");
124 if (verbose_global_b)
125 progress_indication ("[" + path);
126 val = Tex_font_metric::make_tfm (path);
128 if (verbose_global_b)
129 progress_indication ("]");
131 unsmob_metrics (val)->path_ = path;
132 unsmob_metrics (val)->description_ = gh_cons (name_str, gh_double2scm (1.0));
133 tfm_p_dict_->set (sname, val);
135 scm_unprotect_object (val);
139 dynamic_cast<Tex_font_metric*> (unsmob_metrics (val));
144 All_font_metrics::find_font (String name)
146 Font_metric * f= find_afm (name);
154 warning (_f ("can't find font: `%s'", name.ch_C ()));
155 warning (_ ("Loading default font"));
157 String def_name = default_font_sz_;
160 we're in emergency recovery mode here anyway, so don't try to do
161 anything smart that runs the risk of failing. */
162 f= find_afm (def_name);
166 f = find_tfm (def_name);
170 error (_f ("can't find default font: `%s'", def_name.ch_C ()));
171 error (_f ("(search path: `%s')", search_path_.str ()));
172 error (_ ("Giving up"));