2 font-select.cc -- implement property -> font_metric routines.
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2004 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_VECTOR_LENGTH (font_vector);
26 Real last_size = -1e6;
29 String pango_description_string;
32 SCM entry = SCM_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
46 = ly_scm2string (scm_cdr (entry));
59 if ((requested / last_size) < (size / requested))
67 if (pango_description_string != "")
70 PangoFontDescription *description
71 = pango_font_description_from_string (pango_description_string.to_str0 ());
72 fm = all_fonts_global->find_pango_font (description);
74 error ("Trying to retrieve pango font without HAVE_PANGO_FT2.");
79 fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i)));
82 return find_scaled_font (layout, fm, requested / size);
86 get_font_by_mag_step (Output_def *layout, Real requested_step,
87 SCM font_vector, Real default_size)
89 return get_font_by_design_size (layout, default_size
90 * pow (2.0, requested_step / 6.0),
95 properties_to_font_size_family (SCM fonts, SCM alist_chain)
97 return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts, alist_chain);
101 select_encoded_font (Output_def *layout, SCM chain)
103 SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
105 if (!scm_is_pair (name) || !scm_is_string (scm_cdr (name)))
107 SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts"));
108 name = properties_to_font_size_family (fonts, chain);
111 name = scm_cdr (name);
114 if (scm_is_string (name)
115 && is_pango_format_global)
117 select_pango_font (layout, chain);
121 if (scm_is_string (name))
123 SCM mag = ly_chain_assoc (ly_symbol2scm ("font-magnification"), chain);
124 Real rmag = (scm_is_pair (mag)
125 ? robust_scm2double (scm_cdr (mag), 1.0)
127 Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name));
129 return find_scaled_font (layout, fm, rmag);
131 else if (scm_instance_p (name))
133 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
134 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
136 SCM font_size = ly_chain_assoc (ly_symbol2scm ("font-size"), chain);
138 if (scm_is_pair (font_size))
139 req = scm_to_double (scm_cdr (font_size));
141 return get_font_by_mag_step (layout, req, vec,
142 scm_to_double (base_size));
150 select_font (Output_def *layout, SCM chain)
152 return select_encoded_font (layout, chain);