]> git.donarmstrong.com Git - lilypond.git/blob - lily/font-metric.cc
* flower
[lilypond.git] / lily / font-metric.cc
1 /*
2   font-metric.cc -- implement Font_metric
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8   Mats Bengtsson <matsb@s3.kth.se> (the ugly TeX parsing in text_dimension)
9 */
10
11 #include "font-metric.hh"
12
13 #include <math.h>
14 #include <cctype>
15
16 #include "dimensions.hh"
17 #include "modified-font-metric.hh"
18 #include "open-type-font.hh"
19 #include "stencil.hh"
20 #include "virtual-methods.hh"
21 #include "warn.hh"
22
23 #include "ly-smobs.icc"
24
25 Real
26 Font_metric::design_size () const
27 {
28   return 1.0 * point_constant;
29 }
30
31 Stencil
32 Font_metric::find_by_name (String s) const
33 {
34   s.substitute_char ('-', "M");
35   int idx = name_to_index (s);
36   Box b;
37
38   SCM expr = SCM_EOL;
39   if (idx >= 0)
40     {
41       expr = scm_list_3 (ly_symbol2scm ("named-glyph"),
42                          self_scm (),
43                          scm_makfrom0str (s.to_str0 ()));
44       b = get_indexed_char (idx);
45     }
46
47   Stencil q (b, expr);
48   return q;
49 }
50
51 Font_metric::Font_metric ()
52 {
53   description_ = SCM_EOL;
54   self_scm_ = SCM_EOL;
55   smobify_self ();
56 }
57
58 Font_metric::Font_metric (Font_metric const &)
59 {
60 }
61
62 Font_metric::~Font_metric ()
63 {
64 }
65
66 int
67 Font_metric::count () const
68 {
69   return 0;
70 }
71
72 Box
73 Font_metric::get_ascii_char (int) const
74 {
75   return Box (Interval (0, 0), Interval (0, 0));
76 }
77
78 Box
79 Font_metric::get_indexed_char (int k) const
80 {
81   return get_ascii_char (k);
82 }
83
84 int
85 Font_metric::name_to_index (String) const
86 {
87   return -1;
88 }
89
90 Offset
91 Font_metric::get_indexed_wxwy (int) const
92 {
93   return Offset (0, 0);
94 }
95
96 void
97 Font_metric::derived_mark () const
98 {
99 }
100
101 SCM
102 Font_metric::mark_smob (SCM s)
103 {
104   Font_metric *m = (Font_metric *) SCM_CELL_WORD_1 (s);
105   m->derived_mark ();
106   return m->description_;
107 }
108
109 int
110 Font_metric::print_smob (SCM s, SCM port, scm_print_state *)
111 {
112   Font_metric *m = unsmob_metrics (s);
113   scm_puts ("#<", port);
114   scm_puts (classname (m), port);
115   scm_puts (" ", port);
116   scm_write (m->description_, port);
117   scm_puts (">", port);
118   return 1;
119 }
120
121 IMPLEMENT_SMOBS (Font_metric);
122 IMPLEMENT_DEFAULT_EQUAL_P (Font_metric);
123 IMPLEMENT_TYPE_P (Font_metric, "ly:font-metric?");
124
125 SCM
126 Font_metric::font_file_name () const
127 {
128   return scm_car (description_);
129 }
130
131 String
132 Font_metric::font_name () const
133 {
134   String s ("unknown");
135   return s;
136 }
137
138 #include "afm.hh"
139
140 int
141 Font_metric::index_to_ascii (int i) const
142 {
143   return i;
144 }
145
146 unsigned
147 Font_metric::index_to_charcode (int i) const
148 {
149   return (unsigned) index_to_ascii (i);
150 }
151
152 Stencil
153 Font_metric::get_ascii_char_stencil (int code) const
154 {
155   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (),
156                        scm_int2num (code));
157   Box b = get_ascii_char (code);
158   return Stencil (b, at);
159 }
160
161 Stencil
162 Font_metric::get_indexed_char_stencil (int code) const
163 {
164   int idx = index_to_ascii (code);
165   SCM at = scm_list_3 (ly_symbol2scm ("char"), self_scm (), scm_int2num (idx));
166   Box b = get_indexed_char (code);
167   return Stencil (b, at);
168 }
169
170 Offset
171 Font_metric::attachment_point (String) const
172 {
173   return Offset (0, 0);
174 }
175
176 SCM
177 Font_metric::sub_fonts () const
178 {
179   return SCM_EOL;
180 }
181
182 Stencil
183 Font_metric::text_stencil (String str) const
184 {
185   SCM lst = scm_list_3 (ly_symbol2scm ("text"),
186                         this->self_scm (),
187                         scm_makfrom0str (str.to_str0 ()));
188
189   Box b = text_dimension (str);
190   return Stencil (b, lst);
191 }
192
193 Box
194 Font_metric::text_dimension (String) const
195 {
196   return Box (Interval (0, 0), Interval (0, 0));
197 }
198