* stepmake/stepmake/generic-vars.make (LOOP): Add PLUS to keep -j
[lilypond/patrick.git] / lily / tfm.cc
blobfa9007a2186093473495c4d757a8b6694e196aee
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 "tfm.hh"
13 #include "dimensions.hh"
14 #include "file-name.hh"
15 #include "international.hh"
16 #include "string-convert.hh"
17 #include "tfm-reader.hh"
18 #include "warn.hh"
20 static Tex_font_char_metric dummy_static_char_metric;
22 Tex_font_char_metric::Tex_font_char_metric ()
24 exists_ = false;
25 code_ = 0;;
26 width_ = 0;
27 height_ = 0;
28 depth_ = 0;
29 italic_correction_ = 0;
30 width_fix_ = 0;
31 height_fix_ = 0;
32 depth_fix_ = 0;
33 italic_correction_fix_ = 0;
36 Box
37 Tex_font_char_metric::dimensions () const
39 if (!exists_)
41 Box b;
42 b.set_empty ();
43 return b;
46 Real d = -depth_;
47 Real point_constant = 1 PT;
49 return Box (Interval (0, width_ * point_constant),
50 Interval (min (d, height_) * point_constant,
51 max (d, height_) * point_constant));
54 Tex_font_metric::Tex_font_metric ()
56 encoding_table_ = SCM_EOL;
59 void
60 Tex_font_metric::derived_mark () const
62 scm_gc_mark (encoding_table_);
65 Tex_font_char_metric const *
66 Tex_font_metric::find_ascii (vsize ascii, bool warn) const
68 if (ascii != VPOS && ascii < ascii_to_metric_idx_.size ()
69 && ascii_to_metric_idx_[ascii] != VPOS)
70 return &char_metrics_[ascii_to_metric_idx_ [ascii]];
71 else if (warn)
72 warning (_f ("can't find ascii character: %d", ascii));
73 return &dummy_static_char_metric;
76 /* UGH: glyphs need not be consecutive in TFM. */
77 vsize
78 Tex_font_metric::count () const
80 for (vsize i = ascii_to_metric_idx_.size (); i--;)
81 if (ascii_to_metric_idx_[i] != VPOS)
82 return i + 1;
83 return 0;
86 Box
87 Tex_font_metric::get_ascii_char (vsize a) const
89 Box b = find_ascii (a)->dimensions ();
90 return b;
93 SCM
94 Tex_font_metric::make_tfm (std::string file_name)
96 Tex_font_metric *tfm = new Tex_font_metric;
97 Tex_font_metric_reader reader (file_name);
99 tfm->info_ = reader.info_;
100 tfm->header_ = reader.header_;
101 tfm->char_metrics_ = reader.char_metrics_;
102 tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
104 File_name fn (file_name);
105 tfm->font_name_ = fn.base_;
106 return tfm->self_scm ();
109 Tfm_info const &
110 Tex_font_metric::info () const
112 return info_;
115 Real
116 Tex_font_metric::design_size () const
118 return info_.design_size * point_constant;
121 std::string
122 Tex_font_metric::font_name () const
124 return font_name_;
127 vsize
128 Tex_font_metric::name_to_index (std::string) const
130 assert (false);
131 return 0;