]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
patch::: 1.3.115.jcn2
[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 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "molecule.hh"
10 #include "text-item.hh"
11 #include "text-spanner.hh"
12 #include "line-spanner.hh"
13 #include "spanner.hh"
14 #include "font-interface.hh"
15 #include "dimensions.hh"
16 #include "paper-def.hh"
17 #include "debug.hh"
18 #include "paper-column.hh"
19 #include "staff-symbol-referencer.hh"
20
21 /*
22   TODO:
23     - vertical start / vertical end (fixme-name) |
24     - contination types (vert. star, vert. end)  |-> eat volta-spanner
25     - more styles
26     - more texts/positions
27  */
28
29 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
30
31 SCM
32 Text_spanner::brew_molecule (SCM smob) 
33 {
34   Grob *me= unsmob_grob (smob);
35   Spanner *spanner = dynamic_cast<Spanner*> (me);
36
37
38
39   /* Ugh, must be same as Hairpin::brew_molecule.  */
40   Real padding = gh_scm2double (me->get_grob_property ("padding"));
41   Real broken_left =  spanner->get_broken_left_end_align ();
42   Real width = spanner->spanner_length ();
43   width -= broken_left;
44
45   Drul_array<bool> broken;
46   Drul_array<Real> extra_off;
47   Direction d = LEFT;
48   do
49     {
50       Item *b = spanner->get_bound (d);
51       broken[d] = b->break_status_dir () != CENTER;
52
53       if (!broken [d])
54         {
55
56           Interval e = b->extent (b, X_AXIS);
57           Real r = 0.0;
58           if (!e.empty_b ())
59             r = e[-d] + padding;
60           width += d * r;
61           extra_off[d] = r;
62         }
63     }
64   while (flip (&d) != LEFT);
65
66   // FIXME: ecs tells us
67   width += gh_scm2double (me->get_grob_property ("width-correct"));
68   /* /Ugh */
69
70
71   SCM properties = Font_interface::font_alist_chain (me);
72   
73   SCM edge_text = me->get_grob_property ("edge-text");
74   Drul_array<Molecule> edge;
75   if (gh_pair_p (edge_text))
76     {
77       Direction d = LEFT;
78       do
79         {
80           SCM text = index_cell (edge_text, d);
81           edge[d] = Text_item::text2molecule (me, text, properties);
82           if (!edge[d].empty_b ())
83             edge[d].align_to (Y_AXIS, CENTER);
84         }
85       while (flip (&d) != LEFT);
86     }
87   width -= edge[LEFT].extent (X_AXIS).length ()
88     + edge[RIGHT].extent (X_AXIS).length ();
89
90   Drul_array<Real> shorten;
91   shorten[LEFT] = 0;
92   shorten[RIGHT] = 0;
93
94   SCM s = me->get_grob_property ("shorten");
95   if (gh_pair_p (s))
96     {
97       shorten[LEFT] = gh_scm2double (gh_car (s));
98       shorten[RIGHT] = gh_scm2double (gh_cdr (s));
99     }
100
101   width -= shorten[LEFT] + shorten[RIGHT];
102   
103   if (width < 0)
104     {
105       warning (_ ("Text_spanner too small"));
106       width = 0;
107     }
108
109   /* ugh */
110   Real thick = me->paper_l ()->get_var ("stafflinethickness");  
111   
112   Molecule line;
113   SCM list = Line_spanner::line_atom (me, width, 0);
114   if (list != SCM_EOL)
115     {
116       
117       Box b (Interval (0, width), Interval (-thick / 2, thick / 2));
118       line = Molecule (b, list);
119     }
120   
121   Drul_array<Molecule> edge_line;
122   s = me->get_grob_property ("edge-height");
123   if (gh_pair_p (s))
124     {
125       Direction d = LEFT;
126       int dir = to_dir (me->get_grob_property ("direction"));
127       do
128         {
129           Real dy = gh_scm2double (index_cell (s, d)) * - dir;
130           if (dy)
131             {
132               SCM list = Line_spanner::line_atom (me, 0, dy);
133               Box b (Interval (0, thick),
134                      dy > 0
135                      ? Interval (0, dy)
136                      : Interval (dy, 0));
137               edge_line[d] = Molecule (b, list);
138             }
139         }
140       while (flip (&d) != LEFT);
141     }
142   
143   Molecule m;
144   if (!edge[LEFT].empty_b ())
145     m = edge[LEFT];
146
147   if (!edge_line[LEFT].empty_b ())
148     m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
149   if (!line.empty_b ())
150     m.add_at_edge (X_AXIS, RIGHT, line, 0);
151   if (!edge_line[RIGHT].empty_b ())
152     m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
153   if (!edge[RIGHT].empty_b ())
154     m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
155   m.translate_axis (broken_left + extra_off[LEFT], X_AXIS);
156
157   return m.smobbed_copy ();
158 }
159
160