当前位置: 首页>>代码示例>>C#>>正文


C# TextFormatting.TextLine类代码示例

本文整理汇总了C#中System.Windows.Media.TextFormatting.TextLine的典型用法代码示例。如果您正苦于以下问题:C# TextLine类的具体用法?C# TextLine怎么用?C# TextLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TextLine类属于System.Windows.Media.TextFormatting命名空间,在下文中一共展示了TextLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormattedTextElement

		/// <summary>
		/// Creates a new FormattedTextElement that displays the specified text
		/// and occupies the specified length in the document.
		/// </summary>
		public FormattedTextElement(TextLine text, int documentLength) : base(1, documentLength)
		{
			if (text == null)
				throw new ArgumentNullException("text");
			this.textLine = text;
			this.BreakBefore = LineBreakCondition.BreakPossible;
			this.BreakAfter = LineBreakCondition.BreakPossible;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:12,代码来源:FormattedTextElement.cs

示例2: GetEndOfLineCaretPosition

		static TextViewPosition GetEndOfLineCaretPosition(VisualLine visualLine, TextLine textLine)
		{
			int newVC = visualLine.GetTextLineVisualStartColumn(textLine) + textLine.Length - textLine.TrailingWhitespaceLength;
			TextViewPosition pos = visualLine.GetTextViewPosition(newVC);
			pos.IsAtEndOfLine = true;
			return pos;
		}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:7,代码来源:CaretNavigationCommandHandler.cs

示例3: GetVisualPos

 double GetVisualPos(VisualLine vl, TextLine tl)
 {
     double pos = vl.GetTextLineVisualYPosition(tl, VisualYPosition.LineTop) + tl.Height / 2 - TextView.VerticalOffset;
     return Math.Round(pos) + 0.5;
 }
开发者ID:kjk,项目名称:kjkpub,代码行数:5,代码来源:FoldingMargin.cs

示例4: GetTextLineVisualYPosition

 /// <summary>
 /// Gets the visual top from the specified text line.
 /// </summary>
 /// <returns>Distance in device-independent pixels
 /// from the top of the document to the top of the specified text line.</returns>
 public double GetTextLineVisualYPosition(TextLine textLine, VisualYPosition yPositionMode)
 {
     if (textLine == null)
         throw new ArgumentNullException("textLine");
     double pos = VisualTop;
     foreach (TextLine tl in TextLines) {
         if (tl == textLine) {
             switch (yPositionMode) {
                 case VisualYPosition.LineTop:
                     return pos;
                 case VisualYPosition.LineMiddle:
                     return pos + tl.Height / 2;
                 case VisualYPosition.LineBottom:
                     return pos + tl.Height;
                 case VisualYPosition.TextTop:
                     return pos + tl.Baseline - textView.DefaultBaseline;
                 case VisualYPosition.TextBottom:
                     return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight;
                 case VisualYPosition.TextMiddle:
                     return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight / 2;
                 case VisualYPosition.Baseline:
                     return pos + tl.Baseline;
                 default:
                     throw new ArgumentException("Invalid yPositionMode:" + yPositionMode);
             }
         } else {
             pos += tl.Height;
         }
     }
     throw new ArgumentException("textLine is not a line in this VisualLine");
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:36,代码来源:VisualLine.cs

示例5: GetTextLineVisualStartColumn

 /// <summary>
 /// Gets the start visual column from the specified text line.
 /// </summary>
 public int GetTextLineVisualStartColumn(TextLine textLine)
 {
     if (!TextLines.Contains(textLine))
         throw new ArgumentException("textLine is not a line in this VisualLine");
     int col = 0;
     foreach (TextLine tl in TextLines) {
         if (tl == textLine)
             break;
         else
             col += tl.Length;
     }
     return col;
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:16,代码来源:VisualLine.cs

示例6: TabTextElement

 public TabTextElement(TextLine text)
     : base(2, 1)
 {
     this.text = text;
 }
开发者ID:JackWangCUMT,项目名称:AvalonEdit,代码行数:5,代码来源:SingleCharacterElementGenerator.cs

示例7: SpaceTextElement

 public SpaceTextElement(TextLine textLine)
     : base(textLine, 1)
 {
     BreakBefore = LineBreakCondition.BreakPossible;
     BreakAfter = LineBreakCondition.BreakDesired;
 }
开发者ID:JackWangCUMT,项目名称:AvalonEdit,代码行数:6,代码来源:SingleCharacterElementGenerator.cs

示例8: Line

			public Line(int number, TextLine textLine, double right, double top) {
				if (number <= 0)
					throw new ArgumentOutOfRangeException(nameof(number));
				if (textLine == null)
					throw new ArgumentNullException(nameof(textLine));
				Number = number;
				this.textLine = textLine;
				this.right = right;
				this.top = top;
			}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:10,代码来源:LineNumberMarginBase.cs

示例9: AdvanceLineOrigin

 private void AdvanceLineOrigin(ref Point lineOrigin, TextLine currentLine)
 {
     double height = currentLine.Height;
     // advance line origin according to the flow direction
     switch (_defaultParaProps.FlowDirection)
     {
         case FlowDirection.LeftToRight:
         case FlowDirection.RightToLeft:
             lineOrigin.Y += height;
             break;
     }
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:12,代码来源:FormattedText.cs

示例10: WpfTextViewLine

		public WpfTextViewLine(IBufferGraph bufferGraph, LinePartsCollection linePartsCollection, int linePartsIndex, int linePartsLength, int startColumn, int endColumn, ITextSnapshotLine bufferLine, SnapshotSpan span, ITextSnapshot visualSnapshot, TextLine textLine, double indentation, double virtualSpaceWidth) {
			if (bufferGraph == null)
				throw new ArgumentNullException(nameof(bufferGraph));
			if (linePartsCollection == null)
				throw new ArgumentNullException(nameof(linePartsCollection));
			if (linePartsIndex < 0)
				throw new ArgumentOutOfRangeException(nameof(linePartsIndex));
			if (linePartsLength < 0)
				throw new ArgumentOutOfRangeException(nameof(linePartsLength));
			if (linePartsIndex + linePartsLength > linePartsCollection.LineParts.Count)
				throw new ArgumentOutOfRangeException(nameof(linePartsLength));
			if (bufferLine == null)
				throw new ArgumentNullException(nameof(bufferLine));
			if (span.Snapshot != bufferLine.Snapshot)
				throw new ArgumentException();
			if (visualSnapshot == null)
				throw new ArgumentNullException(nameof(visualSnapshot));
			if (textLine == null)
				throw new ArgumentNullException(nameof(textLine));

			IsValid = true;
			this.linePartsIndex = linePartsIndex;
			this.linePartsLength = linePartsLength;
			this.bufferGraph = bufferGraph;
			this.linePartsCollection = linePartsCollection;
			this.startColumn = startColumn;
			this.endColumn = endColumn;
			this.visualSnapshot = visualSnapshot;
			textLines = new ReadOnlyCollection<TextLine>(new[] { textLine });
			Debug.Assert(textLines.Count == 1);// Assumed by all code accessing TextLine prop

			realTopSpace = 0;
			realBottomSpace = 0;
			realBaseline = TextLine.Baseline;
			double baseLineHeight = TextLine.TextHeight - TextLine.Baseline;
			var lineParts = linePartsCollection.LineParts;
			for (int i = 0; i < linePartsLength; i++) {
				var adornmentElement = lineParts[linePartsIndex + i].AdornmentElement;
				if (adornmentElement == null)
					continue;
				double adornmentBaseLineHeight = adornmentElement.TextHeight - adornmentElement.Baseline;
				if (adornmentBaseLineHeight > baseLineHeight)
					baseLineHeight = adornmentBaseLineHeight;
				if (adornmentElement.Baseline > realBaseline)
					realBaseline = adornmentElement.Baseline;
				if (adornmentElement.TopSpace > realTopSpace)
					realTopSpace = adornmentElement.TopSpace;
				if (adornmentElement.BottomSpace > realBottomSpace)
					realBottomSpace = adornmentElement.BottomSpace;
			}
			realTextHeight = Math.Ceiling(baseLineHeight + realBaseline);

			isFirstTextViewLineForSnapshotLine = span.Start == bufferLine.Start;
			isLastTextViewLineForSnapshotLine = span.End == bufferLine.EndIncludingLineBreak;
			IsLastVisualLine = bufferLine.LineNumber + 1 == bufferLine.Snapshot.LineCount && IsLastTextViewLineForSnapshotLine;
			lineBreakLength = isLastTextViewLineForSnapshotLine ? bufferLine.LineBreakLength : 0;
			this.virtualSpaceWidth = virtualSpaceWidth;
			textLeft = indentation;
			textWidth = TextLine.WidthIncludingTrailingWhitespace;
			extentIncludingLineBreak = span;
			endOfLineWidth = Math.Floor(realTextHeight * 0.58333333333333337);// Same as VS
			width = textWidth + (lineBreakLength == 0 ? 0 : endOfLineWidth);
			change = TextViewLineChange.NewOrReformatted;
			SetLineTransform(DefaultLineTransform);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:65,代码来源:WpfTextViewLine.cs

示例11: FindSelectedArea

		private void FindSelectedArea(int idx, int txtLen, int txtOffset, double x, TextLine line, ref double start, ref double end)
		{
			int first = Math.Max(txtOffset, this.SelectionStart - idx);
			int last = Math.Min(txtLen - 1 + txtOffset, this.SelectionEnd - idx);
			if (last >= first)
			{
				start = Math.Min(start, line.GetDistanceFromCharacterHit(new CharacterHit(first, 0)) + x);
				end = Math.Max(end, line.GetDistanceFromCharacterHit(new CharacterHit(last, 1)) + x);
			}
		}
开发者ID:derrickcreamer,项目名称:Floe,代码行数:10,代码来源:ChatPresenter_Selecting.cs

示例12: GetUpDownCaretPosition

		static TextViewPosition GetUpDownCaretPosition(TextView textView, TextViewPosition caretPosition, CaretMovementType direction, VisualLine visualLine, TextLine textLine, bool enableVirtualSpace, ref double xPos)
		{
			// moving up/down happens using the desired visual X position
			if (double.IsNaN(xPos))
				xPos = visualLine.GetTextLineVisualXPosition(textLine, caretPosition.VisualColumn);
			// now find the TextLine+VisualLine where the caret will end up in
			VisualLine targetVisualLine = visualLine;
			TextLine targetLine;
			int textLineIndex = visualLine.TextLines.IndexOf(textLine);
			switch (direction) {
				case CaretMovementType.LineUp:
					{
						// Move up: move to the previous TextLine in the same visual line
						// or move to the last TextLine of the previous visual line
						int prevLineNumber = visualLine.FirstDocumentLine.LineNumber - 1;
						if (textLineIndex > 0) {
							targetLine = visualLine.TextLines[textLineIndex - 1];
						} else if (prevLineNumber >= 1) {
							DocumentLine prevLine = textView.Document.GetLineByNumber(prevLineNumber);
							targetVisualLine = textView.GetOrConstructVisualLine(prevLine);
							targetLine = targetVisualLine.TextLines[targetVisualLine.TextLines.Count - 1];
						} else {
							targetLine = null;
						}
						break;
					}
				case CaretMovementType.LineDown:
					{
						// Move down: move to the next TextLine in the same visual line
						// or move to the first TextLine of the next visual line
						int nextLineNumber = visualLine.LastDocumentLine.LineNumber + 1;
						if (textLineIndex < visualLine.TextLines.Count - 1) {
							targetLine = visualLine.TextLines[textLineIndex + 1];
						} else if (nextLineNumber <= textView.Document.LineCount) {
							DocumentLine nextLine = textView.Document.GetLineByNumber(nextLineNumber);
							targetVisualLine = textView.GetOrConstructVisualLine(nextLine);
							targetLine = targetVisualLine.TextLines[0];
						} else {
							targetLine = null;
						}
						break;
					}
				case CaretMovementType.PageUp:
				case CaretMovementType.PageDown:
					{
						// Page up/down: find the target line using its visual position
						double yPos = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineMiddle);
						if (direction == CaretMovementType.PageUp)
							yPos -= textView.RenderSize.Height;
						else
							yPos += textView.RenderSize.Height;
						DocumentLine newLine = textView.GetDocumentLineByVisualTop(yPos);
						targetVisualLine = textView.GetOrConstructVisualLine(newLine);
						targetLine = targetVisualLine.GetTextLineByVisualYPosition(yPos);
						break;
					}
				default:
					throw new NotSupportedException(direction.ToString());
			}
			if (targetLine != null) {
				double yPos = targetVisualLine.GetTextLineVisualYPosition(targetLine, VisualYPosition.LineMiddle);
				int newVisualColumn = targetVisualLine.GetVisualColumn(new Point(xPos, yPos), enableVirtualSpace);
				
				// prevent wrapping to the next line; TODO: could 'IsAtEnd' help here?
				int targetLineStartCol = targetVisualLine.GetTextLineVisualStartColumn(targetLine);
				if (newVisualColumn >= targetLineStartCol + targetLine.Length) {
					if (newVisualColumn <= targetVisualLine.VisualLength)
						newVisualColumn = targetLineStartCol + targetLine.Length - 1;
				}
				return targetVisualLine.GetTextViewPosition(newVisualColumn);
			} else {
				return caretPosition;
			}
		}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:74,代码来源:CaretNavigationCommandHandler.cs

示例13: MoveCaretUpDown

 static void MoveCaretUpDown(TextArea textArea, CaretMovementType direction, VisualLine visualLine, TextLine textLine, int caretVisualColumn)
 {
     // moving up/down happens using the desired visual X position
     double xPos = textArea.Caret.DesiredXPos;
     if (double.IsNaN(xPos))
         xPos = textLine.GetDistanceFromCharacterHit(new CharacterHit(caretVisualColumn, 0));
     // now find the TextLine+VisualLine where the caret will end up in
     VisualLine targetVisualLine = visualLine;
     TextLine targetLine;
     int textLineIndex = visualLine.TextLines.IndexOf(textLine);
     switch (direction) {
         case CaretMovementType.LineUp:
             {
                 // Move up: move to the previous TextLine in the same visual line
                 // or move to the last TextLine of the previous visual line
                 int prevLineNumber = visualLine.FirstDocumentLine.LineNumber - 1;
                 if (textLineIndex > 0) {
                     targetLine = visualLine.TextLines[textLineIndex - 1];
                 } else if (prevLineNumber >= 1) {
                     DocumentLine prevLine = textArea.Document.GetLineByNumber(prevLineNumber);
                     targetVisualLine = textArea.TextView.GetOrConstructVisualLine(prevLine);
                     targetLine = targetVisualLine.TextLines[targetVisualLine.TextLines.Count - 1];
                 } else {
                     targetLine = null;
                 }
                 break;
             }
         case CaretMovementType.LineDown:
             {
                 // Move down: move to the next TextLine in the same visual line
                 // or move to the first TextLine of the next visual line
                 int nextLineNumber = visualLine.LastDocumentLine.LineNumber + 1;
                 if (textLineIndex < visualLine.TextLines.Count - 1) {
                     targetLine = visualLine.TextLines[textLineIndex + 1];
                 } else if (nextLineNumber <= textArea.Document.LineCount) {
                     DocumentLine nextLine = textArea.Document.GetLineByNumber(nextLineNumber);
                     targetVisualLine = textArea.TextView.GetOrConstructVisualLine(nextLine);
                     targetLine = targetVisualLine.TextLines[0];
                 } else {
                     targetLine = null;
                 }
                 break;
             }
         case CaretMovementType.PageUp:
         case CaretMovementType.PageDown:
             {
                 // Page up/down: find the target line using its visual position
                 double yPos = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineMiddle);
                 if (direction == CaretMovementType.PageUp)
                     yPos -= textArea.TextView.RenderSize.Height;
                 else
                     yPos += textArea.TextView.RenderSize.Height;
                 DocumentLine newLine = textArea.TextView.GetDocumentLineByVisualTop(yPos);
                 targetVisualLine = textArea.TextView.GetOrConstructVisualLine(newLine);
                 targetLine = targetVisualLine.GetTextLineByVisualYPosition(yPos);
                 break;
             }
         default:
             throw new NotSupportedException(direction.ToString());
     }
     if (targetLine != null) {
         CharacterHit ch = targetLine.GetCharacterHitFromDistance(xPos);
         SetCaretPosition(textArea, targetVisualLine, targetLine, ch, false);
         textArea.Caret.DesiredXPos = xPos;
     }
 }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:66,代码来源:CaretNavigationCommandHandler.cs

示例14: SetCaretPosition

        static void SetCaretPosition(TextArea textArea, VisualLine targetVisualLine, TextLine targetLine,
		                             CharacterHit ch, bool allowWrapToNextLine)
        {
            int newVisualColumn = ch.FirstCharacterIndex + ch.TrailingLength;
            int targetLineStartCol = targetVisualLine.GetTextLineVisualStartColumn(targetLine);
            if (!allowWrapToNextLine && newVisualColumn >= targetLineStartCol + targetLine.Length)
                newVisualColumn = targetLineStartCol + targetLine.Length - 1;
            int newOffset = targetVisualLine.GetRelativeOffset(newVisualColumn) + targetVisualLine.FirstDocumentLine.Offset;
            SetCaretPosition(textArea, newVisualColumn, newOffset);
        }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:10,代码来源:CaretNavigationCommandHandler.cs

示例15: MoveNext

            /// <summary>
            /// Advances the enumerator to the next text line of the collection
            /// </summary>
            /// <returns>true if the enumerator was successfully advanced to the next element;
            /// false if the enumerator has passed the end of the collection</returns>
            public bool MoveNext()
            {
                if (_currentLine == null)
                {   // this is the first line

                    if (_that._text.Length == 0)
                        return false;

                    _currentLine = FormatLine(
                        _that._textSourceImpl,
                        _textStorePosition,
                        MaxLineLength(_lineCount),
                        _that._defaultParaProps,
                        null // no previous line break
                        );

                    // check if this line fits the text height
                    if (_totalHeight + _currentLine.Height > _that._maxTextHeight)
                    {
                        _currentLine.Dispose();
                        _currentLine = null;
                        return false;
                    }
                    Debug.Assert(_nextLine == null);
                }
                else
                {
                    // there is no next line or it didn't fit
                    // either way we're finished
                    if (_nextLine == null)
                        return false;

                    _totalHeight += _previousHeight;
                    _textStorePosition += _previousLength;
                    ++_lineCount;

                    _currentLine = _nextLine;
                    _nextLine = null;
                }

                TextLineBreak currentLineBreak = _currentLine.GetTextLineBreak();

                // this line is guaranteed to fit the text height
                Debug.Assert(_totalHeight + _currentLine.Height <= _that._maxTextHeight);

                // now, check if the next line fits, we need to do this on this iteration
                // because we might need to add ellipsis to the current line
                // as a result of the next line measurement

                // maybe there is no next line at all
                if (_textStorePosition + _currentLine.Length < _that._text.Length)
                {
                    bool nextLineFits;

                    if (_lineCount + 1 >= _that._maxLineCount)
                        nextLineFits = false;
                    else
                    {
                        _nextLine = FormatLine(
                            _that._textSourceImpl,
                            _textStorePosition + _currentLine.Length,
                            MaxLineLength(_lineCount + 1),
                            _that._defaultParaProps,
                            currentLineBreak
                            );
                        nextLineFits = (_totalHeight + _currentLine.Height + _nextLine.Height <= _that._maxTextHeight);
                    }                       

                    if (!nextLineFits)
                    {
                        // next line doesn't fit
                        if (_nextLine != null)
                        {
                            _nextLine.Dispose();
                            _nextLine = null;
                        }

                        if (_that._trimming != TextTrimming.None && !_currentLine.HasCollapsed)
                        {
                            // recreate the current line with ellipsis added
                            // Note: Paragraph ellipsis is not supported today. We'll workaround
                            // it here by faking a non-wrap text on finite column width.
                            TextWrapping currentWrap = _that._defaultParaProps.TextWrapping;
                            _that._defaultParaProps.SetTextWrapping(TextWrapping.NoWrap);

                            if (currentLineBreak != null)
                                currentLineBreak.Dispose();

                            _currentLine.Dispose();
                            _currentLine = FormatLine(
                                _that._textSourceImpl,
                                _textStorePosition,
                                MaxLineLength(_lineCount),
                                _that._defaultParaProps,
                                _previousLineBreak
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:FormattedText.cs


注:本文中的System.Windows.Media.TextFormatting.TextLine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。