]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
ce660216ffb0d6174a9dac43188e74e703ccb33b
[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   Paper_def * paper = me->get_paper();
50   
51   Interval span_points;
52   Drul_array<bool> broken;
53   Direction d = LEFT;
54   do
55     {
56       Item *b = spanner->get_bound (d);
57       broken[d] = b->break_status_dir () != CENTER;
58
59       if (broken[d])
60         {
61         if (d == LEFT)
62           span_points[d] = spanner->get_broken_left_end_align ();
63         else
64           span_points[d] = b->relative_coordinate (common, X_AXIS);
65         }
66       else
67           {
68             bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
69             span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
70           }
71     }
72   while (flip (&d) != LEFT);
73
74
75
76   SCM properties = Font_interface::font_alist_chain (me);
77   SCM edge_text = me->get_grob_property ("edge-text");
78   Drul_array<Molecule> edge;
79   if (gh_pair_p (edge_text))
80     {
81       Direction d = LEFT;
82       do
83         {
84           /*  Don't repeat edge text for broken end */
85           if (broken[d])
86             continue;
87           
88           SCM text = index_get_cell (edge_text, d);
89
90           if (Text_item::markup_p (text)) 
91             edge[d] = *unsmob_molecule (Text_item::interpret_markup (paper->self_scm (), properties, text));
92           
93           if (!edge[d].empty_b ())
94             edge[d].align_to (Y_AXIS, CENTER);
95         }
96       while (flip (&d) != LEFT);
97     }
98
99
100   Drul_array<Real> shorten;
101   shorten[LEFT] = 0;
102   shorten[RIGHT] = 0;
103
104   SCM ew = me->get_grob_property ("bracket-flare");
105   SCM s = me->get_grob_property ("shorten-pair");
106   if (gh_pair_p (s))
107     {
108       span_points[LEFT] += gh_scm2double (ly_car (s));
109       span_points[RIGHT] -= gh_scm2double (ly_cdr (s));
110     }
111   if (gh_pair_p (ew))
112     {
113       span_points[LEFT] += gh_scm2double (ly_car (ew));
114       span_points[RIGHT] -= gh_scm2double (ly_cdr (ew));
115     }
116
117   Real thick = paper->get_realvar (ly_symbol2scm ("linethickness"));  
118   SCM st = me->get_grob_property ("thickness");
119   if (gh_number_p (st))
120     {
121       thick *=  gh_scm2double (st);
122     }
123   
124   Drul_array<Molecule> edge_line;
125   s = me->get_grob_property ("edge-height");
126   if (gh_pair_p (s))
127     {
128       Direction d = LEFT;
129       int dir = to_dir (me->get_grob_property ("direction"));
130       do
131         {
132           if (broken[d])
133             continue;
134           
135           Real dx = 0.0;
136           if (gh_pair_p (ew))
137             dx = gh_scm2double (index_get_cell (ew, d)) * d;
138
139           Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
140           if (dy)
141             edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0),
142                                                         Offset (dx, dy));
143         }
144       while (flip (&d) != LEFT);
145     }
146   
147   Molecule m;
148   do
149     {
150       Interval ext = edge[d].extent (X_AXIS);
151
152       edge[d].translate_axis (span_points[d], X_AXIS);
153       m.add_molecule (edge[d]);
154       edge_line[d].translate_axis (span_points[d], X_AXIS);
155       m.add_molecule (edge_line[d]);
156       if (!ext.empty_b ())
157         span_points[d] += -d *  ext[-d];
158     }
159   while (flip (&d) != LEFT);
160
161   Molecule l =Line_spanner::line_molecule (me, thick,
162                                            Offset (span_points[LEFT], 0),
163                                            Offset (span_points[RIGHT], 0));
164   m.add_molecule (l);
165
166   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
167   return m.smobbed_copy ();
168 }
169
170
171
172
173 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
174                "generic text spanner",
175                "dash-period if-text-padding dash-fraction edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct");
176