]> git.donarmstrong.com Git - lilypond.git/blob - lily/tfm.cc
* scm/framework-ps.scm (output-variables): separately scale the
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   some code shamelessly copied from GNU fontutils-0.6/tfm/tfm_input.c
9  */
10
11 #include "tfm.hh"
12
13 #include "tfm-reader.hh"
14 #include "string-convert.hh"
15 #include "warn.hh"
16 #include "dimensions.hh"
17
18 static Tex_font_char_metric dummy_static_char_metric;
19
20
21
22 Tex_font_char_metric::Tex_font_char_metric ()
23 {
24   exists_ = false;
25   code_ = 0;;
26   width_ = 0;
27   height_ = 0;
28   depth_ = 0;
29   italic_correction_ = 0;
30   width_fix_ = 0;
31   height_fix_ = 0;
32   depth_fix_ = 0;
33   italic_correction_fix_ = 0;
34 }
35
36 Box
37 Tex_font_char_metric::dimensions () const
38 {
39   if (!exists_)
40     {
41       Box b;
42       b.set_empty ();
43       return b;
44     }
45   
46   Real d = -depth_;
47
48   Real point_constant = 1 PT;
49   
50   return Box (Interval (0, width_* point_constant ),
51               Interval ((d <? height_) * point_constant,
52                         (d >? height_) * point_constant));
53 }
54
55 Tex_font_metric::Tex_font_metric ()
56 {
57   encoding_table_ = SCM_EOL;
58 }
59
60 void
61 Tex_font_metric::derived_mark () const
62 {
63   scm_gc_mark (encoding_table_);
64 }
65
66 Tex_font_char_metric const *
67 Tex_font_metric::find_ascii (int ascii, bool warn) const
68 {
69   if (ascii >= 0 && ascii < ascii_to_metric_idx_.size ()
70       && ascii_to_metric_idx_[ascii] >= 0)
71     return & char_metrics_[ascii_to_metric_idx_ [ascii]];
72   else if (warn)
73     warning (_f ("can't find ascii character: %d", ascii));
74   return &dummy_static_char_metric;  
75 }
76
77 /* UGH: glyphs need not be consecutive in TFM. */
78 int
79 Tex_font_metric::count () const
80 {
81   for (int i = ascii_to_metric_idx_.size (); i--;)
82     if (ascii_to_metric_idx_[i] != -1)
83       return i + 1;
84   return 0;
85 }
86
87 Box
88 Tex_font_metric::get_ascii_char (int a) const
89 {
90   Box b = find_ascii (a)->dimensions ();
91   return b;
92 }
93
94 SCM
95 Tex_font_metric::make_tfm (String file_name)
96 {
97   Tex_font_metric *tfm = new Tex_font_metric;
98   Tex_font_metric_reader reader (file_name);
99
100   tfm->info_ = reader.info_;
101   tfm->header_ = reader.header_;
102   tfm->char_metrics_ = reader.char_metrics_;
103   tfm->ascii_to_metric_idx_ = reader.ascii_to_metric_idx_;
104   tfm->encoding_table_
105     = scm_call_1 (ly_lily_module_constant ("get-coding-table"),
106                   scm_makfrom0str (tfm->coding_scheme ().to_str0 ()));
107
108   return tfm->self_scm ();
109 }
110
111 Real
112 Tex_font_metric::design_size () const
113 {
114   return info_.design_size * point_constant;
115 }
116
117 String
118 Tex_font_metric::coding_scheme () const
119 {
120   String scm = info_.coding_scheme;
121
122   for(int i = 0; i < scm.length (); i++)
123     if (scm[i] == ' ')
124       scm[i] = '-';
125
126   return scm;
127 }
128
129 int
130 Tex_font_metric::name_to_index (String s) const
131 {
132   SCM sym = ly_symbol2scm (s.to_str0 ());
133
134   SCM idx = scm_hash_ref (encoding_table_, sym, SCM_BOOL_F);
135   if (ly_c_char_p (idx))
136     {
137       return (unsigned char) ly_scm2char (idx);
138     }
139   else
140     return -1;  
141 }