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>
12 #include "paper-def.hh"
13 #include "font-interface.hh"
16 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
17 (SCM paper, SCM chain),
19 "Return a font metric satisfying the font-qualifiers "
20 "in the alist chain @var{chain}.\n"
21 "(An alist chain is a list of alists, containing grob properties).\n")
23 Paper_def *pap = unsmob_paper (paper);
24 SCM_ASSERT_TYPE (pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
26 Font_metric *fm = select_font (pap, chain);
27 return fm->self_scm ();
30 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
31 (SCM paper, SCM name),
32 "Return the paper variable @var{name}.")
34 Paper_def *pap = unsmob_paper (paper);
35 SCM_ASSERT_TYPE (pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
36 return gh_double2scm (pap->get_realvar (name));
40 wild_compare (SCM field_val, SCM val)
42 return (val == SCM_BOOL_F || field_val == ly_symbol2scm ("*") || field_val == val);
46 get_font_by_design_size (Paper_def* paper, Real requested,
49 int n = SCM_VECTOR_LENGTH (font_vector);
51 Real last_size = -1e6;
56 size = gh_scm2double (gh_car (SCM_VECTOR_REF (font_vector, i)));
68 if ((requested / last_size) < (size / requested))
75 return paper->find_font (gh_cdr (SCM_VECTOR_REF (font_vector, i)),
81 get_font_by_mag_step (Paper_def* paper, Real requested_step,
82 SCM font_vector, Real default_size)
84 return get_font_by_design_size (paper,
85 default_size * pow (2.0, requested_step / 6.0),
92 properties_to_font_size_family (SCM fonts, SCM alist_chain)
94 return scm_call_2 (ly_scheme_function ("lookup-font"), fonts, alist_chain);
99 select_font (Paper_def *paper, SCM chain)
101 SCM name = ly_assoc_chain (ly_symbol2scm ("font-name"), chain);
103 if (!gh_pair_p (name) || !gh_string_p (gh_cdr (name)))
105 SCM fonts = paper->lookup_variable (ly_symbol2scm ("fonts"));
106 name = properties_to_font_size_family (fonts, chain);
109 name = gh_cdr (name);
112 if (gh_string_p (name))
114 SCM mag = ly_assoc_chain (ly_symbol2scm ("font-magnification"), chain);
116 Real rmag = gh_pair_p (mag) ? robust_scm2double (gh_cdr (mag), 1.0) : 1;
118 return paper->find_font (name, rmag);
120 else if (gh_pair_p (name)) // (DEFAULT . FONT-VEC) pair
122 SCM vec = gh_cdr (name);
123 SCM base_size = gh_car (name);
125 SCM font_size = ly_assoc_chain (ly_symbol2scm ("font-size"), chain);
127 if (gh_pair_p (font_size))
128 req = gh_scm2double (ly_cdr (font_size));
130 return get_font_by_mag_step (paper, req,
131 vec, gh_scm2double (base_size));