lilypond-1.3.7
[lilypond.git] / lily / all-font-metrics.cc
blobeddad21ed05589c5e8efccf885787ca41a85ba6a
1 /*
2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "main.hh"
11 #include "all-font-metrics.hh"
12 #include "debug.hh"
13 #include "warn.hh"
14 #include "afm.hh"
15 #include "tfm.hh"
16 #include "dictionary-iter.hh"
17 #include "lily-guile.hh"
18 #include "tfm-reader.hh"
20 const char * default_font_sz_ = "cmr10";
22 All_font_metrics::All_font_metrics (String path)
24 search_path_.parse_path (path);
27 Adobe_font_metric *
28 All_font_metrics::find_afm (String name)
30 if (!afm_p_dict_.elem_b (name))
32 String path = name + ".afm";
33 path = search_path_.find (path);
34 if (path.empty_b ())
35 return 0;
37 *mlog << "[" << path;
38 Adobe_font_metric
39 * afm_p = new Adobe_font_metric (read_afm_file (path));
41 afm_p->name_str_ = name;
43 *mlog << "]" << flush ;
45 afm_p_dict_[name] = afm_p;
47 return afm_p_dict_[name];
50 Scaled_font_metric *
51 All_font_metrics::find_scaled (String nm, int m)
53 Scaled_font_metric * s=0;
54 String index = nm + "@" + to_str (m);
55 if (!scaled_p_dict_.elem_b (index))
57 Font_metric *f = find_font (nm);
58 s = new Scaled_font_metric (f, m);
59 scaled_p_dict_[index] = s;
60 return s;
62 else
63 return scaled_p_dict_[index];
66 Tex_font_metric *
67 All_font_metrics::find_tfm (String name)
69 if (!tfm_p_dict_.elem_b (name))
71 String path = name + ".tfm";
72 path = search_path_.find (path);
73 if (path.empty_b ())
74 return 0;
76 *mlog << "[" << path;
77 Tex_font_metric * tfm_p = Tex_font_metric_reader::read_file (path);
78 tfm_p->name_str_ = name;
80 *mlog << "]" << flush ;
82 tfm_p_dict_[name] = tfm_p;
84 return tfm_p_dict_[name];
88 Font_metric *
89 All_font_metrics::find_font (String name)
91 Font_metric * f=0;
92 f = find_tfm (name);
93 if (f)
94 return f;
96 f= find_afm (name);
97 if (f)
98 return f;
100 warning (_f ("Can't find font: `%s'", name.ch_C ()));
101 warning (_ ("Loading default font"));
103 f = find_tfm (default_font_sz_);
104 if (f)
105 return f;
106 error (_f ("Can't find default font: `%s'", default_font_sz_));
107 error (_f ("(search path: `%s'", search_path_.str ()));
108 error (_ ("Giving up"));
112 All_font_metrics::font_descriptions () const
114 SCM l = SCM_EOL;
115 for (Dictionary_iter<Adobe_font_metric*> ai(afm_p_dict_); ai.ok (); ai++)
116 l = gh_cons (ai.val ()->description (), l);
117 for (Dictionary_iter<Tex_font_metric*> ai(tfm_p_dict_); ai.ok (); ai++)
118 l = gh_cons(ai.val ()->description (), l);
120 for (Dictionary_iter<Scaled_font_metric*> ai(scaled_p_dict_); ai.ok (); ai++)
121 l = gh_cons (ai.val ()->description (),l);
123 return l;