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