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