]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/atom.cc
release: 1.3.25
[lilypond.git] / lily / atom.cc
index 119f2315ff1490cd61150c68d965d3960a9d4791..cc2bde40be01f211d289b59360968f200294e2f9 100644 (file)
@@ -3,9 +3,12 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include <math.h>
+#include "ly-smobs.icc"
+
 #include "atom.hh"
 #include "interval.hh"
 #include "string.hh"
 #include "lookup.hh"
 #include "main.hh"
 #include "global-ctor.hh"
+#include "font-metric.hh"
 
 Atom::Atom(SCM s)
 {
+  SCM onstack = s;             // protection. just to be sure.
   func_ = s;
-}
-
-
-#if 0
-int
-Atom::smob_display (SCM smob, SCM port, scm_print_state*)
-{
-  Atom* a =(Atom*) SCM_CDR(smob);
-  String i (a->off_.str ());
-  
-  scm_puts ("#<Atom ", port);
-  scm_puts (i.ch_C(), port);
-  gh_display (a->func_);
-  scm_puts (">", port);
-
-  /* non-zero means success */
-  return 1;
-}
-
-
-scm_sizet
-Atom::smob_free (SCM smob)
-{
-  Atom * a= (Atom*) SCM_CDR(smob);
-  delete a;
-  return sizeof (Atom);
+  self_scm_ = SCM_EOL;
+  smobify_self ();
 }
 
 SCM
-Atom::smob_mark (SCM smob) 
+Atom::mark_smob (SCM s)
 {
-  Atom * a= (Atom*) SCM_CDR(smob);
-  scm_gc_mark (a->func_);
-  return a->font_;
+  Atom*  a = SMOB_TO_TYPE(Atom, s);
+  assert (s == a->self_scm_);
+  return a->func_;
 }
 
-long Atom::smob_tag_;
-
 void
-Atom::init_smob ()
+Atom::fontify (Font_metric * met)
 {
-  static scm_smobfuns type_rec;
-
-  type_rec.mark = smob_mark;
-  type_rec.free = smob_free;
-  type_rec.print = smob_display;
-  type_rec.equalp = 0;
-
-  smob_tag_ = scm_newsmob (&type_rec);
+  SCM desc = ly_quote_scm (met->description ());
+  SCM font_switch = gh_list (ly_symbol2scm ("select-font"),
+                            desc,
+                            SCM_UNDEFINED);
+
+  SCM f =func_;
+  func_ = gh_list (ly_symbol2scm ("string-append"),
+                  font_switch , f,
+                  SCM_UNDEFINED);
 }
 
-
-SCM
-Atom::make_smob () const
-{
-  SCM smob;
-  SCM_NEWCELL (smob);
-  SCM_SETCAR (smob, smob_tag_);
-  SCM_SETCDR (smob, this);
-  return smob;
-}
-
-SCM
-Atom::make_atom (SCM outputfunc)
+void
+Atom::do_smobify_self ()
 {
-  Atom * a= new Atom(outputfunc);
-  return a->make_smob ();
 }
 
-SCM
-Atom::copy_self () const
+Atom::Atom (Atom const &s)
 {
-  return (new Atom (*this))->make_smob ();
+  off_ = s.off_;
+  func_ = s.func_;
+  self_scm_= SCM_EOL;
+  smobify_self ();
 }
-
-bool
-Atom::Atom_b (SCM obj)
+int
+Atom::print_smob (SCM s, SCM p, scm_print_state*)
 {
-  return(SCM_NIMP(obj) && SCM_CAR(obj) == smob_tag_);
-}
+  Atom * a = unsmob_atom (s);
 
-Atom* 
-Atom::atom_l (SCM a)
-{
-  assert (Atom_b (a));
-  return (Atom*) SCM_CDR(a);
+  scm_puts ("#<Atom off ",p);
+  String str(a->off_.str ());
+  scm_puts ((char *)str.ch_C(), p);
+  scm_display (a->func_, p);
+  scm_puts ("> ",p);  
+  return 1;
 }
-
-
-ADD_GLOBAL_CTOR_WITHNAME(atomsmob, Atom::init_smob);
-#endif
-
+  
+IMPLEMENT_UNSMOB(Atom, atom)
+IMPLEMENT_SMOBS(Atom)