.
In Depth Banner
Skip Navigation Links

Select your preferred language

Fully justified lines.

    /// <summary>

    /// Fully Justifies a line

    /// </summary>

    /// <param name="words">A reference to the collection of word positions that constitute the current line</param>

    public void JustifyLine(ref WordPosCollection words)

    {

      if(words.Count==0)

        return;

      if(words.ContainsNewline)

      {

        LeftJustifyLine(ref words);

        return;

      }

      TrimEnd(ref words);

      if(words.Count==0)

        return;

      TrimStart(ref words);

      if(words.Count==0)

        return;

      int lastTab = 0;

      int n=0;

      int spacecount=0;

      foreach(WordPos wp in words)

      {

        if(wp.WhiteSpace==WhiteSpace.Tab)

        {

          lastTab=n;

          spacecount=0;

        }

        if(wp.WhiteSpace==WhiteSpace.Space)

          spacecount++;

        n++;

      }

 

      WordPos lastWord = words.Last();

 

      float difference = ColumnWidth - GetLineLength(ref words);

 

      if(spacecount>0)

      {

        for(int i=lastTab;i<words.Count;i++)

        {

          if(words[i].WhiteSpace==WhiteSpace.Space)

            words[i].WordWidth+=difference/spacecount;

        }

      }

 

      RePos(ref words);

    }

 

Return to the article

Copyright © Bob Powell 2000-.  All rights reserved.