]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
release: 1.1.62
[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     }
67   return dummy_static_char_metric;  
68 }
69
70 Character_metric const*
71 Tex_font_metric::get_char (int a, bool w) const
72 {
73   return &find_ascii (a, w);
74 }
75
76
77 String
78 Tex_font_metric::str () const
79 {
80   String outstr;
81   for (int i=0; i < char_metrics_.size (); i++)
82     outstr += char_metrics_[i].str ();
83   
84   return outstr;
85 }
86
87 void
88 Tex_font_metric::clear (int n)
89 {
90   for (int i=0; i < n; i++)
91     ascii_to_metric_idx_.push (-1);
92 }
93
94 void
95 Tex_font_metric::read_file (String name)
96 {
97   Tex_font_metric_reader tfm_reader (name);
98   *this = tfm_reader.read_tfm ();
99 }
100