X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ffont-select.cc;h=dc536a9c7a04aa1cf33173124e26f8295c8b7a85;hb=d59b3e4801e5832c86e9210724ac3d2ec4fef1be;hp=189421e339681dbd3af9ecf7430dc285efa9a2c5;hpb=235a33ac0d166718d2a6f07069a6ffb2c5acaf34;p=lilypond.git diff --git a/lily/font-select.cc b/lily/font-select.cc index 189421e339..dc536a9c7a 100644 --- a/lily/font-select.cc +++ b/lily/font-select.cc @@ -1,12 +1,22 @@ /* - font-select.cc -- implement property -> font_metric routines. + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2003--2010 Han-Wen Nienhuys - (c) 2003--2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include #include "dimensions.hh" #include "all-font-metrics.hh" @@ -16,7 +26,6 @@ #include "pango-font.hh" #include "main.hh" - Font_metric * get_font_by_design_size (Output_def *layout, Real requested, SCM font_vector) @@ -27,10 +36,11 @@ get_font_by_design_size (Output_def *layout, Real requested, int i = 0; SCM pango_description_string = SCM_EOL; + SCM last_pango_description_string = SCM_EOL; for (; i < n; i++) { SCM entry = scm_c_vector_ref (font_vector, i); - + if (scm_promise_p (entry) == SCM_BOOL_T) { Font_metric *fm = unsmob_metrics (scm_force (entry)); @@ -46,10 +56,11 @@ get_font_by_design_size (Output_def *layout, Real requested, = scm_cdr (entry); } #endif - + if (size > requested) break; last_size = size; + last_pango_description_string = pango_description_string; } if (i == n) @@ -60,9 +71,10 @@ get_font_by_design_size (Output_def *layout, Real requested, { i--; size = last_size; + pango_description_string = last_pango_description_string; } } - + Font_metric *fm = 0; if (scm_is_string (pango_description_string)) { @@ -71,13 +83,11 @@ get_font_by_design_size (Output_def *layout, Real requested, pango_description_string, requested / size); #else - error ("Trying to retrieve pango font without HAVE_PANGO_FT2."); + error ("Trying to retrieve pango font without HAVE_PANGO_FT2."); #endif } else - { - fm = unsmob_metrics (scm_force (scm_c_vector_ref (font_vector, i))); - } + fm = unsmob_metrics (scm_force (scm_c_vector_ref (font_vector, i))); return find_scaled_font (layout, fm, requested / size); } @@ -94,49 +104,33 @@ get_font_by_mag_step (Output_def *layout, Real requested_step, SCM properties_to_font_size_family (SCM fonts, SCM alist_chain) { - return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts, alist_chain); + return scm_call_2 (ly_lily_module_constant ("lookup-font"), fonts, + alist_chain); } Font_metric * select_encoded_font (Output_def *layout, SCM chain) { - SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain); + SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F); - if (!scm_is_pair (name) || !scm_is_string (scm_cdr (name))) + if (!scm_is_string (name)) { SCM fonts = layout->lookup_variable (ly_symbol2scm ("fonts")); name = properties_to_font_size_family (fonts, chain); } - else - name = scm_cdr (name); #if HAVE_PANGO_FT2 - if (scm_is_string (name) - && is_pango_format_global) - { - return select_pango_font (layout, chain); - } + if (scm_is_string (name)) + return select_pango_font (layout, chain); else #endif - if (scm_is_string (name)) - { - SCM mag = ly_chain_assoc (ly_symbol2scm ("font-magnification"), chain); - Real rmag = (scm_is_pair (mag) - ? robust_scm2double (scm_cdr (mag), 1.0) - : 1); - Font_metric *fm = all_fonts_global->find_font (ly_scm2string (name)); - - return find_scaled_font (layout, fm, rmag); - } - else if (scm_instance_p (name)) + if (scm_instance_p (name)) { - SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size")); + SCM base_size = scm_slot_ref (name, ly_symbol2scm ("default-size")); SCM vec = scm_slot_ref (name, ly_symbol2scm ("size-vector")); - SCM font_size = ly_chain_assoc (ly_symbol2scm ("font-size"), chain); - Real req = 0; - if (scm_is_pair (font_size)) - req = scm_to_double (scm_cdr (font_size)); + Real req = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F), + 0.0); return get_font_by_mag_step (layout, req, vec, scm_to_double (base_size));