]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 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   replace_all (s, '-', '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.c_str ()));
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 size_t
68 Font_metric::count () const
69 {
70   return 0;
71 }
72
73 Box
74 Font_metric::get_ascii_char (size_t) const
75 {
76   return Box (Interval (0, 0), Interval (0, 0));
77 }
78
79 Box
80 Font_metric::get_indexed_char (size_t k) const
81 {
82   return get_ascii_char (k);
83 }
84
85 size_t
86 Font_metric::name_to_index (string) const
87 {
88   return (size_t)-1;
89 }
90
91 Offset
92 Font_metric::get_indexed_wxwy (size_t) 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 size_t
140 Font_metric::index_to_ascii (size_t i) const
141 {
142   return i;
143 }
144
145 size_t
146 Font_metric::index_to_charcode (size_t i) const
147 {
148   return index_to_ascii (i);
149 }
150
151 Stencil
152 Font_metric::get_ascii_char_stencil (size_t code) const
153 {
154   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
155                        scm_from_unsigned (code));
156   Box b = get_ascii_char (code);
157   return Stencil (b, at);
158 }
159
160 Stencil
161 Font_metric::get_indexed_char_stencil (size_t code) const
162 {
163   size_t idx = index_to_ascii (code);
164   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
165                        scm_from_unsigned (idx));
166   Box b = get_indexed_char (code);
167   return Stencil (b, at);
168 }
169
170 Offset
171 Font_metric::attachment_point (string) const
172 {
173   return Offset (0, 0);
174 }
175
176 SCM
177 Font_metric::sub_fonts () const
178 {
179   return SCM_EOL;
180 }
181
182 Stencil
183 Font_metric::text_stencil (string str) const
184 {
185   SCM lst = scm_list_3 (ly_symbol2scm ("text"),
186                         this->self_scm (),
187                         scm_makfrom0str (str.c_str ()));
188
189   Box b = text_dimension (str);
190   return Stencil (b, lst);
191 }
192
193 Box
194 Font_metric::text_dimension (string) const
195 {
196   return Box (Interval (0, 0), Interval (0, 0));
197 }
198