2 virtual-font-metric.cc -- implement Virtual_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "virtual-font-metric.hh"
12 #include "all-font-metrics.hh"
14 #include "output-def.hh"
18 passing DEF is ughish. Should move into layoutdef?
20 Virtual_font_metric::Virtual_font_metric (SCM font_list)
23 SCM *tail = &font_list_;
26 SCM name_list = SCM_EOL;
27 SCM *name_tail = &name_list;
29 for (SCM s = font_list; scm_is_pair (s); s = scm_cdr (s))
31 if (Font_metric *fm = unsmob_metrics (scm_car (s)))
33 *tail = scm_cons (scm_car (s),SCM_EOL);
34 tail = SCM_CDRLOC (*tail);
36 if (!scm_is_number (mag))
38 mag = scm_cdr (fm->description_);
40 *name_tail = scm_cons (scm_car (fm->description_), SCM_EOL);
41 name_tail = SCM_CDRLOC (*name_tail);
45 description_ = scm_cons (name_list, mag);
49 Virtual_font_metric::design_size () const
51 return unsmob_metrics (scm_car (font_list_))-> design_size ();
55 Virtual_font_metric::derived_mark ()const
57 scm_gc_mark (font_list_);
61 Virtual_font_metric::count () const
64 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
65 k += unsmob_metrics (scm_car (s))->count ();
70 Virtual_font_metric::find_by_name (String glyph) const
73 for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s))
74 m = unsmob_metrics (scm_car (s))->find_by_name (glyph);
80 Virtual_font_metric::get_ascii_char (int) const
82 programming_error ("Virtual font metric cannot be indexed by ASCII.");
87 Virtual_font_metric::get_ascii_char_stencil (int ) const
89 programming_error ("Virtual font metric cannot be indexed by ASCII.");
94 Virtual_font_metric::get_indexed_wxwy (int code) const
97 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
99 Font_metric *fm = unsmob_metrics (scm_car (s));
100 if (code < total + fm->count ())
101 return fm->get_indexed_wxwy (code - total);
102 total += fm->count ();
108 Virtual_font_metric::get_indexed_char (int code) const
111 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
113 Font_metric *fm = unsmob_metrics (scm_car (s));
114 if (code < total + fm->count ())
115 return fm->get_indexed_char (code - total);
116 total += fm->count ();
122 Virtual_font_metric::name_to_index (String glyph) const
126 for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s))
128 Font_metric *m = unsmob_metrics (scm_car (s));
129 int k = m->name_to_index (glyph);
133 total += m->count ();
139 Virtual_font_metric::get_indexed_char_stencil (int code) const
144 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
146 Font_metric *fm = unsmob_metrics (scm_car (s));
147 if (code < total + fm->count ())
150 m = fm->get_indexed_char_stencil (code - total);
153 total += fm->count ();
160 Virtual_font_metric::get_font_list () const
165 LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1,
167 "Make a virtual font metric from @var{args}, "
168 "a list of font objects.")
170 Virtual_font_metric *fm = new Virtual_font_metric (args);
171 return scm_gc_unprotect_object (fm->self_scm ());
175 Virtual_font_metric::coding_scheme () const
177 Font_metric *fm = unsmob_metrics (scm_car (font_list_));
178 return fm->coding_scheme ();