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);
        }
        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);
            }

            var backgroundBrush = ColorBrush(highlight.Background);

            if (backgroundBrush != null)
            {
                trp.SetBackgroundBrush(backgroundBrush);
            }

            if (!string.IsNullOrWhiteSpace(highlight.FontWeight) || !string.IsNullOrWhiteSpace(highlight.FontStyle))
            {
                var tf       = element.TextRunProperties.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);
            }
        }
 private void ApplyLinePart(Highlight highlight, int sourceStart, int sourceLength, int lineStart, int lineEnd, int leadingSpaces, double magnify)
 {
     var start = Math.Max(sourceStart, lineStart + leadingSpaces);
     var end = Math.Min(lineEnd, sourceStart + sourceLength);
     if (start < end) ChangeLinePart(start, end, element => ApplyHighlight(element, highlight, magnify));
 }
 private static void UpdateHilightingColor(HighlightingColor highlightingColor, Highlight highlight)
 {
     highlightingColor.Foreground = new HighlightBrush(highlight.Foreground);
     highlightingColor.Background = new HighlightBrush(highlight.Background);
     highlightingColor.FontStyle  = ConvertFontStyle(highlight.FontStyle);
     highlightingColor.FontWeight = ConvertFontWeight(highlight.FontWeight);
     highlightingColor.Underline  = highlight.Underline;
 }