]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hyphen-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / hyphen-engraver.cc
index 96ec03b3fcb54ae44514801aad4698b01160f721..e4f4f3a9918656e9923eabfcb711f44a0e45eecb 100644 (file)
@@ -2,63 +2,66 @@
   hyphen-engraver.cc -- implement Hyphen_engraver
 
   source file of the GNU LilyPond music typesetter
-  
-  (c) 1999--2004 Glen Prideaux <glenprideaux@iname.com>,
-                  Han-Wen Nienhuys <hanwen@cs.uu.nl>,
-                  Jan Nieuwenhuizen <janneke@gnu.org>
+
+  (c) 1999--2006 Glen Prideaux <glenprideaux@iname.com>,
+  Han-Wen Nienhuys <hanwen@xs4all.nl>,
+  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#include "warn.hh"
-#include "item.hh"
 #include "engraver.hh"
+#include "international.hh"
+#include "item.hh"
+#include "pointer-group-interface.hh"
 #include "spanner.hh"
+#include "warn.hh"
 
 class Hyphen_engraver : public Engraver
 {
-  Music* ev_;
-  Spanner* hyphen_;
-  Spanner * finished_hyphen_;  
+  Music *ev_;
+  Music *finished_ev_;
+
+  Spanner *hyphen_;
+  Spanner *finished_hyphen_;
+
 public:
   TRANSLATOR_DECLARATIONS (Hyphen_engraver);
 
 protected:
-  virtual void acknowledge_grob (Grob_info);
-  virtual void finalize ();
-  virtual bool try_music (Music*);
-  virtual void stop_translation_timestep ();
-  virtual void process_music ();
-private:
-
-};
 
+  DECLARE_ACKNOWLEDGER (lyric_syllable);
 
+  virtual void finalize ();
+  virtual bool try_music (Music *);
 
+  void stop_translation_timestep ();
+  void process_music ();
+};
 
 Hyphen_engraver::Hyphen_engraver ()
 {
   hyphen_ = 0;
   finished_hyphen_ = 0;
+  finished_ev_ = 0;
   ev_ = 0;
 }
 
 void
-Hyphen_engraver::acknowledge_grob (Grob_info i)
+Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i)
 {
-  Item * item =  dynamic_cast<Item*> (i.grob_);
-  // -> text_item
-  if (item && item->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
-    {
-      if (hyphen_)
-       hyphen_->set_bound (LEFT, item);
+  Item *item = i.item ();
+  
+  if (!hyphen_)
+    hyphen_ = make_spanner ("LyricSpace", item->self_scm ());
 
-      if (finished_hyphen_)
-       finished_hyphen_->set_bound (RIGHT, item);
-    }
+  if (hyphen_)
+    hyphen_->set_bound (LEFT, item);
+      
+  if (finished_hyphen_)
+    finished_hyphen_->set_bound (RIGHT, item);
 }
 
-
 bool
-Hyphen_engraver::try_music (Musicr)
+Hyphen_engraver::try_music (Music *r)
 {
   if (ev_)
     return false;
@@ -68,22 +71,16 @@ Hyphen_engraver::try_music (Music* r)
 }
 
 void
-completize_hyphen (Spannersp)
+completize_hyphen (Spanner *sp)
 {
   if (!sp->get_bound (RIGHT))
     {
-      SCM heads = sp->get_property ("heads");
-      if (gh_pair_p (heads))
-       {
-         Item* it = dynamic_cast<Item*> (unsmob_grob (gh_car (heads)));
-         if (it)
-           sp->set_bound (RIGHT, it);
-       }
+      extract_item_set (sp, "heads", heads);
+      if (heads.size ())
+       sp->set_bound (RIGHT, heads.back ());
     }
 }
 
-  
-
 void
 Hyphen_engraver::finalize ()
 {
@@ -93,11 +90,10 @@ Hyphen_engraver::finalize ()
 
       if (!hyphen_->get_bound (RIGHT))
        {
-         hyphen_->warning (_ ("unterminated hyphen; removing"));
+         hyphen_->warning (_ ("removing unterminated hyphen"));
          hyphen_->suicide ();
        }
 
-      typeset_grob (hyphen_);
       hyphen_ = 0;
     }
 
@@ -107,11 +103,11 @@ Hyphen_engraver::finalize ()
 
       if (!finished_hyphen_->get_bound (RIGHT))
        {
-         finished_hyphen_->warning (_("unterminated hyphen; removing"));
+         if (finished_ev_)
+           finished_hyphen_->warning (_ ("unterminated hyphen; removing"));
          finished_hyphen_->suicide ();
        }
-      typeset_grob (finished_hyphen_);
-      finished_hyphen_ =0;
+      finished_hyphen_ = 0;
     }
 }
 
@@ -119,43 +115,43 @@ void
 Hyphen_engraver::process_music ()
 {
   if (ev_)
-    {
-      hyphen_ = make_spanner ("LyricHyphen");
-      announce_grob (hyphen_, ev_->self_scm ());
-    }
+    hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ());
 }
 
-
 void
 Hyphen_engraver::stop_translation_timestep ()
 {
   if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
     {
-      typeset_grob (finished_hyphen_);
       finished_hyphen_ = 0;
+      finished_ev_ = 0;
     }
-
+  
   if (finished_hyphen_ && hyphen_)
     {
-      programming_error ("Haven't finished hyphen yet.");
-      typeset_grob (finished_hyphen_);
-      finished_hyphen_ =0;
+      programming_error ("hyphen not finished yet");
+      finished_hyphen_ = 0;
+      finished_ev_ = 0;
     }
-  
+
   if (hyphen_)
-    finished_hyphen_ = hyphen_;
+    {
+      finished_hyphen_ = hyphen_;
+      finished_ev_ = ev_;
+    }
+  
   hyphen_ = 0;
-
   ev_ = 0;
 }
 
+#include "translator.icc"
 
+ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
 
-
-ENTER_DESCRIPTION (Hyphen_engraver,
-/* descr */       "Create lyric hyphens",
-/* creats*/       "LyricHyphen",
-/* accepts */     "hyphen-event",
-/* acks  */      "lyric-syllable-interface",
-/* reads */       "",
-/* write */       "");
+ADD_TRANSLATOR (Hyphen_engraver,
+               /* doc */ "Create lyric hyphens and "
+               "distance constraints between words.",
+               /* create */ "LyricHyphen LyricSpace",
+               /* accept */ "hyphen-event",
+               /* read */ "",
+               /* write */ "");