*** empty log message ***
[lilypond.git] / lily / line-interface.cc
blobeb5f8e975626707ed17ca8814e5cf0aae42080e0
1 /*
2 line-interface.cc -- implement Line_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "line-interface.hh"
11 #include "stencil.hh"
12 #include "grob.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "lookup.hh"
15 #include "paper-def.hh"
18 Stencil
19 Line_interface::make_dashed_line (Real thick, Offset from, Offset to,
20 Real dash_period, Real dash_fraction)
22 dash_fraction = (dash_fraction >? 0) <? 1.0;
23 Real on = dash_fraction * dash_period + thick;
24 Real off = dash_period - on;
26 SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
27 gh_double2scm (thick),
28 gh_double2scm (on),
29 gh_double2scm (off),
30 gh_double2scm (to[X_AXIS] - from[X_AXIS]),
31 gh_double2scm (to[Y_AXIS] - from[Y_AXIS]),
32 SCM_UNDEFINED);
34 Box box;
35 box.add_point (Offset (0,0));
36 box.add_point (to - from);
38 box[X_AXIS].widen (thick/2);
39 box[Y_AXIS].widen (thick/2);
41 Stencil m = Stencil (box, at);
42 m.translate (from);
43 return m;
46 Stencil
47 Line_interface::make_line (Real th, Offset from, Offset to)
49 SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
50 gh_double2scm (th),
51 gh_double2scm (from[X_AXIS]),
52 gh_double2scm (from[Y_AXIS]),
53 gh_double2scm (to[X_AXIS]),
54 gh_double2scm (to[Y_AXIS]),
55 SCM_UNDEFINED);
57 Box box;
58 box.add_point (from);
59 box.add_point (to);
61 box[X_AXIS].widen (th/2);
62 box[Y_AXIS].widen (th/2);
64 return Stencil (box, at);
67 Stencil
68 Line_interface::line (Grob *me, Offset from, Offset to)
70 Real thick = Staff_symbol_referencer::line_thickness (me)
71 * robust_scm2double (me->get_property ("thickness"),1);
73 SCM type = me->get_property ("style");
75 SCM dash_fraction = me->get_property ("dash-fraction");
76 if (gh_number_p (dash_fraction) || type == ly_symbol2scm ("dotted-line"))
79 Real fraction
80 = type == ly_symbol2scm ("dotted-line")
81 ? 0.0
82 : robust_scm2double (dash_fraction, 0.4);
84 fraction = (fraction >? 0) <? 1.0;
85 Real period = Staff_symbol_referencer::staff_space (me)
86 * robust_scm2double (me->get_property ("dash-period"), 1.0);
88 if (period < 0)
89 return Stencil ();
91 return make_dashed_line (thick, from, to, period, fraction);
93 else
95 return make_line (thick, from, to);
99 ADD_INTERFACE (Line_interface, "line-interface",
100 "Generic line objects. Any object using lines supports this. Normally,"
101 "you get a straight line. If @code{dash-period} is defined, a dashed line is "
102 "produced; the length of the dashes is tuned with "
103 "@code{dash-fraction}. If the latter is set to 0, a dotted line is "
104 "produced. If @code{dash-fraction} is negative, the line is made "
105 "transparent.",
107 "dash-period dash-fraction thickness style")