[EMAIL PROTECTED] writes:
> 
> [EMAIL PROTECTED] said:
> > [EMAIL PROTECTED] writes:
> > > There will always be TeX commands (or Postscript or whatever output
> > > language
> > > Lilypond will use) in text scripts and in lyrics, so it will always be
> > > impossible to calculate the exact extent of the text unless we
> > > implement
> > > TeX or call TeX and look at the output. However, the current solution
> > > (text_str_.length_i() * const) is not sufficient. It's probably better
> > > on 
> > > the average to count each TeX command as a single symbol in the
> > > approximation.
> >
> > That sounds like a passable solution for now.  
> 
> Here is a patch for the length calculations. Also changed the 
> alignment of textual scripts to LEFT. Even better would be to 
> set this from a property. 
> 

oops.  I had a go myself as well...


        Interval
        Text_def::width (Paper_def * p) const
        {
          Atom a = get_atom (p,CENTER);

          /* TODO: check string for \texcommand
           */
          const char * f = text_str_.ch_C ();
          const char *end = f + text_str_.length_i ();
          int l =0;
          for (; f < end; f++)
            {
              if (*f == '$')
                continue;
              l ++;
              if (*f == '\\')
                {
                  const char *g = f+1;
                  if (!isalpha (*g))
                    f = g;
                  else
                    for (; isalpha (*g); g++)
                      f = g;
                }
            }


          Real guess_width_f = l * a.dim_.x ().length (); // ugh
          Interval i (0, guess_width_f);
          i += - (align_dir_ + 1)* i.center();
          return i;
        }



Now I understand why patch didn't work :-)
>  
> -  /* TODO: check string for \texcommand
> -   */
>  
> -  Real guess_width_f = text_str_.length_i() * a.dim_.x ().length (); // ugh
> +  // Count each TeX command as one character, ugh
> +  int index, length=0;
> +  int total_length=text_str_.length_i();
> +  const char* str=text_str_.ch_C();
> +  for (index=0;index<total_length;index++) {
> +    length++;
> +    if (str[index]=='\\')
> +      for (index++;(index < total_length) && isalpha(str[index]);index++)
> +     ;
> +  }
> +  Real guess_width_f = length * a.dim_.x ().length (); // ugh
>    Interval i (0, guess_width_f);
>    i += - (align_dir_ + 1)* i.center();
[..]
> +  int total_length=text_str_.length_i();
> +  const char* str=text_str_.ch_C();
> +  for (index=0;index<total_length;index++) {
> +    length++;
> +    if (str[index]=='\\')
> +      for (index++;(index < total_length) && isalpha(str[index]);index++)
> +     ;

this looks like shared code.  Could it be merged into one function?


-- 

Han-Wen Nienhuys, [EMAIL PROTECTED] ** GNU LilyPond - The Music Typesetter 
      http://www.cs.uu.nl/people/hanwen/lilypond/index.html 

Reply via email to