3 all-font-metrics.cc -- implement All_font_metrics
5 source file of the GNU LilyPond music typesetter
7 (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "all-font-metrics.hh"
18 #include "lily-guile.hh"
19 #include "scm-hash.hh"
22 static const char * default_font_str0_ = "cmr10";
24 All_font_metrics::All_font_metrics (String path)
26 afm_p_dict_ = new Scheme_hash_table;
27 tfm_p_dict_ = new Scheme_hash_table;
29 search_path_.parse_path (path);
32 All_font_metrics::~All_font_metrics ()
34 scm_gc_unprotect_object (afm_p_dict_->self_scm ());
35 scm_gc_unprotect_object (tfm_p_dict_->self_scm ());
39 TODO: our AFM handling is broken: the units in an AFM file are
40 relative to the design size (1000 units = 1 designsize). Hence we
41 should include design size when generating an AFM metric.
44 All_font_metrics::find_afm (String name)
46 SCM sname = ly_symbol2scm (name.to_str0 ());
48 SCM name_string = scm_makfrom0str (name.to_str0 ());
52 if (!afm_p_dict_->try_retrieve (sname, &val))
57 path = search_path_.find (name + ".afm");
61 String p = kpathsea_find_afm (name.to_str0 ());
70 progress_indication ("[" + path);
71 val = read_afm_file (path);
72 unsmob_metrics (val)->path_ = path;
74 unsmob_metrics (val)->description_ = gh_cons (name_string, gh_double2scm (1.0));
77 progress_indication ("]");
79 afm_p_dict_->set (sname,val);
81 scm_gc_unprotect_object (val);
84 Adobe_font_metric *afm
85 = dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
88 only check checksums if there is one. We take the risk that
89 some file has valid checksum 0
93 Tex_font_metric * tfm = find_tfm (name);
95 /* FIXME: better warning message
96 (maybe check upon startup for feta16.afm, feta16.tfm?)
98 if (tfm && tfm->info_.checksum != afm->checksum_)
100 String s = _f ("checksum mismatch for font file: `%s'",
102 s += " " + _f ("does not match: `%s'", tfm->path_.to_str0 ()); // FIXME
104 s += " TFM: " + to_string ((int) tfm->info_.checksum);
105 s += " AFM: " + to_string ((int) afm->checksum_);
107 s += _ (" Rebuild all .afm files, and remove all .pk and .tfm files.\nRerun with -V to show font paths.\n");
108 s += _("A script for removing font-files is delivered with the source-code,\n"
109 "in buildscripts/clean-fonts.sh");
115 return dynamic_cast<Adobe_font_metric*> (unsmob_metrics (val));
120 All_font_metrics::find_tfm (String name)
122 SCM sname = ly_symbol2scm (name.to_str0 ());
123 SCM name_string = scm_makfrom0str (name.to_str0 ());
126 if (!tfm_p_dict_->try_retrieve (sname, &val))
130 if (path.is_empty ())
132 String p = kpathsea_find_tfm (name.to_str0 ());
137 if (path.is_empty ())
138 path = search_path_.find (name + ".tfm");
139 if (path.is_empty ())
142 if (verbose_global_b)
143 progress_indication ("[" + path);
145 val = Tex_font_metric::make_tfm (path);
147 if (verbose_global_b)
148 progress_indication ("]");
150 unsmob_metrics (val)->path_ = path;
151 unsmob_metrics (val)->description_ = gh_cons (name_string, gh_double2scm (1.0));
152 tfm_p_dict_->set (sname, val);
154 scm_gc_unprotect_object (val);
158 dynamic_cast<Tex_font_metric*> (unsmob_metrics (val));
164 All_font_metrics::find_font (String name)
166 if ((name.left_string (4) == "feta") ||
167 (name.left_string (8) == "parmesan"))
169 Font_metric * f = find_afm (name);
179 Font_metric * f = find_tfm (name);
188 warning (_f ("can't find font: `%s'", name.to_str0 ()));
189 warning (_ ("Loading default font"));
191 String def_name = default_font_str0_;
194 we're in emergency recovery mode here anyway, so don't try to do
195 anything smart that runs the risk of failing. */
196 Font_metric* f= find_afm (def_name);
200 f = find_tfm (def_name);
204 error (_f ("can't find default font: `%s'", def_name.to_str0 ()));
205 error (_f ("(search path: `%s')", search_path_.to_string ()));
206 error (_ ("Giving up"));