]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
* input/regression/new-markup-scheme.ly: oops. font-family=music
[lilypond.git] / lily / tfm.cc
1 /*   
2   tfm.cc -- implement Tex_font_metric
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
9  */
10
11 #include "tfm.hh"
12 #include "tfm-reader.hh"
13 #include "string-convert.hh"
14 #include "warn.hh"
15 #include "dimensions.hh"
16
17 static Tex_font_char_metric dummy_static_char_metric;
18
19 Tex_font_char_metric::Tex_font_char_metric ()
20 {
21   exists_ = false;
22   code_ = 0;;
23   width_ = 0;
24   height_ = 0;
25   depth_ = 0;
26   italic_correction_ = 0;
27   width_fix_ = 0;
28   height_fix_ = 0;
29   depth_fix_ = 0;
30   italic_correction_fix_ = 0;
31 }
32
33 Box
34 Tex_font_char_metric::dimensions () const
35 {
36   if (!exists_)
37     {
38       Box b;
39       b.set_empty ();
40       return b;
41     }
42   
43   Real d = -depth_;
44   Real point_constant = 1 PT;
45   
46   return Box (Interval (0, width_* point_constant ),
47               Interval ((d <? height_) * point_constant,
48                         (d >? height_) * point_constant));
49 }
50
51 Tex_font_metric::Tex_font_metric ()
52 {
53   encoding_table_ = SCM_EOL;
54 }
55
56 void
57 Tex_font_metric::derived_mark () const
58 {
59   scm_gc_mark (encoding_table_);
60 }
61
62 Tex_font_char_metric const *
63 Tex_font_metric::find_ascii (int ascii, bool warn) const
64 {
65   if (ascii >= 0 && ascii < ascii_to_metric_idx_.size ()
66       && ascii_to_metric_idx_[ascii] >= 0)
67     return & char_metrics_[ascii_to_metric_idx_ [ascii]];
68   else if (warn)
69     warning (_f ("can't find ascii character: %d", ascii));
70   return &dummy_static_char_metric;  
71 }
72
73 /* UGH: glyphs need not be consecutive in TFM. */
74 int
75 Tex_font_metric::count () const
76 {
77   for (int i = ascii_to_metric_idx_.size (); i--;)
78     if (ascii_to_metric_idx_[i] != -1)
79       return i + 1;
80   return 0;
81 }
82
83 Box
84 Tex_font_metric::get_ascii_char (int a) const
85 {
86   Box b = find_ascii (a)->dimensions ();
87   return b;
88 }
89
90 SCM
91 Tex_font_metric::make_tfm (String file_name)
92 {
93   Tex_font_metric *tfm = new Tex_font_metric;
94   Tex_font_metric_reader reader (file_name);
95
96   tfm->info_ = reader.info_;
97   tfm->header_ = reader.header_;
98   tfm->char_metrics_ = reader.char_metrics_;
99   tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
100
101   return tfm->self_scm ();
102 }
103
104 Real
105 Tex_font_metric::design_size () const
106 {
107   return info_.design_size * point_constant;
108 }
109
110 int
111 Tex_font_metric::name_to_index (String s) const
112 {
113   assert (false);
114 }