]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
release: 1.5.29
[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--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7   
8
9   some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
10  */
11
12 #include "tfm.hh"
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
15 #include "debug.hh"
16 #include "warn.hh"
17
18 Box
19 Tex_font_char_metric::dimensions () const
20 {
21   if (!exists_b_)
22     {
23       Box b;
24       b.set_empty ();
25       return b;
26     }
27   
28   Real d = -depth_;
29   return Box (Interval (0, width_),Interval (d <? height_, d >? height_));
30 }
31
32 Tex_font_char_metric::Tex_font_char_metric ()
33 {
34   exists_b_ = false;
35   code_ = 0;;
36   width_ = 0;
37   height_ = 0;
38   depth_ = 0;
39   italic_correction_ = 0;
40   width_fix_ = 0;
41   height_fix_ = 0;
42   depth_fix_ = 0;
43   italic_correction_fix_ = 0;
44 }
45
46 #define APPEND_CHAR_METRIC_ELT(k)  outstr += to_str (#k) + " "  + to_str (k ## _)  + "; "
47
48 String
49 Tex_font_char_metric::str () const
50 {
51   String outstr ;
52
53   APPEND_CHAR_METRIC_ELT (exists_b);
54   APPEND_CHAR_METRIC_ELT (code);
55   APPEND_CHAR_METRIC_ELT (width);
56   APPEND_CHAR_METRIC_ELT (height);
57   APPEND_CHAR_METRIC_ELT (depth);
58   APPEND_CHAR_METRIC_ELT (italic_correction);
59   
60   return outstr + "\n";
61 }
62
63 Tex_font_metric::Tex_font_metric ()
64 {
65 }
66
67
68 static Tex_font_char_metric dummy_static_char_metric;
69
70 Tex_font_char_metric const *
71 Tex_font_metric::find_ascii (int ascii, bool warn) const
72 {
73   if (ascii < ascii_to_metric_idx_.size () && ascii_to_metric_idx_[ascii] >= 0)
74     return & char_metrics_[ascii_to_metric_idx_ [ascii]];
75   else if (warn)
76     {
77       warning (_f ("can't find ascii character: %d", ascii));
78     }
79   return &dummy_static_char_metric;  
80 }
81
82
83 /*
84   UGH: glyphs need not be consecutive in TFM.
85  */
86 int
87 Tex_font_metric::count () const
88 {
89   for (int i = ascii_to_metric_idx_.size (); i--;)
90     {
91       if (ascii_to_metric_idx_[i] != -1)
92         return i + 1;
93     }
94   return 0;
95 }
96
97 Box
98 Tex_font_metric::get_char (int a) const
99 {
100   Box b = find_ascii (a)->dimensions () ;
101   return b;
102 }
103
104
105 String
106 Tex_font_metric::str () const
107 {
108   String outstr;
109   for (int i=0; i < char_metrics_.size (); i++)
110     outstr += char_metrics_[i].str ();
111   
112   return outstr;
113 }
114
115
116
117
118 SCM
119 Tex_font_metric::make_tfm (String fn)
120 {
121   Tex_font_metric * tfm_p = new Tex_font_metric;
122   Tex_font_metric_reader reader (fn);
123
124   tfm_p->info_ = reader.info_;
125   tfm_p->header_ = reader.header_;
126   tfm_p->char_metrics_ = reader.char_metrics_;
127   tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
128   
129   return tfm_p->self_scm ();
130 }