2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 ugh. Rewrite not finished yet. Still must copy atom lists.
16 #include "font-metric.hh"
17 #include "dimensions.hh"
18 #include "interval.hh"
20 #include "molecule.hh"
23 #include "killing-cons.tcc"
27 Molecule::extent() const
33 Molecule::extent(Axis a
) const
38 Molecule::Molecule (Box b
, SCM func
)
51 Molecule::translate (Offset o
)
57 || isinf (o
[a
]) || isnan (o
[a
]))
59 programming_error ("Improbable offset for translation: setting to zero");
65 expr_
= gh_list (ly_symbol2scm ("translate-molecule"),
67 expr_
, SCM_UNDEFINED
);
74 Molecule::translate_axis (Real x
,Axis a
)
84 Molecule::add_molecule (Molecule
const &m
)
86 expr_
= gh_list (ly_symbol2scm ("combine-molecule"),
88 expr_
, SCM_UNDEFINED
);
93 Molecule::set_empty (bool e
)
97 dim_
[X_AXIS
].set_empty ();
98 dim_
[Y_AXIS
].set_empty ();
102 dim_
[X_AXIS
] = Interval(0,0);
103 dim_
[Y_AXIS
] = Interval (0,0);
108 Molecule::print () const
116 Molecule::align_to (Axis a
, Direction d
)
118 Interval
i (extent (a
));
119 Real r
= (d
== CENTER
) ? i
.center () : i
[d
];
120 translate_axis (-r
, a
);
125 Molecule::add_at_edge (Axis a
, Direction d
, Molecule
const &m
, Real padding
)
127 Real my_extent
= empty_b () ? 0.0 : dim_
[a
][d
];
128 Interval
i (m
.extent ()[a
]);
130 programming_error ("Molecule::add_at_edge: adding empty molecule.");
132 Real his_extent
= i
[-d
];
133 Real offset
= my_extent
- his_extent
;
135 toadd
.translate_axis (offset
+ d
* padding
, a
);
136 add_molecule (toadd
);
140 Molecule::empty_b () const
142 return expr_
== SCM_EOL
;
147 fontify_atom(Font_metric
* met
, SCM f
)
149 return gh_list (ly_symbol2scm ("fontify"),
150 ly_quote_scm (met
->description ()), f
, SCM_UNDEFINED
);