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>
11 #include "virtual-font-metric.hh"
12 #include "all-font-metrics.hh"
14 #include "output-def.hh"
18 passing DEF is ughish. Should move into paperdef?
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))
75 m = unsmob_metrics (scm_car (s))->find_by_name (glyph);
82 Virtual_font_metric::get_ascii_char (int) const
84 programming_error ("Virtual font metric cannot be indexed by ASCII.");
89 Virtual_font_metric::get_ascii_char_stencil (int ) const
91 programming_error ("Virtual font metric cannot be indexed by ASCII.");
96 Virtual_font_metric::get_indexed_wxwy (int code) const
99 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
101 Font_metric *fm = unsmob_metrics (scm_car (s));
102 if (code < total + fm->count ())
103 return fm->get_indexed_wxwy (code - total);
104 total += fm->count ();
110 Virtual_font_metric::get_indexed_char (int code) const
113 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
115 Font_metric *fm = unsmob_metrics (scm_car (s));
116 if (code < total + fm->count ())
117 return fm->get_indexed_char (code - total);
118 total += fm->count ();
124 Virtual_font_metric::name_to_index (String glyph) const
128 for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s))
130 Font_metric *m =unsmob_metrics (scm_car (s));
131 int k = m->name_to_index (glyph);
135 total += m->count ();
141 Virtual_font_metric::get_indexed_char_stencil (int code) const
146 for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
148 Font_metric *fm = unsmob_metrics (scm_car (s));
149 if (code < total + fm->count ())
152 m = fm->get_indexed_char_stencil (code - total);
155 total += fm->count ();
162 Virtual_font_metric::get_font_list () const
167 LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1,
169 "Make a virtual font metric from @var{args}, "
170 "a list of font objects.")
172 Virtual_font_metric *fm = new Virtual_font_metric (args);
173 return scm_gc_unprotect_object (fm->self_scm ());
177 Virtual_font_metric::coding_scheme () const
179 Font_metric *fm = unsmob_metrics (scm_car (font_list_));
180 return fm->coding_scheme ();