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 "paper-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; gh_pair_p (s); s = gh_cdr (s))
31 if (Font_metric*fm = unsmob_metrics (gh_car (s)))
33 *tail = scm_cons (gh_car (s),SCM_EOL);
34 tail = SCM_CDRLOC (*tail);
36 if (!gh_number_p (mag))
38 mag = gh_cdr (fm->description_); // ugh.
41 *name_tail = scm_cons (gh_car (fm->description_), SCM_EOL);
42 name_tail = SCM_CDRLOC (*name_tail);
46 description_ = scm_cons (name_list, mag);
50 Virtual_font_metric::design_size () const
52 return unsmob_metrics (gh_car (font_list_))-> design_size ();
57 Virtual_font_metric::derived_mark ()const
59 scm_gc_mark (font_list_);
63 Virtual_font_metric::count () const
66 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
68 k+= unsmob_metrics (gh_car (s))->count ();
75 Virtual_font_metric::find_by_name (String glyph) const
78 for (SCM s = font_list_; m.is_empty () && gh_pair_p (s); s = gh_cdr (s))
80 m = unsmob_metrics (gh_car (s))->find_by_name (glyph);
89 Virtual_font_metric::get_ascii_char (int) const
91 programming_error ("Virtual font metric cannot be indexed by ASCII.");
96 Virtual_font_metric::get_ascii_char_stencil (int ) const
98 programming_error ("Virtual font metric cannot be indexed by ASCII.");
104 Virtual_font_metric::get_indexed_wxwy (int code) const
107 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
109 Font_metric* fm = unsmob_metrics (gh_car (s));
110 if (code < total + fm->count ())
112 return fm->get_indexed_wxwy (code - total);
114 total += fm->count ();
122 Virtual_font_metric::get_indexed_char (int code) const
125 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
127 Font_metric* fm = unsmob_metrics (gh_car (s));
128 if (code < total + fm->count ())
130 return fm->get_indexed_char (code - total);
132 total += fm->count ();
141 Virtual_font_metric::name_to_index (String glyph) const
145 for (SCM s = font_list_; m.is_empty () && gh_pair_p (s); s = gh_cdr (s))
147 Font_metric *m =unsmob_metrics (gh_car (s));
148 int k = m->name_to_index (glyph);
152 total += m->count ();
160 Virtual_font_metric::get_indexed_char_stencil (int code) const
165 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
167 Font_metric* fm = unsmob_metrics (gh_car (s));
168 if (code < total + fm->count ())
170 m = fm->get_indexed_char_stencil (code - total); // ugh.
173 total += fm->count ();
181 Virtual_font_metric::get_font_list () const
186 LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1,
188 "Make a virtual font metric from @var{args}, a list of font objects.")
190 Virtual_font_metric *fm = new Virtual_font_metric (args);
192 return scm_gc_unprotect_object (fm->self_scm ());