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"
20 get_font_by_design_size (Output_def *layout, Real requested,
23 int n = scm_c_vector_length (font_vector);
25 Real last_size = -1e6;
28 SCM pango_description_string = SCM_EOL;
29 SCM last_pango_description_string = SCM_EOL;
32 SCM entry = scm_c_vector_ref (font_vector, i);
34 if (scm_promise_p (entry) == SCM_BOOL_T)
36 Font_metric *fm = unsmob_metrics (scm_force (entry));
37 size = fm->design_size ();
40 else if (scm_is_pair (entry)
41 && scm_is_number (scm_car (entry))
42 && scm_is_string (scm_cdr (entry)))
44 size = scm_to_double (scm_car (entry));
45 pango_description_string
53 last_pango_description_string = pango_description_string;
60 if ((requested / last_size) < (size / requested))
64 pango_description_string = last_pango_description_string;
69 if (scm_is_string (pango_description_string))
72 return find_pango_font (layout,
73 pango_description_string,
76 error ("Trying to retrieve pango font without HAVE_PANGO_FT2.");
81 fm = unsmob_metrics (scm_force (scm_c_vector_ref (font_vector, i)));
84 return find_scaled_font (layout, fm, requested / size);
88 get_font_by_mag_step (Output_def *layout, Real requested_step,
89 SCM font_vector, Real default_size)
91 return get_font_by_design_size (layout, default_size
92 * pow (2.0, requested_step / 6.0),
97 properties_to_font_size_family (SCM fonts, SCM alist_chain)
99 return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts, alist_chain);
103 select_encoded_font (Output_def *layout, SCM chain)
105 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
107 if (!scm_is_string (name))
109 SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts"));
110 name = properties_to_font_size_family (fonts, chain);
114 if (scm_is_string (name)
115 && is_pango_format_global)
117 return select_pango_font (layout, chain);
121 if (scm_is_string (name))
124 robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-magnification"), chain, SCM_BOOL_F),
126 Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name));
128 return find_scaled_font (layout, fm, rmag);
130 else if (scm_instance_p (name))
132 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
133 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
135 Real req = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
138 return get_font_by_mag_step (layout, req, vec,
139 scm_to_double (base_size));
147 select_font (Output_def *layout, SCM chain)
149 return select_encoded_font (layout, chain);