2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2003--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "dimensions.hh"
22 #include "all-font-metrics.hh"
23 #include "output-def.hh"
24 #include "font-interface.hh"
26 #include "pango-font.hh"
30 get_font_by_design_size (Output_def
*layout
, Real requested
,
33 int n
= scm_c_vector_length (font_vector
);
35 Real last_size
= -1e6
;
38 SCM pango_description_string
= SCM_EOL
;
39 SCM last_pango_description_string
= SCM_EOL
;
42 SCM entry
= scm_c_vector_ref (font_vector
, i
);
44 if (scm_promise_p (entry
) == SCM_BOOL_T
)
46 Font_metric
*fm
= unsmob_metrics (scm_force (entry
));
47 size
= fm
->design_size ();
50 else if (scm_is_pair (entry
)
51 && scm_is_number (scm_car (entry
))
52 && scm_is_string (scm_cdr (entry
)))
54 size
= scm_to_double (scm_car (entry
));
55 pango_description_string
63 last_pango_description_string
= pango_description_string
;
70 if ((requested
/ last_size
) < (size
/ requested
))
74 pango_description_string
= last_pango_description_string
;
79 if (scm_is_string (pango_description_string
))
82 return find_pango_font (layout
,
83 pango_description_string
,
86 error ("Trying to retrieve pango font without HAVE_PANGO_FT2.");
90 fm
= unsmob_metrics (scm_force (scm_c_vector_ref (font_vector
, i
)));
92 return find_scaled_font (layout
, fm
, requested
/ size
);
96 get_font_by_mag_step (Output_def
*layout
, Real requested_step
,
97 SCM font_vector
, Real default_size
)
99 return get_font_by_design_size (layout
, default_size
100 * pow (2.0, requested_step
/ 6.0),
105 properties_to_font_size_family (SCM fonts
, SCM alist_chain
)
107 return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts
,
112 select_encoded_font (Output_def
*layout
, SCM chain
)
114 SCM name
= ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain
, SCM_BOOL_F
);
116 if (!scm_is_string (name
))
118 SCM fonts
= layout
->lookup_variable (ly_symbol2scm ("fonts"));
119 name
= properties_to_font_size_family (fonts
, chain
);
123 if (scm_is_string (name
))
124 return select_pango_font (layout
, chain
);
127 if (scm_instance_p (name
))
129 SCM base_size
= scm_slot_ref (name
, ly_symbol2scm ("default-size"));
130 SCM vec
= scm_slot_ref (name
, ly_symbol2scm ("size-vector"));
132 Real req
= robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain
, SCM_BOOL_F
),
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
);