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
11 #include "file-name.hh"
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
16 #include "dimensions.hh"
18 static Tex_font_char_metric dummy_static_char_metric
;
20 Tex_font_char_metric::Tex_font_char_metric ()
27 italic_correction_
= 0;
31 italic_correction_fix_
= 0;
35 Tex_font_char_metric::dimensions () const
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
;
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
]];
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. */
76 Tex_font_metric::count () const
78 for (int i
= ascii_to_metric_idx_
.size (); i
--;)
79 if (ascii_to_metric_idx_
[i
] != -1)
85 Tex_font_metric::get_ascii_char (int a
) const
87 Box b
= find_ascii (a
)->dimensions ();
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 ();
108 Tex_font_metric::info () const
114 Tex_font_metric::design_size () const
116 return info_
.design_size
* point_constant
;
120 Tex_font_metric::font_name () const
126 Tex_font_metric::name_to_index (String
) const