本文整理汇总了C#中ITextPointer.MoveByOffset方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.MoveByOffset方法的具体用法?C# ITextPointer.MoveByOffset怎么用?C# ITextPointer.MoveByOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.MoveByOffset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WalkTextRun
// GetText handler for text runs.
private static bool WalkTextRun(ITextPointer navigator, ITextPointer limit, char[] text, int cchReq, ref int charsCopied, UnsafeNativeMethods.TS_RUNINFO[] runInfo, int cRunInfoReq, ref int cRunInfoRcv)
{
int runCount;
int offset;
bool hitLimit;
Invariant.Assert(navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text);
Invariant.Assert(limit == null || navigator.CompareTo(limit) <= 0);
hitLimit = false;
if (cchReq > 0)
{
runCount = TextPointerBase.GetTextWithLimit(navigator, LogicalDirection.Forward, text, charsCopied, Math.Min(cchReq, text.Length - charsCopied), limit);
navigator.MoveByOffset(runCount);
charsCopied += runCount;
hitLimit = (text.Length == charsCopied) || (limit != null && navigator.CompareTo(limit) == 0);
}
else
{
// Caller doesn't want text, just run info.
// Advance the navigator.
runCount = navigator.GetTextRunLength(LogicalDirection.Forward);
navigator.MoveToNextContextPosition(LogicalDirection.Forward);
// If the caller passed in a non-null limit, backup to the limit if
// we've passed it.
if (limit != null)
{
if (navigator.CompareTo(limit) >= 0)
{
offset = limit.GetOffsetToPosition(navigator);
Invariant.Assert(offset >= 0 && offset <= runCount, "Bogus offset -- extends past run!");
runCount -= offset;
navigator.MoveToPosition(limit);
hitLimit = true;
}
}
}
if (cRunInfoReq > 0 && runCount > 0)
{
// Be sure to merge this text run with the previous run, if they are both text runs.
// (A good robustness fix would be to make cicero handle this, if we ever get the chance.)
if (cRunInfoRcv > 0 && runInfo[cRunInfoRcv - 1].type == UnsafeNativeMethods.TsRunType.TS_RT_PLAIN)
{
runInfo[cRunInfoRcv - 1].count += runCount;
}
else
{
runInfo[cRunInfoRcv].count = runCount;
runInfo[cRunInfoRcv].type = UnsafeNativeMethods.TsRunType.TS_RT_PLAIN;
cRunInfoRcv++;
}
}
return hitLimit;
}
示例2: WalkRegionBoundary
// GetText handler for Blocks and TableCell to add '\n' or TS_CHAR_REGION.
private static bool WalkRegionBoundary(ITextPointer navigator, ITextPointer limit, char[] text, int cchReq, ref int charsCopied, UnsafeNativeMethods.TS_RUNINFO[] runInfo, int cRunInfoReq, ref int cRunInfoRcv)
{
bool hitLimit;
Invariant.Assert(navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart || navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd);
Invariant.Assert(limit == null || navigator.CompareTo(limit) <= 0);
// If the caller passed in a non-null limit, we don't do anything and just return true.
// we've passed it.
if (limit != null)
{
if (navigator.CompareTo(limit) >= 0)
{
return true;
}
}
hitLimit = false;
if (cchReq > 0)
{
// Add one TS_CHAR_REGION (TableCell) or '\n' (everything else) char.
char ch = (navigator.GetAdjacentElement(LogicalDirection.Forward) is TableCell) ? UnsafeNativeMethods.TS_CHAR_REGION : '\n';
text[charsCopied] = ch;
navigator.MoveByOffset(1);
charsCopied += 1;
hitLimit = (text.Length == charsCopied) || (limit != null && navigator.CompareTo(limit) == 0);
}
else
{
// Caller doesn't want text, just run info.
// Advance the navigator.
// Add one TS_CHAR_REGION char.
navigator.MoveByOffset(1);
}
if (cRunInfoReq > 0)
{
// Be sure to merge this text run with the previous run, if they are both text runs.
// (A good robustness fix would be to make cicero handle this, if we ever get the chance.)
if (cRunInfoRcv > 0 && runInfo[cRunInfoRcv - 1].type == UnsafeNativeMethods.TsRunType.TS_RT_PLAIN)
{
runInfo[cRunInfoRcv - 1].count += 1;
}
else
{
runInfo[cRunInfoRcv].count = 1;
runInfo[cRunInfoRcv].type = UnsafeNativeMethods.TsRunType.TS_RT_PLAIN;
cRunInfoRcv++;
}
}
return hitLimit;
}
示例3: MoveToNextInsertionPosition
/// <summary>
/// Advances this TextNavigator by a count number of characters.
/// </summary>
/// <param name="thisNavigator">ITextPointer to advance.</param>
/// <param name="direction">
/// A direction in which to search a next characters.
/// </param>
/// <returns>
/// True if the navigator is advanced, false if the end of document is
/// encountered and the navigator is not repositioned.
/// </returns>
/// <remarks>
/// A "character" in this context is a sequence of one or several text
/// symbols: one or more Unicode code points may be a character, every
/// embedded object is a character, a sequence of closing block tags
/// followed by opening block tags may also be a unit. Formatting tags
/// do not contribute in any unit.
/// </remarks>
internal static bool MoveToNextInsertionPosition(ITextPointer thisNavigator, LogicalDirection direction)
{
Invariant.Assert(!thisNavigator.IsFrozen, "Can't reposition a frozen pointer!");
bool moved = true;
int increment = direction == LogicalDirection.Forward ? +1 : -1;
ITextPointer initialPosition = thisNavigator.CreatePointer();
if (!IsAtInsertionPosition(thisNavigator))
{
// If the TextPointer is not currently at an insertion position,
// move the TextPointer to the next insertion position in
// the indicated direction, just like the MoveToInsertionPosition method.
if (!MoveToInsertionPosition(thisNavigator, direction))
{
// No insertion position in all content. MoveToInsertionPosition() guarantees that navigator is moved back to initial position.
moved = false;
goto Exit;
}
if ((direction == LogicalDirection.Forward && initialPosition.CompareTo(thisNavigator) < 0) ||
(direction == LogicalDirection.Backward && thisNavigator.CompareTo(initialPosition) < 0))
{
// We have found an insertion position in requested direction.
goto Exit;
}
}
// Start with skipping character formatting tags in this direction
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(direction)))
{
thisNavigator.MoveByOffset(increment);
}
do
{
if (thisNavigator.GetPointerContext(direction) != TextPointerContext.None)
{
thisNavigator.MoveByOffset(increment);
}
else
{
// No insertion position in this direction; Move back
thisNavigator.MoveToPosition(initialPosition);
moved = false;
goto Exit;
}
}
while (!IsAtInsertionPosition(thisNavigator));
// We must leave position normalized in backward direction
if (direction == LogicalDirection.Backward)
{
// For this we must skip character formatting tags if we have any
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(direction)))
{
thisNavigator.MoveByOffset(increment);
}
// However if it is block start we should back off
TextPointerContext context = thisNavigator.GetPointerContext(direction);
if (context == TextPointerContext.ElementStart || context == TextPointerContext.None)
{
increment = -increment;
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(LogicalDirection.Forward))
&& !IsAtInsertionPosition(thisNavigator))
{
thisNavigator.MoveByOffset(increment);
}
}
}
Exit:
if (moved)
{
if (direction == LogicalDirection.Forward)
{
Invariant.Assert(thisNavigator.CompareTo(initialPosition) > 0, "thisNavigator is expected to be moved from initialPosition - 1");
}
//.........这里部分代码省略.........
示例4: NormalizePosition
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
// Worker for MoveToNextFormatNormalizedPosition/MoveToNextInsertionPosition.
private static bool NormalizePosition(ITextPointer thisNavigator, LogicalDirection direction, bool respectCaretUnitBoundaries)
{
Invariant.Assert(!thisNavigator.IsFrozen, "Can't reposition a frozen pointer!");
int symbolCount = 0;
int increment;
LogicalDirection oppositeDirection;
TextPointerContext directEnterScope;
TextPointerContext oppositeEnterScope;
if (direction == LogicalDirection.Forward)
{
increment = +1;
oppositeDirection = LogicalDirection.Backward;
directEnterScope = TextPointerContext.ElementStart;
oppositeEnterScope = TextPointerContext.ElementEnd;
}
else
{
increment = -1;
oppositeDirection = LogicalDirection.Forward;
directEnterScope = TextPointerContext.ElementEnd;
oppositeEnterScope = TextPointerContext.ElementStart;
}
// When the pointer appears in between structural tags we need to start
// from sliding into the deepest possible position without
// leaving any structural units. We need to do that only
// if we are not at insertion position already.
if (!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries))
{
// Go inside an innermost structured element (non-inline)
while (
thisNavigator.GetPointerContext(direction) == directEnterScope &&
!typeof(Inline).IsAssignableFrom(thisNavigator.GetElementType(direction)) &&
!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries))
{
thisNavigator.MoveToNextContextPosition(direction);
symbolCount += increment;
}
while (
thisNavigator.GetPointerContext(oppositeDirection) == oppositeEnterScope &&
!typeof(Inline).IsAssignableFrom(thisNavigator.GetElementType(oppositeDirection)) &&
!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries))
{
thisNavigator.MoveToNextContextPosition(oppositeDirection);
symbolCount -= increment;
}
}
// Get out of a Hyperlink, etc. inner edge.
symbolCount = LeaveNonMergeableInlineBoundary(thisNavigator, direction, symbolCount);
// Get out of a compound sequence if any.
if (respectCaretUnitBoundaries)
{
while (!IsAtCaretUnitBoundary(thisNavigator))
{
symbolCount += increment;
thisNavigator.MoveByOffset(increment);
}
}
// Here is the core part of this method's logic - skipping all formatting tags in the given direction.
// Skip character formatting tags if they are present in this direction.
// Even if an insertion position can be in the middle of this formatting sequence,
// we want to skip it all and reach the farthest possible insertion position in that direction.
// Such approach guarantees that repeated calls of this normalization will give the same reauls.
// In case if there is an inserrtion position in the middle (say, in empty Run),
// the loop moving in opposite direction below will find it if needed.
while (TextSchema.IsMergeableInline(thisNavigator.GetElementType(direction)))
{
thisNavigator.MoveToNextContextPosition(direction);
symbolCount += increment;
}
if (!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries))
{
// If still not at insertion point, try skipping inline tags in the opposite direction
// now possibly stopping inside of empty element
while (!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries) &&
TextSchema.IsMergeableInline(thisNavigator.GetElementType(oppositeDirection)))
{
thisNavigator.MoveToNextContextPosition(oppositeDirection);
symbolCount -= increment;
}
// If still not at insertion point, then try harder - skipping block tags
// First in "preferred" direction
while (!IsAtNormalizedPosition(thisNavigator, respectCaretUnitBoundaries) &&
thisNavigator.MoveToNextContextPosition(direction))
//.........这里部分代码省略.........
示例5: _SkipFormattingTags
private void _SkipFormattingTags(ITextPointer textPointer)
{
Debug.Assert(!textPointer.IsFrozen, "Can't reposition a frozen pointer!");
LogicalDirection dir = textPointer.LogicalDirection;
int increment = (dir == LogicalDirection.Forward ? +1 : -1);
while (TextSchema.IsFormattingType( textPointer.GetElementType(dir)) )
{
textPointer.MoveByOffset(increment);
}
}
示例6: MoveToNextCharPos
//
// Move the TextPointer by offset in char count.
//
private static ITextPointer MoveToNextCharPos(ITextPointer position, int offset)
{
bool done = false;
if (offset < 0)
{
while ((offset < 0) && !done)
{
switch (position.GetPointerContext(LogicalDirection.Backward))
{
case TextPointerContext.Text:
offset++;
break;
case TextPointerContext.None:
done = true;
break;
}
position.MoveByOffset(-1);
}
}
else if (offset > 0)
{
while ((offset > 0) && !done)
{
switch (position.GetPointerContext(LogicalDirection.Forward))
{
case TextPointerContext.Text:
offset--;
break;
case TextPointerContext.None:
done = true;
break;
}
position.MoveByOffset(1);
}
}
return position;
}
示例7: SetFindTextAndFindTextPositionMap
/// <summary>
/// Set the find text content from reading the text on the current text position.
/// </summary>
/// <returns>
/// Returns the number of characters actually loaded into the findText array.
/// </returns>
private static int SetFindTextAndFindTextPositionMap(
ITextPointer startPosition,
ITextPointer endPosition,
ITextPointer navigator,
LogicalDirection direction,
bool matchLast,
char[] findText,
int[] findTextPositionMap)
{
Invariant.Assert(startPosition.CompareTo(navigator) <= 0);
Invariant.Assert(endPosition.CompareTo(navigator) >= 0);
int runCount;
int inlineCount = 0;
int findTextLength = 0;
// Set the first offset which is zero on TextBufferSize + 1 location of
// the text position map in case of the backward searching
if (matchLast && findTextLength == 0)
{
findTextPositionMap[findTextPositionMap.Length - 1] = 0;
}
while ((matchLast ? startPosition.CompareTo(navigator) : navigator.CompareTo(endPosition)) < 0)
{
switch (navigator.GetPointerContext(direction))
{
case TextPointerContext.Text:
runCount = navigator.GetTextRunLength(direction);
runCount = Math.Min(runCount, findText.Length - findTextLength);
if (!matchLast)
{
runCount = Math.Min(runCount, navigator.GetOffsetToPosition(endPosition));
navigator.GetTextInRun(direction, findText, findTextLength, runCount);
for (int i = findTextLength; i < findTextLength + runCount; i++)
{
findTextPositionMap[i] = i + inlineCount;
}
}
else
{
runCount = Math.Min(runCount, startPosition.GetOffsetToPosition(navigator));
navigator.GetTextInRun(
direction,
findText,
findText.Length - findTextLength - runCount,
runCount);
// Set the text offest for the amount of runCount from the last index
// of text position map
int mapIndex = findText.Length - findTextLength - 1;
for (int i = findTextLength; i < findTextLength + runCount; i++)
{
findTextPositionMap[mapIndex--] = i + inlineCount + 1;
}
}
// Move the navigator position for the amount of runCount
navigator.MoveByOffset(matchLast ? - runCount : runCount);
findTextLength += runCount;
break;
case TextPointerContext.None:
case TextPointerContext.ElementStart:
case TextPointerContext.ElementEnd:
if (IsAdjacentToFormatElement(navigator, direction))
{
// Filter out formatting tags since find text content is plain.
inlineCount++;
}
else
{
if (!matchLast)
{
// Stick in a line break to account for the block element.
findText[findTextLength] = '\n';
findTextPositionMap[findTextLength] = findTextLength + inlineCount;
findTextLength++;
}
else
{
// Increse the find text length first since adding text and map reversely
findTextLength++;
// Stick in a line break to account for the block element and
// add text offset on the last index of text position map
findText[findText.Length - findTextLength] = '\n';
findTextPositionMap[findText.Length - findTextLength] = findTextLength + inlineCount;
}
}
//.........这里部分代码省略.........