Bump version.
[lilypond.git] / lily / font-metric.cc
blob215bf679812bee9da7f56682e67dd41cfd9b9bb9
1 /*
2 font-metric.cc -- implement Font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
9 */
11 #include "font-metric.hh"
13 #include <cmath>
14 #include <cctype>
15 using namespace std;
17 #include "dimensions.hh"
18 #include "modified-font-metric.hh"
19 #include "open-type-font.hh"
20 #include "stencil.hh"
21 #include "warn.hh"
23 #include "ly-smobs.icc"
25 Real
26 Font_metric::design_size () const
28 return 1.0 * point_constant;
31 Stencil
32 Font_metric::find_by_name (string s) const
34 replace_all (&s, '-', 'M');
35 int idx = name_to_index (s);
36 Box b;
38 SCM expr = SCM_EOL;
39 if (idx >= 0)
41 expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
42 self_scm (),
43 ly_string2scm (s));
44 b = get_indexed_char (idx);
47 Stencil q (b, expr);
48 return q;
51 Font_metric::Font_metric ()
53 description_ = SCM_EOL;
54 self_scm_ = SCM_EOL;
55 smobify_self ();
58 Font_metric::Font_metric (Font_metric const &)
62 Font_metric::~Font_metric ()
66 size_t
67 Font_metric::count () const
69 return 0;
72 Box
73 Font_metric::get_ascii_char (size_t) const
75 return Box (Interval (0, 0), Interval (0, 0));
78 Box
79 Font_metric::get_indexed_char (size_t k) const
81 return get_ascii_char (k);
84 size_t
85 Font_metric::name_to_index (string) const
87 return (size_t)-1;
90 Offset
91 Font_metric::get_indexed_wxwy (size_t) const
93 return Offset (0, 0);
96 void
97 Font_metric::derived_mark () const
102 Font_metric::mark_smob (SCM s)
104 Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
105 m->derived_mark ();
106 return m->description_;
110 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
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;
121 IMPLEMENT_SMOBS (Font_metric);
122 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
123 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
126 Font_metric::font_file_name () const
128 return scm_car (description_);
131 string
132 Font_metric::font_name () const
134 string s ("unknown");
135 return s;
138 size_t
139 Font_metric::index_to_ascii (size_t i) const
141 return i;
144 size_t
145 Font_metric::index_to_charcode (size_t i) const
147 return index_to_ascii (i);
150 Stencil
151 Font_metric::get_ascii_char_stencil (size_t code) const
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);
159 Stencil
160 Font_metric::get_indexed_char_stencil (size_t code) const
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);
169 Offset
170 Font_metric::attachment_point (string) const
172 return Offset (0, 0);
176 Font_metric::sub_fonts () const
178 return SCM_EOL;
181 Stencil
182 Font_metric::word_stencil (string str) const
184 return text_stencil (str);
187 Stencil
188 Font_metric::text_stencil (string str) const
190 (void) str;
191 programming_error("Cannot get a text stencil from this font");
192 return Stencil (Box (), SCM_EOL);
196 Font_metric::text_dimension (string) const
198 return Box (Interval (0, 0), Interval (0, 0));