]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/stencil.hh
11baeaf76e0a1bbc52de69a19f3b3331665bea00
[lilypond.git] / lily / include / stencil.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef STENCIL_HH
20 #define STENCIL_HH
21
22 #include <cstdlib>              // size_t
23 using namespace std;
24
25 #include "lily-proto.hh"
26 #include "box.hh"
27 #include "smobs.hh"
28
29 /** a group of individually translated symbols. You can add stencils
30     to the top, to the right, etc.
31
32     It is implemented as a "tree" of scheme expressions, as in
33
34     Expr = combine Expr-list
35     | translate Offset Expr
36     | origin (ORIGIN) Expr
37     | no-origin Expr
38     | (SCHEME)
39     ;
40
41     SCHEME is a Scheme expression that --when eval'd-- produces the
42     desired output.
43
44     Notes:
45
46     * Because of the way that Stencil is implemented, it is the most
47     efficient to add "fresh" stencils to what you're going to build.
48
49     * Do not create Stencil objects on the heap. That includes passing
50     around Stencil* which are produced by unsmob_stencil(). Either
51     copy Stencil objects, or use SCM references.
52
53     * Empty stencils have empty dimensions.  If add_at_edge is used to
54     init the stencil, we assume that
55
56     DIMENSIONS = (Interval (0, 0), Interval (0, 0)
57 */
58 class Stencil
59 {
60   Box dim_;
61   SCM expr_;
62
63   DECLARE_SIMPLE_SMOBS (Stencil);
64 public:
65   Stencil (Box, SCM s);
66   Stencil ();
67
68   SCM expr () const;
69
70   /**
71      Set dimensions to empty, or to (Interval (0, 0), Interval (0, 0) */
72   void set_empty (bool);
73   void add_at_edge (Axis a, Direction d, const Stencil &m, Real padding);
74   void stack (Axis a, Direction d, const Stencil &m, Real padding, Real mindist);
75   void add_stencil (Stencil const &m);
76   void translate (Offset);
77   Stencil translated (Offset) const;
78   void rotate (Real, Offset);
79   void rotate_degrees (Real, Offset);
80   void rotate_degrees_absolute (Real, Offset);
81   void align_to (Axis a, Real x);
82   void translate_axis (Real, Axis);
83   void scale (Real, Real);
84
85   Interval extent (Axis) const;
86   Box extent_box () const;
87   bool is_empty () const;
88   bool is_empty (Axis) const;
89   Stencil in_color (Real r, Real g, Real b) const;
90   static SCM skylines_from_stencil (SCM, Real, Axis);
91 };
92
93 DECLARE_UNSMOB (Stencil, stencil);
94
95 void interpret_stencil_expression (SCM expr,
96                                    SCM (*func) (void *, SCM),
97                                    void *func_arg,
98                                    Offset o);
99 SCM find_expression_fonts (SCM expr);
100
101 void register_stencil_head (SCM symbol);
102 bool is_stencil_head (SCM symbol);
103 SCM all_stencil_heads ();
104
105 #endif /* STENCIL_HH */