2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2002 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"
17 #include "dimensions.hh"
20 Tex_font_char_metric::dimensions () const
31 Real point_constant = 1 PT;
33 return Box (Interval (0, width_*point_constant ),
34 Interval ((d <? height_)*point_constant,
35 (d >? height_)*point_constant));
38 Tex_font_char_metric::Tex_font_char_metric ()
45 italic_correction_ = 0;
49 italic_correction_fix_ = 0;
52 #define APPEND_CHAR_METRIC_ELT(k) outstr += to_string (#k) + " " + to_string (k ## _) + "; "
55 Tex_font_char_metric::string () const
59 APPEND_CHAR_METRIC_ELT (exists_b);
60 APPEND_CHAR_METRIC_ELT (code);
61 APPEND_CHAR_METRIC_ELT (width);
62 APPEND_CHAR_METRIC_ELT (height);
63 APPEND_CHAR_METRIC_ELT (depth);
64 APPEND_CHAR_METRIC_ELT (italic_correction);
69 Tex_font_metric::Tex_font_metric ()
74 static Tex_font_char_metric dummy_static_char_metric;
76 Tex_font_char_metric const *
77 Tex_font_metric::find_ascii (int ascii, bool warn) const
79 if (ascii < ascii_to_metric_idx_.size () && ascii_to_metric_idx_[ascii] >= 0)
80 return & char_metrics_[ascii_to_metric_idx_ [ascii]];
83 warning (_f ("can't find ascii character: %d", ascii));
85 return &dummy_static_char_metric;
90 UGH: glyphs need not be consecutive in TFM.
93 Tex_font_metric::count () const
95 for (int i = ascii_to_metric_idx_.size (); i--;)
97 if (ascii_to_metric_idx_[i] != -1)
104 Tex_font_metric::get_char (int a) const
106 Box b = find_ascii (a)->dimensions () ;
112 Tex_font_metric::string () const
115 for (int i=0; i < char_metrics_.size (); i++)
116 outstr += char_metrics_[i].string ();
125 Tex_font_metric::make_tfm (String fn)
127 Tex_font_metric * tfm = new Tex_font_metric;
128 Tex_font_metric_reader reader (fn);
130 tfm->info_ = reader.info_;
131 tfm->header_ = reader.header_;
132 tfm->char_metrics_ = reader.char_metrics_;
133 tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
135 return tfm->self_scm ();