]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
Issue 1388: Initial work to support opentype font features.
[lilypond.git] / lily / font-metric.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 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
33 Real
34 Font_metric::design_size () const
35 {
36   return 1.0 * point_constant;
37 }
38
39 Stencil
40 Font_metric::find_by_name (string s) const
41 {
42   replace_all (&s, '-', 'M');
43   int idx = name_to_index (s);
44   Box b;
45
46   SCM expr = SCM_EOL;
47   if (idx >= 0)
48     {
49       expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
50                          self_scm (),
51                          ly_string2scm (s));
52       b = get_indexed_char_dimensions (idx);
53     }
54
55   Stencil q (b, expr);
56   return q;
57 }
58
59 Font_metric::Font_metric ()
60 {
61   description_ = SCM_EOL;
62   smobify_self ();
63 }
64
65 Font_metric::Font_metric (Font_metric const &)
66   : Smob<Font_metric> ()
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 () const
99 {
100   derived_mark ();
101   return description_;
102 }
103
104 int
105 Font_metric::print_smob (SCM port, scm_print_state *) const
106 {
107   scm_puts ("#<", port);
108   scm_puts (class_name (), port);
109   scm_puts (" ", port);
110   scm_write (description_, port);
111   scm_puts (">", port);
112   return 1;
113 }
114
115 const char * const Font_metric::type_p_name_ = "ly:font-metric?";
116
117 SCM
118 Font_metric::font_file_name () const
119 {
120   return scm_car (description_);
121 }
122
123 string
124 Font_metric::font_name () const
125 {
126   string s ("unknown");
127   return s;
128 }
129
130 size_t
131 Font_metric::index_to_charcode (size_t i) const
132 {
133   return i;
134 }
135
136 Offset
137 Font_metric::attachment_point (const string&) const
138 {
139   return Offset (0, 0);
140 }
141
142 SCM
143 Font_metric::sub_fonts () const
144 {
145   return SCM_EOL;
146 }
147
148 Stencil
149 Font_metric::text_stencil (Output_def *state,
150                            const string&,
151                            bool,
152                            const string&) const
153 {
154   (void) state;
155
156   programming_error ("Cannot get a text stencil from this font");
157   return Stencil (Box (), SCM_EOL);
158 }