]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-spanner.cc
patch::: 1.3.111.jcn1
[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 MAKE_SCHEME_CALLBACK (Line_spanner, brew_molecule, 1);
67 SCM
68 Line_spanner::brew_molecule (SCM smob) 
69 {
70   Grob *me= unsmob_grob (smob);
71   Spanner *spanner = dynamic_cast<Spanner*> (me);
72
73   Grob *common[] = { 0, 0 };
74   common[X_AXIS] = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
75   common[Y_AXIS] = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), Y_AXIS);
76
77   if (!common[X_AXIS] || !common[Y_AXIS])
78     return SCM_EOL;
79   
80   Real dx =
81     spanner->get_bound (LEFT)->relative_coordinate (common[X_AXIS], X_AXIS)
82     - spanner->get_bound (RIGHT)->relative_coordinate (common[X_AXIS], X_AXIS)
83     + spanner->get_bound (RIGHT)->extent (spanner->get_bound (RIGHT),
84                                           X_AXIS)[LEFT]
85     - spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT),
86                                          X_AXIS)[RIGHT];
87   
88   Real dy =
89     spanner->get_bound (LEFT)->relative_coordinate (common[Y_AXIS], Y_AXIS)
90     - spanner->get_bound (RIGHT)->relative_coordinate (common[Y_AXIS], Y_AXIS)
91     + spanner->get_bound (RIGHT)->extent (spanner->get_bound (RIGHT),
92                                           Y_AXIS).center ()
93     - spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT),
94                                          Y_AXIS).center ();
95   
96   Molecule line;
97   Real gap = gh_scm2double (me->get_grob_property ("gap"));
98   Offset o (dx, dy);
99   o *= (o.length () - 2 * gap) / o.length ();
100   
101   SCM list = Line_spanner::line_atom (me, o[X_AXIS], o[Y_AXIS]);
102     
103   if (list == SCM_EOL)
104     return SCM_EOL;
105   
106   Box b (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
107   
108   line = Molecule (b, list);
109   line.translate_axis (spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT), X_AXIS).length (), X_AXIS);
110   Offset g = o * (gap / o.length ());
111   line.translate (g);
112       
113   return line.smobbed_copy ();
114 }
115
116