]> git.donarmstrong.com Git - lilypond.git/blob - lily/line-interface.cc
* flower
[lilypond.git] / lily / line-interface.cc
1 /*
2   line-interface.cc -- implement Line_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "line-interface.hh"
10
11 #include "staff-symbol-referencer.hh"
12 #include "lookup.hh"
13 #include "output-def.hh"
14
15 Stencil
16 Line_interface::make_dashed_line (Real thick, Offset from, Offset to,
17                                   Real dash_period, Real dash_fraction)
18 {
19   dash_fraction = (dash_fraction >? 0) <? 1.0;
20   Real on = dash_fraction * dash_period + thick;
21   Real off = dash_period - on;
22
23   SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
24                        scm_make_real (thick),
25                        scm_make_real (on),
26                        scm_make_real (off),
27                        scm_make_real (to[X_AXIS] - from[X_AXIS]),
28                        scm_make_real (to[Y_AXIS] - from[Y_AXIS]),
29                        SCM_UNDEFINED);
30
31   Box box;
32   box.add_point (Offset (0, 0));
33   box.add_point (to - from);
34
35   box[X_AXIS].widen (thick / 2);
36   box[Y_AXIS].widen (thick / 2);
37
38   Stencil m = Stencil (box, at);
39   m.translate (from);
40   return m;
41 }
42
43 Stencil
44 Line_interface::make_line (Real th, Offset from, Offset to)
45 {
46   SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
47                        scm_make_real (th),
48                        scm_make_real (from[X_AXIS]),
49                        scm_make_real (from[Y_AXIS]),
50                        scm_make_real (to[X_AXIS]),
51                        scm_make_real (to[Y_AXIS]),
52                        SCM_UNDEFINED);
53
54   Box box;
55   box.add_point (from);
56   box.add_point (to);
57
58   box[X_AXIS].widen (th / 2);
59   box[Y_AXIS].widen (th / 2);
60
61   return Stencil (box, at);
62 }
63
64 Stencil
65 Line_interface::line (Grob *me, Offset from, Offset to)
66 {
67   Real thick = Staff_symbol_referencer::line_thickness (me)
68     * robust_scm2double (me->get_property ("thickness"), 1);
69
70   SCM type = me->get_property ("style");
71
72   SCM dash_fraction = me->get_property ("dash-fraction");
73   if (scm_is_number (dash_fraction) || type == ly_symbol2scm ("dotted-line"))
74     {
75
76       Real fraction
77         = type == ly_symbol2scm ("dotted-line")
78         ? 0.0
79         : robust_scm2double (dash_fraction, 0.4);
80
81       fraction = (fraction >? 0) <? 1.0;
82       Real period = Staff_symbol_referencer::staff_space (me)
83         * robust_scm2double (me->get_property ("dash-period"), 1.0);
84
85       if (period < 0)
86         return Stencil ();
87
88       return make_dashed_line (thick, from, to, period, fraction);
89     }
90   else
91     {
92       return make_line (thick, from, to);
93     }
94 }
95
96 ADD_INTERFACE (Line_interface, "line-interface",
97                "Generic line objects. Any object using lines supports this.  Normally, "
98                "you get a straight line. If @code{dash-period} is defined, a dashed line is "
99                "produced; the length of the dashes is tuned with "
100                "@code{dash-fraction}. If the latter is set to 0, a dotted line is "
101                "produced. If @code{dash-fraction} is negative, the line is made "
102                "transparent.",
103
104                "dash-period dash-fraction thickness style")