]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
6037882dd6a8d3303d4f017ce3d97ac8441a0444
[lilypond.git] / lily / text-spanner.cc
1 /*
2   text-spanner.cc -- implement Text_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Revised over good by Han-Wen. 
9 */
10
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "text-spanner.hh"
14 #include "line-spanner.hh"
15 #include "spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "paper-def.hh"
19 #include "warn.hh"
20 #include "paper-column.hh"
21 #include "staff-symbol-referencer.hh"
22
23 /*
24   TODO:
25   - vertical start / vertical end (fixme-name) |
26   - contination types (vert. star, vert. end)  |-> eat volta-bracket
27   - more styles
28   - more texts/positions
29 */
30
31 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
32
33 /*
34   TODO: this function is too long
35 */
36 SCM
37 Text_spanner::brew_molecule (SCM smob) 
38 {
39   Grob *me= unsmob_grob (smob);
40   Spanner *spanner = dynamic_cast<Spanner*> (me);
41   
42   /* Ugh, must be same as Hairpin::brew_molecule.  */
43   Real padding = 0.0;
44   SCM itp= me->get_grob_property ("if-text-padding");
45   if (gh_number_p (itp))
46     padding = gh_scm2double (itp);
47
48   Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
49   
50   Interval span_points;
51   Drul_array<bool> broken;
52   Direction d = LEFT;
53   do
54     {
55       Item *b = spanner->get_bound (d);
56       broken[d] = b->break_status_dir () != CENTER;
57
58       if (broken[d])
59         {
60         if (d == LEFT)
61           span_points[d] = spanner->get_broken_left_end_align ();
62         else
63           span_points[d] = b->relative_coordinate (common, X_AXIS);
64         }
65       else
66           {
67             bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
68             span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
69           }
70     }
71   while (flip (&d) != LEFT);
72
73
74
75   SCM properties = Font_interface::font_alist_chain (me);
76   SCM edge_text = me->get_grob_property ("edge-text");
77   Drul_array<Molecule> edge;
78   if (gh_pair_p (edge_text))
79     {
80       Direction d = LEFT;
81       do
82         {
83           /*  Don't repeat edge text for broken end */
84           if (broken[d])
85             continue;
86           
87           SCM text = index_get_cell (edge_text, d);
88
89           if (Text_item::markup_p (text)) 
90             edge[d] = *unsmob_molecule (Text_item::interpret_markup (smob, properties, text));
91           
92           if (!edge[d].empty_b ())
93             edge[d].align_to (Y_AXIS, CENTER);
94         }
95       while (flip (&d) != LEFT);
96     }
97
98
99   Drul_array<Real> shorten;
100   shorten[LEFT] = 0;
101   shorten[RIGHT] = 0;
102
103   SCM ew = me->get_grob_property ("bracket-flare");
104   SCM s = me->get_grob_property ("shorten-pair");
105   if (gh_pair_p (s))
106     {
107       span_points[LEFT] += gh_scm2double (ly_car (s));
108       span_points[RIGHT] -= gh_scm2double (ly_cdr (s));
109     }
110   if (gh_pair_p (ew))
111     {
112       span_points[LEFT] += gh_scm2double (ly_car (ew));
113       span_points[RIGHT] -= gh_scm2double (ly_cdr (ew));
114     }
115   
116   Real thick = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));  
117   SCM st = me->get_grob_property ("thickness");
118   if (gh_number_p (st))
119     {
120       thick *=  gh_scm2double (st);
121     }
122   
123   Drul_array<Molecule> edge_line;
124   s = me->get_grob_property ("edge-height");
125   if (gh_pair_p (s))
126     {
127       Direction d = LEFT;
128       int dir = to_dir (me->get_grob_property ("direction"));
129       do
130         {
131           if (broken[d])
132             continue;
133           
134           Real dx = 0.0;
135           if (gh_pair_p (ew))
136             dx = gh_scm2double (index_get_cell (ew, d)) * d;
137
138           Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
139           if (dy)
140             edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0),
141                                                         Offset (dx, dy));
142         }
143       while (flip (&d) != LEFT);
144     }
145   
146   Molecule m;
147   do
148     {
149       Interval ext = edge[d].extent (X_AXIS);
150
151       edge[d].translate_axis (span_points[d], X_AXIS);
152       m.add_molecule (edge[d]);
153       edge_line[d].translate_axis (span_points[d], X_AXIS);
154       m.add_molecule (edge_line[d]);
155       if (!ext.empty_b ())
156         span_points[d] += -d *  ext[-d];
157     }
158   while (flip (&d) != LEFT);
159
160   Molecule l =Line_spanner::line_molecule (me, thick,
161                                            Offset (span_points[LEFT], 0),
162                                            Offset (span_points[RIGHT], 0));
163   m.add_molecule (l);
164
165   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
166   return m.smobbed_copy ();
167 }
168
169
170
171
172 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
173                "generic text spanner",
174                "dash-period if-text-padding dash-length edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct");
175