Académique Documents
Professionnel Documents
Culture Documents
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
namespace Text_to_Speech
{
public static class WordBreaker
{
/// <summary>
/// Returns a TextRange covering a word containing or following this Tex
tPointer.
/// </summary>
/// <remarks>
/// If this TextPointer is within a word or at start of word, the contai
ning word range is returned.
/// If this TextPointer is between two words, the following word range i
s returned.
/// If this TextPointer is at trailing word boundary, the following word
range is returned.
/// </remarks>
public static TextRange GetWordRange(TextPointer position)
{
TextRange wordRange = null;
TextPointer wordStartPosition = null;
TextPointer wordEndPosition = null;
if (wordEndPosition != null)
{
// Then travel backwards, to find word start position.
wordStartPosition = GetPositionAtWordBoundary(wordEndPosition, /
*wordBreakDirection*/LogicalDirection.Backward);
}
return wordRange;
}
/// <summary>
/// 1. When wordBreakDirection = Forward, returns a position at the end
of the word,
///
.
/// 3. Returns null when there is no workbreak in the requested directi
on.
/// </summary>
private static TextPointer GetPositionAtWordBoundary(TextPointer positio
n, LogicalDirection wordBreakDirection)
{
if (!position.IsAtInsertionPosition)
{
position = position.GetInsertionPosition(wordBreakDirection);
}
return navigator;
}
if (position.GetPointerContext(wordBreakDirection) == TextPointerCon
text.Text)
{
LogicalDirection oppositeDirection = (wordBreakDirection == Logi
calDirection.Forward) ?
LogicalDirection.Backward : LogicalDirection.Forward;
}
}
else
{
// If we're not adjacent to text then we always want to consider
this position a "word break".
// In practice, we're most likely next to an embedded object or
a block boundary.
isAtWordBoundary = true;
}
return isAtWordBoundary;
}
}
}