From 11b3094461e045deafd0e2b1cef8c60f79e259a1 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 14 Sep 2003 13:55:30 +0000 Subject: [PATCH] * scm/chord-name.scm: remove new-chord-name-brew-molecule ; use ChordNames.SeparationItem #'padding for adjusting space after chords. * lily/music-output-def.cc (LY_DEFINE): new function ly:paper-lookup. * lily/paper-def.cc: new function ly:paper-font; this function replaces ly:get-font. * lily/include/font-interface.hh (struct Font_interface): take Paper_def iso. Grob for get_font(). --- ChangeLog | 6 ++ lily/accidental.cc | 9 +- lily/break-align-interface.cc | 1 - lily/font-interface.cc | 167 +-------------------------------- lily/grob-scheme.cc | 16 ++++ lily/include/font-interface.hh | 4 - lily/include/paper-def.hh | 2 + lily/line-spanner.cc | 2 +- lily/multi-measure-rest.cc | 2 +- lily/music-output-def.cc | 21 +++++ lily/paper-column.cc | 5 +- lily/paper-def.cc | 28 ------ lily/system-start-delimiter.cc | 2 +- lily/text-item.cc | 7 +- lily/text-spanner.cc | 7 +- lily/time-signature.cc | 4 +- lily/tuplet-bracket.cc | 7 +- lily/volta-bracket.cc | 5 +- ly/params-init.ly | 1 - scm/chord-name.scm | 22 ----- scm/define-grobs.scm | 4 +- 21 files changed, 82 insertions(+), 240 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f56d462cb..333324b916 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2003-09-14 Han-Wen Nienhuys + * scm/chord-name.scm: remove new-chord-name-brew-molecule ; use + ChordNames.SeparationItem #'padding for adjusting space after chords. + + * lily/music-output-def.cc (LY_DEFINE): + new function ly:paper-lookup. + * mf/parmesan-clefs.mf: use # quantities for char_box offsets. Fixes overflow errors in the PFA. diff --git a/lily/accidental.cc b/lily/accidental.cc index 6e5e4aeace..daf5b68b18 100644 --- a/lily/accidental.cc +++ b/lily/accidental.cc @@ -1,7 +1,14 @@ +/* + accidental.cc -- implement Accidental_interface + + (c) 2001--2003 Han-Wen Nienhuys + + */ #include "font-interface.hh" #include "item.hh" #include "molecule.hh" #include "accidental-interface.hh" +#include "paper-def.hh" /* TODO: insert support for smaller cautionaries, tie-break-reminders. @@ -184,7 +191,7 @@ Accidental_interface::brew_molecule (SCM smob) (ly_symbol2scm ("font-relative-size"), scm_int2num (-1)), SCM_EOL), ac); - fm = Font_interface::get_font (me->get_paper (), ac); + fm = select_font (me->get_paper (), ac); } else fm = Font_interface::get_default_font (me); diff --git a/lily/break-align-interface.cc b/lily/break-align-interface.cc index 72a944c3d8..c18f8ff78e 100644 --- a/lily/break-align-interface.cc +++ b/lily/break-align-interface.cc @@ -72,7 +72,6 @@ void Break_align_interface::do_alignment (Grob *me) { Item * item = dynamic_cast (me); - int rank = Paper_column::get_rank (item->get_column ()); Link_array elems = Pointer_group_interface__extract_grobs (me, (Grob*)0, "elements"); diff --git a/lily/font-interface.cc b/lily/font-interface.cc index d120bd2d0e..65fc05983a 100644 --- a/lily/font-interface.cc +++ b/lily/font-interface.cc @@ -15,45 +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) -{ - /* - Ugh: why the defaults? - */ - SCM defaults = me->get_paper ()->lookup_variable (ly_symbol2scm ("font-defaults")); - - SCM ch = me->get_property_alist_chain (defaults); - return ch; -} - - -MAKE_SCHEME_CALLBACK(Font_interface, get_property_alist_chain, 1); -SCM -Font_interface::get_property_alist_chain (SCM grob) -{ - Grob * g = unsmob_grob (grob); - SCM_ASSERT_TYPE(g, grob, SCM_ARG1, __FUNCTION__, "grob"); - return font_alist_chain (g); -} - /* todo: split up this func, reuse in text_item? */ @@ -64,7 +25,7 @@ Font_interface::get_default_font (Grob*me) if (fm) return fm; - fm = get_font (me->get_paper (), font_alist_chain (me)); + fm = select_font (me->get_paper (), font_alist_chain (me)); me->set_grob_property ("font", fm->self_scm ()); return fm; } @@ -81,134 +42,16 @@ LY_DEFINE(ly_font_interface_get_default_font, } -Font_metric * -Font_interface::get_font (Paper_def *paper, SCM chain) -{ - SCM name = ly_assoc_chain (ly_symbol2scm ("font-name"), chain); - - if (!gh_pair_p (name) || !gh_string_p (gh_cdr (name))) - { - SCM proc = paper->lookup_variable (ly_symbol2scm ("properties-to-font")); - SCM fonts = paper->lookup_variable (ly_symbol2scm ("fonts")); - - assert (gh_procedure_p (proc)); - name = gh_call2 (proc, fonts, chain); - } - else - name = gh_cdr (name); - - SCM mag = ly_assoc_chain (ly_symbol2scm ("font-magnification"), chain); - - Real rmag = gh_pair_p (mag) && gh_number_p (gh_cdr (mag)) - ? gh_scm2double (gh_cdr (mag)) : 1.0; - - Font_metric *fm = paper->find_font (name, rmag); - return fm; -} - -/* -SCM routines for looking up fonts. - -wtk-fugue2, SCM: - -real 0m31.862s -user 0m29.110s -sys 0m0.260s - -wtk-fugue2, C++: - -real 0m26.964s -user 0m24.850s -sys 0m0.280s - - -so a 14% speedup. - -*/ - -static SCM shape_sym, family_sym, series_sym, rel_str0_sym, design_str0_sym, wild_sym; - - -static void -init_syms () -{ - 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_str0_sym = scm_permanent_object (ly_symbol2scm ("font-relative-size")); - design_str0_sym = scm_permanent_object (ly_symbol2scm ("font-design-size")); - wild_sym = scm_permanent_object (ly_symbol2scm ("*")); -} - -ADD_SCM_INIT_FUNC(fi_init_syms, init_syms); - -bool -Font_interface::wild_compare (SCM field_val, SCM val) -{ - return (val == SCM_BOOL_F || field_val == wild_sym || field_val == val); -} - - -MAKE_SCHEME_CALLBACK (Font_interface,properties_to_font_name,2); SCM -Font_interface::properties_to_font_name (SCM fonts, SCM alist_chain) +Font_interface::font_alist_chain (Grob*g) { - SCM shape = SCM_BOOL_F; - SCM family = SCM_BOOL_F; - SCM series = SCM_BOOL_F; - + SCM defaults = g->get_paper ()->lookup_variable (ly_symbol2scm ("font-defaults")); - SCM point_str0 = ly_assoc_chain (design_str0_sym, alist_chain); - SCM rel_str0 = SCM_BOOL_F; - - 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 = ly_cdr (shape); - if (gh_pair_p (family)) - family = ly_cdr (family); - if (gh_pair_p (series)) - series = ly_cdr (series); - - - if (gh_pair_p (point_str0)) - point_str0 = ly_cdr (point_str0); - else - { - rel_str0 = ly_assoc_chain (rel_str0_sym, alist_chain); - if (gh_pair_p (rel_str0)) - rel_str0 = ly_cdr (rel_str0); - } + return g->get_property_alist_chain (defaults); +} - for (SCM s = fonts ; gh_pair_p (s); s = ly_cdr (s)) - { - SCM qlist = ly_caar (s); - 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_str0 == SCM_BOOL_F && !wild_compare (ly_car (qlist), rel_str0)) - continue; - - SCM qname = ly_cdar (s); - return qname; - } - - warning (_ ("couldn't find any font satisfying ")); - scm_write (scm_list_n (point_str0, shape, series , family, rel_str0, - SCM_UNDEFINED), scm_current_error_port ()); - scm_flush (scm_current_error_port ()); - - return scm_makfrom0str ("cmr10"); - -} - ADD_INTERFACE (Font_interface, "font-interface", diff --git a/lily/grob-scheme.cc b/lily/grob-scheme.cc index eb49ddf153..a4cb06249c 100644 --- a/lily/grob-scheme.cc +++ b/lily/grob-scheme.cc @@ -163,3 +163,19 @@ LY_DEFINE (get_broken_into, return s; } + + +LY_DEFINE(ly_property_alist_chain, "ly:grob-property-chain", + 1,1,0, + (SCM grob, SCM defaults), + "Return all the properties of @code{grob}. Glue @var{defaults} at the end of the chain.") +{ + Grob * g = unsmob_grob (grob); + SCM_ASSERT_TYPE(g, grob, SCM_ARG1, __FUNCTION__, "grob"); + + if (defaults == SCM_UNDEFINED) + defaults = SCM_EOL; + + SCM ch = g->get_property_alist_chain (defaults); + return ch; +} diff --git a/lily/include/font-interface.hh b/lily/include/font-interface.hh index 1ebee16316..11a3d3af8d 100644 --- a/lily/include/font-interface.hh +++ b/lily/include/font-interface.hh @@ -16,11 +16,7 @@ struct Font_interface { static SCM font_alist_chain (Grob*); - static Font_metric * get_font (Paper_def*, SCM alist_chain); static Font_metric * get_default_font (Grob*); - static bool wild_compare (SCM field_val, SCM val); - DECLARE_SCHEME_CALLBACK (properties_to_font_name, (SCM,SCM)); - DECLARE_SCHEME_CALLBACK (get_property_alist_chain, (SCM)); static bool has_interface (Grob*); }; diff --git a/lily/include/paper-def.hh b/lily/include/paper-def.hh index 76d723a33e..c177436ec8 100644 --- a/lily/include/paper-def.hh +++ b/lily/include/paper-def.hh @@ -77,4 +77,6 @@ public: }; Paper_def * unsmob_paper (SCM x); +Font_metric *select_font (Paper_def *paper, SCM chain); + #endif // Paper_def_HH diff --git a/lily/line-spanner.cc b/lily/line-spanner.cc index ee5c0e9c2c..cc5011dbb1 100644 --- a/lily/line-spanner.cc +++ b/lily/line-spanner.cc @@ -168,7 +168,7 @@ Line_spanner::line_molecule (Grob *me, Real thick, ly_symbol2scm ("music")), SCM_UNDEFINED); - Font_metric *fm = Font_interface::get_font (me->get_paper (), + Font_metric *fm = select_font (me->get_paper (), gh_cons (style_alist, alist_chain)); Molecule m = fm->find_by_name ("scripts-trill-element"); diff --git a/lily/multi-measure-rest.cc b/lily/multi-measure-rest.cc index ad4c377b1f..1fb8e620ca 100644 --- a/lily/multi-measure-rest.cc +++ b/lily/multi-measure-rest.cc @@ -136,7 +136,7 @@ Multi_measure_rest::symbol_molecule (Grob *me, Real space) Real staff_space = Staff_symbol_referencer::staff_space (me); Font_metric *musfont - = Font_interface::get_font (me->get_paper (), alist_chain); + = select_font (me->get_paper (), alist_chain); SCM sml = me->get_grob_property ("use-breve-rest"); if (measures == 1) diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index f9a305127c..8c353b6bc7 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -161,3 +161,24 @@ Music_output_def::lookup_variable (SCM sym) const return scm_variable_ref (var); } + + +LY_DEFINE(ly_paper_lookup, + "ly:paper-lookup", + 2, 0,0, + (SCM pap, SCM sym), + "Lookup @var{sym} in @var{pap}. Return the value " + " or '() if undefined. " + ) +{ + Music_output_def *op = unsmob_music_output_def (pap); + SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Paper"); + SCM_ASSERT_TYPE (gh_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol"); + + SCM v = op->lookup_variable (sym); + + if (SCM_VARIABLEP(v)) + return SCM_VARIABLE_REF(v); + else + return SCM_EOL; +} diff --git a/lily/paper-column.cc b/lily/paper-column.cc index ab2f46da8b..54151c63cb 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -16,7 +16,7 @@ #include "text-item.hh" #include "lookup.hh" #include "font-interface.hh" - +#include "paper-def.hh" @@ -120,7 +120,8 @@ Paper_column::brew_molecule (SCM p) String r = to_string (Paper_column::get_rank (me)); SCM properties = Font_interface::font_alist_chain (me); - SCM scm_mol = Text_item::interpret_markup (p, properties, + SCM scm_mol = Text_item::interpret_markup (me->get_paper ()->self_scm (), + properties, scm_makfrom0str (r.to_str0 ())); Molecule t = *unsmob_molecule (scm_mol); t.align_to (X_AXIS, CENTER); diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 217e337524..4d59d1f763 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -153,34 +153,6 @@ Paper_def::font_descriptions ()const return l; } -/* - Font_interface should be reorganised? -*/ -#include "font-interface.hh" - - -LY_DEFINE(ly_paper_get_font,"ly:paper-get-font", 2, 0, 0, - (SCM paper, SCM chain), - "Return a font metric satisfying the font-qualifiers in the alist chain @var{chain}.\n" -"\n" -"The font object represents the metric information of a font. Every font\n" -"that is loaded into LilyPond can be accessed via Scheme. \n" -"\n" -"LilyPond only needs to know the dimension of glyph to be able to process\n" -"them. This information is stored in font metric files. LilyPond can read\n" -"two types of font-metrics: @TeX{} Font Metric files (TFM files) and\n" -"Adobe Font Metric files (AFM files). LilyPond will always try to load\n" -"AFM files first since they are more versatile.\n" -"\n" -"An alist chain is a list of alists, containing grob properties.\n") -{ - Paper_def *pap = unsmob_paper (paper); - SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "paper definition"); - - Font_metric*fm = Font_interface::get_font (pap, chain); - return fm->self_scm(); -} - Paper_def* unsmob_paper (SCM x) { diff --git a/lily/system-start-delimiter.cc b/lily/system-start-delimiter.cc index dca2d8d27b..4254c4b672 100644 --- a/lily/system-start-delimiter.cc +++ b/lily/system-start-delimiter.cc @@ -152,7 +152,7 @@ System_start_delimiter::staff_brace (Grob*me, Real y) SCM sz = gh_cons (ly_symbol2scm ("font-relative-size"), ly_symbol2scm ("*")); SCM alist = scm_list_n (fam, sz, SCM_UNDEFINED); - fm = Font_interface::get_font (me->get_paper (), scm_list_n (alist, SCM_UNDEFINED)); + fm = select_font (me->get_paper (), scm_list_n (alist, SCM_UNDEFINED)); int lo = 0; diff --git a/lily/text-item.cc b/lily/text-item.cc index f695a06f50..fef4babe23 100644 --- a/lily/text-item.cc +++ b/lily/text-item.cc @@ -15,7 +15,6 @@ #include "virtual-font-metric.hh" #include "paper-def.hh" - MAKE_SCHEME_CALLBACK(Text_item,interpret_markup,3); SCM Text_item::interpret_markup (SCM paper, SCM props, SCM markup) @@ -23,7 +22,7 @@ Text_item::interpret_markup (SCM paper, SCM props, SCM markup) if (gh_string_p (markup)) { Paper_def *pap = unsmob_paper (paper); - Font_metric *fm = Font_interface::get_font (pap, props); + Font_metric *fm = select_font (pap, props); SCM list = scm_list_n (ly_symbol2scm ("text"), markup, SCM_UNDEFINED); @@ -60,10 +59,10 @@ SCM Text_item::brew_molecule (SCM grob) { Grob * me = unsmob_grob (grob); - + SCM t = me->get_grob_property ("text"); SCM chain = Font_interface::font_alist_chain (me); - return interpret_markup (grob, chain, t); + return interpret_markup (me->get_paper ()->self_scm (), chain, t); } diff --git a/lily/text-spanner.cc b/lily/text-spanner.cc index 6037882dd6..88d20d457b 100644 --- a/lily/text-spanner.cc +++ b/lily/text-spanner.cc @@ -46,6 +46,7 @@ Text_spanner::brew_molecule (SCM smob) padding = gh_scm2double (itp); Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS); + Paper_def * paper = me->get_paper(); Interval span_points; Drul_array broken; @@ -87,7 +88,7 @@ Text_spanner::brew_molecule (SCM smob) SCM text = index_get_cell (edge_text, d); if (Text_item::markup_p (text)) - edge[d] = *unsmob_molecule (Text_item::interpret_markup (smob, properties, text)); + edge[d] = *unsmob_molecule (Text_item::interpret_markup (paper->self_scm (), properties, text)); if (!edge[d].empty_b ()) edge[d].align_to (Y_AXIS, CENTER); @@ -112,8 +113,8 @@ Text_spanner::brew_molecule (SCM smob) span_points[LEFT] += gh_scm2double (ly_car (ew)); span_points[RIGHT] -= gh_scm2double (ly_cdr (ew)); } - - Real thick = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + + Real thick = paper->get_realvar (ly_symbol2scm ("linethickness")); SCM st = me->get_grob_property ("thickness"); if (gh_number_p (st)) { diff --git a/lily/time-signature.cc b/lily/time-signature.cc index 187b88b832..67c03a8ef3 100644 --- a/lily/time-signature.cc +++ b/lily/time-signature.cc @@ -96,10 +96,10 @@ Time_signature::numbered_time_signature (Grob*me,int num, int den) me->set_grob_property ("font-family", ly_symbol2scm ("number")); SCM sn = - Text_item::interpret_markup (me->self_scm(), chain, + Text_item::interpret_markup (me->get_paper ()->self_scm(), chain, scm_makfrom0str (to_string (num).to_str0 ())); SCM sd = - Text_item::interpret_markup (me->self_scm(), chain, + Text_item::interpret_markup (me->get_paper ()->self_scm(), chain, scm_makfrom0str (to_string (den).to_str0 ())); Molecule n = *unsmob_molecule (sn); diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 973ac4bc93..21d57e9394 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -154,11 +154,12 @@ Tuplet_bracket::brew_molecule (SCM smob) Real ly = gh_scm2double (me->get_grob_property ("left-position")); Real ry = gh_scm2double (me->get_grob_property ("right-position")); SCM number = me->get_grob_property ("text"); - + + Paper_def *pap = me->get_paper (); if (gh_string_p (number) && number_visibility) { SCM properties = Font_interface::font_alist_chain (me); - SCM snum = Text_item::interpret_markup (smob, properties, number); + SCM snum = Text_item::interpret_markup (pap->self_scm (), properties, number); Molecule num = *unsmob_molecule (snum); num.align_to (X_AXIS, CENTER); num.translate_axis (w/2, X_AXIS); @@ -171,7 +172,7 @@ Tuplet_bracket::brew_molecule (SCM smob) if (bracket_visibility) { - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Real lt = pap->get_realvar (ly_symbol2scm ("linethickness")); SCM thick = me->get_grob_property ("thickness"); if (gh_number_p (thick)) diff --git a/lily/volta-bracket.cc b/lily/volta-bracket.cc index 05b5f973fd..2200983609 100644 --- a/lily/volta-bracket.cc +++ b/lily/volta-bracket.cc @@ -65,7 +65,8 @@ Volta_bracket_interface::brew_molecule (SCM smob) (strcmp(cs,":|")!=0 && strcmp(cs,"|:")!=0 && strcmp(cs,"|.")!=0 && strcmp(cs,":|:")!=0 && strcmp(cs,".|")!=0); - Real staff_thick = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); + Paper_def * paper =me->get_paper (); + Real staff_thick = paper->get_realvar (ly_symbol2scm ("linethickness")); Real half_space = 0.5; Item * bound = dynamic_cast (me)->get_bound (LEFT); @@ -107,7 +108,7 @@ Volta_bracket_interface::brew_molecule (SCM smob) { SCM text = me->get_grob_property ("text"); SCM properties = me->get_property_alist_chain (SCM_EOL); - SCM snum = Text_item::interpret_markup (smob, properties, text); + SCM snum = Text_item::interpret_markup (paper->self_scm (), properties, text); Molecule num = *unsmob_molecule (snum); mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length () diff --git a/ly/params-init.ly b/ly/params-init.ly index 3fb8ab5352..726128c7e5 100644 --- a/ly/params-init.ly +++ b/ly/params-init.ly @@ -68,5 +68,4 @@ interscoreline = 4. \mm (font-series . medium) )) -#(define properties-to-font Font_interface::properties_to_font_name) diff --git a/scm/chord-name.scm b/scm/chord-name.scm index 7ed0f184d4..c15cb36ec5 100644 --- a/scm/chord-name.scm +++ b/scm/chord-name.scm @@ -121,25 +121,3 @@ FOOBAR-MARKUP) if OMIT-ROOT is given and non-false. (alist (map chord-to-exception-entry elts))) (filter (lambda (x) (cdr x)) alist))) - -(define-public (new-chord-name-brew-molecule grob) - (let* - ( - (ws (ly:get-grob-property grob 'word-space)) - (markup (ly:get-grob-property grob 'text)) - (molecule (interpret-markup grob - (cons '((word-space . 0.0)) - (Font_interface::get_property_alist_chain grob)) - markup)) - ) - - ;; - ;; chord names aren't in staffs, so WS is in global staff space. - (if (number? ws) - (ly:molecule-combine-at-edge - molecule - X RIGHT (ly:make-molecule "" (cons 0 ws) '(-1 . 1) ) - 0.0) - molecule) - )) - diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index aca39f17bb..10d9d597ed 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -254,9 +254,9 @@ (ChordName . ( - (molecule-callback . ,new-chord-name-brew-molecule) + (molecule-callback . ,Text_item::brew_molecule) (after-line-breaking-callback . ,Chord_name::after_line_breaking) - (word-space . 1.0) + (word-space . 0.0) (font-family . roman) (meta . ((interfaces . (font-interface rhythmic-grob-interface text-interface chord-name-interface item-interface )))) -- 2.39.5