2 font-interface.cc -- implement Font_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "all-font-metrics.hh"
11 #include "font-metric.hh"
12 #include "font-interface.hh"
14 #include "paper-def.hh"
19 TODO revise font handling.
22 * relative sizes should relate to staff-space, eg. font-staff-space
25 * If a relative size is given, lily should magnify the closest
26 design size font to match that. (ie. fonts should have variable
29 (this requires that fonts are stored as (filename , designsize))
36 Font_interface::font_alist_chain (Grob *me)
39 Ugh: why the defaults?
41 SCM defaults = ly_cdr (scm_assoc (ly_symbol2scm ("font-defaults"),
42 me->paper_l ()->style_sheet_));
44 SCM ch = scm_list_n (me->mutable_property_alist_,
45 me->immutable_property_alist_,
53 todo: split up this func, reuse in text_item?
56 Font_interface::get_default_font (Grob*me)
58 Font_metric * fm = unsmob_metrics (me->get_grob_property ("font"));
62 fm = get_font (me, font_alist_chain (me));
63 me->set_grob_property ("font", fm->self_scm ());
69 ly_font_interface_get_default_font (SCM grob)
71 Grob * gr = unsmob_grob (grob);
72 SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "grob");
74 return Font_interface::get_default_font (gr)->self_scm ();
78 ly_font_interface_get_font (SCM grob, SCM alist)
80 Grob * gr = unsmob_grob (grob);
81 SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "grob");
84 Font_interface::get_font (gr, gh_cons (alist,
85 Font_interface::font_alist_chain (gr)));
87 return fm->self_scm();
93 Font_interface::get_font (Grob *me, SCM chain)
95 SCM name = me->get_grob_property ("font-name");
97 if (!gh_string_p (name))
99 SCM ss = me->paper_l ()->style_sheet_;
101 SCM proc = ly_cdr (scm_assoc (ly_symbol2scm ("properties-to-font"),
104 SCM fonts = ly_cdr (scm_assoc (ly_symbol2scm ("fonts"), ss));
106 assert (gh_procedure_p (proc));
107 name = gh_call2 (proc, fonts, chain);
110 SCM mag = me->get_grob_property ("font-magnification");
111 Real rmag = gh_number_p (mag) ? gh_scm2double (mag) : 1.0;
113 Font_metric *fm = me->paper_l ()->find_font (name, rmag);
118 Font_interface::add_style (Grob* me, SCM style, SCM chain)
120 assert (gh_symbol_p (style));
122 SCM sheet = me->paper_l ()->style_sheet_;
124 SCM style_alist = ly_cdr (scm_assoc (ly_symbol2scm ("style-alist"), sheet));
125 SCM entry = scm_assoc (style, style_alist);
126 if (gh_pair_p (entry))
128 chain = gh_cons (ly_cdr (entry), chain);
136 Interpreting music...
137 MIDI output to wtk1-fugue2.midi...
153 static SCM shape_sym, family_sym, series_sym, rel_sz_sym, design_sz_sym, wild_sym;
159 shape_sym = scm_permanent_object (ly_symbol2scm ("font-shape"));
160 family_sym = scm_permanent_object (ly_symbol2scm ("font-family"));
161 series_sym = scm_permanent_object (ly_symbol2scm ("font-series"));
162 rel_sz_sym = scm_permanent_object (ly_symbol2scm ("font-relative-size"));
163 design_sz_sym = scm_permanent_object (ly_symbol2scm ("font-design-size"));
164 wild_sym = scm_permanent_object (ly_symbol2scm ("*"));
166 scm_c_define_gsubr ("ly-get-default-font", 1 , 0, 0,
167 (Scheme_function_unknown) ly_font_interface_get_default_font);
168 scm_c_define_gsubr ("ly-get-font", 2, 0, 0,
169 (Scheme_function_unknown) ly_font_interface_get_font);
174 Font_interface::wild_compare (SCM field_val, SCM val)
176 return (val == SCM_BOOL_F || field_val == wild_sym || field_val == val);
179 ADD_SCM_INIT_FUNC (Font_interface_syms,init_syms);
182 MAKE_SCHEME_CALLBACK (Font_interface,properties_to_font_name,2);
184 Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain)
186 SCM shape = SCM_BOOL_F;
187 SCM family = SCM_BOOL_F;
188 SCM series = SCM_BOOL_F;
191 SCM point_sz = ly_assoc_chain (design_sz_sym, alist_chain);
192 SCM rel_sz = SCM_BOOL_F;
194 shape = ly_assoc_chain (shape_sym, alist_chain);
195 family = ly_assoc_chain (family_sym, alist_chain);
196 series = ly_assoc_chain (series_sym, alist_chain);
198 if (gh_pair_p (shape))
199 shape = ly_cdr (shape);
200 if (gh_pair_p (family))
201 family = ly_cdr (family);
202 if (gh_pair_p (series))
203 series = ly_cdr (series);
206 if (gh_pair_p (point_sz))
207 point_sz = ly_cdr (point_sz);
210 rel_sz = ly_assoc_chain (rel_sz_sym, alist_chain);
211 if (gh_pair_p (rel_sz))
212 rel_sz = ly_cdr (rel_sz);
215 for (SCM s = fonts ; gh_pair_p (s); s = ly_cdr (s))
217 SCM qlist = ly_caar (s);
219 if (!wild_compare (scm_list_ref (qlist, gh_int2scm (1)), series))
221 if (!wild_compare (scm_list_ref (qlist, gh_int2scm (2)), shape))
223 if (!wild_compare (scm_list_ref (qlist, gh_int2scm (3)), family))
226 if (point_sz == SCM_BOOL_F && !wild_compare (ly_car (qlist), rel_sz))
229 SCM qname = ly_cdar (s);
233 warning (_ ("couldn't find any font satisfying "));
234 scm_write (scm_list_n (point_sz, shape, series , family, rel_sz, SCM_UNDEFINED), scm_current_error_port ());
235 scm_flush (scm_current_error_port ());
237 return ly_str02scm ("cmr10");
243 ADD_INTERFACE (Font_interface, "font-interface",
244 "Any symbol that is typeset through fixed sets of glyphs (ie. fonts)",
245 "font-magnification font-style font font-series font-shape font-family font-name font-design-size font-relative-size");