]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-name.cc
patch::: 1.3.48.jcn1
[lilypond.git] / lily / chord-name.cc
1 /*
2   chord-name.cc -- implement Chord_name
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "chord-name.hh"
10 #include "musical-request.hh"
11 #include "warn.hh"
12 #include "debug.hh"
13 #include "molecule.hh"
14 #include "paper-def.hh"
15 #include "lookup.hh"
16 #include "staff-symbol-referencer.hh"
17
18
19 /*
20   TODO: move text lookup out of Chord_name
21  */
22
23 /*
24   word is roman text or styled text:
25    "text"
26    ("style" . "text")
27  */
28 Molecule
29 Chord_name::ly_word2molecule (SCM word) const
30 {
31   Dictionary<SCM> option_dict;
32   if (gh_pair_p (word))
33     {
34       SCM options = gh_cdr (word);
35       word = gh_car (word);
36       while (gh_pair_p (options))
37         {
38           SCM option = gh_car (options);
39           if (option != SCM_UNDEFINED && option != SCM_BOOL_F
40               && gh_pair_p (option))
41             {
42               SCM key = gh_car (option);
43               SCM val = gh_cdr (option);
44               String k;
45               if (gh_symbol_p (key))
46                 k = ly_symbol2string (key);
47               else if (gh_string_p (key))
48                 k = ly_scm2string (key);
49               else
50                 continue;
51               option_dict[k] = val;
52             }
53           options = gh_cdr (options);
54         }
55     }
56   Real ex = lookup_l ()->text ("", "x", paper_l ()).extent
57             ()[Y_AXIS].length ();
58   if (gh_string_p (word))
59     {
60       String w = ly_scm2string (word);
61       Molecule mol;
62       Offset offset;
63
64       int size = 0;
65       if (option_dict.elem_b ("size"))
66         size = gh_scm2int (option_dict["size"]);
67
68       String style;
69       if (option_dict.elem_b ("style"))
70         style = ly_scm2string (option_dict["style"]);
71
72       if (option_dict.elem_b ("type")
73           && ly_scm2string (option_dict["type"]) == "super")
74         {
75           Real super_y = ex / 2;
76           //super_y += -acc.extent ()[Y_AXIS][MIN];
77           offset = Offset (0, super_y);
78           if (!size)
79             size = -2;
80         }
81       if (option_dict.elem_b ("offset"))
82         {
83           // hmm
84           SCM s = option_dict["offset"];
85           if (gh_pair_p (s))
86             offset = Offset (gh_scm2double (gh_car (s)),
87                              gh_scm2double (gh_cdr (s))) * ex;
88         }
89       if (option_dict.elem_b ("font") 
90           && ly_scm2string (option_dict["font"]) == "feta")
91         mol = paper_l ()->lookup_l (size)->afm_find (w);
92       else
93         mol = paper_l ()->lookup_l (size)->text (style, w, paper_l ());
94
95       mol.translate (offset);
96       return mol;
97     }
98   return Molecule ();
99 }
100
101 /*
102   ;; text: list of word
103   ;; word: string + optional list of property
104   ;; property: align, kern, font (?), size
105  */
106 Molecule
107 Chord_name::ly_text2molecule (SCM text) const
108 {
109   Molecule mol;
110   if (gh_list_p (text))
111     {
112       while (gh_cdr (text) != SCM_EOL)
113         {
114           Molecule m = ly_word2molecule (gh_car (text));
115           if (!m.empty_b ())
116             mol.add_at_edge (X_AXIS, RIGHT, m, 0);
117           text = gh_cdr (text);
118         }
119       text = gh_car (text);
120     }  
121   Molecule m = ly_word2molecule (text);
122   if (!m.empty_b ())
123     mol.add_at_edge (X_AXIS, RIGHT, m, 0);
124   return mol;
125 }
126
127 Molecule 
128 Chord_name::do_brew_molecule () const
129 {
130   SCM style = get_elt_property ("style");
131   if (style == SCM_UNDEFINED)
132     style = ly_str02scm ("banter");
133
134   SCM inversion = get_elt_property ("inversion");
135   if (inversion == SCM_UNDEFINED)
136     inversion = SCM_BOOL_F;
137
138   SCM bass = get_elt_property ("bass");
139   if (bass == SCM_UNDEFINED)
140     bass = SCM_BOOL_F;
141
142   SCM pitches = get_elt_property ("pitches");
143
144   SCM text = scm_eval (gh_list (ly_symbol2scm ("chord::user-name"),
145                                 style,
146                                 ly_quote_scm (pitches),
147                                 ly_quote_scm (gh_cons (inversion, bass)),
148                                 SCM_UNDEFINED));
149
150   return ly_text2molecule (text);
151 }