]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
Add Output_def argument to Font_metric::text_stencil().
[lilypond.git] / lily / font-metric.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5   Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "font-metric.hh"
22
23 #include <cmath>
24 #include <cctype>
25 using namespace std;
26
27 #include "dimensions.hh"
28 #include "modified-font-metric.hh"
29 #include "open-type-font.hh"
30 #include "stencil.hh"
31 #include "warn.hh"
32
33 #include "ly-smobs.icc"
34
35 Real
36 Font_metric::design_size () const
37 {
38   return 1.0 * point_constant;
39 }
40
41 Stencil
42 Font_metric::find_by_name (string s) const
43 {
44   replace_all (&s, '-', 'M');
45   int idx = name_to_index (s);
46   Box b;
47
48   SCM expr = SCM_EOL;
49   if (idx >= 0)
50     {
51       expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
52                          self_scm (),
53                          ly_string2scm (s));
54       b = get_indexed_char (idx);
55     }
56
57   Stencil q (b, expr);
58   return q;
59 }
60
61 Font_metric::Font_metric ()
62 {
63   description_ = SCM_EOL;
64   self_scm_ = SCM_EOL;
65   smobify_self ();
66 }
67
68 Font_metric::Font_metric (Font_metric const &)
69 {
70 }
71
72 Font_metric::~Font_metric ()
73 {
74 }
75
76 size_t
77 Font_metric::count () const
78 {
79   return 0;
80 }
81
82 Box
83 Font_metric::get_ascii_char (size_t) const
84 {
85   return Box (Interval (0, 0), Interval (0, 0));
86 }
87
88 Box
89 Font_metric::get_indexed_char (size_t k) const
90 {
91   return get_ascii_char (k);
92 }
93
94 size_t
95 Font_metric::name_to_index (string) const
96 {
97   return (size_t)-1;
98 }
99
100 Offset
101 Font_metric::get_indexed_wxwy (size_t) const
102 {
103   return Offset (0, 0);
104 }
105
106 void
107 Font_metric::derived_mark () const
108 {
109 }
110
111 SCM
112 Font_metric::mark_smob (SCM s)
113 {
114   Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
115   m->derived_mark ();
116   return m->description_;
117 }
118
119 int
120 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
121 {
122   Font_metric *m = unsmob_metrics (s);
123   scm_puts ("#<", port);
124   scm_puts (m->class_name (), port);
125   scm_puts (" ", port);
126   scm_write (m->description_, port);
127   scm_puts (">", port);
128   return 1;
129 }
130
131 IMPLEMENT_SMOBS (Font_metric);
132 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
133 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
134
135 SCM
136 Font_metric::font_file_name () const
137 {
138   return scm_car (description_);
139 }
140
141 string
142 Font_metric::font_name () const
143 {
144   string s ("unknown");
145   return s;
146 }
147
148 size_t
149 Font_metric::index_to_ascii (size_t i) const
150 {
151   return i;
152 }
153
154 size_t
155 Font_metric::index_to_charcode (size_t i) const
156 {
157   return index_to_ascii (i);
158 }
159
160 Stencil
161 Font_metric::get_ascii_char_stencil (size_t code) const
162 {
163   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
164                        scm_from_unsigned (code));
165   Box b = get_ascii_char (code);
166   return Stencil (b, at);
167 }
168
169 Stencil
170 Font_metric::get_indexed_char_stencil (size_t code) const
171 {
172   size_t idx = index_to_ascii (code);
173   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
174                        scm_from_unsigned (idx));
175   Box b = get_indexed_char (code);
176   return Stencil (b, at);
177 }
178
179 Offset
180 Font_metric::attachment_point (string) const
181 {
182   return Offset (0, 0);
183 }
184
185 SCM
186 Font_metric::sub_fonts () const
187 {
188   return SCM_EOL;
189 }
190
191 Stencil
192 Font_metric::text_stencil (Output_def* state,
193                            string, bool) const
194 {
195   (void) state;
196   
197   programming_error ("Cannot get a text stencil from this font");
198   return Stencil (Box (), SCM_EOL);
199 }
200
201 Box
202 Font_metric::text_dimension (string) const
203 {
204   return Box (Interval (0, 0), Interval (0, 0));
205 }
206