本文整理汇总了C#中TextUnit类的典型用法代码示例。如果您正苦于以下问题:C# TextUnit类的具体用法?C# TextUnit怎么用?C# TextUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextUnit类属于命名空间,在下文中一共展示了TextUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: switch
void ITextRangeProvider.ExpandToEnclosingUnit(TextUnit unit)
{
Misc.SetFocus(_pattern._hwnd);
switch (unit)
{
case TextUnit.Format:
{
// take the minimum of expanding by character and paragraph formatting.
ITextRange charRange = _range.GetDuplicate();
charRange.Expand(TomUnit.tomCharFormat);
ITextRange paraRange = _range.GetDuplicate();
paraRange.Expand(TomUnit.tomParaFormat);
_range.SetRange(Math.Max(charRange.Start, paraRange.Start), Math.Min(charRange.End, paraRange.End));
}
break;
default:
_range.Expand(TomUnitFromTextUnit(unit, "unit"));
break;
}
}
示例2: Normalize
/// <summary>
/// Moves one endpoint of the range the specified number of units in the text.
/// If the endpoint being moved crosses the other endpoint then the other endpoint
/// is moved along too resulting in a degenerate range and ensuring the correct ordering
/// of the endpoints. (i.e. always Start<=End)
/// </summary>
/// <param name="endpoint">The endpoint to move.</param>
/// <param name="unit">The textual unit for moving.</param>
/// <param name="count">The number of units to move. A positive count moves the endpoint forward.
/// A negative count moves backward. A count of 0 has no effect.</param>
/// <returns>The number of units actually moved, which can be less than the number requested if
/// moving the endpoint runs into the beginning or end of the document.</returns>
int ITextRangeProvider.MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
{
Normalize();
int movedCount = 0;
if (count != 0)
{
// Move endpoint by number of units.
bool start = (endpoint == TextPatternRangeEndpoint.Start);
ITextPointer positionRef = start ? _start : _end;
ITextPointer position = positionRef.CreatePointer();
if (MoveToUnitBoundary(position, start, count < 0 ? LogicalDirection.Backward : LogicalDirection.Forward, unit))
{
movedCount = (count > 0) ? 1 : -1;
}
if (count != movedCount)
{
movedCount += MovePositionByUnits(position, unit, count - movedCount);
}
// If endpoint has been moved at least by one unit, snap it to TextUnit boundary,
// because movement done by MovePositionByUnits does not guarantee position snapping.
if ((count > 0 && position.CompareTo(positionRef) > 0) ||
(count < 0 && position.CompareTo(positionRef) < 0) ||
(position.CompareTo(positionRef) == 0 && position.LogicalDirection != positionRef.LogicalDirection))
{
if (start)
{
_start = position;
}
else
{
_end = position;
}
if (unit != TextUnit.Page)
{
ExpandToEnclosingUnit(unit, start, !start);
}
// If endpoint has been moved, but 'movedCount' is 0, it means that we snapped to neariest
// unit boundary. Treat this situation as actual move.
if (movedCount == 0)
{
movedCount = (count > 0) ? 1 : -1;
}
}
// Ensure the correct ordering of the endpoint.
if (_start.CompareTo(_end) > 0)
{
if (start)
{
_end = _start.CreatePointer();
}
else
{
_start = _end.CreatePointer();
}
}
}
return movedCount;
}
示例3: Move
public int Move(TextUnit unit, int count)
{
Log("{0}.Move({1}, {2})", ID, unit, count);
int movedCount = MoveEndpointByUnit(TextPatternRangeEndpoint.Start, unit, count);
segment = new SimpleSegment(segment.Offset, 0); // Collapse to empty range
ExpandToEnclosingUnit(unit);
return movedCount;
}
示例4: win32_IdentifySupportedTextUnits
//-------------------------------------------------------------------
// Identify supported TextUnits in Win32
//-------------------------------------------------------------------
internal static TextUnit win32_IdentifySupportedTextUnits(AutomationElement element, TextUnit targetUnit)
{
return TextLibraryCount.win32_IdentifySupportedTextUnits(element, targetUnit);
}
示例5: Win32CountTextUnit
/// -------------------------------------------------------------------
/// <summary>
/// Count a single TextUnit
/// </summary>
/// -------------------------------------------------------------------
internal static int Win32CountTextUnit(TextUnit textUnit, TextPatternRange rangeToCount)
{
return Win32CountTextUnit(textUnit, rangeToCount);
}
示例6: Token
/// <summary>
/// Constructor.
/// </summary>
/// <param name="unit">TextUnit</param>
/// <param name="type">TokenType</param>
public Token(TextUnit unit, TokenType type)
{
this.TextUnit = unit;
this.Text = unit.Text;
this.Type = type;
}
示例7: Visit
/// <summary>
/// Visits the syntax node.
/// </summary>
/// <param name="parentNode">Node</param>
internal void Visit(StateDeclaration parentNode)
{
if (parentNode.Machine.IsMonitor)
{
throw new ParsingException("Monitors cannot \"defer\".",
new List<TokenType>());
}
base.TokenStream.Index++;
base.TokenStream.SkipWhiteSpaceAndCommentTokens();
var nameVisitor = new NameVisitor(base.TokenStream);
// Consumes multiple generic event names.
var eventIdentifiers =
nameVisitor.ConsumeMultipleNames(TokenType.EventIdentifier,
tt => nameVisitor.ConsumeGenericEventName(tt));
var resolvedEventIdentifiers = new Dictionary<Token, List<Token>>();
foreach (var eventIdentifier in eventIdentifiers)
{
if (eventIdentifier.Count == 1)
{
// We don't want to collapse halt and default
// events to event identifiers.
resolvedEventIdentifiers.Add(eventIdentifier[0], eventIdentifier);
}
else
{
var identifierBuilder = new StringBuilder();
foreach (var token in eventIdentifier)
{
identifierBuilder.Append(token.TextUnit.Text);
}
TextUnit textUnit = new TextUnit(identifierBuilder.ToString(),
eventIdentifier[0].TextUnit.Line);
resolvedEventIdentifiers.Add(new Token(textUnit, TokenType.EventIdentifier),
eventIdentifier);
}
}
foreach (var kvp in resolvedEventIdentifiers)
{
if (!parentNode.AddDeferredEvent(kvp.Key, kvp.Value))
{
throw new ParsingException("Unexpected defer declaration.",
new List<TokenType>());
}
}
if (!base.TokenStream.Done &&
base.TokenStream.Peek().Type == TokenType.Identifier)
{
throw new ParsingException("Expected \",\".",
new List<TokenType>
{
TokenType.Comma
});
}
if (!base.TokenStream.Done &&
(base.TokenStream.Peek().Type == TokenType.LeftAngleBracket ||
base.TokenStream.Peek().Type == TokenType.RightAngleBracket))
{
throw new ParsingException("Invalid generic expression.",
new List<TokenType> { });
}
if (base.TokenStream.Done ||
base.TokenStream.Peek().Type != TokenType.Semicolon)
{
throw new ParsingException("Expected \";\".",
new List<TokenType>
{
TokenType.Semicolon
});
}
}
示例8: Move
public int Move(TextUnit unit, int count)
{
return 0;
}
示例9: if
int ITextRangeProvider.MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
{
Misc.SetFocus(_provider._hwnd);
// positive count means move forward. negative count means move backwards.
int moved = 0;
bool moveStart = endpoint == TextPatternRangeEndpoint.Start;
int start = Start;
int end = End;
if (count > 0)
{
if (moveStart)
{
Start = MoveEndpointForward(Start, unit, count, out moved);
// if the start did not change then no move was done.
if (start == Start)
{
moved = 0;
}
}
else
{
End = MoveEndpointForward(End, unit, count, out moved);
// if the end did not change then no move was done.
if (end == End)
{
moved = 0;
}
}
}
else if (count < 0)
{
if (moveStart)
{
Start = MoveEndpointBackward(Start, unit, count, out moved);
// if the start did not change then no move was done.
if (start == Start)
{
moved = 0;
}
}
else
{
End = MoveEndpointBackward(End, unit, count, out moved);
// if the end did not change then no move was done.
if (end == End)
{
moved = 0;
}
}
}
else
{
// moving zero of any unit has no effect.
moved = 0;
}
return moved;
}
示例10: MoveEndpointByUnit
public int MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
{
try
{
return this._range.MoveEndpointByUnit(
(UIAutomationClient.TextPatternRangeEndpoint)endpoint,
(UIAutomationClient.TextUnit)unit,
count);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
示例11: ExpandToEnclosingUnit
public void ExpandToEnclosingUnit(TextUnit unit)
{
try
{
this._range.ExpandToEnclosingUnit((UIAutomationClient.TextUnit)unit);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
示例12: MovePositionByUnits
/// <summary>
/// Re-positions the given position by an integral number of text units, but it does
/// not guarantee that position is snapped to TextUnit boundary.
/// This method assumes that input position is already snapped to appropriate TextUnit boundary.
/// </summary>
/// <param name="position">The position to move</param>
/// <param name="unit">Text units to step by</param>
/// <param name="count">Number of units to step over. Also specifies the direction of moving:
/// forward if positive, backward otherwise</param>
/// <returns>The actual number of units the position was moved over</returns>
private int MovePositionByUnits(ITextPointer position, TextUnit unit, int count)
{
ITextView textView;
int moved = 0;
int absCount = (count == int.MinValue) ? int.MaxValue : Math.Abs(count);
LogicalDirection direction = (count > 0) ? LogicalDirection.Forward : LogicalDirection.Backward;
// This method assumes that position is already snapped to appropriate TextUnit.
switch (unit)
{
case TextUnit.Character:
while (moved < absCount)
{
if (!TextPointerBase.MoveToNextInsertionPosition(position, direction))
{
break;
}
moved++;
}
break;
case TextUnit.Word:
while (moved < absCount)
{
if (!MoveToNextWordBoundary(position, direction))
{
break;
}
moved++;
}
break;
case TextUnit.Format:
// Formatting changes can be introduced by elements. Hence it is fair to
// assume that formatting boundaries are defined by non-text context.
while (moved < absCount)
{
ITextPointer positionOrig = position.CreatePointer();
// First skip all text in given direction.
while (position.GetPointerContext(direction) == TextPointerContext.Text)
{
if (!position.MoveToNextContextPosition(direction))
{
break;
}
}
// Move to next context
if (!position.MoveToNextContextPosition(direction))
{
break;
}
// Skip all formatting elements and position the pointer next to text.
while (position.GetPointerContext(direction) != TextPointerContext.Text)
{
if (!position.MoveToNextContextPosition(direction))
{
break;
}
}
// If moving backwards, position the pointer at the beginning of formatting range.
if (direction == LogicalDirection.Backward)
{
while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text)
{
if (!position.MoveToNextContextPosition(LogicalDirection.Backward))
{
break;
}
}
}
if (position.GetPointerContext(direction) != TextPointerContext.None)
{
moved++;
}
else
{
position.MoveToPosition(positionOrig);
break;
}
}
// Adjust logical direction to point to the following text (forward or backward movement).
// If we don't do this, we'll normalize in the wrong direction and get stuck in a loop
// if caller tries to advance again.
position.SetLogicalDirection(LogicalDirection.Forward);
break;
//.........这里部分代码省略.........
示例13: MoveToUnitBoundary
/// <summary>
/// Moves the position to the closes unit boundary.
/// </summary>
private bool MoveToUnitBoundary(ITextPointer position, bool isStart, LogicalDirection direction, TextUnit unit)
{
bool moved = false;
ITextView textView;
switch (unit)
{
case TextUnit.Character:
if (!TextPointerBase.IsAtInsertionPosition(position))
{
if (TextPointerBase.MoveToNextInsertionPosition(position, direction))
{
moved = true;
}
}
break;
case TextUnit.Word:
if (!IsAtWordBoundary(position))
{
if (MoveToNextWordBoundary(position, direction))
{
moved = true;
}
}
break;
case TextUnit.Format:
// Formatting changes can be introduced by elements. Hence it is fair to
// assume that formatting boundaries are defined by non-text context.
while (position.GetPointerContext(direction) == TextPointerContext.Text)
{
if (position.MoveToNextContextPosition(direction))
{
moved = true;
}
}
// Make sure we end with text on the right, so that later ExpandToEnclosingUnit calls
// do the right thing.
if (moved && direction == LogicalDirection.Forward)
{
while (true)
{
TextPointerContext context = position.GetPointerContext(LogicalDirection.Forward);
if (context != TextPointerContext.ElementStart && context != TextPointerContext.ElementEnd)
break;
position.MoveToNextContextPosition(LogicalDirection.Forward);
}
}
break;
case TextUnit.Line:
// Positions are snapped to closest line boundaries. But since line information
// is based on the layout, positions are not changed, if:
// a) they are not currently in the view, or
// b) containing line cannot be found.
textView = _textAdaptor.GetUpdatedTextView();
if (textView != null && textView.IsValid && textView.Contains(position))
{
TextSegment lineRange = textView.GetLineRange(position);
if (!lineRange.IsNull)
{
double newSuggestedX;
int linesMoved = 0;
if (direction == LogicalDirection.Forward)
{
ITextPointer nextLineStart = null;
if (isStart)
{
nextLineStart = textView.GetPositionAtNextLine(lineRange.End, Double.NaN, 1, out newSuggestedX, out linesMoved);
}
if (linesMoved != 0)
{
lineRange = textView.GetLineRange(nextLineStart);
nextLineStart = lineRange.Start;
}
else
{
nextLineStart = lineRange.End;
}
nextLineStart = GetInsertionPosition(nextLineStart, LogicalDirection.Forward);
if (position.CompareTo(nextLineStart) != 0)
{
position.MoveToPosition(nextLineStart);
position.SetLogicalDirection(isStart ? LogicalDirection.Forward : LogicalDirection.Backward);
moved = true;
}
}
else
{
ITextPointer previousLineEnd = null;
//.........这里部分代码省略.........
示例14: ExpandToEnclosingUnit
/// <summary>
/// Expands the range to an integral number of enclosing units. If the range is already an
/// integral number of the specified units then it remains unchanged.
/// </summary>
private void ExpandToEnclosingUnit(TextUnit unit, bool expandStart, bool expandEnd)
{
ITextView textView;
switch (unit)
{
case TextUnit.Character:
if (expandStart && !TextPointerBase.IsAtInsertionPosition(_start))
{
TextPointerBase.MoveToNextInsertionPosition(_start, LogicalDirection.Backward);
}
if (expandEnd && !TextPointerBase.IsAtInsertionPosition(_end))
{
TextPointerBase.MoveToNextInsertionPosition(_end, LogicalDirection.Forward);
}
break;
case TextUnit.Word:
if (expandStart && !IsAtWordBoundary(_start))
{
MoveToNextWordBoundary(_start, LogicalDirection.Backward);
}
if (expandEnd && !IsAtWordBoundary(_end))
{
MoveToNextWordBoundary(_end, LogicalDirection.Forward);
}
break;
case TextUnit.Format:
// Formatting changes can be introduced by elements. Hence it is fair to
// assume that formatting boundaries are defined by non-text context.
if (expandStart)
{
TextPointerContext forwardContext = _start.GetPointerContext(LogicalDirection.Forward);
while (true)
{
TextPointerContext backwardContext = _start.GetPointerContext(LogicalDirection.Backward);
if (backwardContext == TextPointerContext.None)
break;
if (forwardContext == TextPointerContext.Text && backwardContext != TextPointerContext.Text)
break;
forwardContext = backwardContext;
_start.MoveToNextContextPosition(LogicalDirection.Backward);
}
}
if (expandEnd)
{
TextPointerContext backwardContext = _end.GetPointerContext(LogicalDirection.Backward);
while (true)
{
TextPointerContext forwardContext = _end.GetPointerContext(LogicalDirection.Forward);
if (forwardContext == TextPointerContext.None)
break;
if (forwardContext == TextPointerContext.Text && backwardContext != TextPointerContext.Text)
break;
backwardContext = forwardContext;
_end.MoveToNextContextPosition(LogicalDirection.Forward);
}
}
// Set LogicalDirection to prevent end points from crossing a formatting
// boundary when normalized.
_start.SetLogicalDirection(LogicalDirection.Forward);
_end.SetLogicalDirection(LogicalDirection.Forward);
break;
case TextUnit.Line:
// Positions are snapped to closest line boundaries. But since line information
// is based on the layout, positions are not changed, if:
// a) they are not currently in the view, or
// b) containing line cannot be found.
textView = _textAdaptor.GetUpdatedTextView();
if (textView != null && textView.IsValid)
{
bool snapEndPosition = true;
if (expandStart && textView.Contains(_start))
{
TextSegment lineRange = textView.GetLineRange(_start);
if (!lineRange.IsNull)
{
// Move start position to the beginning of containing line.
if (_start.CompareTo(lineRange.Start) != 0)
{
_start = lineRange.Start.CreatePointer();
}
// If this line contains also end position, move it to the
// end of this line.
if (lineRange.Contains(_end))
{
snapEndPosition = false;
if (_end.CompareTo(lineRange.End) != 0)
//.........这里部分代码省略.........
示例15: SummarizationInformationContainer
public SummarizationInformationContainer()
{
TextUnit = new TextUnit
{
RawValue = TextUnitText,
FormattedValue = TextUnitText,
Stem = TextUnitText
};
ScoredTextUnits = new List<TextUnitScore>
{
new TextUnitScore {Score = 15, ScoredTextUnit = TextUnit},
new TextUnitScore {Score = 30, ScoredTextUnit = TextUnit}
};
Sentence = new Sentence
{
OriginalSentence = SentenceText,
OriginalSentenceIndex = 0,
TextUnits = new List<TextUnit>
{
TextUnit
}
};
ScoredSentences = new List<SentenceScore>
{
new SentenceScore {Score = 10, ScoredSentence = Sentence},
new SentenceScore {Score = 20, ScoredSentence = Sentence}
};
}