]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
release commit
[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@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 "virtual-methods.hh"
22 #include "warn.hh"
23
24 #include "ly-smobs.icc"
25
26 Real
27 Font_metric::design_size () const
28 {
29   return 1.0 * point_constant;
30 }
31
32 Stencil
33 Font_metric::find_by_name (String s) const
34 {
35   s.substitute ('-', '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       b = get_indexed_char (idx);
46     }
47
48   Stencil q (b, expr);
49   return q;
50 }
51
52 Font_metric::Font_metric ()
53 {
54   description_ = SCM_EOL;
55   self_scm_ = SCM_EOL;
56   smobify_self ();
57 }
58
59 Font_metric::Font_metric (Font_metric const &)
60 {
61 }
62
63 Font_metric::~Font_metric ()
64 {
65 }
66
67 int
68 Font_metric::count () const
69 {
70   return 0;
71 }
72
73 Box
74 Font_metric::get_ascii_char (int) const
75 {
76   return Box (Interval (0, 0), Interval (0, 0));
77 }
78
79 Box
80 Font_metric::get_indexed_char (int k) const
81 {
82   return get_ascii_char (k);
83 }
84
85 int
86 Font_metric::name_to_index (String) const
87 {
88   return -1;
89 }
90
91 Offset
92 Font_metric::get_indexed_wxwy (int) const
93 {
94   return Offset (0, 0);
95 }
96
97 void
98 Font_metric::derived_mark () const
99 {
100 }
101
102 SCM
103 Font_metric::mark_smob (SCM s)
104 {
105   Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
106   m->derived_mark ();
107   return m->description_;
108 }
109
110 int
111 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
112 {
113   Font_metric *m = unsmob_metrics (s);
114   scm_puts ("#<", port);
115   scm_puts (m->class_name (), port);
116   scm_puts (" ", port);
117   scm_write (m->description_, port);
118   scm_puts (">", port);
119   return 1;
120 }
121
122 IMPLEMENT_SMOBS (Font_metric);
123 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
124 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
125
126 SCM
127 Font_metric::font_file_name () const
128 {
129   return scm_car (description_);
130 }
131
132 String
133 Font_metric::font_name () const
134 {
135   String s ("unknown");
136   return s;
137 }
138
139 #include "afm.hh"
140
141 int
142 Font_metric::index_to_ascii (int i) const
143 {
144   return i;
145 }
146
147 unsigned
148 Font_metric::index_to_charcode (int i) const
149 {
150   return (unsigned) index_to_ascii (i);
151 }
152
153 Stencil
154 Font_metric::get_ascii_char_stencil (int code) const
155 {
156   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
157                        scm_from_int (code));
158   Box b = get_ascii_char (code);
159   return Stencil (b, at);
160 }
161
162 Stencil
163 Font_metric::get_indexed_char_stencil (int code) const
164 {
165   int idx = index_to_ascii (code);
166   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (), scm_from_int (idx));
167   Box b = get_indexed_char (code);
168   return Stencil (b, at);
169 }
170
171 Offset
172 Font_metric::attachment_point (String) const
173 {
174   return Offset (0, 0);
175 }
176
177 SCM
178 Font_metric::sub_fonts () const
179 {
180   return SCM_EOL;
181 }
182
183 Stencil
184 Font_metric::text_stencil (String str) const
185 {
186   SCM lst = scm_list_3 (ly_symbol2scm ("text"),
187                         this->self_scm (),
188                         scm_makfrom0str (str.to_str0 ()));
189
190   Box b = text_dimension (str);
191   return Stencil (b, lst);
192 }
193
194 Box
195 Font_metric::text_dimension (String) const
196 {
197   return Box (Interval (0, 0), Interval (0, 0));
198 }
199