]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/syllable-group.cc
nested grace beams
[lilypond.git] / lily / syllable-group.cc
index afe3ad10788c0b56567053b0b4766c680510a65a..506f6a466dc548f9563f7ef91514377f932c6f0e 100644 (file)
@@ -104,7 +104,7 @@ Syllable_group::set_lyric_align (const char *punc, Grob *default_notehead_l)
 
   Grob * lyric;
   alignment_i_ = appropriate_alignment (punc);
-
+  
   // If there was no notehead in the matching voice context, use the first 
   // notehead caught from any voice context (any port in a storm).
   if (!notehead_l_) {
@@ -120,7 +120,7 @@ Syllable_group::set_lyric_align (const char *punc, Grob *default_notehead_l)
     // centre on notehead ... if we have one. 
     if (notehead_l_) {
       lyric->set_parent (notehead_l_, X_AXIS);
-      lyric->add_offset_callback (Side_position_interface::centered_on_parent_proc, X_AXIS);
+      lyric->add_offset_callback (Self_alignment_interface::centered_on_parent_proc, X_AXIS);
       // reference is on the right of the notehead; move it left half way, and add translation
       lyric->translate_axis (group_translation_f_- (notehead_l_->extent (notehead_l_, X_AXIS)).center (), X_AXIS);
     }
@@ -131,7 +131,7 @@ Syllable_group::set_lyric_align (const char *punc, Grob *default_notehead_l)
 /** determine the distance to translate lyrics to get correct alignment
     Rules: If alignment is centre, translate = 0
            Otherwise,
-             If (length of longest lyric) < 2 * (length of shortest lyric),
+             If (length of longest lyric) < (property {begin,end}-alignment) * (length of shortest lyric),
                 - centre longest lyric on notehead
              Otherwise
                 - move so shortest lyric just reaches notehead centre
@@ -141,11 +141,20 @@ Syllable_group::amount_to_translate ()
 {
   Real translate = 0.0;
   if (alignment_i_ != CENTER) {
-    // FIXME: do we really know the lyric extent here? Some font sizing comes later?
-    Real l1 = longest_lyric_l_->extent (longest_lyric_l_, X_AXIS).length () / 2;
-    Real l2 = shortest_lyric_l_->extent (shortest_lyric_l_, X_AXIS).length ();
-
-    translate = l1 <? l2;
+    switch (alignment_i_) {
+      // FIXME: do we really know the lyric extent here? Some font sizing comes later?
+    case LEFT: 
+      translate =  longest_lyric_l_->extent (longest_lyric_l_, X_AXIS).length () / gh_scm2double (longest_lyric_l_->get_grob_property("begin-alignment"));
+      break;
+    case RIGHT: 
+      translate =   longest_lyric_l_->extent (longest_lyric_l_, X_AXIS).length () / gh_scm2double (longest_lyric_l_->get_grob_property("end-alignment"));
+      break;
+    }
+    if (!gh_scm2bool(longest_lyric_l_->get_grob_property("ignore-length-mismatch"))) {
+      Real l = shortest_lyric_l_->extent (shortest_lyric_l_, X_AXIS).length ();
+      translate = l <? translate;
+    }
+    
     translate *= alignment_i_ ;
   }
   return translate;
@@ -153,13 +162,20 @@ Syllable_group::amount_to_translate ()
 
 
 /** determine what alignment we want.
-    Rules: if first_in_phrase_b_ is set, then alignment is LEFT.
+    Rules: if property alignment is set it specifies the alignment
+           if first_in_phrase_b_ is set, then alignment is LEFT.
            otherwise if each syllable ends in punctuation, then alignment is RIGHT
           otherwise alignment is centre.
 */
 int 
 Syllable_group::appropriate_alignment (const char *punc)
 {
+
+  SCM s=this->longest_lyric_l_->get_grob_property ("alignment");
+    if (s!=SCM_EOL) {
+      return gh_scm2int (s);
+    }
+
   if (first_in_phrase_b_)
     return LEFT;
 
@@ -175,7 +191,10 @@ Syllable_group::appropriate_alignment (const char *punc)
       lastchar = lyric_str[lyric_str.length_i ()-1];
       /* If it doesn't end in punctuation then it ain't an end of phrase */
       if (! strchr (punc, lastchar)) {
-       /* Special case: trailing space. Here examine the previous character and reverse the
+       /*
+         FIXME: Document this.
+         
+         Special case: trailing space. Here examine the previous character and reverse the
           sense of the test (i.e. trailing space makes a break without punctuation, or 
           suppresses a break with punctuation).
           This behaviour can be suppressed by including a space in the 
@@ -256,7 +275,7 @@ Syllable_group::print_smob (SCM, SCM port, scm_print_state *)
   return 1;
 }
 
-IMPLEMENT_UNSMOB (Syllable_group, voice_entry);
+
 IMPLEMENT_SIMPLE_SMOBS (Syllable_group);
 IMPLEMENT_DEFAULT_EQUAL_P (Syllable_group);
 
@@ -266,3 +285,12 @@ Syllable_group::make_entry ()
   Syllable_group *vi = new Syllable_group;
   return vi->smobbed_self ();
 }
+
+struct Lyric_syllable
+{
+    static bool has_interface (Grob*);
+};
+ADD_INTERFACE (Lyric_syllable,"lyric-syllable-interface",
+  "a single piece of lyrics",
+  "word-space alignment ignore-length-mismatch begin-alignment end-alignment");
+