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 "molecule.hh"
11 #include "paper-def.hh"
13 #include "score-element.hh"
16 TODO: move text lookup out of Chord_name
20 word is roman text or property-styled text:
22 ("text" . property-alist)
26 Chord_name::ly_word2molecule (Score_element * me, SCM word, Real* x)
30 SCM options_alist = SCM_EOL;
33 options_alist = gh_cdr (word);
37 if (gh_string_p (word))
40 UGH. Should read from font metric structure.
42 Real ex = me->lookup_l ()->text ("", "x",
43 me->paper_l ()).extent (Y_AXIS).length ();
44 Real em = me->lookup_l ()->text ("", "m",
45 me->paper_l ()).extent (X_AXIS).length ();
47 String w = ly_scm2string (word);
50 SCM s = scm_assoc (ly_symbol2scm ("style"), options_alist);
53 style = ly_scm2string (gh_cdr (s));
61 s = scm_assoc (ly_symbol2scm ("type"), options_alist);
62 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "super")
64 Real super_y = ex / 2;
65 offset = Offset (0, super_y);
70 s = scm_assoc (ly_symbol2scm ("size"), options_alist);
73 size = gh_scm2int (gh_cdr (s));
76 s = scm_assoc (ly_symbol2scm ("offset"), options_alist);
82 offset = Offset (0, gh_scm2double (gh_cdr (o))) * ex;
83 *x = gh_scm2double (gh_car (o)) * em;
87 s = scm_assoc (ly_symbol2scm ("font"), options_alist);
88 if (s != SCM_BOOL_F && ly_scm2string (gh_cdr (s)) == "feta")
89 mol = me->paper_l ()->lookup_l (size)->afm_find (w);
91 mol = me->paper_l ()->lookup_l (size)->text (style, w, me->paper_l ());
93 mol.translate (offset);
100 ;; text: list of word
101 ;; word: string + optional list of property
102 ;; property: align, kern, font (?), size
105 Chord_name::ly_text2molecule (Score_element * me, SCM text)
108 if (gh_list_p (text))
110 while (gh_cdr (text) != SCM_EOL)
113 Molecule m = ly_word2molecule (me, gh_car (text), &x);
115 mol.add_at_edge (X_AXIS, RIGHT, m, x);
116 text = gh_cdr (text);
118 text = gh_car (text);
121 Molecule m = ly_word2molecule (me,text, &x);
123 mol.add_at_edge (X_AXIS, RIGHT, m, x);
127 MAKE_SCHEME_CALLBACK(Chord_name,brew_molecule);
130 Chord_name::brew_molecule (SCM smob)
132 Score_element *sc = unsmob_element (smob);
133 SCM style = sc->get_elt_property ("style");
134 if (style == SCM_UNDEFINED)
135 style = ly_str02scm ("banter");
137 SCM inversion = sc-> get_elt_property ("inversion");
138 if (inversion == SCM_UNDEFINED)
139 inversion = SCM_BOOL_F;
141 SCM bass = sc->get_elt_property ("bass");
142 if (bass == SCM_UNDEFINED)
145 SCM pitches = sc->get_elt_property ("pitches");
147 SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
149 ly_quote_scm (pitches),
150 ly_quote_scm (gh_cons (inversion, bass)),
153 return ly_text2molecule (sc, text).create_scheme ();