]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-spanner.cc
release: 1.3.112
[lilypond.git] / lily / line-spanner.cc
1 /*
2   line-spanner.cc -- implement Line_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 "item.hh"
11 #include "spanner.hh"
12 #include "line-spanner.hh"
13 #include "paper-def.hh"
14 #include "paper-column.hh"
15 #include "staff-symbol-referencer.hh"
16
17 SCM
18 Line_spanner::line_atom (Grob* me, Real dx, Real dy)
19 {
20   SCM list = SCM_EOL;
21   SCM type = me->get_grob_property ("type");
22   if (gh_symbol_p (type)
23       && (type == ly_symbol2scm ("line")
24           || type == ly_symbol2scm ("dashed-line")
25           || type == ly_symbol2scm ("dotted-line")))
26     {
27       Real staff_space = Staff_symbol_referencer::staff_space (me);
28       Real thick = me->paper_l ()->get_var ("stafflinethickness");  
29
30       SCM s = me->get_grob_property ("line-thickness");
31       if (gh_number_p (s))
32         thick *= gh_scm2double (s);
33   
34       // maybe these should be in line-thickness?
35       Real length = staff_space;
36       s = me->get_grob_property ("dash-length");
37       if (gh_number_p (s))
38         length = gh_scm2double (s) * staff_space;
39
40       Real period = 2 * length + thick;
41       s = me->get_grob_property ("dash-period");
42       if (gh_number_p (s))
43         period = gh_scm2double (s) * staff_space;
44       
45       if (type == ly_symbol2scm ("dotted-line"))
46         length = thick;
47         
48       if (type == ly_symbol2scm ("line"))
49         length = period + thick;
50
51       Real on = length - thick;
52       Real off = period - on;
53
54       list = gh_list (ly_symbol2scm ("dashed-line"),
55                       gh_double2scm (thick),
56                       gh_double2scm (on),
57                       gh_double2scm (off),
58                       gh_double2scm (dx),
59                       gh_double2scm (dy),
60                       SCM_UNDEFINED);
61     }
62   return list;
63 }
64
65
66
67 /*
68   Warning: this thing is a cross-staff object, so it should have empty Y-dimensions.
69
70   (If not, you risk that this is called from the staff-alignment
71   routine, via molecule_extent. At this point, the staffs aren't
72   separated yet, so it doesn't work cross-staff.
73
74 */
75
76 MAKE_SCHEME_CALLBACK (Line_spanner, brew_molecule, 1);
77 SCM
78 Line_spanner::brew_molecule (SCM smob) 
79 {
80   Grob *me= unsmob_grob (smob);
81   Spanner *spanner = dynamic_cast<Spanner*> (me);
82
83   Grob *common[] = { 0, 0 };
84
85   Item *l = spanner->get_bound (LEFT);
86   Item *r = spanner->get_bound (RIGHT);  
87
88   /*
89     FIXME: should also do something sensible across line breaks.
90    */
91   if (l->break_status_dir () || r->break_status_dir ())
92     return SCM_EOL;
93   
94   for (Axis a = X_AXIS;  a < NO_AXES; a = Axis (a + 1))
95     {
96       common[a] = l->common_refpoint (r, a);
97   
98     if (!common[a])
99       return SCM_EOL;
100     }
101   
102   Offset dxy ; 
103   for (Axis a = X_AXIS;  a < NO_AXES; a = Axis (a + 1))
104     {
105       dxy[a] = r->extent (common[a], a)[LEFT] -
106         l->extent (common[a], a)[RIGHT];
107     }
108   
109   Molecule line;
110   Real gap = gh_scm2double (me->get_grob_property ("gap"));
111
112   Offset my_off(me->relative_coordinate (common[X_AXIS], X_AXIS),
113                 me->relative_coordinate (common[Y_AXIS], Y_AXIS) ); 
114  
115   Offset his_off(l->relative_coordinate (common[X_AXIS], X_AXIS),
116                  l->relative_coordinate (common[Y_AXIS], Y_AXIS) ); 
117  
118   dxy *= (dxy.length () - 2 * gap) / dxy.length ();
119   
120   SCM list = Line_spanner::line_atom (me, dxy[X_AXIS], dxy[Y_AXIS]);
121     
122   if (list == SCM_EOL)
123     return SCM_EOL;
124   
125   Box b (Interval (0, dxy[X_AXIS]), Interval (0, dxy[Y_AXIS]));
126   
127   line = Molecule (b, list);
128   line.translate_axis (l->extent (l, X_AXIS).length (), X_AXIS); 
129   
130   
131   Offset g = dxy * (gap / dxy.length ());
132   line.translate (g - my_off + his_off);
133       
134   return line.smobbed_copy ();
135 }
136
137