]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
patch::: 1.3.34.jcn2
[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 static Tex_font_char_metric dummy_static_char_metric;
61
62 Tex_font_char_metric const *
63 Tex_font_metric::find_ascii (int ascii, bool warn) const
64 {
65   if (ascii < ascii_to_metric_idx_.size() && ascii_to_metric_idx_[ascii] >= 0)
66     return & char_metrics_[ascii_to_metric_idx_ [ascii]];
67   else if (warn)
68
69     {
70       warning (_f ("can't find ascii character: `%d'", ascii));
71     }
72   return &dummy_static_char_metric;  
73 }
74
75 Box
76 Tex_font_metric::get_char (int a, bool w) const
77 {
78   return find_ascii (a, w)->dimensions ();
79 }
80
81
82 String
83 Tex_font_metric::str () const
84 {
85   String outstr;
86   for (int i=0; i < char_metrics_.size (); i++)
87     outstr += char_metrics_[i].str ();
88   
89   return outstr;
90 }
91
92 void
93 Tex_font_metric::clear (int n)
94 {
95   for (int i=0; i < n; i++)
96     ascii_to_metric_idx_.push (-1);
97 }
98
99