]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
* scm/music-functions.scm (has-request-chord): don't use
[lilypond.git] / lily / font-metric.cc
1 /*   
2   font-metric.cc -- implement Font_metric
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8     Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
9 */
10
11 #include "font-metric.hh"
12
13 #include <math.h>
14 #include <cctype>
15
16 #include "dimensions.hh"
17 #include "modified-font-metric.hh"
18 #include "open-type-font.hh"
19 #include "stencil.hh"
20 #include "virtual-methods.hh"
21 #include "warn.hh"
22
23 #include "ly-smobs.icc"
24
25 Real
26 Font_metric::design_size () const
27 {
28   return 1.0 * point_constant;
29 }
30
31
32 Stencil
33 Font_metric::find_by_name (String s) const
34 {
35   s.substitute_char ('-', "M");
36   int idx = name_to_index (s);
37   Box b;
38   
39   SCM expr = SCM_EOL;
40   if (idx >= 0)
41     {
42       expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
43                          self_scm (),
44                          scm_makfrom0str (s.to_str0 ())
45                          );
46       b = get_indexed_char (idx);
47     }
48   
49   Stencil q (b, expr);
50   return q;
51 }
52
53 Font_metric::Font_metric ()
54 {
55   description_ = SCM_EOL;
56   self_scm_ = SCM_EOL;
57   smobify_self ();
58 }
59
60 Font_metric::Font_metric (Font_metric const &)
61 {
62 }
63
64
65 Font_metric::~Font_metric ()
66 {
67 }
68
69 int
70 Font_metric::count () const
71 {
72   return 0;
73 }
74
75 Box 
76 Font_metric::get_ascii_char (int) const
77 {
78   return Box (Interval (0, 0), Interval (0, 0));
79 }
80
81 Box 
82 Font_metric::get_indexed_char (int k) const
83 {
84   return get_ascii_char (k);
85 }
86
87 int
88 Font_metric::name_to_index (String) const
89 {
90   return -1;
91 }
92
93 Offset
94 Font_metric::get_indexed_wxwy (int) const
95 {
96   return Offset (0, 0);
97 }
98
99 void
100 Font_metric::derived_mark () const
101 {
102 }
103
104 SCM
105 Font_metric::mark_smob (SCM s)
106 {
107   Font_metric *m = (Font_metric*) SCM_CELL_WORD_1 (s);
108   m->derived_mark ();
109   return m->description_;
110 }
111
112 int
113 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
114 {
115   Font_metric *m = unsmob_metrics (s);
116   scm_puts ("#<", port);
117   scm_puts (classname (m), port);
118   scm_puts (" ", port);
119   scm_write (m->description_, port);
120   scm_puts (">", port);
121   return 1;
122 }
123
124
125
126 IMPLEMENT_SMOBS (Font_metric);
127 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
128 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
129
130
131 SCM 
132 Font_metric::font_file_name () const
133 {
134   return scm_car (description_);
135 }
136
137 String
138 Font_metric::font_name () const
139 {
140   String s ("unknown");
141   return s;
142 }
143
144 #include "afm.hh"
145
146
147 int
148 Font_metric::index_to_ascii (int i) const
149 {
150   return i;
151 }
152
153 unsigned
154 Font_metric::index_to_charcode (int i) const
155 {
156   return (unsigned) index_to_ascii (i);
157 }
158
159 Stencil
160 Font_metric::get_ascii_char_stencil (int code) const
161 {
162   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
163                        scm_int2num (code));
164   Box b = get_ascii_char (code);
165   return Stencil (b, at);
166 }
167
168 Stencil
169 Font_metric::get_indexed_char_stencil (int code) const
170 {
171   int idx = index_to_ascii (code);
172   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (), scm_int2num (idx));
173   Box b = get_indexed_char (code);
174   return Stencil (b, at);
175 }
176
177
178 Offset
179 Font_metric::attachment_point (String) const
180 {
181   return Offset (0, 0);
182 }
183
184 SCM
185 Font_metric::sub_fonts () const
186 {
187   return SCM_EOL;
188 }
189
190 Stencil
191 Font_metric::text_stencil (String str) const
192 {
193   SCM lst = scm_list_3 (ly_symbol2scm ("text"),
194                         this->self_scm (),
195                         scm_makfrom0str (str.to_str0 ()));
196   
197   Box b = text_dimension (str);
198   return Stencil (b, lst);
199 }
200
201 Box
202 Font_metric::text_dimension (String) const
203 {
204   return Box (Interval (0, 0), Interval (0, 0));
205 }
206