2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 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
29 return Box (Interval (0, width_),Interval (d <? height_, d >? height_));
32 Tex_font_char_metric::Tex_font_char_metric ()
39 italic_correction_ = 0;
43 italic_correction_fix_ = 0;
46 #define APPEND_CHAR_METRIC_ELT(k) outstr += to_str (#k) + " " + to_str (k ## _) + "; "
49 Tex_font_char_metric::str () const
53 APPEND_CHAR_METRIC_ELT (exists_b);
54 APPEND_CHAR_METRIC_ELT (code);
55 APPEND_CHAR_METRIC_ELT (width);
56 APPEND_CHAR_METRIC_ELT (height);
57 APPEND_CHAR_METRIC_ELT (depth);
58 APPEND_CHAR_METRIC_ELT (italic_correction);
63 Tex_font_metric::Tex_font_metric ()
68 static Tex_font_char_metric dummy_static_char_metric;
70 Tex_font_char_metric const *
71 Tex_font_metric::find_ascii (int ascii, bool warn) const
73 if (ascii < ascii_to_metric_idx_.size () && ascii_to_metric_idx_[ascii] >= 0)
74 return & char_metrics_[ascii_to_metric_idx_ [ascii]];
77 warning (_f ("can't find ascii character: %d", ascii));
79 return &dummy_static_char_metric;
83 Tex_font_metric::get_char (int a) const
85 Box b = find_ascii (a)->dimensions () ;
91 Tex_font_metric::str () const
94 for (int i=0; i < char_metrics_.size (); i++)
95 outstr += char_metrics_[i].str ();
104 Tex_font_metric::make_tfm (String fn)
106 Tex_font_metric * tfm_p = new Tex_font_metric;
107 Tex_font_metric_reader reader (fn);
109 tfm_p->info_ = reader.info_;
110 tfm_p->header_ = reader.header_;
111 tfm_p->char_metrics_ = reader.char_metrics_;
112 tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
114 return tfm_p->self_scm ();