release commit
[lilypond.git] / lily / tfm.cc
blobdf8d2d0dbcb623d90ad3704c723ffcdb58be2d25
1 /*
2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 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 "warn.hh"
16 #include "warn.hh"
17 #include "dimensions.hh"
19 Box
20 Tex_font_char_metric::dimensions () const
22 if (!exists_b_)
24 Box b;
25 b.set_empty ();
26 return b;
29 Real d = -depth_;
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 ()
40 exists_b_ = false;
41 code_ = 0;;
42 width_ = 0;
43 height_ = 0;
44 depth_ = 0;
45 italic_correction_ = 0;
46 width_fix_ = 0;
47 height_fix_ = 0;
48 depth_fix_ = 0;
49 italic_correction_fix_ = 0;
52 #define APPEND_CHAR_METRIC_ELT(k) outstr += ::to_string (#k) + " " + ::to_string (k ## _) + "; "
54 String
55 Tex_font_char_metric::to_string () const
57 String outstr ;
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);
66 return outstr + "\n";
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]];
81 else if (warn)
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.
92 int
93 Tex_font_metric::count () const
95 for (int i = ascii_to_metric_idx_.size (); i--;)
97 if (ascii_to_metric_idx_[i] != -1)
98 return i + 1;
100 return 0;
104 Tex_font_metric::get_char (int a) const
106 Box b = find_ascii (a)->dimensions () ;
107 return b;
111 String
112 Tex_font_metric::to_string () const
114 String outstr;
115 for (int i=0; i < char_metrics_.size (); i++)
116 outstr += char_metrics_[i].to_string ();
118 return outstr;
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 ();