Esempio n. 1
0
        void OnTextPropertiesChanged()
        {
            OnTextPropertiesChangedCore();
            useDisplayMode = wpfTextViewHost.TextView.FormattedLineSource.UseDisplayMode;
            var textFormattingMode = useDisplayMode ? TextFormattingMode.Display : TextFormattingMode.Ideal;
            var defaultProps       = GetDefaultTextFormattingRunProperties();

            if (defaultProps is null)
            {
                return;
            }
            var brush = defaultProps.BackgroundBrush ?? Brushes.Transparent;

            if (brush.CanFreeze)
            {
                brush.Freeze();
            }
            Background = brush;
#pragma warning disable CS0618 // Type or member is obsolete
            var ft = new FormattedText("8", defaultProps.CultureInfo, FlowDirection.LeftToRight, defaultProps.Typeface, defaultProps.FontRenderingEmSize, defaultProps.ForegroundBrush, null, textFormattingMode);
#pragma warning restore CS0618 // Type or member is obsolete
            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);
        }
Esempio n. 2
0
        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");
            }

            this.textFormatter      = textFormatterProvider.Create(useDisplayMode);
            this.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);
            this.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           = textAndAdornmentSequencer;
            this.aggregateClassifier            = aggregateClassifier;
            this.textAndAdornmentSequencer      = sequencer;
            this.classificationFormatMap        = classificationFormatMap;
            this.defaultTextParagraphProperties = new TextFormattingParagraphProperties(classificationFormatMap.DefaultTextProperties, ColumnWidth * TabSize);
        }
Esempio n. 3
0
		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);
		}