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