]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
Merge branch 'master' into lilypond/translation
[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
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 k) 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   return m->description_;
110 }
111
112 int
113 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
114 {
115   Font_metric *m = unsmob_metrics (s);
116   scm_puts ("#<", port);
117   scm_puts (m->class_name (), port);
118   scm_puts (" ", port);
119   scm_write (m->description_, port);
120   scm_puts (">", port);
121   return 1;
122 }
123
124 IMPLEMENT_SMOBS (Font_metric);
125 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
126 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
127
128 SCM
129 Font_metric::font_file_name () const
130 {
131   return scm_car (description_);
132 }
133
134 string
135 Font_metric::font_name () const
136 {
137   string s ("unknown");
138   return s;
139 }
140
141 size_t
142 Font_metric::index_to_charcode (size_t i) const
143 {
144   return i;
145 }
146
147 Offset
148 Font_metric::attachment_point (string) const
149 {
150   return Offset (0, 0);
151 }
152
153 SCM
154 Font_metric::sub_fonts () const
155 {
156   return SCM_EOL;
157 }
158
159 Stencil
160 Font_metric::text_stencil (Output_def* state,
161                            string, bool) const
162 {
163   (void) state;
164   
165   programming_error ("Cannot get a text stencil from this font");
166   return Stencil (Box (), SCM_EOL);
167 }