2 font-select.cc -- implement property -> font_metric routines.
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "dimensions.hh"
12 #include "all-font-metrics.hh"
13 #include "output-def.hh"
14 #include "font-interface.hh"
16 #include "pango-font.hh"
21 get_font_by_design_size (Output_def *layout, Real requested,
24 int n = scm_c_vector_length (font_vector);
26 Real last_size = -1e6;
29 SCM pango_description_string = SCM_EOL;
30 SCM last_pango_description_string = SCM_EOL;
33 SCM entry = scm_c_vector_ref (font_vector, i);
35 if (scm_promise_p (entry) == SCM_BOOL_T)
37 Font_metric *fm = unsmob_metrics (scm_force (entry));
38 size = fm->design_size ();
41 else if (scm_is_pair (entry)
42 && scm_is_number (scm_car (entry))
43 && scm_is_string (scm_cdr (entry)))
45 size = scm_to_double (scm_car (entry));
46 pango_description_string
54 last_pango_description_string = pango_description_string;
61 if ((requested / last_size) < (size / requested))
65 pango_description_string = last_pango_description_string;
70 if (scm_is_string (pango_description_string))
73 return find_pango_font (layout,
74 pango_description_string,
77 error ("Trying to retrieve pango font without HAVE_PANGO_FT2.");
82 fm = unsmob_metrics (scm_force (scm_c_vector_ref (font_vector, i)));
85 return find_scaled_font (layout, fm, requested / size);
89 get_font_by_mag_step (Output_def *layout, Real requested_step,
90 SCM font_vector, Real default_size)
92 return get_font_by_design_size (layout, default_size
93 * pow (2.0, requested_step / 6.0),
98 properties_to_font_size_family (SCM fonts, SCM alist_chain)
100 return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts, alist_chain);
104 select_encoded_font (Output_def *layout, SCM chain)
106 SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
108 if (!scm_is_pair (name) || !scm_is_string (scm_cdr (name)))
110 SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts"));
111 name = properties_to_font_size_family (fonts, chain);
114 name = scm_cdr (name);
117 if (scm_is_string (name)
118 && is_pango_format_global)
120 return select_pango_font (layout, chain);
124 if (scm_is_string (name))
126 SCM mag = ly_chain_assoc (ly_symbol2scm ("font-magnification"), chain);
127 Real rmag = (scm_is_pair (mag)
128 ? robust_scm2double (scm_cdr (mag), 1.0)
130 Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name));
132 return find_scaled_font (layout, fm, rmag);
134 else if (scm_instance_p (name))
136 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
137 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
139 SCM font_size = ly_chain_assoc (ly_symbol2scm ("font-size"), chain);
141 if (scm_is_pair (font_size))
142 req = scm_to_double (scm_cdr (font_size));
144 return get_font_by_mag_step (layout, req, vec,
145 scm_to_double (base_size));
153 select_font (Output_def *layout, SCM chain)
155 return select_encoded_font (layout, chain);