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 #include <libc-extension.hh>
12 #include "font-metric.hh"
13 #include "dimensions.hh"
14 #include "interval.hh"
16 #include "molecule.hh"
18 #include "killing-cons.tcc"
20 #include "ly-smobs.icc"
24 Molecule::smobbed_copy () const
26 Molecule
* m
= new Molecule(*this);
28 return m
->smobbed_self ();
32 Molecule::extent(Axis a
) const
37 Molecule::Molecule (Box b
, SCM func
)
50 Molecule::translate (Offset o
)
56 || isinf (o
[a
]) || isnan (o
[a
]))
58 programming_error ("Improbable offset for translation: setting to zero");
64 expr_
= gh_list (ly_symbol2scm ("translate-molecule"),
66 expr_
, SCM_UNDEFINED
);
73 Molecule::translate_axis (Real x
,Axis a
)
83 Molecule::add_molecule (Molecule
const &m
)
85 expr_
= gh_list (ly_symbol2scm ("combine-molecule"),
87 expr_
, SCM_UNDEFINED
);
92 Molecule::set_empty (bool e
)
96 dim_
[X_AXIS
].set_empty ();
97 dim_
[Y_AXIS
].set_empty ();
101 dim_
[X_AXIS
] = Interval(0,0);
102 dim_
[Y_AXIS
] = Interval (0,0);
108 Molecule::align_to (Axis a
, Direction d
)
110 Interval
i (extent (a
));
111 Real r
= (d
== CENTER
) ? i
.center () : i
[d
];
112 translate_axis (-r
, a
);
116 Molecule::add_at_edge (Axis a
, Direction d
, Molecule
const &m
, Real padding
)
118 Real my_extent
= empty_b () ? 0.0 : dim_
[a
][d
];
119 Interval
i (m
.extent (a
));
123 programming_error ("Molecule::add_at_edge: adding empty molecule.");
129 Real offset
= my_extent
- his_extent
;
131 toadd
.translate_axis (offset
+ d
* padding
, a
);
132 add_molecule (toadd
);
136 Molecule::empty_b () const
138 return expr_
== SCM_EOL
;
142 fontify_atom(Font_metric
* met
, SCM f
)
147 return gh_list (ly_symbol2scm ("fontify"),
148 ly_quote_scm (met
->description_
), f
, SCM_UNDEFINED
);
152 Molecule::get_expr () const
160 Molecule::extent_box () const
164 IMPLEMENT_SIMPLE_SMOBS(Molecule
);
168 Molecule::print_smob (SCM s
, SCM port
, scm_print_state
*)
170 Molecule
*r
= (Molecule
*) gh_cdr (s
);
172 scm_puts ("#<Molecule ", port
);
173 /* String str(r->str());
174 scm_puts ((char *)str.ch_C(), port);*/
175 scm_puts (" >", port
);
182 Molecule::mark_smob (SCM s
)
184 Molecule
*r
= (Molecule
*) gh_cdr (s
);
189 IMPLEMENT_TYPE_P(Molecule
, "molecule?");
190 IMPLEMENT_DEFAULT_EQUAL_P(Molecule
);
191 IMPLEMENT_UNSMOB(Molecule
, molecule
);