release commit
[lilypond.git] / lily / virtual-font-metric.cc
blob7b66c5bfc126b130474aa50d1c9a2e292b6eaf07
1 /*
2 virtual-font-metric.cc -- implement Virtual_font_metric
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "virtual-font-metric.hh"
11 #include "all-font-metrics.hh"
12 #include "main.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
18 passing DEF is ughish. Should move into paperdef?
20 Virtual_font_metric::Virtual_font_metric (SCM name_list,
21 Real mag,Paper_def*def)
23 font_list_ = SCM_EOL;
24 SCM *tail = &font_list_;
25 for (SCM s = name_list; gh_pair_p (s); s = gh_cdr (s))
27 SCM nm = gh_car (s);
29 Font_metric *fm = def->find_font (nm, mag);
30 *tail = scm_cons (fm->self_scm(),SCM_EOL);
31 tail = SCM_CDRLOC (*tail);
35 void
36 Virtual_font_metric::derived_mark()const
38 scm_gc_mark (font_list_);
41 int
42 Virtual_font_metric::count () const
44 int k = 0;
45 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
47 k+= unsmob_metrics (gh_car (s))->count ();
50 return k;
53 Molecule
54 Virtual_font_metric::find_by_name (String glyph) const
56 Molecule m;
57 for (SCM s = font_list_; m.empty_b () && gh_pair_p (s); s = gh_cdr (s))
59 m = unsmob_metrics (gh_car (s))->find_by_name (glyph);
62 return m;
67 Box
68 Virtual_font_metric::get_char (int code) const
70 int last_k = 0;
71 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
73 Font_metric* fm = unsmob_metrics (gh_car (s));
74 int k = last_k + fm->count ();
75 if (last_k <= code && code < k)
77 return fm->get_char (code - last_k);
79 last_k = k;
83 return Box();
87 Molecule
88 Virtual_font_metric::get_char_molecule (int code) const
90 Molecule m ;
91 int last_k = 0;
92 for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
94 Font_metric* fm = unsmob_metrics (gh_car (s));
95 int k = last_k + fm->count ();
96 if (last_k <= code && code < k)
98 m = fm->get_char_molecule (code - last_k);
99 break;
101 last_k = k;
104 return m;