2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 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_str0_ = "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_gc_unprotect_object (afm_p_dict_->self_scm ());
34 scm_gc_unprotect_object (tfm_p_dict_->self_scm ());
38 All_font_metrics::find_afm (String name)
40 SCM sname = ly_symbol2scm (name.to_str0 ());
42 SCM name_string = scm_makfrom0str (name.to_str0 ());
46 if (!afm_p_dict_->try_retrieve (sname, &val))
51 path = search_path_.find (name + ".afm");
55 String p = ly_find_afm (name.to_str0 ());
64 progress_indication ("[" + path);
65 val = read_afm_file (path);
66 unsmob_metrics (val)->path_ = path;
68 unsmob_metrics (val)->description_ = gh_cons (name_string, gh_double2scm (1.0));
71 progress_indication ("]");
73 afm_p_dict_->set (sname,val);
75 scm_gc_unprotect_object (val);
78 Adobe_font_metric *afm
79 = dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
82 only check checksums if there is one. We take the risk that
83 some file has valid checksum 0
88 Tex_font_metric * tfm = find_tfm (name);
90 /* FIXME: better warning message
91 (maybe check upon startup for feta16.afm, feta16.tfm?)
93 if (tfm && tfm->info_.checksum != afm->checksum_)
95 String s = _f ("checksum mismatch for font file: `%s'",
97 s += " " + _f ("does not match: `%s'", tfm->path_.to_str0 ()); // FIXME
99 s += " TFM: " + to_string ((int) tfm->info_.checksum);
100 s += " AFM: " + to_string ((int) afm->checksum_);
102 s += _ (" Rebuild all .afm files, and remove all .pk and .tfm files. Rerun with -V to show font paths.");
103 s += _("A script for removing font-files is delivered with the source-code,\n"
104 "in buildscripts/clean-fonts.sh")
110 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
115 All_font_metrics::find_tfm (String name)
117 SCM sname = ly_symbol2scm (name.to_str0 ());
118 SCM name_string = scm_makfrom0str (name.to_str0 ());
121 if (!tfm_p_dict_->try_retrieve (sname, &val))
127 String p = ly_find_tfm (name.to_str0 ());
133 path = search_path_.find (name + ".tfm");
138 if (verbose_global_b)
139 progress_indication ("[" + path);
140 val = Tex_font_metric::make_tfm (path);
142 if (verbose_global_b)
143 progress_indication ("]");
145 unsmob_metrics (val)->path_ = path;
146 unsmob_metrics (val)->description_ = gh_cons (name_string, gh_double2scm (1.0));
147 tfm_p_dict_->set (sname, val);
149 scm_gc_unprotect_object (val);
153 dynamic_cast<Tex_font_metric*> (unsmob_metrics (val));
159 All_font_metrics::find_font (String name)
161 Font_metric * f= find_afm (name);
169 warning (_f ("can't find font: `%s'", name.to_str0 ()));
170 warning (_ ("Loading default font"));
172 String def_name = default_font_str0_;
175 we're in emergency recovery mode here anyway, so don't try to do
176 anything smart that runs the risk of failing. */
177 f= find_afm (def_name);
181 f = find_tfm (def_name);
185 error (_f ("can't find default font: `%s'", def_name.to_str0 ()));
186 error (_f ("(search path: `%s')", search_path_.to_string ()));
187 error (_ ("Giving up"));