* The grand 2005-2006 replace.
[lilypond/patrick.git] / lily / tfm.cc
blob9a8d7ee08a2c6289ee4cf4d7444de46e29b63ed6
1 /*
2 tfm.cc -- implement Tex_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2006 Jan Nieuwenhuizen <janneke@gnu.org>
8 some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
9 */
11 #include "file-name.hh"
12 #include "tfm.hh"
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
15 #include "warn.hh"
16 #include "dimensions.hh"
18 static Tex_font_char_metric dummy_static_char_metric;
20 Tex_font_char_metric::Tex_font_char_metric ()
22 exists_ = false;
23 code_ = 0;;
24 width_ = 0;
25 height_ = 0;
26 depth_ = 0;
27 italic_correction_ = 0;
28 width_fix_ = 0;
29 height_fix_ = 0;
30 depth_fix_ = 0;
31 italic_correction_fix_ = 0;
34 Box
35 Tex_font_char_metric::dimensions () const
37 if (!exists_)
39 Box b;
40 b.set_empty ();
41 return b;
44 Real d = -depth_;
45 Real point_constant = 1 PT;
47 return Box (Interval (0, width_ * point_constant),
48 Interval (min (d, height_) * point_constant,
49 max (d, height_) * point_constant));
52 Tex_font_metric::Tex_font_metric ()
54 encoding_table_ = SCM_EOL;
57 void
58 Tex_font_metric::derived_mark () const
60 scm_gc_mark (encoding_table_);
63 Tex_font_char_metric const *
64 Tex_font_metric::find_ascii (int ascii, bool warn) const
66 if (ascii >= 0 && ascii < ascii_to_metric_idx_.size ()
67 && ascii_to_metric_idx_[ascii] >= 0)
68 return &char_metrics_[ascii_to_metric_idx_ [ascii]];
69 else if (warn)
70 warning (_f ("can't find ascii character: %d", ascii));
71 return &dummy_static_char_metric;
74 /* UGH: glyphs need not be consecutive in TFM. */
75 int
76 Tex_font_metric::count () const
78 for (int i = ascii_to_metric_idx_.size (); i--;)
79 if (ascii_to_metric_idx_[i] != -1)
80 return i + 1;
81 return 0;
84 Box
85 Tex_font_metric::get_ascii_char (int a) const
87 Box b = find_ascii (a)->dimensions ();
88 return b;
91 SCM
92 Tex_font_metric::make_tfm (String file_name)
94 Tex_font_metric *tfm = new Tex_font_metric;
95 Tex_font_metric_reader reader (file_name);
97 tfm->info_ = reader.info_;
98 tfm->header_ = reader.header_;
99 tfm->char_metrics_ = reader.char_metrics_;
100 tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
102 File_name fn (file_name);
103 tfm->font_name_ = fn.base_;
104 return tfm->self_scm ();
107 Tfm_info const &
108 Tex_font_metric::info () const
110 return info_;
113 Real
114 Tex_font_metric::design_size () const
116 return info_.design_size * point_constant;
119 String
120 Tex_font_metric::font_name () const
122 return font_name_;
126 Tex_font_metric::name_to_index (String) const
128 assert (false);
129 return 0;