-#include "musicalrequest.hh"
-#include "paper-def.hh"
+/*
+ script.cc -- implement Script_interface
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ */
+
+#include "directional-element-interface.hh"
+#include "warn.hh"
#include "script.hh"
-#include "stem.hh"
+#include "font-interface.hh"
+#include "side-position-interface.hh"
+#include "paper-def.hh"
+#include "item.hh"
#include "molecule.hh"
#include "lookup.hh"
+#include "stem.hh"
+#include "note-column.hh"
-
-
-void
-Script::set_stem(Stem*st_l)
+Molecule
+Script_interface::get_molecule (Grob * me, Direction d)
{
- stem_l_ = st_l;
- add_dependency(st_l);
-}
+ SCM s = me->get_grob_property ("script-molecule");
+ assert (gh_pair_p (s));
-void
-Script::set_support(Item*i)
-{
- support.push(i);
- add_dependency(i);
-}
+ SCM key = ly_car (s);
+ if (key == ly_symbol2scm ("feta"))
+ {
+ SCM name_entry = ly_cdr (s);
-Script::Script(Script_req* rq, int staflen)
-{
- staffsize =staflen;
- specs_l_ = rq->scriptdef_p_;
- stem_l_ = 0;
- pos = 0;
- symdir=1;
- dir =rq->dir_i_;
-}
+ SCM str = (gh_pair_p (name_entry)) ? index_get_cell (name_entry, d) : name_entry;
+ return Font_interface::get_default_font (me)->find_by_name ("scripts-" +
+ ly_scm2string (str));
+ }
+ else if (key == ly_symbol2scm ("accordion"))
+ {
+ return Lookup::accordion (ly_cdr (s), 1.0, Font_interface::get_default_font (me));
+ }
+ else
+ assert (false);
-void
-Script::set_symdir()
-{
- if (specs_l_->invertsym)
- symdir = (dir < 0) ? -1:1;
+ return Molecule ();
}
-void
-Script::set_default_dir()
+MAKE_SCHEME_CALLBACK (Script_interface,before_line_breaking,1);
+SCM
+Script_interface::before_line_breaking (SCM smob)
{
- if (specs_l_->stemdir) {
- if (!stem_l_)
- dir = 1;
- else
- dir = stem_l_->dir * specs_l_->stemdir;
- }
-}
+ Grob * me = unsmob_grob (smob);
-Interval
-Script::support_height() const return r;
-{
- for (int i=0; i < support.size(); i++)
- r.unite(support[i]->height());
-}
+ Direction d = Side_position_interface::get_direction (me);
-void
-Script::set_default_index()
-{
- Real inter_f= paper()->internote();
- Interval dy = symbol().dim.y;
-
- int d = specs_l_->staffdir;
- Real y ;
- if (!d) {
- Interval v= support_height();
- y = v[dir] -dy[-dir] + 2*dir*inter_f;
- } else {
- y = (d > 0) ? staffsize + 2: -2; // ug
- y *=inter_f;
- Interval v= support_height();
-
- if (d > 0) {
- y = y >? v.max();
- } else if (d < 0) {
- y = y <? v.min();
- }
+ if (!d)
+ {
+ /*
+ we should not have `arbitrary' directions.
+ */
+ programming_error ("Script direction not yet known!");
+ d = DOWN;
}
-
- if (stem_l_) {
- Interval v= stem_l_->height();
-
- if (d > 0 || (!d && dir > 0)) {
- y = y >? v.max();
- }else if (d < 0 || (!d && dir < 0)) {
- y = y <? v.min();
+
+ set_grob_direction (me, d);
+
+ if (Grob * par = me->get_parent (X_AXIS))
+ {
+ Grob * stem = Note_column::get_stem (par);
+ if (stem && Stem::first_head (stem))
+ {
+ me->set_parent (Stem::first_head (stem), X_AXIS);
}
}
-
- pos = int(rint(Real(y)/inter_f));
+
+ return SCM_UNSPECIFIED;
}
-Interval
-Script::width() const
-{
- return symbol().dim.x;
-}
-Symbol
-Script::symbol()const
-{
- String preidx_str = (symdir < 0) ?"-" :"";
- return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
-}
+MAKE_SCHEME_CALLBACK (Script_interface,brew_molecule,1);
-void
-Script::do_pre_processing()
+SCM
+Script_interface::brew_molecule (SCM smob)
{
- set_default_dir();
- set_symdir();
+ Grob *me= unsmob_grob (smob);
+
+ Direction dir = Side_position_interface::get_direction (me);
+ if (!dir)
+ {
+ programming_error ("Script direction not known, but molecule wanted.");
+ dir= DOWN;
+ }
+
+ return get_molecule (me, dir).smobbed_copy ();
}
-void
-Script::do_post_processing()
+
+
+struct Text_script
{
- set_default_index();
-}
+ static bool has_interface (Grob*);
+};
-Molecule*
-Script::brew_molecule_p() const
+struct Skript
{
- Real dy = paper()->internote();
-
- Molecule*out = new Molecule(Atom(symbol()));
- out->translate(Offset(0,dy * pos));
- return out;
-}
+ static bool has_interface (Grob*);
+};
+
+ADD_INTERFACE (Text_script,"text-script-interface",
+ "Any text script",
+ "script-priority");
+
+ADD_INTERFACE (Script_interface, "script-interface",
+ "",
+ "script-priority script-molecule");
+