]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
215bf679812bee9da7f56682e67dd41cfd9b9bb9
[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--2007 Han-Wen Nienhuys <hanwen@xs4all.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 <cmath>
14 #include <cctype>
15 using namespace std;
16
17 #include "dimensions.hh"
18 #include "modified-font-metric.hh"
19 #include "open-type-font.hh"
20 #include "stencil.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 Stencil
32 Font_metric::find_by_name (string s) const
33 {
34   replace_all (&s, '-', 'M');
35   int idx = name_to_index (s);
36   Box b;
37
38   SCM expr = SCM_EOL;
39   if (idx >= 0)
40     {
41       expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
42                          self_scm (),
43                          ly_string2scm (s));
44       b = get_indexed_char (idx);
45     }
46
47   Stencil q (b, expr);
48   return q;
49 }
50
51 Font_metric::Font_metric ()
52 {
53   description_ = SCM_EOL;
54   self_scm_ = SCM_EOL;
55   smobify_self ();
56 }
57
58 Font_metric::Font_metric (Font_metric const &)
59 {
60 }
61
62 Font_metric::~Font_metric ()
63 {
64 }
65
66 size_t
67 Font_metric::count () const
68 {
69   return 0;
70 }
71
72 Box
73 Font_metric::get_ascii_char (size_t) const
74 {
75   return Box (Interval (0, 0), Interval (0, 0));
76 }
77
78 Box
79 Font_metric::get_indexed_char (size_t k) const
80 {
81   return get_ascii_char (k);
82 }
83
84 size_t
85 Font_metric::name_to_index (string) const
86 {
87   return (size_t)-1;
88 }
89
90 Offset
91 Font_metric::get_indexed_wxwy (size_t) const
92 {
93   return Offset (0, 0);
94 }
95
96 void
97 Font_metric::derived_mark () const
98 {
99 }
100
101 SCM
102 Font_metric::mark_smob (SCM s)
103 {
104   Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
105   m->derived_mark ();
106   return m->description_;
107 }
108
109 int
110 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
111 {
112   Font_metric *m = unsmob_metrics (s);
113   scm_puts ("#<", port);
114   scm_puts (m->class_name (), port);
115   scm_puts (" ", port);
116   scm_write (m->description_, port);
117   scm_puts (">", port);
118   return 1;
119 }
120
121 IMPLEMENT_SMOBS (Font_metric);
122 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
123 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
124
125 SCM
126 Font_metric::font_file_name () const
127 {
128   return scm_car (description_);
129 }
130
131 string
132 Font_metric::font_name () const
133 {
134   string s ("unknown");
135   return s;
136 }
137
138 size_t
139 Font_metric::index_to_ascii (size_t i) const
140 {
141   return i;
142 }
143
144 size_t
145 Font_metric::index_to_charcode (size_t i) const
146 {
147   return index_to_ascii (i);
148 }
149
150 Stencil
151 Font_metric::get_ascii_char_stencil (size_t code) const
152 {
153   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
154                        scm_from_unsigned (code));
155   Box b = get_ascii_char (code);
156   return Stencil (b, at);
157 }
158
159 Stencil
160 Font_metric::get_indexed_char_stencil (size_t code) const
161 {
162   size_t idx = index_to_ascii (code);
163   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
164                        scm_from_unsigned (idx));
165   Box b = get_indexed_char (code);
166   return Stencil (b, at);
167 }
168
169 Offset
170 Font_metric::attachment_point (string) const
171 {
172   return Offset (0, 0);
173 }
174
175 SCM
176 Font_metric::sub_fonts () const
177 {
178   return SCM_EOL;
179 }
180
181 Stencil
182 Font_metric::word_stencil (string str) const
183 {
184   return text_stencil (str);
185 }
186
187 Stencil
188 Font_metric::text_stencil (string str) const
189 {
190   (void) str;
191   programming_error("Cannot get a text stencil from this font");
192   return Stencil (Box (), SCM_EOL);
193 }
194
195 Box
196 Font_metric::text_dimension (string) const
197 {
198   return Box (Interval (0, 0), Interval (0, 0));
199 }
200