2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 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 ()
29 width_ = height_ = depth_ = italic_correction_ = 0;
30 width_fix_ = height_fix_ = depth_fix_ = italic_correction_fix_ = 0;
33 #define APPEND_CHAR_METRIC_ELT(k) outstr += to_str (#k) + " " + to_str (k ## _) + "; "
36 Tex_font_char_metric::str () const
40 APPEND_CHAR_METRIC_ELT (exists_b);
41 APPEND_CHAR_METRIC_ELT (code);
42 APPEND_CHAR_METRIC_ELT (width);
43 APPEND_CHAR_METRIC_ELT (height);
44 APPEND_CHAR_METRIC_ELT (depth);
45 APPEND_CHAR_METRIC_ELT (italic_correction);
50 Tex_font_metric::Tex_font_metric ()
54 static Tex_font_char_metric dummy_static_char_metric;
56 Tex_font_char_metric const &
57 Tex_font_metric::find_ascii (int ascii, bool warn) const
59 if (ascii < ascii_to_metric_idx_.size() && ascii_to_metric_idx_[ascii] >= 0)
60 return char_metrics_[ascii_to_metric_idx_ [ascii]];
64 warning (_f ("can't find ascii character `%d'", ascii));
67 return dummy_static_char_metric;
70 Character_metric const*
71 Tex_font_metric::get_char (int a, bool w) const
73 return &find_ascii (a, w);
78 Tex_font_metric::str () const
81 for (int i=0; i < char_metrics_.size (); i++)
82 outstr += char_metrics_[i].str ();
88 Tex_font_metric::clear (int n)
90 for (int i=0; i < n; i++)
91 ascii_to_metric_idx_.push (-1);
95 Tex_font_metric::read_file (String name)
97 Tex_font_metric_reader tfm_reader (name);
98 *this = tfm_reader.read_tfm ();