X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ffont-interface.cc;h=4c3bf6524b9e774438f38ad1863845daea04d19f;hb=c484fb1da7751d35734194e623cb823b559e190f;hp=f801cefa01f59c23eebaa86d21a7bbb9bfca512e;hpb=60fdc53305e8628dad96b4ebea177bc6ee8d95cd;p=lilypond.git diff --git a/lily/font-interface.cc b/lily/font-interface.cc index f801cefa01..4c3bf6524b 100644 --- a/lily/font-interface.cc +++ b/lily/font-interface.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2001 Han-Wen Nienhuys + (c) 2000--2004 Han-Wen Nienhuys */ @@ -15,37 +15,6 @@ #include "warn.hh" -/* - TODO revise font handling. - - -* relative sizes should relate to staff-space, eg. font-staff-space -= 1.2 ^ relative-size - -* If a relative size is given, lily should magnify the closest -design size font to match that. (ie. fonts should have variable -scaling) - -(this requires that fonts are stored as (filename , designsize)) - - - - */ - -SCM -Font_interface::font_alist_chain (Grob *me) -{ - SCM defaults = gh_cdr (scm_assoc (ly_symbol2scm ("font-defaults"), - me->paper_l ()->style_sheet_)); - - SCM ch = gh_list (me->mutable_property_alist_, - me->immutable_property_alist_, - defaults, - SCM_UNDEFINED); - - return ch; -} - /* todo: split up this func, reuse in text_item? */ @@ -56,188 +25,36 @@ Font_interface::get_default_font (Grob*me) if (fm) return fm; - fm = get_font (me, font_alist_chain (me)); + fm = select_font (me->get_paper (), font_alist_chain (me)); me->set_grob_property ("font", fm->self_scm ()); return fm; } -SCM -ly_font_interface_get_default_font (SCM grob) +LY_DEFINE(ly_font_interface_get_default_font, + "ly:get-default-font", 1 , 0, 0, + (SCM grob), "Return the default font for grob @var{gr}.") { Grob * gr = unsmob_grob (grob); - - if (!gr) - { - warning ("ly_font_interface_get_default_font (): invalid argument"); - return SCM_UNDEFINED; - } + SCM_ASSERT_TYPE(gr, grob, SCM_ARG1, __FUNCTION__, "grob"); return Font_interface::get_default_font (gr)->self_scm (); } -Font_metric * -Font_interface::get_font (Grob *me, SCM chain) -{ - - SCM ss = me->paper_l ()->style_sheet_; - - SCM proc = gh_cdr (scm_assoc (ly_symbol2scm ("properties-to-font"), - ss)); - - SCM fonts = gh_cdr (scm_assoc (ly_symbol2scm ("fonts"), ss)); - - assert (gh_procedure_p (proc)); - SCM font_name = gh_call2 (proc, fonts, chain); - - Font_metric *fm = me->paper_l ()->find_font (font_name, 1.0); - return fm; -} SCM -Font_interface::add_style (Grob* me, SCM style, SCM chain) +Font_interface::font_alist_chain (Grob*g) { - assert (gh_symbol_p (style)); + SCM defaults = g->get_paper ()->lookup_variable (ly_symbol2scm ("font-defaults")); - SCM sheet = me->paper_l ()->style_sheet_; - - SCM style_alist = gh_cdr (scm_assoc (ly_symbol2scm ("style-alist"), sheet)); - SCM entry = scm_assoc (style, style_alist); - if (gh_pair_p (entry)) - { - chain = gh_cons (gh_cdr (entry), chain); - } - return chain; + return g->get_property_alist_chain (defaults); } -/* -SCM routines: - -Interpreting music... -MIDI output to wtk1-fugue2.midi... -Track ... - -real 0m31.862s -user 0m29.110s -sys 0m0.260s -real 0m26.964s -user 0m24.850s -sys 0m0.280s - - -so a 14% speedup. - -*/ - -static SCM name_sym, shape_sym, family_sym, series_sym, rel_sz_sym, design_sz_sym, wild_sym; - - -static void -init_syms () -{ - name_sym = scm_permanent_object (ly_symbol2scm ("font-name")); - shape_sym = scm_permanent_object (ly_symbol2scm ("font-shape")); - family_sym = scm_permanent_object (ly_symbol2scm ("font-family")); - series_sym = scm_permanent_object (ly_symbol2scm ("font-series")); - rel_sz_sym = scm_permanent_object (ly_symbol2scm ("font-relative-size")); - design_sz_sym = scm_permanent_object (ly_symbol2scm ("font-design-size")); - wild_sym = scm_permanent_object (ly_symbol2scm ("*")); - - scm_make_gsubr ("ly-get-default-font", 1 , 0, 0, (Scheme_function_unknown) ly_font_interface_get_default_font); -} - - -bool -Font_interface::wild_compare (SCM field_val, SCM val) -{ - return (val == SCM_BOOL_F || field_val == wild_sym || field_val == val); -} - -ADD_SCM_INIT_FUNC (Font_interface_syms,init_syms); - - -MAKE_SCHEME_CALLBACK (Font_interface,properties_to_font_name,2); -SCM -Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain) -{ - SCM name = ly_assoc_chain (name_sym, alist_chain); - - SCM shape = SCM_BOOL_F; - SCM family = SCM_BOOL_F; - SCM series = SCM_BOOL_F; - - - SCM point_sz = ly_assoc_chain (design_sz_sym, alist_chain); - SCM rel_sz = SCM_BOOL_F; - - if (!gh_pair_p (name)) - { - shape = ly_assoc_chain (shape_sym, alist_chain); - family = ly_assoc_chain (family_sym, alist_chain); - series = ly_assoc_chain (series_sym, alist_chain); - - if (gh_pair_p (shape)) - shape = gh_cdr (shape); - if (gh_pair_p (family)) - family = gh_cdr (family); - if (gh_pair_p (series)) - series = gh_cdr (series); - } - else - name = gh_cdr (name); - - - if (gh_pair_p (point_sz)) - point_sz = gh_cdr (point_sz); - else - { - rel_sz = ly_assoc_chain (rel_sz_sym, alist_chain); - if (gh_pair_p (rel_sz)) - rel_sz = gh_cdr (rel_sz); - } - - for (SCM s = fonts ; gh_pair_p (s); s = gh_cdr (s)) - { - SCM qlist = gh_caar (s); - - if (name != SCM_BOOL_F) - { - if (!wild_compare (scm_list_ref (qlist, gh_int2scm (4)), name)) - continue; - } - else - { - if (!wild_compare (scm_list_ref (qlist, gh_int2scm (1)), series)) - continue; - if (!wild_compare (scm_list_ref (qlist, gh_int2scm (2)), shape)) - continue; - if (!wild_compare (scm_list_ref (qlist, gh_int2scm (3)), family)) - continue; - } - if (point_sz != SCM_BOOL_F) - { - // This if statement will always be true since name must - // be SCM_BOOL_F here, right? /MB - if (!wild_compare (scm_list_ref (qlist, gh_int2scm (4)), name)) - continue; - } - else - { - if (!wild_compare (gh_car (qlist), rel_sz)) - continue; - } - - SCM qname = gh_cdar (s); - return qname; - } - warning (_ ("couldn't find any font satisfying ")); - scm_write (gh_list (name, point_sz, shape, series , family, rel_sz, SCM_UNDEFINED), scm_current_error_port ()); - scm_flush (scm_current_error_port ()); - - return ly_str02scm ("cmr10"); - -} +ADD_INTERFACE (Font_interface, "font-interface", + "Any symbol that is typeset through fixed sets of glyphs (ie. fonts)", + "font-magnification font font-series font-shape " + "font-family font-name font-size");