lilypond-1.3.19
[lilypond.git] / lily / tfm.cc
bloba46d2a8dab612c2da75b984bd49d454c5c910cd0
1 /*
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
12 #include "tfm.hh"
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
15 #include "debug.hh"
16 #include "warn.hh"
18 Box
19 Tex_font_char_metric::dimensions () const
21 Real d = -depth_;
22 return Box (Interval (0, width_),Interval ( d <? height_, d >? height_));
25 Tex_font_char_metric::Tex_font_char_metric ()
27 exists_b_ = false;
28 code_ = 0;;
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 ## _) + "; "
35 String
36 Tex_font_char_metric::str () const
38 String outstr ;
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);
47 return outstr + "\n";
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]];
61 else if (warn)
64 warning (_f ("Can't find ascii character: `%d'", ascii));
66 return dummy_static_char_metric;
69 Character_metric const*
70 Tex_font_metric::get_char (int a, bool w) const
72 return &find_ascii (a, w);
76 String
77 Tex_font_metric::str () const
79 String outstr;
80 for (int i=0; i < char_metrics_.size (); i++)
81 outstr += char_metrics_[i].str ();
83 return outstr;
86 void
87 Tex_font_metric::clear (int n)
89 for (int i=0; i < n; i++)
90 ascii_to_metric_idx_.push (-1);