]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/stencil.hh
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / include / stencil.hh
1 /*
2   stencil.hh -- declare Stencil
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8 #ifndef STENCIL_HH
9 #define STENCIL_HH
10
11 #include <cstdlib>              // size_t
12 using namespace std;
13
14 #include "lily-proto.hh"
15 #include "box.hh"
16 #include "smobs.hh"
17
18 /** a group of individually translated symbols. You can add stencils
19     to the top, to the right, etc.
20
21     It is implemented as a "tree" of scheme expressions, as in
22
23     Expr = combine Expr-list
24     | translate Offset Expr
25     | origin (ORIGIN) Expr
26     | no-origin Expr
27     | (SCHEME)
28     ;
29
30     SCHEME is a Scheme expression that --when eval'd-- produces the
31     desired output.
32
33     Notes:
34
35     * Because of the way that Stencil is implemented, it is the most
36     efficient to add "fresh" stencils to what you're going to build.
37
38     * Do not create Stencil objects on the heap. That includes passing
39     around Stencil* which are produced by unsmob_stencil(). Either
40     copy Stencil objects, or use SCM references.
41
42     * Empty stencils have empty dimensions.  If add_at_edge is used to
43     init the stencil, we assume that
44
45     DIMENSIONS = (Interval (0, 0), Interval (0, 0)
46 */
47 class Stencil
48 {
49   /*
50     This provides the reference point of the symbol, for example with
51     characters, it is on the base line of the character. Usually,
52     ORIGIN is inside DIM_
53   */
54   Offset origin_;
55   Box dim_;
56   SCM expr_;
57
58   DECLARE_SIMPLE_SMOBS (Stencil);
59 public:
60   Stencil (Box, SCM s);
61   Stencil ();
62
63   Offset origin () const;
64   SCM expr () const;
65
66   /**
67      Set dimensions to empty, or to (Interval (0, 0), Interval (0, 0) */
68   void set_empty (bool);
69   Stencil moved_to_edge (Axis a, Direction d, const Stencil &m, Real padding,
70                          Real minimum) const;
71
72   void add_at_edge (Axis a, Direction d, const Stencil &m, Real padding,
73                     Real minimum);
74   void add_stencil (Stencil const &m);
75   void translate (Offset);
76   void rotate (Real, Offset);
77   void align_to (Axis a, Real x);
78   void translate_axis (Real, Axis);
79
80   Interval extent (Axis) const;
81   Box extent_box () const;
82   bool is_empty () const;
83   Stencil in_color (Real r, Real g, Real b) const;
84 };
85
86 DECLARE_UNSMOB (Stencil, stencil);
87
88 void interpret_stencil_expression (SCM expr,
89                                    void (*func) (void *, SCM),
90                                    void *func_arg,
91                                    Offset o);
92 SCM find_expression_fonts (SCM expr);
93
94 void register_stencil_head (SCM symbol);
95 bool is_stencil_head (SCM symbol);
96 SCM all_stencil_heads ();
97
98
99 #endif /* STENCIL_HH */