]> git.donarmstrong.com Git - lilypond.git/blob - lily/virtual-font-metric.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / virtual-font-metric.cc
1 /*   
2   virtual-font-metric.cc --  implement Virtual_font_metric
3
4 source file of the GNU LilyPond music typesetter
5
6 (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9
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"
15
16
17 /*
18   passing DEF is ughish. Should move into paperdef?
19   */
20 Virtual_font_metric::Virtual_font_metric (SCM name_list, 
21                                           Real mag,Paper_def*def)
22 {
23   font_list_ = SCM_EOL;
24   SCM *tail = &font_list_;
25   for (SCM s = name_list; gh_pair_p (s); s = gh_cdr (s))
26     {
27       SCM nm = gh_car (s);
28
29       Font_metric *fm = def->find_font (nm, mag);
30       *tail =  scm_cons (fm->self_scm(),SCM_EOL);
31       tail = SCM_CDRLOC (*tail);
32     }
33 }
34
35 void
36 Virtual_font_metric::derived_mark()const
37 {
38   scm_gc_mark (font_list_);
39 }
40
41 int
42 Virtual_font_metric::count () const
43 {
44   int k = 0;
45   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
46     {
47       k+= unsmob_metrics (gh_car (s))->count ();
48     }
49
50   return k;
51 }
52
53 Molecule
54 Virtual_font_metric::find_by_name (String glyph) const
55 {
56   Molecule m;  
57   for (SCM s = font_list_; m.empty_b () && gh_pair_p (s); s = gh_cdr (s))
58     {
59       m = unsmob_metrics (gh_car (s))->find_by_name (glyph);
60     }
61
62   return m;
63 }
64   
65   
66
67 Box
68 Virtual_font_metric::get_char (int code)  const
69 {
70   int last_k = 0;
71   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
72     {
73       Font_metric* fm = unsmob_metrics (gh_car (s));
74       int k = last_k + fm->count ();
75       if (last_k <= code && code < k)
76         {
77           return fm->get_char (code - last_k);
78         }
79       last_k = k;
80     }
81
82   
83   return Box();
84 }
85   
86   
87 Molecule
88 Virtual_font_metric::get_char_molecule (int code)  const
89 {
90   Molecule  m ;  
91   int last_k = 0;
92   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
93     {
94       Font_metric* fm = unsmob_metrics (gh_car (s));
95       int k = last_k + fm->count ();
96       if (last_k <= code && code < k)
97         {
98           m = fm->get_char_molecule (code - last_k);
99           break; 
100         }
101       last_k = k;
102     }
103
104   return m;
105 }
106