2 chord-name.cc -- implement Chord_name
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "chord-name.hh"
10 #include "musical-request.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
16 #include "staff-symbol-referencer.hh"
20 TODO: move text lookup out of Chord_name
24 word is roman text or property-styled text:
26 ("text" . property-alist)
30 Chord_name::ly_word2molecule (SCM word, Real* x) const
34 SCM options_alist = SCM_EOL;
37 options_alist = gh_cdr (word);
41 if (gh_string_p (word))
44 UGH. Should read from font metric structure.
46 Real ex = lookup_l ()->text ("", "x",
47 paper_l ()).extent (Y_AXIS).length ();
48 Real em = lookup_l ()->text ("", "m",
49 paper_l ()).extent (X_AXIS).length ();
51 String w = ly_scm2string (word);
54 SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
57 style = ly_scm2string (gh_cdr (s));
65 s = scm_assoc (ly_symbol2scm ("type"), options_alist);
66 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
68 Real super_y = ex / 2;
69 offset = Offset (0, super_y);
74 s = scm_assoc (ly_symbol2scm ("size"), options_alist);
77 size = gh_scm2int (gh_cdr (s));
80 s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
86 offset = Offset (0, gh_scm2double (gh_cdr (o))) * ex;
87 *x = gh_scm2double (gh_car (o)) * em;
91 s = scm_assoc (ly_symbol2scm ("font"), options_alist);
92 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "feta")
93 mol = paper_l ()->lookup_l (size)->afm_find (w);
95 mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
97 mol.translate (offset);
104 ;; text: list of word
105 ;; word: string + optional list of property
106 ;; property: align, kern, font (?), size
109 Chord_name::ly_text2molecule (SCM text) const
112 if (gh_list_p (text))
114 while (gh_cdr (text) != SCM_EOL)
117 Molecule m = ly_word2molecule (gh_car (text), &x);
119 mol.add_at_edge (X_AXIS, RIGHT, m, x);
120 text = gh_cdr (text);
122 text = gh_car (text);
125 Molecule m = ly_word2molecule (text, &x);
127 mol.add_at_edge (X_AXIS, RIGHT, m, x);
131 MAKE_SCHEME_SCORE_ELEMENT_NON_DEFAULT_CALLBACKS(Chord_name);
134 Chord_name::scheme_molecule (SCM smob)
136 Score_element *sc = unsmob_element (smob);
137 SCM style = sc->get_elt_property ("style");
138 if (style == SCM_UNDEFINED)
139 style = ly_str02scm ("banter");
141 SCM inversion = sc-> get_elt_property ("inversion");
142 if (inversion == SCM_UNDEFINED)
143 inversion = SCM_BOOL_F;
145 SCM bass = sc->get_elt_property ("bass");
146 if (bass == SCM_UNDEFINED)
149 SCM pitches = sc->get_elt_property ("pitches");
151 SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
153 ly_quote_scm (pitches),
154 ly_quote_scm (gh_cons (inversion, bass)),
157 return dynamic_cast<Chord_name*> (sc)->
158 ly_text2molecule (text).create_scheme ();
161 Chord_name::Chord_name (SCM s)