]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
Don't assign 'safe' values to self_scm_ outside of smobify_self
[lilypond.git] / lily / font-metric.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2014 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   smobify_self ();
64 }
65
66 Font_metric::Font_metric (Font_metric const &)
67 {
68 }
69
70 Font_metric::~Font_metric ()
71 {
72 }
73
74 size_t
75 Font_metric::count () const
76 {
77   return 0;
78 }
79
80 Box
81 Font_metric::get_indexed_char_dimensions (size_t) const
82 {
83   return Box (Interval (0, 0), Interval (0, 0));
84 }
85
86 Offset
87 Font_metric::get_indexed_wxwy (size_t) const
88 {
89   return Offset (0, 0);
90 }
91
92 void
93 Font_metric::derived_mark () const
94 {
95 }
96
97 SCM
98 Font_metric::mark_smob (SCM s)
99 {
100   Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
101   m->derived_mark ();
102   return m->description_;
103 }
104
105 int
106 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
107 {
108   Font_metric *m = Font_metric::unsmob (s);
109   scm_puts ("#<", port);
110   scm_puts (m->class_name (), port);
111   scm_puts (" ", port);
112   scm_write (m->description_, port);
113   scm_puts (">", port);
114   return 1;
115 }
116
117 IMPLEMENT_SMOBS (Font_metric);
118 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
119 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
120
121 SCM
122 Font_metric::font_file_name () const
123 {
124   return scm_car (description_);
125 }
126
127 string
128 Font_metric::font_name () const
129 {
130   string s ("unknown");
131   return s;
132 }
133
134 size_t
135 Font_metric::index_to_charcode (size_t i) const
136 {
137   return i;
138 }
139
140 Offset
141 Font_metric::attachment_point (const string&) const
142 {
143   return Offset (0, 0);
144 }
145
146 SCM
147 Font_metric::sub_fonts () const
148 {
149   return SCM_EOL;
150 }
151
152 Stencil
153 Font_metric::text_stencil (Output_def *state,
154                            const string&, bool) const
155 {
156   (void) state;
157
158   programming_error ("Cannot get a text stencil from this font");
159   return Stencil (Box (), SCM_EOL);
160 }