lilypond-1.4.2
[lilypond.git] / lily / tfm.cc
blob6a8afd6e5626dea5528cad592c350378abb49d9c
1 /*
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
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 if (!exists_b_)
23 Box b;
24 b.set_empty ();
25 return b;
28 Real d = -depth_;
29 return Box (Interval (0, width_),Interval (d <? height_, d >? height_));
32 Tex_font_char_metric::Tex_font_char_metric ()
34 exists_b_ = false;
35 code_ = 0;;
36 width_ = 0;
37 height_ = 0;
38 depth_ = 0;
39 italic_correction_ = 0;
40 width_fix_ = 0;
41 height_fix_ = 0;
42 depth_fix_ = 0;
43 italic_correction_fix_ = 0;
46 #define APPEND_CHAR_METRIC_ELT(k) outstr += to_str (#k) + " " + to_str (k ## _) + "; "
48 String
49 Tex_font_char_metric::str () const
51 String outstr ;
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);
60 return outstr + "\n";
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]];
75 else if (warn)
77 warning (_f ("can't find ascii character: %d", ascii));
79 return &dummy_static_char_metric;
84 UGH: glyphs need not be consecutive in TFM.
86 int
87 Tex_font_metric::count () const
89 for (int i = ascii_to_metric_idx_.size (); i--;)
91 if (ascii_to_metric_idx_[i] != -1)
92 return i + 1;
94 return 0;
97 Box
98 Tex_font_metric::get_char (int a) const
100 Box b = find_ascii (a)->dimensions () ;
101 return b;
105 String
106 Tex_font_metric::str () const
108 String outstr;
109 for (int i=0; i < char_metrics_.size (); i++)
110 outstr += char_metrics_[i].str ();
112 return outstr;
119 Tex_font_metric::make_tfm (String fn)
121 Tex_font_metric * tfm_p = new Tex_font_metric;
122 Tex_font_metric_reader reader (fn);
124 tfm_p->info_ = reader.info_;
125 tfm_p->header_ = reader.header_;
126 tfm_p->char_metrics_ = reader.char_metrics_;
127 tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
129 return tfm_p->self_scm ();