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"
17 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
18 (SCM paper_smob, SCM chain),
20 "Return a font metric satisfying the font-qualifiers "
21 "in the alist chain @var{chain}.\n"
22 "(An alist chain is a list of alists, "
23 "containing grob properties).\n")
25 Output_def *paper = unsmob_output_def (paper_smob);
26 SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1,
27 __FUNCTION__, "paper definition");
29 Font_metric *fm = select_font (paper, chain);
30 return fm->self_scm ();
33 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
34 (SCM layout_smob, SCM name),
35 "Return the layout variable @var{name}.")
37 Output_def *layout = unsmob_output_def (layout_smob);
38 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
39 __FUNCTION__, "layout definition");
40 return scm_make_real (layout->get_dimension (name));
44 wild_compare (SCM field_val, SCM val)
46 return (val == SCM_BOOL_F
47 || field_val == ly_symbol2scm ("*")
52 get_font_by_design_size (Output_def *layout, Real requested,
55 int n = SCM_VECTOR_LENGTH (font_vector);
57 Real last_size = -1e6;
62 SCM entry = SCM_VECTOR_REF (font_vector, i);
63 Font_metric *fm = unsmob_metrics (scm_force (entry));
64 size = fm->design_size ();
75 if ((requested / last_size) < (size / requested))
82 Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector,
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 (ly_symbol2scm ("font-name"), chain);
107 if (!scm_is_pair (name) || !scm_is_string (scm_cdr (name)))
109 SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts"));
110 name = properties_to_font_size_family (fonts, chain);
113 name = scm_cdr (name);
115 if (scm_is_string (name))
117 SCM mag = ly_chain_assoc (ly_symbol2scm ("font-magnification"), chain);
118 Real rmag = (scm_is_pair (mag)
119 ? robust_scm2double (scm_cdr (mag), 1.0)
121 Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name));
123 return find_scaled_font (layout, fm, rmag);
125 else if (scm_instance_p (name))
127 SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size"));
128 SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector"));
130 SCM font_size = ly_chain_assoc (ly_symbol2scm ("font-size"), chain);
132 if (scm_is_pair (font_size))
133 req = scm_to_double (scm_cdr (font_size));
135 return get_font_by_mag_step (layout, req, vec,
136 scm_to_double (base_size));
144 select_font (Output_def *layout, SCM chain)
146 return select_encoded_font (layout, chain);