2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
8 some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
12 #include "tfm-reader.hh"
13 #include "string-convert.hh"
16 #include "dimensions.hh"
18 static Tex_font_char_metric dummy_static_char_metric;
20 Tex_font_char_metric::Tex_font_char_metric ()
27 italic_correction_ = 0;
31 italic_correction_fix_ = 0;
35 Tex_font_char_metric::dimensions () const
46 Real point_constant = 1 PT;
48 return Box (Interval (0, width_*point_constant ),
49 Interval ((d <? height_)*point_constant,
50 (d >? height_)*point_constant));
53 Tex_font_metric::Tex_font_metric ()
55 encoding_table_ = SCM_EOL;
61 Tex_font_metric::derived_mark () const
63 scm_gc_mark (encoding_table_);
66 Tex_font_char_metric const *
67 Tex_font_metric::find_ascii (int ascii, bool warn) const
69 if (ascii >= 0 && ascii < ascii_to_metric_idx_.size ()
70 && ascii_to_metric_idx_[ascii] >= 0)
71 return & char_metrics_[ascii_to_metric_idx_ [ascii]];
73 warning (_f ("can't find ascii character: %d", ascii));
74 return &dummy_static_char_metric;
77 /* UGH: glyphs need not be consecutive in TFM. */
79 Tex_font_metric::count () const
81 for (int i = ascii_to_metric_idx_.size (); i--;)
82 if (ascii_to_metric_idx_[i] != -1)
88 Tex_font_metric::get_ascii_char (int a) const
90 Box b = find_ascii (a)->dimensions ();
95 Tex_font_metric::make_tfm (String filename)
97 Tex_font_metric *tfm = new Tex_font_metric;
98 Tex_font_metric_reader reader (filename);
100 tfm->info_ = reader.info_;
101 tfm->header_ = reader.header_;
102 tfm->char_metrics_ = reader.char_metrics_;
103 tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
106 tfm->encoding_table_ =
107 scm_call_1 (ly_scheme_function ("get-coding-table"),
108 scm_makfrom0str (tfm->coding_scheme ().to_str0 ()));
110 return tfm->self_scm ();
114 Tex_font_metric::design_size () const
116 return info_.design_size;
120 Tex_font_metric::coding_scheme () const
122 String scm = info_.coding_scheme;
124 for(int i = 0; i < scm.length (); i++)
132 Tex_font_metric::name_to_index (String s) const
134 SCM sym = ly_symbol2scm (s.to_str0 ());
136 SCM idx = scm_hash_ref (encoding_table_, sym, SCM_BOOL_F);
137 if (ly_c_char_p (idx))
139 return (unsigned char) ly_scm2char (idx);