]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
release: 1.3.6
[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 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_ = height_ = depth_ = italic_correction_ = 0;
30   width_fix_ = height_fix_ = depth_fix_ = italic_correction_fix_ = 0;
31 }
32
33 #define APPEND_CHAR_METRIC_ELT(k)  outstr += to_str (#k) + " "  + to_str (k ## _)  + "; "
34
35 String
36 Tex_font_char_metric::str () const
37 {
38   String outstr ;
39
40   APPEND_CHAR_METRIC_ELT (exists_b);
41   APPEND_CHAR_METRIC_ELT (code);
42   APPEND_CHAR_METRIC_ELT (width);
43   APPEND_CHAR_METRIC_ELT (height);
44   APPEND_CHAR_METRIC_ELT (depth);
45   APPEND_CHAR_METRIC_ELT (italic_correction);
46   
47   return outstr + "\n";
48 }
49
50 Tex_font_metric::Tex_font_metric ()
51 {
52 }
53
54 static Tex_font_char_metric dummy_static_char_metric;
55
56 Tex_font_char_metric const &
57 Tex_font_metric::find_ascii (int ascii, bool warn) const
58 {
59   if (ascii < ascii_to_metric_idx_.size() && ascii_to_metric_idx_[ascii] >= 0)
60     return char_metrics_[ascii_to_metric_idx_ [ascii]];
61   else if (warn)
62
63     {
64       warning (_f ("Can't find ascii character: `%d'", ascii));
65     }
66   return dummy_static_char_metric;  
67 }
68
69 Character_metric const*
70 Tex_font_metric::get_char (int a, bool w) const
71 {
72   return &find_ascii (a, w);
73 }
74
75
76 String
77 Tex_font_metric::str () const
78 {
79   String outstr;
80   for (int i=0; i < char_metrics_.size (); i++)
81     outstr += char_metrics_[i].str ();
82   
83   return outstr;
84 }
85
86 void
87 Tex_font_metric::clear (int n)
88 {
89   for (int i=0; i < n; i++)
90     ascii_to_metric_idx_.push (-1);
91 }
92
93