///
<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);
}
'/ <summary>
'/
Fully Justifies a line
'/
</summary>
'/
<param name="words">A reference to the collection of word positions that
constitute the current line</param>
Public
Sub JustifyLine(ByRef
words As WordPosCollection)
If
words.Count = 0 Then
Return
End
If
If
words.ContainsNewline Then
LeftJustifyLine(words)
Return
End
If
TrimEnd(words)
If
words.Count = 0 Then
Return
End
If
TrimStart(words)
If
words.Count = 0 Then
Return
End
If
Dim
lastTab As Integer
= 0
Dim
n As Integer = 0
Dim
spacecount As Integer
= 0
Dim
wp As WordPos
For
Each wp In words
If
wp.WhiteSpace = WhiteSpace.Tab Then
lastTab
= n
spacecount
= 0
End
If
If
wp.WhiteSpace = WhiteSpace.Space Then
spacecount
+= 1
End
If
n +=
1
Next
wp
Dim
lastWord As WordPos = words.Last()
Dim
difference As Single
= ColumnWidth - GetLineLength(words)
If
spacecount > 0 Then
Dim
i As Integer
For
i = lastTab To words.Count - 1
If
words(i).WhiteSpace = WhiteSpace.Space Then
words(i).WordWidth
+= difference / spacecount
End
If
Next
i
End
If
RePos(words)
End
Sub 'JustifyLine