2 font-select.cc -- implement property -> font_metric routines.
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2007 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_instance_p (name))
119 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
120 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
122 Real req = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
125 return get_font_by_mag_step (layout, req, vec,
126 scm_to_double (base_size));
134 select_font (Output_def *layout, SCM chain)
136 return select_encoded_font (layout, chain);