private static void ApplyHighlight(VisualLineElement element, Highlight highlight, double magnify)
        {
            var trp = element.TextRunProperties;

            var foregroundBrush = ColorBrush(highlight.Foreground);
            if (foregroundBrush != null) trp.SetForegroundBrush(foregroundBrush);

            // Block background highlighting handled by BlockBackgroundRenderer
            // Otherwise selection highlight does not work as expected
            if (!highlight.Name.Contains("Block"))
            {
                var backgroundBrush = ColorBrush(highlight.Background);
                if (backgroundBrush != null) trp.SetBackgroundBrush(backgroundBrush);
            }

            if (!string.IsNullOrWhiteSpace(highlight.FontWeight) || !string.IsNullOrWhiteSpace(highlight.FontStyle))
            {
                var tf = trp.Typeface;
                var weight = ConvertFontWeight(highlight.FontWeight) ?? tf.Weight;
                var style = ConvertFontStyle(highlight.FontStyle) ?? tf.Style;
                var typeFace = new Typeface(tf.FontFamily, style, weight, tf.Stretch);
                trp.SetTypeface(typeFace);
            }

            if (highlight.Underline) trp.SetTextDecorations(TextDecorations.Underline);
            if (double.IsNaN(magnify) == false) trp.SetFontRenderingEmSize(trp.FontRenderingEmSize*magnify);
        }
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     if (color.Foreground != null)
     {
         Brush b = color.Foreground.GetBrush(CurrentContext);
         if (b != null)
             element.TextRunProperties.SetForegroundBrush(b);
     }
     if (color.Background != null)
     {
         Brush b = color.Background.GetBrush(CurrentContext);
         if (b != null)
             element.TextRunProperties.SetBackgroundBrush(b);
     }
     if (color.FontStyle != null || color.FontWeight != null)
     {
         Typeface tf = element.TextRunProperties.Typeface;
         element.TextRunProperties.SetTypeface(new Typeface(
             tf.FontFamily,
             color.FontStyle ?? tf.Style,
             color.FontWeight ?? tf.Weight,
             tf.Stretch
         ));
     }
 }
Ejemplo n.º 3
0
 private void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
   if (color.Foreground != null)
   {
     Brush brush = color.Foreground.GetBrush(base.CurrentContext);
     if (brush != null)
     {
       element.TextRunProperties.SetForegroundBrush(brush);
     }
   }
   if (color.Background != null)
   {
     Brush brush2 = color.Background.GetBrush(base.CurrentContext);
     if (brush2 != null)
     {
       element.TextRunProperties.SetBackgroundBrush(brush2);
     }
   }
   if (color.FontStyle.HasValue || color.FontWeight.HasValue)
   {
     Typeface typeface = element.TextRunProperties.Typeface;
     element.TextRunProperties.SetTypeface(new Typeface(typeface.FontFamily, color.FontStyle ?? typeface.Style, color.FontWeight ?? typeface.Weight, typeface.Stretch));
   }
 }
Ejemplo n.º 4
0
 internal static void ApplyColorToElement(VisualLineElement element, HighlightingColor color, ITextRunConstructionContext context)
 {
     if (color.Foreground != null) {
         Brush b = color.Foreground.GetBrush(context);
         if (b != null)
             element.TextRunProperties.SetForegroundBrush(b);
     }
     if (color.Background != null) {
         Brush b = color.Background.GetBrush(context);
         if (b != null)
             element.BackgroundBrush = b;
     }
     if (color.FontStyle != null || color.FontWeight != null) {
         Typeface tf = element.TextRunProperties.Typeface;
         element.TextRunProperties.SetTypeface(new Typeface(
             tf.FontFamily,
             color.FontStyle ?? tf.Style,
             color.FontWeight ?? tf.Weight,
             tf.Stretch
         ));
     }
     if(color.Underline ?? false)
        element.TextRunProperties.SetTextDecorations(TextDecorations.Underline);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     ApplyColorToElement(element, color, CurrentContext);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Helper method for splitting this line element into two, correctly updating the
        /// <see cref="VisualLength"/>, <see cref="DocumentLength"/>, <see cref="VisualColumn"/>
        /// and <see cref="RelativeTextOffset"/> properties.
        /// </summary>
        /// <param name="firstPart">The element before the split position.</param>
        /// <param name="secondPart">The element after the split position.</param>
        /// <param name="splitVisualColumn">The split position as visual column.</param>
        /// <param name="splitRelativeTextOffset">The split position as text offset.</param>
        protected void SplitHelper(VisualLineElement firstPart, VisualLineElement secondPart, int splitVisualColumn, int splitRelativeTextOffset)
        {
            if (firstPart == null)
                throw new ArgumentNullException(nameof(firstPart));
            if (secondPart == null)
                throw new ArgumentNullException(nameof(secondPart));
            int relativeSplitVisualColumn = splitVisualColumn - VisualColumn;
            int relativeSplitRelativeTextOffset = splitRelativeTextOffset - RelativeTextOffset;

            if (relativeSplitVisualColumn <= 0 || relativeSplitVisualColumn >= VisualLength)
                throw new ArgumentOutOfRangeException(nameof(splitVisualColumn), splitVisualColumn, "Value must be between " + (VisualColumn + 1) + " and " + (VisualColumn + VisualLength - 1));
            if (relativeSplitRelativeTextOffset < 0 || relativeSplitRelativeTextOffset > DocumentLength)
                throw new ArgumentOutOfRangeException(nameof(splitRelativeTextOffset), splitRelativeTextOffset, "Value must be between " + (RelativeTextOffset) + " and " + (RelativeTextOffset + DocumentLength));

            int oldVisualLength = VisualLength;
            int oldDocumentLength = DocumentLength;
            int oldVisualColumn = VisualColumn;
            int oldRelativeTextOffset = RelativeTextOffset;

            firstPart.VisualColumn = oldVisualColumn;
            secondPart.VisualColumn = oldVisualColumn + relativeSplitVisualColumn;
            firstPart.RelativeTextOffset = oldRelativeTextOffset;
            secondPart.RelativeTextOffset = oldRelativeTextOffset + relativeSplitRelativeTextOffset;
            firstPart.VisualLength = relativeSplitVisualColumn;
            secondPart.VisualLength = oldVisualLength - relativeSplitVisualColumn;
            firstPart.DocumentLength = relativeSplitRelativeTextOffset;
            secondPart.DocumentLength = oldDocumentLength - relativeSplitRelativeTextOffset;

            if (firstPart.TextRunProperties == null)
                firstPart.TextRunProperties = TextRunProperties.Clone();
            if (secondPart.TextRunProperties == null)
                secondPart.TextRunProperties = TextRunProperties.Clone();
        }
        void PerformVisualElementConstruction(VisualLineElementGenerator[] generators)
        {
            TextDocument document       = this.Document;
            int          offset         = FirstDocumentLine.Offset;
            int          currentLineEnd = offset + FirstDocumentLine.Length;

            LastDocumentLine = FirstDocumentLine;
            int askInterestOffset = 0;             // 0 or 1

            while (offset + askInterestOffset <= currentLineEnd)
            {
                int textPieceEndOffset = currentLineEnd;
                foreach (VisualLineElementGenerator g in generators)
                {
                    g.cachedInterest = g.GetFirstInterestedOffset(offset + askInterestOffset);
                    if (g.cachedInterest != -1)
                    {
                        if (g.cachedInterest < offset)
                        {
                            throw new ArgumentOutOfRangeException(g.GetType().Name + ".GetFirstInterestedOffset",
                                                                  g.cachedInterest,
                                                                  "GetFirstInterestedOffset must not return an offset less than startOffset. Return -1 to signal no interest.");
                        }
                        if (g.cachedInterest < textPieceEndOffset)
                        {
                            textPieceEndOffset = g.cachedInterest;
                        }
                    }
                }
                Debug.Assert(textPieceEndOffset >= offset);
                if (textPieceEndOffset > offset)
                {
                    int textPieceLength = textPieceEndOffset - offset;
                    elements.Add(new VisualLineText(this, textPieceLength));
                    offset = textPieceEndOffset;
                }
                // If no elements constructed / only zero-length elements constructed:
                // do not asking the generators again for the same location (would cause endless loop)
                askInterestOffset = 1;
                foreach (VisualLineElementGenerator g in generators)
                {
                    if (g.cachedInterest == offset)
                    {
                        VisualLineElement element = g.ConstructElement(offset);
                        if (element != null)
                        {
                            elements.Add(element);
                            if (element.DocumentLength > 0)
                            {
                                // a non-zero-length element was constructed
                                askInterestOffset = 0;
                                offset           += element.DocumentLength;
                                if (offset > currentLineEnd)
                                {
                                    DocumentLine newEndLine = document.GetLineByOffset(offset);
                                    currentLineEnd        = newEndLine.Offset + newEndLine.Length;
                                    this.LastDocumentLine = newEndLine;
                                    if (currentLineEnd < offset)
                                    {
                                        throw new InvalidOperationException(
                                                  "The VisualLineElementGenerator " + g.GetType().Name +
                                                  " produced an element which ends within the line delimiter");
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void HighlightError(VisualLineElement visualLineElement)
 {
     visualLineElement.TextRunProperties.SetBackgroundBrush(Brushes.PaleVioletRed);
 }
        protected void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
        {
            var style = _themeManager.CurrentTheme.Colors.FirstOrDefault(item => item.Expression.Equals(color.Name, StringComparison.InvariantCultureIgnoreCase));

            if (style == null)
                style = _defaultStyle;

            if (style.Foreground != null)
            {
                var b = style.GetForegroundBrush();
                if (b != null)
                    element.TextRunProperties.SetForegroundBrush(b);
            }

            if (style.Background != null)
            {
                var b = style.GetBackgroundBrush();
                if (b != null)
                    element.TextRunProperties.SetBackgroundBrush(b);
            }

            if (style.Bold || style.Italic)
            {
                Typeface tf = element.TextRunProperties.Typeface;
                element.TextRunProperties.SetTypeface(new Typeface(
                    tf.FontFamily,
                    style.Italic ? FontStyles.Italic : tf.Style,
                    style.Bold ? FontWeights.Bold : tf.Weight,
                    tf.Stretch
                ));
            }
        }
Ejemplo n.º 10
0
		void HighlightIgnored(VisualLineElement element)
		{
			element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.IgnoredForegroundColor.ToBrush());
			element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.IgnoredBackgroundColor.ToBrush());
		}
Ejemplo n.º 11
0
		void HighlightNamespaceDeclaration(VisualLineElement element)
		{
			element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.NamespaceDeclarationForegroundColor.ToBrush());
			element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.NamespaceDeclarationBackgroundColor.ToBrush());
		}
Ejemplo n.º 12
0
 /// <summary>
 /// Metoda określająca sposób kolorowania linii
 /// </summary>
 /// <param name="element">styl podświetlenia</param>
 void ApplyChanges(VisualLineElement element)
 {
     element.TextRunProperties.SetBackgroundBrush(Brushes.LightSkyBlue);
 }
Ejemplo n.º 13
0
 void ApplyChanges(VisualLineElement element)
 {
     element.TextRunProperties.SetForegroundBrush(Brushes.Black);
     element.TextRunProperties.SetBackgroundBrush(Brushes.Red);
 }