]> git.donarmstrong.com Git - lilypond.git/blob - lily/stencil-scheme.cc
(print): remove neutral position.
[lilypond.git] / lily / stencil-scheme.cc
1 /*
2   stencil-scheme.cc -- implement Stencil scheme accessors
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "font-metric.hh"
10 #include "stencil.hh"
11
12
13 /*
14   UMGH. junkme!
15   
16  */
17 LY_DEFINE (ly_stencil_set_extent_x,"ly:stencil-set-extent!",
18            3, 0, 0, (SCM stil, SCM axis, SCM np),
19            "Set the extent of @var{stil} "
20            "(@var{extent} must be a pair of numbers) "
21            "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
22 {
23   Stencil *s = unsmob_stencil (stil);
24   SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
25   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
26   SCM_ASSERT_TYPE (is_number_pair (np), np, SCM_ARG3, __FUNCTION__, "number pair");
27
28   Interval iv = ly_scm2interval (np);
29   s->dim_[Axis (gh_scm2int (axis))] = iv;
30
31   return SCM_UNDEFINED;
32 }
33
34 LY_DEFINE (ly_translate_stencil_axis, "ly:stencil-translate-axis",
35            3, 0, 0, (SCM stil, SCM amount, SCM axis),
36            "Return a @var{stil}, "
37            "but translated by @var{amount} in @var{axis} direction.")
38 {
39   Stencil *s = unsmob_stencil (stil);
40   SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
41   SCM_ASSERT_TYPE (gh_number_p (amount), amount, SCM_ARG2, __FUNCTION__, "number pair");
42   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
43
44   Stencil q (*s);
45   q.translate_axis (gh_scm2double (amount), Axis (gh_scm2int (axis)));
46
47   return q.smobbed_copy ();
48 }
49
50 LY_DEFINE (ly_translate_stencil,"ly:stencil-translate",
51            2, 0, 0, (SCM stil, SCM offset),
52            "Return a @var{stil}, "
53            "but translated by @var{offset} (a pair of numbers).")
54 {
55   Stencil *s = unsmob_stencil (stil);
56   SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
57   SCM_ASSERT_TYPE (is_number_pair (offset), offset, SCM_ARG2, __FUNCTION__, "number pair");
58   Offset o = ly_scm2offset (offset);
59
60   Stencil q (*s);
61   q.translate (o);
62   return q.smobbed_copy ();
63 }
64
65 LY_DEFINE (ly_stencil_get_expr, "ly:stencil-get-expr",
66            1 , 0, 0, (SCM stil),
67            "Return the expression of @var{stil}.")
68 {
69   Stencil *s = unsmob_stencil (stil);
70   SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
71   return s->get_expr ();
72 }
73
74 LY_DEFINE (ly_stencil_get_extent,
75            "ly:stencil-extent", 2 , 0, 0,  (SCM stil, SCM axis),
76            "Return a pair of numbers signifying the extent of @var{stil} in "
77            "@var{axis} direction (0 or 1 for x and y axis respectively).")
78 {
79   Stencil *s = unsmob_stencil (stil);
80   SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
81   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
82
83   return ly_interval2scm (s->extent (Axis (gh_scm2int (axis))));
84 }
85
86 LY_DEFINE (ly_stencil_combined_at_edge,
87            "ly:stencil-combine-at-edge",
88            4, 2, 0,  (SCM first, SCM axis, SCM direction,
89                       SCM second,
90                       SCM padding,
91                       SCM minimum),
92            "Construct a stencil by putting @var{second} next to @var{first}. "
93            "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
94            "@var{direction} can be -1 (left or down) or 1 (right or up). "
95            "The stencils are juxtaposed with  @var{padding} as extra space. "
96            "If this puts the reference points closer than @var{minimum}, "
97            "they are moved by the latter amount.")
98 {
99   Stencil *s1 = unsmob_stencil (first);
100   Stencil *s2 = unsmob_stencil (second);
101   Stencil result;
102
103   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
104   SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
105
106   Real p = 0.0;
107   if (padding != SCM_UNDEFINED)
108     {
109       SCM_ASSERT_TYPE (gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
110       p = gh_scm2double (padding);
111     }
112   Real m = 0.0;
113   if (minimum != SCM_UNDEFINED)
114     {
115       SCM_ASSERT_TYPE (gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
116       m = gh_scm2double (minimum);
117     }
118
119   if (s1)
120     result = *s1;
121   if (s2)
122     result.add_at_edge (Axis (gh_scm2int (axis)),
123                         Direction (gh_scm2int (direction)), *s2, p, m);
124
125   return result.smobbed_copy ();
126 }
127
128 /*  FIXME: support variable number of arguments.  */
129 LY_DEFINE (ly_stencil_add ,
130            "ly:stencil-add", 0, 0, 1, (SCM args),
131            "Combine stencils. Takes any number of arguments.")
132 {
133 #define FUNC_NAME __FUNCTION__
134   SCM_VALIDATE_REST_ARGUMENT (args);
135
136   Stencil result;
137
138   while (!SCM_NULLP (args))
139     {
140       Stencil *s = unsmob_stencil (gh_car (args));
141       if (!s)
142         SCM_ASSERT_TYPE (s, gh_car (args), SCM_ARGn, __FUNCTION__, "Stencil");
143
144       result.add_stencil (*s);
145       args = gh_cdr (args);
146     }
147
148   return result.smobbed_copy ();
149 }
150
151 LY_DEFINE (ly_make_stencil,
152            "ly:make-stencil", 3, 0, 0,  (SCM expr, SCM xext, SCM yext),
153            " \n"
154            "Stencils are a device independent output expressions."
155            "They carry two pieces of information: \n\n"
156            "1: a specification of how to print this object. "
157            "This specification is processed by the output backends, "
158            " for example @file{scm/output-tex.scm}.\n\n"
159            "2: the vertical and horizontal extents of the object.\n\n")
160 {
161   SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
162   SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
163
164   Box b (ly_scm2interval (xext), ly_scm2interval (yext));
165   Stencil s (b, expr);
166   return s.smobbed_copy ();
167 }
168
169 SCM
170 fontify_atom (Font_metric const *met, SCM f)
171 {
172   if (f == SCM_EOL)
173     return f;
174   else
175     return  scm_list_n (ly_symbol2scm ("fontify"),
176                         ly_quote_scm (met->description_), f, SCM_UNDEFINED);
177 }
178
179 LY_DEFINE (ly_fontify_atom,"ly:fontify-atom", 2, 0, 0,
180            (SCM met, SCM f),
181            "Add a font selection command for the font metric @var{met} "
182            "to @var{f}.")
183 {
184   SCM_ASSERT_TYPE (unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
185
186   return fontify_atom (unsmob_metrics (met), f);
187 }
188
189 LY_DEFINE (ly_align_to_x, "ly:stencil-align-to!",
190            3, 0, 0, (SCM stil, SCM axis, SCM dir),
191            "Align @var{stil} using its own extents. "
192            "@var{dir} is a number -1, 1 are left and right respectively. "
193            "Other values are interpolated (so 0 means the center. ")
194 {
195   SCM_ASSERT_TYPE (unsmob_stencil (stil), stil, SCM_ARG1, __FUNCTION__, "stencil");
196   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
197   SCM_ASSERT_TYPE (gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
198
199   unsmob_stencil (stil)->align_to ((Axis)gh_scm2int (axis),
200                                    gh_scm2double (dir));
201   return SCM_UNDEFINED;
202 }