2 font-select.cc -- implement property -> font_metric routines.
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "dimensions.hh"
11 #include "all-font-metrics.hh"
12 #include "output-def.hh"
13 #include "font-interface.hh"
15 #include "pango-font.hh"
19 get_font_by_design_size (Output_def *layout, Real requested,
22 int n = scm_c_vector_length (font_vector);
24 Real last_size = -1e6;
27 SCM pango_description_string = SCM_EOL;
28 SCM last_pango_description_string = SCM_EOL;
31 SCM entry = scm_c_vector_ref (font_vector, i);
33 if (scm_promise_p (entry) == SCM_BOOL_T)
35 Font_metric *fm = unsmob_metrics (scm_force (entry));
36 size = fm->design_size ();
39 else if (scm_is_pair (entry)
40 && scm_is_number (scm_car (entry))
41 && scm_is_string (scm_cdr (entry)))
43 size = scm_to_double (scm_car (entry));
44 pango_description_string
52 last_pango_description_string = pango_description_string;
59 if ((requested / last_size) < (size / requested))
63 pango_description_string = last_pango_description_string;
68 if (scm_is_string (pango_description_string))
71 return find_pango_font (layout,
72 pango_description_string,
75 error ("Trying to retrieve pango font without HAVE_PANGO_FT2.");
79 fm = unsmob_metrics (scm_force (scm_c_vector_ref (font_vector, i)));
81 return find_scaled_font (layout, fm, requested / size);
85 get_font_by_mag_step (Output_def *layout, Real requested_step,
86 SCM font_vector, Real default_size)
88 return get_font_by_design_size (layout, default_size
89 * pow (2.0, requested_step / 6.0),
94 properties_to_font_size_family (SCM fonts, SCM alist_chain)
96 return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts,
101 select_encoded_font (Output_def *layout, SCM chain)
103 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
105 if (!scm_is_string (name))
107 SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts"));
108 name = properties_to_font_size_family (fonts, chain);
112 if (scm_is_string (name)
113 && is_pango_format_global)
114 return select_pango_font (layout, chain);
117 if (scm_is_string (name))
120 = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-magnification"), chain, SCM_BOOL_F),
122 Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name));
124 return find_scaled_font (layout, fm, rmag);
126 else if (scm_instance_p (name))
128 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
129 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
131 Real req = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
134 return get_font_by_mag_step (layout, req, vec,
135 scm_to_double (base_size));
143 select_font (Output_def *layout, SCM chain)
145 return select_encoded_font (layout, chain);