]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-text-spanner.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[lilypond.git] / lily / dynamic-text-spanner.cc
1
2 /*
3   crescendo-text-spanner.cc -- implement Text_spanner
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
8
9   Revised over good by Han-Wen. 
10 */
11
12 #include "text-item.hh"
13 #include "text-spanner.hh"
14 #include "line-spanner.hh"
15 #include "spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "output-def.hh"
19 #include "warn.hh"
20 #include "paper-column.hh"
21
22
23
24 class Dynamic_text_spanner
25 {
26 public:
27   DECLARE_SCHEME_CALLBACK (print, (SCM));
28   static bool has_interface (Grob*);
29 };
30
31
32
33 /*
34   This is a partial C&P from text-spanner.cc
35
36   Dynamic_text_spanner is similar, but
37
38   * does not require bracket functionality.
39
40   * should make room for spanning points (mf/f/mp texts).
41  
42   * In the future, we should  support
43
44    cresc - - - - poco - - - a - - - - poco - - - 
45
46   as well
47
48
49   The cut & paste is rather inelegant, but text-spanner was a failed
50   and buggy attempt at being generic.
51   
52   
53 */
54 MAKE_SCHEME_CALLBACK (Dynamic_text_spanner, print, 1);
55 SCM
56 Dynamic_text_spanner::print (SCM smob) 
57 {
58   Grob *me= unsmob_grob (smob);
59   Spanner *spanner = dynamic_cast<Spanner*> (me);
60
61   Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
62   Output_def * layout = me->get_layout ();
63
64   Interval span_points;
65   Drul_array<bool> broken;
66   Direction d = LEFT;
67   do
68     {
69       Item *b = spanner->get_bound (d);
70       broken[d] = b->break_status_dir () != CENTER;
71
72       if (broken[d])
73         {
74           if (d == LEFT)
75             span_points[d] = spanner->get_broken_left_end_align ();
76           else
77             span_points[d] = b->relative_coordinate (common, X_AXIS);
78         }
79       else
80         {
81           Real pad = 0.0;
82           Real encl = d;
83           if (b->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
84             {
85               pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
86               encl = -d;
87             }
88
89           Interval ext  = b->extent (common, X_AXIS);
90           span_points[d] = -d  * pad
91             + robust_relative_extent (b,common, X_AXIS)
92             .linear_combination (encl);
93         }
94     }
95   while (flip (&d) != LEFT);
96
97
98   Stencil m;
99   SCM properties = Font_interface::text_font_alist_chain (me);
100   SCM edge_text = me->get_property ("edge-text");
101   Drul_array<Stencil> edge;
102   if (scm_is_pair (edge_text))
103     {
104       Direction d = LEFT;
105       do
106         {
107           if (broken[d])
108             continue;
109           
110           SCM text = index_get_cell (edge_text, d);
111
112           if (Text_interface::markup_p (text)) 
113             edge[d] = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, text));
114           
115           if (!edge[d].is_empty ())
116             edge[d].align_to (Y_AXIS, CENTER);
117         }
118       while (flip (&d) != LEFT);
119     }
120
121   do
122     {
123       Interval ext = edge[d].extent (X_AXIS);
124       if (!ext.is_empty ())
125         {
126           edge[d].translate_axis (span_points[d], X_AXIS);
127           m.add_stencil (edge[d]);
128           span_points[d] += -d *  ext[-d];
129         }
130     }
131   while (flip (&d) != LEFT);
132
133   
134   if (!span_points.is_empty ())
135     {
136       Stencil l =Line_spanner::line_stencil (me,
137                                              Offset (span_points[LEFT], 0),
138                                              Offset (span_points[RIGHT], 0));
139       m.add_stencil (l);
140     }
141   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
142   return m.smobbed_copy ();
143 }
144
145 ADD_INTERFACE (Dynamic_text_spanner,
146                "dynamic-text-spanner-interface",
147                "A text spanner for crescendo texts",
148                "bound-padding dash-period dash-fraction edge-text style thickness");
149