lilypond-1.3.130
[lilypond.git] / lily / tfm.cc
blob4e7d22f4fadb894ad3a27cc223ea1de6d0ecad1d
1 /*
2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 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;
82 Box
83 Tex_font_metric::get_char (int a) const
85 Box b = find_ascii (a)->dimensions () ;
86 return b;
90 String
91 Tex_font_metric::str () const
93 String outstr;
94 for (int i=0; i < char_metrics_.size (); i++)
95 outstr += char_metrics_[i].str ();
97 return outstr;
104 Tex_font_metric::make_tfm (String fn)
106 Tex_font_metric * tfm_p = new Tex_font_metric;
107 Tex_font_metric_reader reader (fn);
109 tfm_p->info_ = reader.info_;
110 tfm_p->header_ = reader.header_;
111 tfm_p->char_metrics_ = reader.char_metrics_;
112 tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
114 return tfm_p->self_scm ();