// ------------------------------------------------------------------ // // TextSource Implementation // // ------------------------------------------------------------------ #region TextSource Implementation // ------------------------------------------------------------------ // Get a text run at specified text source position. // ------------------------------------------------------------------ public override TextRun GetTextRun(int dcp) { TextRun run = null; StaticTextPointer position = _owner.TextContainer.CreateStaticPointerAtOffset(dcp); switch (position.GetPointerContext(LogicalDirection.Forward)) { case TextPointerContext.Text: run = HandleText(position); break; case TextPointerContext.ElementStart: run = HandleElementStartEdge(position); break; case TextPointerContext.ElementEnd: run = HandleElementEndEdge(position); break; case TextPointerContext.EmbeddedElement: run = HandleInlineObject(position, dcp); break; case TextPointerContext.None: run = new TextEndOfParagraph(_syntheticCharacterLength); break; } Debug.Assert(run != null, "TextRun has not been created."); Debug.Assert(run.Length > 0, "TextRun has to have positive length."); return(run); }
// Token: 0x060065FF RID: 26111 RVA: 0x001CAA74 File Offset: 0x001C8C74 public override TextRun GetTextRun(int dcp) { TextRun textRun = null; StaticTextPointer position = this._owner.TextContainer.CreateStaticPointerAtOffset(dcp); switch (position.GetPointerContext(LogicalDirection.Forward)) { case TextPointerContext.None: textRun = new TextEndOfParagraph(Line._syntheticCharacterLength); break; case TextPointerContext.Text: textRun = this.HandleText(position); break; case TextPointerContext.EmbeddedElement: textRun = this.HandleInlineObject(position, dcp); break; case TextPointerContext.ElementStart: textRun = this.HandleElementStartEdge(position); break; case TextPointerContext.ElementEnd: textRun = this.HandleElementEndEdge(position); break; } if (textRun.Properties != null) { textRun.Properties.PixelsPerDip = base.PixelsPerDip; } return(textRun); }
// ------------------------------------------------------------------ // Fetch the next run at UIElment position. // // position - current position in the text array // dcp - current position in the text array // ------------------------------------------------------------------ private TextRun HandleInlineObject(StaticTextPointer position, int dcp) { Debug.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement, "TextPointer does not point to embedded object."); TextRun run = null; DependencyObject element = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject; if (element is UIElement) { // TextRunProperties textProps = new TextProperties(element, position, true /* inline objects */, true /* get background */); // Create object run. run = new InlineObject(dcp, TextContainerHelper.EmbeddedObjectLength, (UIElement)element, textProps, _owner); } else { // If the embedded object is of an unknown type (not UIElement), // treat it as element edge. run = HandleElementEndEdge(position); } return(run); }
// Token: 0x06004131 RID: 16689 RVA: 0x0012A0E0 File Offset: 0x001282E0 public override TextRun GetTextRun(int dcp) { TextRun textRun = null; StaticTextPointer position = this._owner.Host.TextContainer.CreateStaticPointerAtOffset(dcp); switch (position.GetPointerContext(LogicalDirection.Forward)) { case TextPointerContext.None: textRun = new TextEndOfParagraph(1); goto IL_5C; case TextPointerContext.Text: textRun = this.HandleText(position); goto IL_5C; } Invariant.Assert(false, "Unsupported position type."); IL_5C: Invariant.Assert(textRun != null, "TextRun has not been created."); Invariant.Assert(textRun.Length > 0, "TextRun has to have positive length."); if (textRun.Properties != null) { textRun.Properties.PixelsPerDip = base.PixelsPerDip; } return(textRun); }
// Gathers text decorations set on scoping highlights. // If no highlight properties are found, returns null private static TextDecorationCollection GetHighlightTextDecorations(StaticTextPointer highlightPosition) { TextDecorationCollection textDecorations = null; Highlights highlights = highlightPosition.TextContainer.Highlights; if (highlights == null) { return(textDecorations); } // // Speller // textDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection; // // IME composition // #if UNUSED_IME_HIGHLIGHT_LAYER TextDecorationCollection imeTextDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(FrameworkTextComposition)) as TextDecorationCollection; if (imeTextDecorations != null) { textDecorations = imeTextDecorations; } #endif return(textDecorations); }
// ------------------------------------------------------------------ // // TextSource Implementation // // ------------------------------------------------------------------ #region TextSource Implementation /// <summary> /// Get a text run at specified text source position and return it. /// </summary> /// <param name="dcp"> /// dcp of position relative to start of line /// </param> internal override TextRun GetTextRun(int dcp) { TextRun run = null; ITextContainer textContainer = _paraClient.Paragraph.StructuralCache.TextContainer; StaticTextPointer position = textContainer.CreateStaticPointerAtOffset(_cpPara + dcp); switch (position.GetPointerContext(LogicalDirection.Forward)) { case TextPointerContext.Text: run = HandleText(position); break; case TextPointerContext.ElementStart: run = HandleElementStartEdge(position); break; case TextPointerContext.ElementEnd: run = HandleElementEndEdge(position); break; case TextPointerContext.EmbeddedElement: run = HandleEmbeddedObject(dcp, position); break; case TextPointerContext.None: run = new ParagraphBreakRun(_syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph); break; } Invariant.Assert(run != null, "TextRun has not been created."); Invariant.Assert(run.Length > 0, "TextRun has to have positive length."); return(run); }
// Token: 0x0600688D RID: 26765 RVA: 0x001D7D74 File Offset: 0x001D5F74 protected TextRun HandleText(StaticTextPointer position) { Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text, "TextPointer does not point to characters."); DependencyObject target; if (position.Parent != null) { target = position.Parent; } else { target = this._paraClient.Paragraph.Element; } TextProperties textRunProperties = new TextProperties(target, position, false, true, this._paraClient.Paragraph.StructuralCache.TextFormatterHost.PixelsPerDip); StaticTextPointer position2 = position.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward); if (position.GetOffsetToPosition(position2) > 4096) { position2 = position.CreatePointer(4096); } char[] array = new char[position.GetOffsetToPosition(position2)]; int textInRun = position.GetTextInRun(LogicalDirection.Forward, array, 0, array.Length); return(new TextCharacters(array, 0, textInRun, textRunProperties)); }
/// <summary> /// Get a text run at specified text source position. /// </summary> public override TextRun GetTextRun(int dcp) { TextRun run = null; StaticTextPointer position = _owner.Host.TextContainer.CreateStaticPointerAtOffset(dcp); switch (position.GetPointerContext(LogicalDirection.Forward)) { case TextPointerContext.Text: run = HandleText(position); break; case TextPointerContext.None: run = new TextEndOfParagraph(_syntheticCharacterLength); break; case TextPointerContext.ElementStart: case TextPointerContext.ElementEnd: case TextPointerContext.EmbeddedElement: default: Invariant.Assert(false, "Unsupported position type."); break; } Invariant.Assert(run != null, "TextRun has not been created."); Invariant.Assert(run.Length > 0, "TextRun has to have positive length."); return(run); }
// Token: 0x06006607 RID: 26119 RVA: 0x001CB000 File Offset: 0x001C9200 private TextRun HandleElementStartEdge(StaticTextPointer position) { TextElement textElement = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward); TextRun result; if (textElement is LineBreak) { result = new TextEndOfLine(ComplexLine._elementEdgeCharacterLength * 2); } else if (textElement.IsEmpty) { TextRunProperties textRunProperties = new TextProperties(textElement, position, false, true, base.PixelsPerDip); char[] array = new char[ComplexLine._elementEdgeCharacterLength * 2]; array[0] = ''; array[1] = ''; result = new TextCharacters(array, 0, array.Length, textRunProperties); } else { Inline inline = textElement as Inline; if (inline == null) { result = new TextHidden(ComplexLine._elementEdgeCharacterLength); } else { DependencyObject parent = inline.Parent; FlowDirection flowDirection = inline.FlowDirection; FlowDirection flowDirection2 = flowDirection; if (parent != null) { flowDirection2 = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); } TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline); if (flowDirection != flowDirection2) { if (textDecorations == null || textDecorations.Count == 0) { result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, null, null, flowDirection); } else { result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, textDecorations, inline.Foreground, flowDirection); } } else if (textDecorations == null || textDecorations.Count == 0) { result = new TextHidden(ComplexLine._elementEdgeCharacterLength); } else { result = new TextSpanModifier(ComplexLine._elementEdgeCharacterLength, textDecorations, inline.Foreground); } } } return(result); }
internal TextProperties(DependencyObject target, StaticTextPointer position, bool inlineObjects, bool getBackground, double pixelsPerDip) { // if none of the number substitution properties have changed, we may be able to // initialize the _numberSubstitution field to a known default value FrameworkContentElement fce = target as FrameworkContentElement; if (fce != null) { if (!fce.HasNumberSubstitutionChanged) { _numberSubstitution = FrameworkContentElement.DefaultNumberSubstitution; } } else { FrameworkElement fe = target as FrameworkElement; if (fe != null && !fe.HasNumberSubstitutionChanged) { _numberSubstitution = FrameworkElement.DefaultNumberSubstitution; } } PixelsPerDip = pixelsPerDip; InitCommon(target); _typographyProperties = GetTypographyProperties(target); if (!inlineObjects) { _baselineAlignment = DynamicPropertyReader.GetBaselineAlignment(target); if (!position.IsNull) { TextDecorationCollection highlightDecorations = GetHighlightTextDecorations(position); if (highlightDecorations != null) { // Highlights (if present) take precedence over property value TextDecorations. _textDecorations = highlightDecorations; } } if (getBackground) { _backgroundBrush = DynamicPropertyReader.GetBackgroundBrush(target); } } else { _baselineAlignment = DynamicPropertyReader.GetBaselineAlignmentForInlineObject(target); _textDecorations = DynamicPropertyReader.GetTextDecorationsForInlineObject(target, _textDecorations); if (getBackground) { _backgroundBrush = DynamicPropertyReader.GetBackgroundBrushForInlineObject(position); } } }
// Token: 0x060066A1 RID: 26273 RVA: 0x001CCD98 File Offset: 0x001CAF98 private static TextDecorationCollection GetHighlightTextDecorations(StaticTextPointer highlightPosition) { TextDecorationCollection result = null; Highlights highlights = highlightPosition.TextContainer.Highlights; if (highlights == null) { return(result); } return(highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection); }
// Token: 0x0600669E RID: 26270 RVA: 0x001CCBB0 File Offset: 0x001CADB0 internal TextProperties(DependencyObject target, StaticTextPointer position, bool inlineObjects, bool getBackground, double pixelsPerDip) { FrameworkContentElement frameworkContentElement = target as FrameworkContentElement; if (frameworkContentElement != null) { if (!frameworkContentElement.HasNumberSubstitutionChanged) { this._numberSubstitution = FrameworkContentElement.DefaultNumberSubstitution; } } else { FrameworkElement frameworkElement = target as FrameworkElement; if (frameworkElement != null && !frameworkElement.HasNumberSubstitutionChanged) { this._numberSubstitution = FrameworkElement.DefaultNumberSubstitution; } } base.PixelsPerDip = pixelsPerDip; this.InitCommon(target); this._typographyProperties = TextProperties.GetTypographyProperties(target); if (!inlineObjects) { this._baselineAlignment = DynamicPropertyReader.GetBaselineAlignment(target); if (!position.IsNull) { TextDecorationCollection highlightTextDecorations = TextProperties.GetHighlightTextDecorations(position); if (highlightTextDecorations != null) { this._textDecorations = highlightTextDecorations; } } if (getBackground) { this._backgroundBrush = DynamicPropertyReader.GetBackgroundBrush(target); return; } } else { this._baselineAlignment = DynamicPropertyReader.GetBaselineAlignmentForInlineObject(target); this._textDecorations = DynamicPropertyReader.GetTextDecorationsForInlineObject(target, this._textDecorations); if (getBackground) { this._backgroundBrush = DynamicPropertyReader.GetBackgroundBrushForInlineObject(position); } } }
// Token: 0x06006618 RID: 26136 RVA: 0x001CB514 File Offset: 0x001C9714 internal static Brush GetBackgroundBrushForInlineObject(StaticTextPointer position) { object highlightValue = position.TextContainer.Highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(TextSelection)); Brush result; if (highlightValue == DependencyProperty.UnsetValue) { result = (Brush)position.GetValue(TextElement.BackgroundProperty); } else { result = SelectionHighlightInfo.BackgroundBrush; } return(result); }
// Token: 0x06004143 RID: 16707 RVA: 0x0012A510 File Offset: 0x00128710 private TextRun HandleText(StaticTextPointer position) { StaticTextPointer position2 = this._owner.Host.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward); if (position.GetOffsetToPosition(position2) > 4096) { position2 = position.CreatePointer(4096); } Highlights highlights = position.TextContainer.Highlights; TextDecorationCollection textDecorationCollection = highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection; TextRunProperties textRunProperties = this._lineProperties.DefaultTextRunProperties; if (textDecorationCollection != null) { if (this._spellerErrorProperties == null) { this._spellerErrorProperties = new TextProperties((TextProperties)textRunProperties, textDecorationCollection); } textRunProperties = this._spellerErrorProperties; } ITextSelection textSelection = position.TextContainer.TextSelection; TextEditor textEditor = (textSelection != null) ? textSelection.TextEditor : null; if (textEditor != null) { ITextView textView = textEditor.TextView; if (((textView != null) ? new bool?(textView.RendersOwnSelection) : null) == true && highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(TextSelection)) != DependencyProperty.UnsetValue) { TextProperties textProperties = new TextProperties((TextProperties)textRunProperties, textDecorationCollection); FrameworkElement frameworkElement = (textEditor != null) ? textEditor.UiScope : null; if (frameworkElement != null) { textProperties.SetBackgroundBrush(null); Brush brush = frameworkElement.GetValue(TextBoxBase.SelectionTextBrushProperty) as Brush; if (brush != null) { textProperties.SetForegroundBrush(brush); } } textRunProperties = textProperties; } } char[] array = new char[position.GetOffsetToPosition(position2)]; int textInRun = position.GetTextInRun(LogicalDirection.Forward, array, 0, array.Length); Invariant.Assert(textInRun == array.Length); return(new TextCharacters(array, 0, textInRun, textRunProperties)); }
// Token: 0x06007C9C RID: 31900 RVA: 0x00230F64 File Offset: 0x0022F164 private ITextPointer GetNextForwardPosition(StaticTextPointer pos) { for (int i = 0; i < this._segments.Count; i++) { AnnotationHighlightLayer.HighlightSegment highlightSegment = this._segments[i]; if (pos.CompareTo(highlightSegment.Segment.Start) < 0) { return(highlightSegment.Segment.Start); } if (pos.CompareTo(highlightSegment.Segment.End) < 0) { return(highlightSegment.Segment.End); } } return(null); }
// Token: 0x06007C9D RID: 31901 RVA: 0x00230FE4 File Offset: 0x0022F1E4 private ITextPointer GetNextBackwardPosition(StaticTextPointer pos) { for (int i = this._segments.Count - 1; i >= 0; i--) { AnnotationHighlightLayer.HighlightSegment highlightSegment = this._segments[i]; if (pos.CompareTo(highlightSegment.Segment.End) > 0) { return(highlightSegment.Segment.End); } if (pos.CompareTo(highlightSegment.Segment.Start) > 0) { return(highlightSegment.Segment.Start); } } return(null); }
// Token: 0x06006609 RID: 26121 RVA: 0x001CB1DC File Offset: 0x001C93DC private TextRun HandleInlineObject(StaticTextPointer position, int dcp) { DependencyObject dependencyObject = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject; TextRun result; if (dependencyObject is UIElement) { TextRunProperties textProps = new TextProperties(dependencyObject, position, true, true, base.PixelsPerDip); result = new InlineObject(dcp, TextContainerHelper.EmbeddedObjectLength, (UIElement)dependencyObject, textProps, this._owner); } else { result = this.HandleElementEndEdge(position); } return(result); }
//------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- #region Protected Methods /// <summary> /// Fetch the next run at text position. /// </summary> /// <param name="position"> /// Current position in text array /// </param> /// <returns></returns> protected TextRun HandleText(StaticTextPointer position) { DependencyObject element; StaticTextPointer endOfRunPosition; Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text, "TextPointer does not point to characters."); if (position.Parent != null) { element = position.Parent; } else { element = _paraClient.Paragraph.Element; } // Extract the aggregated properties into something that the textrun can use. // TextProperties textProps = new TextProperties(element, position, false /* inline objects */, true /* get background */, _paraClient.Paragraph.StructuralCache.TextFormatterHost.PixelsPerDip); // Calculate the end of the run by finding either: // a) the next intersection of highlight ranges, or // b) the natural end of this textrun endOfRunPosition = position.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward); // Clamp the text run at an arbitrary limit, so we don't make // an unbounded allocation. if (position.GetOffsetToPosition(endOfRunPosition) > 4096) { endOfRunPosition = position.CreatePointer(4096); } // Get character buffer for the text run. char[] textBuffer = new char[position.GetOffsetToPosition(endOfRunPosition)]; // Copy characters from text run into buffer. Note the actual number of characters copied, // which may be different than the buffer's length. Buffer length only specifies the maximum // number of characters int charactersCopied = position.GetTextInRun(LogicalDirection.Forward, textBuffer, 0, textBuffer.Length); // Create text run using the actual number of characters copied return(new TextCharacters(textBuffer, 0, charactersCopied, textProps)); }
// Token: 0x06006890 RID: 26768 RVA: 0x001D80F4 File Offset: 0x001D62F4 protected TextRun HandleEmbeddedObject(int dcp, StaticTextPointer position) { Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement, "TextPointer does not point to embedded object."); DependencyObject dependencyObject = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject; TextRun result; if (dependencyObject is UIElement) { TextRunProperties textProps = new TextProperties(dependencyObject, position, true, true, this._paraClient.Paragraph.StructuralCache.TextFormatterHost.PixelsPerDip); result = new InlineObjectRun(TextContainerHelper.EmbeddedObjectLength, (UIElement)dependencyObject, textProps, this._paraClient.Paragraph as TextParagraph); } else { result = new TextHidden(TextContainerHelper.EmbeddedObjectLength); } return(result); }
/// <summary> /// Fetch the next run at element end edge position. /// ElementEndEdge; we can have 2 possibilities: /// (1) Close edge of element associated with the text paragraph, /// create synthetic LineBreak run to end the current line. /// (2) End of inline element, hide CloseEdge character and continue /// </summary> /// <param name="position"></param> /// Position in current text array protected TextRun HandleElementEndEdge(StaticTextPointer position) { Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge."); TextRun run; if (position.Parent == _paraClient.Paragraph.Element) { // (1) Close edge of element associated with the text paragraph, // create synthetic LineBreak run to end the current line. run = new ParagraphBreakRun(_syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph); } else { TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward); Debug.Assert(element != null, "Element should be here."); Inline inline = (Inline)element; DependencyObject parent = inline.Parent; FlowDirection parentFlowDirection = inline.FlowDirection; if (parent != null) { parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); } if (inline.FlowDirection != parentFlowDirection) { run = new TextEndOfSegment(_elementEdgeCharacterLength); } else { TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline); if (textDecorations == null || textDecorations.Count == 0) { // (2) End of inline element, hide CloseEdge character and continue run = new TextHidden(_elementEdgeCharacterLength); } else { run = new TextEndOfSegment(_elementEdgeCharacterLength); } } } return(run); }
// ------------------------------------------------------------------ // Fetch the next run at element close edge position. // // position - current position in the text array // ------------------------------------------------------------------ private TextRun HandleElementEndEdge(StaticTextPointer position) { Debug.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge."); TextRun run = null; TextElement element = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward); Debug.Assert(element != null, "Element should be here."); Inline inline = element as Inline; if (inline == null) { run = new TextHidden(_elementEdgeCharacterLength); } else { DependencyObject parent = inline.Parent; FlowDirection parentFlowDirection = inline.FlowDirection; if (parent != null) { parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); } if (inline.FlowDirection != parentFlowDirection) { run = new TextEndOfSegment(_elementEdgeCharacterLength); } else { TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline); if (textDecorations == null || textDecorations.Count == 0) { // (2) End of inline element, hide CloseEdge character and continue run = new TextHidden(_elementEdgeCharacterLength); } else { run = new TextEndOfSegment(_elementEdgeCharacterLength); } } } return(run); }
// Token: 0x06007C97 RID: 31895 RVA: 0x00230BD0 File Offset: 0x0022EDD0 internal override StaticTextPointer GetNextChangePosition(StaticTextPointer textPosition, LogicalDirection direction) { ITextPointer textPointer; if (direction == LogicalDirection.Forward) { textPointer = this.GetNextForwardPosition(textPosition); } else { textPointer = this.GetNextBackwardPosition(textPosition); } if (textPointer != null) { return(textPointer.CreateStaticPointer()); } return(StaticTextPointer.Null); }
// ------------------------------------------------------------------ // Retrieve background brush property from specified UIElement. // // position - Exact position of the content. // ------------------------------------------------------------------ internal static Brush GetBackgroundBrushForInlineObject(StaticTextPointer position) { object selected; Brush backgroundBrush; Debug.Assert(!position.IsNull); selected = position.TextContainer.Highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(TextSelection)); if (selected == DependencyProperty.UnsetValue) { backgroundBrush = (Brush)position.GetValue(TextElement.BackgroundProperty); } else { backgroundBrush = SelectionHighlightInfo.BackgroundBrush; } return(backgroundBrush); }
//------------------------------------------------------------------- // // Private Methods // //------------------------------------------------------------------- #region Private Methods /// <summary> /// Fetch the next run at text position. /// </summary> private TextRun HandleText(StaticTextPointer position) { // Calculate the end of the run by finding either: // a) the next intersection of highlight ranges, or // b) the natural end of this textrun StaticTextPointer endOfRunPosition = _owner.Host.TextContainer.Highlights.GetNextPropertyChangePosition(position, LogicalDirection.Forward); // Clamp the text run at an arbitrary limit, so we don't make // an unbounded allocation. if (position.GetOffsetToPosition(endOfRunPosition) > 4096) { endOfRunPosition = position.CreatePointer(4096); } // Factor in any speller error squiggles on the run. TextDecorationCollection highlightDecorations = position.TextContainer.Highlights.GetHighlightValue(position, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection; TextRunProperties properties; if (highlightDecorations == null) { properties = _lineProperties.DefaultTextRunProperties; } else { if (_spellerErrorProperties == null) { _spellerErrorProperties = new TextProperties((TextProperties)_lineProperties.DefaultTextRunProperties, highlightDecorations); } properties = _spellerErrorProperties; } // Get character buffer for the text run. char[] textBuffer = new char[position.GetOffsetToPosition(endOfRunPosition)]; // Copy characters from text run into buffer. Since we are dealing with plain text content, // we expect to get all the characters from position to endOfRunPosition. int charactersCopied = position.GetTextInRun(LogicalDirection.Forward, textBuffer, 0, textBuffer.Length); Invariant.Assert(charactersCopied == textBuffer.Length); // Create text run, using characters copied as length return(new TextCharacters(textBuffer, 0, charactersCopied, properties)); }
// Token: 0x06007C95 RID: 31893 RVA: 0x00230B1C File Offset: 0x0022ED1C internal override object GetHighlightValue(StaticTextPointer textPosition, LogicalDirection direction) { object result = DependencyProperty.UnsetValue; for (int i = 0; i < this._segments.Count; i++) { AnnotationHighlightLayer.HighlightSegment highlightSegment = this._segments[i]; if (highlightSegment.Segment.Start.CompareTo(textPosition) > 0 || (highlightSegment.Segment.Start.CompareTo(textPosition) == 0 && direction == LogicalDirection.Backward)) { break; } if (highlightSegment.Segment.End.CompareTo(textPosition) > 0 || (highlightSegment.Segment.End.CompareTo(textPosition) == 0 && direction == LogicalDirection.Backward)) { result = highlightSegment; break; } } return(result); }
/// <summary> /// Get text immediately before specified text source position. Return CharacterBufferRange /// containing this text. /// </summary> /// <param name="dcp"> /// dcp of position relative to start of line /// </param> internal override TextSpan <CultureSpecificCharacterBufferRange> GetPrecedingText(int dcp) { // Parameter validation Invariant.Assert(dcp >= 0); int nonTextLength = 0; CharacterBufferRange precedingText = CharacterBufferRange.Empty; CultureInfo culture = null; if (dcp > 0) { // Create TextPointer at dcp, and pointer at paragraph start to compare ITextPointer startPosition = TextContainerHelper.GetTextPointerFromCP(_paraClient.Paragraph.StructuralCache.TextContainer, _cpPara, LogicalDirection.Forward); ITextPointer position = TextContainerHelper.GetTextPointerFromCP(_paraClient.Paragraph.StructuralCache.TextContainer, _cpPara + dcp, LogicalDirection.Forward); // Move backward until we find a position at the end of a text run, or reach start of TextContainer while (position.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.Text && position.CompareTo(startPosition) != 0) { position.MoveByOffset(-1); nonTextLength++; } // Return text in run. If it is at start of TextContainer this will return an empty string string precedingTextString = position.GetTextInRun(LogicalDirection.Backward); precedingText = new CharacterBufferRange(precedingTextString, 0, precedingTextString.Length); StaticTextPointer pointer = position.CreateStaticPointer(); DependencyObject element = (pointer.Parent != null) ? pointer.Parent : _paraClient.Paragraph.Element; culture = DynamicPropertyReader.GetCultureInfo(element); } return(new TextSpan <CultureSpecificCharacterBufferRange>( nonTextLength + precedingText.Length, new CultureSpecificCharacterBufferRange(culture, precedingText) )); }
/// <summary> /// Fetch the next run at embedded object position. /// </summary> /// <param name="dcp"> /// Character offset of this run. /// </param> /// <param name="position"> /// Current position in the text array. /// </param> protected TextRun HandleEmbeddedObject(int dcp, StaticTextPointer position) { Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement, "TextPointer does not point to embedded object."); TextRun run = null; DependencyObject embeddedObject = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject; if (embeddedObject is UIElement) { // Extract the aggregated properties into something that the textrun can use. TextRunProperties textProps = new TextProperties(embeddedObject, position, true /* inline objects */, true /* get background */); // Create inline object run. run = new InlineObjectRun(TextContainerHelper.EmbeddedObjectLength, (UIElement)embeddedObject, textProps, _paraClient.Paragraph as TextParagraph); } else { // If the embedded object is of an unknown type, treat it as hidden content. run = new TextHidden(TextContainerHelper.EmbeddedObjectLength); } return(run); }
// Token: 0x06006600 RID: 26112 RVA: 0x001CAB08 File Offset: 0x001C8D08 public override TextSpan <CultureSpecificCharacterBufferRange> GetPrecedingText(int dcp) { int num = 0; CharacterBufferRange empty = CharacterBufferRange.Empty; CultureInfo culture = null; if (dcp > 0) { ITextPointer textPointer = this._owner.TextContainer.CreatePointerAtOffset(dcp, LogicalDirection.Backward); while (textPointer.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.Text && textPointer.CompareTo(this._owner.TextContainer.Start) != 0) { textPointer.MoveByOffset(-1); num++; } string textInRun = textPointer.GetTextInRun(LogicalDirection.Backward); empty = new CharacterBufferRange(textInRun, 0, textInRun.Length); StaticTextPointer staticTextPointer = textPointer.CreateStaticPointer(); DependencyObject element = (staticTextPointer.Parent != null) ? staticTextPointer.Parent : this._owner; culture = DynamicPropertyReader.GetCultureInfo(element); } return(new TextSpan <CultureSpecificCharacterBufferRange>(num + empty.Length, new CultureSpecificCharacterBufferRange(culture, empty))); }
// Token: 0x0600688F RID: 26767 RVA: 0x001D802C File Offset: 0x001D622C protected TextRun HandleElementEndEdge(StaticTextPointer position) { Invariant.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd, "TextPointer does not point to element end edge."); TextRun result; if (position.Parent == this._paraClient.Paragraph.Element) { result = new ParagraphBreakRun(LineBase._syntheticCharacterLength, PTS.FSFLRES.fsflrEndOfParagraph); } else { TextElement textElement = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward); Inline inline = (Inline)textElement; DependencyObject parent = inline.Parent; FlowDirection flowDirection = inline.FlowDirection; if (parent != null) { flowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); } if (inline.FlowDirection != flowDirection) { result = new TextEndOfSegment(LineBase._elementEdgeCharacterLength); } else { TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline); if (textDecorations == null || textDecorations.Count == 0) { result = new TextHidden(LineBase._elementEdgeCharacterLength); } else { result = new TextEndOfSegment(LineBase._elementEdgeCharacterLength); } } } return(result); }
// Token: 0x06006608 RID: 26120 RVA: 0x001CB13C File Offset: 0x001C933C private TextRun HandleElementEndEdge(StaticTextPointer position) { TextElement textElement = (TextElement)position.GetAdjacentElement(LogicalDirection.Forward); Inline inline = textElement as Inline; TextRun result; if (inline == null) { result = new TextHidden(ComplexLine._elementEdgeCharacterLength); } else { DependencyObject parent = inline.Parent; FlowDirection flowDirection = inline.FlowDirection; if (parent != null) { flowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty); } if (inline.FlowDirection != flowDirection) { result = new TextEndOfSegment(ComplexLine._elementEdgeCharacterLength); } else { TextDecorationCollection textDecorations = DynamicPropertyReader.GetTextDecorations(inline); if (textDecorations == null || textDecorations.Count == 0) { result = new TextHidden(ComplexLine._elementEdgeCharacterLength); } else { result = new TextEndOfSegment(ComplexLine._elementEdgeCharacterLength); } } } return(result); }