2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
19 Tex_font_char_metric::dimensions () const
22 return Box (Interval (0, width_),Interval ( d <? height_, d >? height_));
25 Tex_font_char_metric::Tex_font_char_metric ()
32 italic_correction_ = 0;
36 italic_correction_fix_ = 0;
39 #define APPEND_CHAR_METRIC_ELT(k) outstr += to_str (#k) + " " + to_str (k ## _) + "; "
42 Tex_font_char_metric::str () const
46 APPEND_CHAR_METRIC_ELT (exists_b);
47 APPEND_CHAR_METRIC_ELT (code);
48 APPEND_CHAR_METRIC_ELT (width);
49 APPEND_CHAR_METRIC_ELT (height);
50 APPEND_CHAR_METRIC_ELT (depth);
51 APPEND_CHAR_METRIC_ELT (italic_correction);
56 Tex_font_metric::Tex_font_metric ()
61 static Tex_font_char_metric dummy_static_char_metric;
63 Tex_font_char_metric const *
64 Tex_font_metric::find_ascii (int ascii, bool warn) const
66 if (ascii < ascii_to_metric_idx_.size() && ascii_to_metric_idx_[ascii] >= 0)
67 return & char_metrics_[ascii_to_metric_idx_ [ascii]];
71 warning (_f ("can't find ascii character %d", ascii));
73 return &dummy_static_char_metric;
77 Tex_font_metric::get_char (int a, Real mag) const
79 Box b = find_ascii (a)->dimensions () ;
86 Tex_font_metric::str () const
89 for (int i=0; i < char_metrics_.size (); i++)
90 outstr += char_metrics_[i].str ();
99 Tex_font_metric::make_tfm (String fn)
101 Tex_font_metric * tfm_p = new Tex_font_metric;
102 Tex_font_metric_reader reader (fn);
104 tfm_p->info_ = reader.info_;
105 tfm_p->header_ = reader.header_;
106 tfm_p->char_metrics_ = reader.char_metrics_;
107 tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
109 return tfm_p->self_scm ();