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