]> git.donarmstrong.com Git - lilypond.git/blob - lily/virtual-font-metric.cc
24d7bcdd6af77225c08df5d0feacce64eba9ecec
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8  */
9
10 #include "warn.hh"
11 #include "virtual-font-metric.hh"
12 #include "all-font-metrics.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.is_empty () && 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_ascii_char (int)  const
69 {
70   programming_error ("Virtual font metric cannot be indexed by ASCII.");
71   return Box();
72 }
73
74 Molecule
75 Virtual_font_metric::get_ascii_char_molecule (int )  const
76 {
77   programming_error ("Virtual font metric cannot be indexed by ASCII.");
78   return Molecule();
79 }
80
81
82 Offset
83 Virtual_font_metric::get_indexed_wxwy (int code)  const
84 {
85   int total = 0;
86   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
87     {
88       Font_metric* fm = unsmob_metrics (gh_car (s));
89       if (code < total + fm->count ())
90         {
91           return fm->get_indexed_wxwy (code - total);
92         }
93       total += fm->count ();
94     }
95
96   
97   return Offset (0,0);
98 }
99
100 Box
101 Virtual_font_metric::get_indexed_char (int code)  const
102 {
103   int total = 0;
104   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
105     {
106       Font_metric* fm = unsmob_metrics (gh_car (s));
107       if (code < total + fm->count ())
108         {
109           return fm->get_indexed_char (code - total);
110         }
111       total += fm->count ();
112     }
113
114   
115   return Box();
116 }
117
118
119 int 
120 Virtual_font_metric::name_to_index (String glyph) const
121 {
122   Molecule m;
123   int total = 0; 
124   for (SCM s = font_list_; m.is_empty () && gh_pair_p (s); s = gh_cdr (s))
125     {
126       Font_metric *m =unsmob_metrics (gh_car (s));
127       int k = m->name_to_index (glyph);
128       if (k >= 0)
129         return total + k;
130
131       total += m->count ();
132     }
133
134   return -1;
135 }
136
137   
138 Molecule
139 Virtual_font_metric::get_indexed_char_molecule (int code)  const
140 {
141   Molecule  m ;  
142   int total = 0;
143   
144   for (SCM s = font_list_; gh_pair_p (s); s = gh_cdr (s))
145     {
146       Font_metric* fm = unsmob_metrics (gh_car (s));
147       if (code < total + fm->count())
148         {
149           m = fm->get_indexed_char_molecule (code - total); // ugh.
150           break; 
151         }
152       total += fm->count ();
153     }
154
155   return m;
156 }
157