]> git.donarmstrong.com Git - lilypond.git/blob - lily/virtual-font-metric.cc
(transform_heads): replace
[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 "virtual-font-metric.hh"
11
12 #include "all-font-metrics.hh"
13 #include "stencil.hh"
14 #include "output-def.hh"
15 #include "warn.hh"
16
17 /*
18   passing DEF is ughish. Should move into layoutdef?
19   */
20 Virtual_font_metric::Virtual_font_metric (SCM font_list)
21 {
22   font_list_ = SCM_EOL;
23   SCM *tail = &font_list_;
24
25   SCM mag = SCM_EOL;
26   SCM name_list = SCM_EOL;
27   SCM *name_tail = &name_list;
28   
29   for (SCM s = font_list; scm_is_pair (s); s = scm_cdr (s))
30     {
31       if (Font_metric *fm = unsmob_metrics (scm_car (s)))
32         {
33           *tail =  scm_cons (scm_car (s),SCM_EOL);
34           tail = SCM_CDRLOC (*tail);
35
36           if (!scm_is_number (mag))
37             /* Ugh.  */
38             mag = scm_cdr (fm->description_);
39
40           *name_tail = scm_cons (scm_car (fm->description_), SCM_EOL);
41           name_tail = SCM_CDRLOC (*name_tail);
42         }
43     }
44
45   description_ = scm_cons (name_list, mag);
46 }
47
48 Real 
49 Virtual_font_metric::design_size () const
50 {
51   return unsmob_metrics (scm_car (font_list_))-> design_size ();
52 }
53
54 void
55 Virtual_font_metric::derived_mark ()const
56 {
57   scm_gc_mark (font_list_);
58 }
59
60 int
61 Virtual_font_metric::count () const
62 {
63   int k = 0;
64   for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
65       k += unsmob_metrics (scm_car (s))->count ();
66   return k;
67 }
68
69 Stencil
70 Virtual_font_metric::find_by_name (String glyph) const
71 {
72   Stencil m;  
73   for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s))
74     m = unsmob_metrics (scm_car (s))->find_by_name (glyph);
75
76   return m;
77 }
78
79 Box
80 Virtual_font_metric::get_ascii_char (int)  const
81 {
82   programming_error ("Virtual font metric cannot be indexed by ASCII.");
83   return Box ();
84 }
85
86 Stencil
87 Virtual_font_metric::get_ascii_char_stencil (int )  const
88 {
89   programming_error ("Virtual font metric cannot be indexed by ASCII.");
90   return Stencil ();
91 }
92
93 Offset
94 Virtual_font_metric::get_indexed_wxwy (int code)  const
95 {
96   int total = 0;
97   for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
98     {
99       Font_metric *fm = unsmob_metrics (scm_car (s));
100       if (code < total + fm->count ())
101         return fm->get_indexed_wxwy (code - total);
102       total += fm->count ();
103     }
104   return Offset (0,0);
105 }
106
107 Box
108 Virtual_font_metric::get_indexed_char (int code)  const
109 {
110   int total = 0;
111   for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
112     {
113       Font_metric *fm = unsmob_metrics (scm_car (s));
114       if (code < total + fm->count ())
115         return fm->get_indexed_char (code - total);
116       total += fm->count ();
117     }
118   return Box ();
119 }
120
121 int 
122 Virtual_font_metric::name_to_index (String glyph) const
123 {
124   Stencil m;
125   int total = 0; 
126   for (SCM s = font_list_; m.is_empty () && scm_is_pair (s); s = scm_cdr (s))
127     {
128       Font_metric *m = unsmob_metrics (scm_car (s));
129       int k = m->name_to_index (glyph);
130       if (k >= 0)
131         return total + k;
132
133       total += m->count ();
134     }
135   return -1;
136 }
137   
138 Stencil
139 Virtual_font_metric::get_indexed_char_stencil (int code)  const
140 {
141   Stencil  m ;  
142   int total = 0;
143   
144   for (SCM s = font_list_; scm_is_pair (s); s = scm_cdr (s))
145     {
146       Font_metric *fm = unsmob_metrics (scm_car (s));
147       if (code < total + fm->count ())
148         {
149           /* Ugh.  */
150           m = fm->get_indexed_char_stencil (code - total);
151           break; 
152         }
153       total += fm->count ();
154     }
155   return m;
156 }
157
158
159 SCM
160 Virtual_font_metric::get_font_list () const
161 {
162   return font_list_;
163 }
164
165 LY_DEFINE (ly_make_virtual_font, "ly:make-virtual-font", 0, 0, 1,
166            (SCM args),
167            "Make a virtual font metric from @var{args}, "
168            "a list of font objects.")
169 {
170   Virtual_font_metric *fm = new Virtual_font_metric (args);
171   return scm_gc_unprotect_object (fm->self_scm ());
172 }
173
174 String
175 Virtual_font_metric::coding_scheme () const
176 {
177   Font_metric *fm = unsmob_metrics (scm_car (font_list_));
178   return fm->coding_scheme ();
179 }