public ChatFormatter(Typeface typeface, double fontSize, Brush foreground, IDictionary<string,Brush> palette) { _runProperties = new CustomTextRunProperties(typeface, fontSize, foreground, Brushes.Transparent, false); _paraProperties = new CustomParagraphProperties(_runProperties); _formatter = TextFormatter.Create(TextFormattingMode.Display); _palette = palette; }
internal TextFormatterHost(TextFormatter textFormatter, TextFormattingMode textFormattingMode) { if(textFormatter == null) { TextFormatter = TextFormatter.FromCurrentDispatcher(textFormattingMode); } else { TextFormatter = textFormatter; } }
public TextLine GetTextForNonPrintableCharacter(string text, ITextRunConstructionContext context) { if (nonPrintableCharacterTexts == null) nonPrintableCharacterTexts = new Dictionary<string, TextLine>(); TextLine textLine; if (!nonPrintableCharacterTexts.TryGetValue(text, out textLine)) { var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties); p.SetForegroundBrush(context.TextView.NonPrintableCharacterBrush); if (formatter == null) formatter = TextFormatterFactory.Create(context.TextView); textLine = FormattedTextElement.PrepareText(formatter, text, p); nonPrintableCharacterTexts[text] = textLine; } return textLine; }
public TextLine GetSimpleLightGrayText(string text, ITextRunConstructionContext context) { if (simpleLightGrayTexts == null) simpleLightGrayTexts = new Dictionary<string, TextLine>(); TextLine textLine; if (!simpleLightGrayTexts.TryGetValue(text, out textLine)) { var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties); p.SetForegroundBrush(Brushes.LightGray); if (formatter == null) formatter = TextFormatterFactory.Create(context.TextView); textLine = FormattedTextElement.PrepareText(formatter, text, p); simpleLightGrayTexts[text] = textLine; } return textLine; }
public IList<TextLineVisual> CreateLineVisual(Int32 lineNumber, IList<SpaceNegotiation> spaceNegotiations) { IList<ClassificationSpan> classificationSpans; Int32 startOfLineFromLineNumber = _textView.TextBuffer.GetStartOfLineFromLineNumber(lineNumber); Int32 startOfNextLineFromPosition = _textView.TextBuffer.GetStartOfNextLineFromPosition(startOfLineFromLineNumber); Int32 lengthOfLineFromLineNumber = _textView.TextBuffer.GetLengthOfLineFromLineNumber(lineNumber); Int32 length = 0; if (startOfNextLineFromPosition == startOfLineFromLineNumber) { length = _textView.TextBuffer.GetEndOfLineFromPosition(startOfLineFromLineNumber) - startOfLineFromLineNumber; } else { length = startOfNextLineFromPosition - startOfLineFromLineNumber; } if (length > 0) { classificationSpans = _classifier.GetClassificationSpans(new VersionedTextSpan(_textView.TextBuffer, startOfLineFromLineNumber, length)); } else { classificationSpans = new List<ClassificationSpan>(0); } TextFormattingSource textSource = new TextFormattingSource(_textView.TextBuffer, _classificationFormatMap, startOfLineFromLineNumber, length, classificationSpans, spaceNegotiations); if (_textFormatter == null) { _textFormatter = TextFormatter.Create(); } List<TextLine> textLines = new List<TextLine>(); Int32 firstCharIndex = 0; TextLineBreak previousLineBreak = null; while (firstCharIndex <= length) { TextLine item = _textFormatter.FormatLine(textSource, firstCharIndex, this.MaxLineWidth, _paragraphProperties, previousLineBreak); firstCharIndex += item.Length; previousLineBreak = item.GetTextLineBreak(); textLines.Add(item); } List<TextLineVisual> list3 = new List<TextLineVisual>(); list3.Add(new TextLineVisual(_textView, textLines, new TextSpan(_textView.TextBuffer, startOfLineFromLineNumber, length), length - lengthOfLineFromLineNumber, textSource.VirtualCharacterPositions)); return list3; }
public FormattedLineSource(ITextFormatterProvider textFormatterProvider, ITextParagraphPropertiesFactoryService textParagraphPropertiesFactoryService, ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap, bool isViewWrapEnabled) { if (textFormatterProvider == null) throw new ArgumentNullException(nameof(textFormatterProvider)); if (sourceTextSnapshot == null) throw new ArgumentNullException(nameof(sourceTextSnapshot)); if (visualBufferSnapshot == null) throw new ArgumentNullException(nameof(visualBufferSnapshot)); if (aggregateClassifier == null) throw new ArgumentNullException(nameof(aggregateClassifier)); if (sequencer == null) throw new ArgumentNullException(nameof(sequencer)); if (classificationFormatMap == null) throw new ArgumentNullException(nameof(classificationFormatMap)); if (tabSize <= 0) throw new ArgumentOutOfRangeException(nameof(tabSize)); if (sourceTextSnapshot != visualBufferSnapshot) throw new NotSupportedException("Text snapshot must be identical to visual snapshot"); textFormatter = textFormatterProvider.Create(useDisplayMode); formattedTextCache = new FormattedTextCache(useDisplayMode); this.textParagraphPropertiesFactoryService = textParagraphPropertiesFactoryService; SourceTextSnapshot = sourceTextSnapshot; TopTextSnapshot = visualBufferSnapshot; UseDisplayMode = useDisplayMode; TabSize = tabSize; BaseIndentation = baseIndent; WordWrapWidth = wordWrapWidth; MaxAutoIndent = Math.Round(maxAutoIndent); ColumnWidth = formattedTextCache.GetColumnWidth(classificationFormatMap.DefaultTextProperties); wrapGlyphWidth = isViewWrapEnabled ? 1.5 * ColumnWidth : 0; LineHeight = WpfTextViewLine.DEFAULT_TOP_SPACE + WpfTextViewLine.DEFAULT_BOTTOM_SPACE + formattedTextCache.GetLineHeight(classificationFormatMap.DefaultTextProperties); TextHeightAboveBaseline = formattedTextCache.GetTextHeightAboveBaseline(classificationFormatMap.DefaultTextProperties); TextHeightBelowBaseline = formattedTextCache.GetTextHeightBelowBaseline(classificationFormatMap.DefaultTextProperties); TextAndAdornmentSequencer = sequencer; this.aggregateClassifier = aggregateClassifier; this.classificationFormatMap = classificationFormatMap; defaultTextParagraphProperties = new TextFormattingParagraphProperties(classificationFormatMap.DefaultTextProperties, ColumnWidth * TabSize); }
void LineNumberMargin_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (Visibility == Visibility.Visible) { if (!hasRegisteredEvents) { RegisterEvents(); SetTop(textLayer, -wpfTextViewHost.TextView.ViewportTop); UpdateMaxLineDigits(); UpdateLineNumberLayerSize(); UpdateForceClearTypeIfNeeded(); OnTextPropertiesChanged(); UpdateLines(Array.Empty<ITextViewLine>(), Array.Empty<ITextViewLine>()); } } else { if (hasRegisteredEvents) UnregisterEvents(); ClearLines(); defaultTextParagraphProperties = null; textFormatter = null; } }
void OnTextPropertiesChanged() { OnTextPropertiesChangedCore(); useDisplayMode = wpfTextViewHost.TextView.FormattedLineSource.UseDisplayMode; var textFormattingMode = useDisplayMode ? TextFormattingMode.Display : TextFormattingMode.Ideal; var defaultProps = GetDefaultTextFormattingRunProperties(); if (defaultProps == null) return; var brush = defaultProps.BackgroundBrush ?? Brushes.Transparent; if (brush.CanFreeze) brush.Freeze(); Background = brush; var ft = new FormattedText("8", defaultProps.CultureInfo, FlowDirection.LeftToRight, defaultProps.Typeface, defaultProps.FontRenderingEmSize, defaultProps.ForegroundBrush, null, textFormattingMode); currentMaxLineDigits = GetMaxLineDigits(); int maxLineNumberValue = Math.Min(int.MaxValue, (int)(Math.Pow(10, currentMaxLineDigits) - 1)); // Just in case non-digits are part of the string, calculate max string length var lineNumberString = GetLineNumberString(maxLineNumberValue); double leftMarginWidth = ft.Width; double rightMarginWidth = ft.Width; double width = leftMarginWidth + rightMarginWidth + ft.Width * lineNumberString.Length; lineNumberTextRight = width - rightMarginWidth; Width = width; ClearLines(); defaultTextParagraphProperties = new TextFormattingParagraphProperties(defaultProps); textFormatter = textFormatterProvider.Create(useDisplayMode); }
/// <summary> /// Constructs a TextLine from a simple text. /// </summary> public static TextLine PrepareText(TextFormatter formatter, string text, TextRunProperties properties) { if (formatter == null) throw new ArgumentNullException("formatter"); if (text == null) throw new ArgumentNullException("text"); if (properties == null) throw new ArgumentNullException("properties"); return formatter.FormatLine( new SimpleTextSource(text, properties), 0, 32000, new VisualLineTextParagraphProperties { defaultTextRunProperties = properties, textWrapping = TextWrapping.NoWrap, tabSize = 40 }, null); }
//------------------------------------------------------------------- // // Internal Methods // //------------------------------------------------------------------- #region Internal Methods /// <summary> /// Create and format text line. /// </summary> /// <param name="dcp">First character position for the line.</param> /// <param name="formatWidth">Width to pass to LS formatter.</param> /// <param name="paragraphWidth">Line wrapping width.</param> /// <param name="lineProperties">Line's properties.</param> /// <param name="textRunCache">Run cache.</param> /// <param name="formatter">Text formatter.</param> /// <remarks> /// formatWidth/paragraphWidth is an attempt to work around bug 114719. /// Unfortunately, Line Services cannot guarantee that once a line /// has been measured, measuring the same content with the actual line /// width will produce the same line. /// /// For example, suppose we format dcp 0 with paragraphWidth = 100. /// Suppose this results in a line from dcp 0 - 10, with width = 95. /// /// We would expect that a call to FormatLine with dcp = 0, /// paragraphWidth = 95 would result in the same 10 char line. /// But in practice it might return a 9 char line. /// /// The workaround is to pass in an explicit formatting width across /// multiple calls, even if the paragraphWidth changes. /// </remarks> internal void Format(int dcp, double formatWidth, double paragraphWidth, LineProperties lineProperties, TextRunCache textRunCache, TextFormatter formatter) { _lineProperties = lineProperties; _dcp = dcp; _paragraphWidth = paragraphWidth; // We must ignore TextAlignment here since formatWidth does not // necessarilly equal paragraphWidth. We'll adjust on later calls. lineProperties.IgnoreTextAlignment = (lineProperties.TextAlignment != TextAlignment.Justify); try { _line = formatter.FormatLine(this, dcp, formatWidth, lineProperties, null, textRunCache); } finally { lineProperties.IgnoreTextAlignment = false; } }
internal LineEnumerator(FormattedText text) { _previousHeight = 0; _previousLength = 0; _previousLineBreak = null; _textStorePosition = 0; _lineCount = 0; _totalHeight = 0; _currentLine = null; _nextLine = null; _formatter = TextFormatter.FromCurrentDispatcher(text._textFormattingMode); _that = text; if (_that._textSourceImpl == null) _that._textSourceImpl = new TextSourceImplementation(_that); }
static VisualTextLine() { formatter = TextFormatter.Create(); paragraphProperties = new SimpleParagraphProperties { defaultTextRunProperties = TextConfiguration.GetGlobalTextRunProperties() }; }
public WpfTextFormatter(TextFormattingMode mode) { formatter = TextFormatter.Create(mode); }
void InitializeAll() { textFormatter = TextFormatter.Create(TextOptions.GetTextFormattingMode(this)); InitializeFontProperties(); InitializeSizeProperties(false); RepaintLayers(); InvalidateScrollInfo(); }
TextFormatterProvider() { idealModeTextFormatter = TextFormatter.Create(TextFormattingMode.Ideal); displayModeTextFormatter = TextFormatter.Create(TextFormattingMode.Display); }