]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
2ce125cdbe49a8b689e0688d714837871738735e
[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--2000 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   Real d = -depth_;
22   return Box (Interval (0, width_),Interval ( d <? height_, d >? height_));
23 }
24
25 Tex_font_char_metric::Tex_font_char_metric ()
26 {
27   exists_b_ = false;
28   code_ = 0;;
29   width_ = 0;
30   height_ = 0;
31   depth_ = 0;
32   italic_correction_ = 0;
33   width_fix_ = 0;
34   height_fix_ = 0;
35   depth_fix_ = 0;
36   italic_correction_fix_ = 0;
37 }
38
39 #define APPEND_CHAR_METRIC_ELT(k)  outstr += to_str (#k) + " "  + to_str (k ## _)  + "; "
40
41 String
42 Tex_font_char_metric::str () const
43 {
44   String outstr ;
45
46   APPEND_CHAR_METRIC_ELT (exists_b);
47   APPEND_CHAR_METRIC_ELT (code);
48   APPEND_CHAR_METRIC_ELT (width);
49   APPEND_CHAR_METRIC_ELT (height);
50   APPEND_CHAR_METRIC_ELT (depth);
51   APPEND_CHAR_METRIC_ELT (italic_correction);
52   
53   return outstr + "\n";
54 }
55
56 Tex_font_metric::Tex_font_metric ()
57 {
58 }
59
60
61 static Tex_font_char_metric dummy_static_char_metric;
62
63 Tex_font_char_metric const *
64 Tex_font_metric::find_ascii (int ascii, bool warn) const
65 {
66   if (ascii < ascii_to_metric_idx_.size() && ascii_to_metric_idx_[ascii] >= 0)
67     return & char_metrics_[ascii_to_metric_idx_ [ascii]];
68   else if (warn)
69
70     {
71       warning (_f ("can't find ascii character %d", ascii));
72     }
73   return &dummy_static_char_metric;  
74 }
75
76 Box
77 Tex_font_metric::get_char (int a) const
78 {
79   Box b = find_ascii (a)->dimensions () ;
80   return b;
81 }
82
83
84 String
85 Tex_font_metric::str () const
86 {
87   String outstr;
88   for (int i=0; i < char_metrics_.size (); i++)
89     outstr += char_metrics_[i].str ();
90   
91   return outstr;
92 }
93
94
95
96
97 SCM
98 Tex_font_metric::make_tfm (String fn)
99 {
100   Tex_font_metric * tfm_p = new Tex_font_metric;
101   Tex_font_metric_reader reader (fn);
102
103   tfm_p->info_ = reader.info_;
104   tfm_p->header_ = reader.header_;
105   tfm_p->char_metrics_ = reader.char_metrics_;
106   tfm_p->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
107   
108   return tfm_p->self_scm ();
109 }