]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/text-engraver.cc
release: 1.3.55
[lilypond.git] / lily / text-engraver.cc
index ba48473450e0da8ea869d48cb70cac022a7e183d..a3d72332f9f13b6ce1b623d8f9f6099d877cd14b 100644 (file)
@@ -3,47 +3,43 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
+#include "dimension-cache.hh"
 #include "engraver.hh"
-#include "g-staff-side.hh"
-#include "g-text-item.hh"
-#include "text-def.hh"
+#include "side-position-interface.hh"
+#include "text-item.hh"
+#include "musical-request.hh"
 #include "note-head.hh"
 #include "stem.hh"
-#include "staff-sym.hh"
+#include "staff-symbol.hh"
 
+/**
+   typeset directions that are  plain text.
+ */
 class Text_engraver : public Engraver
 {
-  Link_array<Script_req> reqs_;
-  Link_array<G_staff_side_item> positionings_;
-  Link_array<G_text_item> texts_;
+  Link_array<Text_script_req> reqs_;
+  Link_array<Text_item> texts_;
 public:
-  Text_engraver();
+
   VIRTUAL_COPY_CONS(Translator);
 protected:
   virtual bool do_try_music (Music* m);
   virtual void do_pre_move_processing ();
   virtual void do_post_move_processing ();
-  virtual void do_process_requests ();
+  virtual void do_process_music ();
   virtual void acknowledge_element (Score_element_info);
 };
 
-Text_engraver::Text_engraver ()
-{
-  
-}
 
 bool
 Text_engraver::do_try_music (Music *m)
 {
-  if (Script_req *r = dynamic_cast<Script_req*> (m))
+  if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
     {
-      Text_def * t = dynamic_cast<Text_def*> (r->scriptdef_p_);
-      if (!t)
-       return false;
       reqs_.push (r);
       return true;
     }
@@ -56,59 +52,80 @@ Text_engraver::acknowledge_element (Score_element_info i)
 {
   if (Note_head *n = dynamic_cast<Note_head*> (i.elem_l_))
     {
-      for (int i=0; i < positionings_.size (); i++)
+      for (int i=0; i < texts_.size (); i++)
        {
-         positionings_[i]->add_support (n);
+         Side_position_interface st (texts_[i]);
+         st.add_support (n);
+         if (st.get_axis( ) == X_AXIS
+             && !texts_[i]->parent_l (Y_AXIS))
+           texts_[i]->set_parent (n, Y_AXIS);
        }
     }
   if (Stem *n = dynamic_cast<Stem*> (i.elem_l_))
     {
-      for (int i=0; i < positionings_.size (); i++)
+      for (int i=0; i < texts_.size (); i++)
        {
-         positionings_[i]->add_support (n);
+         Side_position_interface st(texts_[i]);
+         st.add_support (n);
        }
     }
 }
 
 void
-Text_engraver::do_process_requests ()
+Text_engraver::do_process_music ()
 {
   for (int i=0; i < reqs_.size (); i++)
     {
-      Script_req * r = reqs_[i];
-      Text_def * t= dynamic_cast<Text_def*> (r->scriptdef_p_);
+      Text_script_req * r = reqs_[i];
 
-      G_text_item *text = new G_text_item;
-      G_staff_side_item *ss = new G_staff_side_item;
-      ss->set_victim (text);
-      ss->dir_ = r->dir_;
+      Text_item *text = new Text_item (SCM_EOL);
+      Side_position_interface stafy (text);
 
-      text->text_str_ = t->text_str_;
+      SCM axisprop = get_property ("scriptHorizontal");
+      if (to_boolean (axisprop))
+       {
+         stafy.set_axis (X_AXIS);
+         //      text->set_parent (ss, Y_AXIS);
+       }
+      else
+       stafy.set_axis (Y_AXIS);
 
-      announce_element (Score_element_info (text, r));
-      announce_element (Score_element_info (ss, r));
+      /*
+       make sure they're in order by adding i to the priority field.
+       */
+      text->set_elt_property ("script-priority",
+                           gh_int2scm (200 + i));
 
+      if (r->get_direction ())
+       stafy.set_direction (r->get_direction ());
+      
+      text->set_elt_property ("text",
+                             ly_str02scm ( r->text_str_.ch_C ()));
+      
+      if (r->style_str_.length_i ())
+       text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
+      
+      SCM empty = get_property ("textNonEmpty");
+      if (!to_boolean (empty))
+       {
+         text->set_elt_property ("no-spacing-rods" , SCM_BOOL_T);
+         text->set_extent_callback (0, X_AXIS);
+       }
+      announce_element (Score_element_info (text, r));
       texts_.push (text);
-      positionings_.push (ss);
     }
 }
 
 void
 Text_engraver::do_pre_move_processing ()
 {
-  Staff_symbol* s_l = get_staff_info().staff_sym_l_;
   for (int i=0; i < texts_.size (); i++)
     {
-      if (s_l != 0)
-       {
-         positionings_[i]->add_support (s_l);
-       }
-
-      typeset_element (texts_[i]);
-      typeset_element (positionings_[i]);
+      Text_item *ti = texts_[i];
+      Side_position_interface (ti).add_staff_support ();
+      typeset_element (ti);
     }
   texts_.clear ();
-  positionings_.clear ();
 }
 
 void
@@ -118,3 +135,4 @@ Text_engraver::do_post_move_processing ()
 }
 
 ADD_THIS_TRANSLATOR(Text_engraver);
+