예제 #1
0
 void PushColor(HighlightingColor color)
 {
     if (highlightedLine == null)
     {
         return;
     }
     if (color == null)
     {
         highlightedSectionStack.Push(null);
     }
     else if (lastPoppedSection != null && lastPoppedSection.Color == color &&
              lastPoppedSection.Offset + lastPoppedSection.Length == position + lineStartOffset)
     {
         highlightedSectionStack.Push(lastPoppedSection);
         lastPoppedSection = null;
     }
     else
     {
         HighlightedSection hs = new HighlightedSection {
             Offset = position + lineStartOffset,
             Color  = color
         };
         highlightedLine.Sections.Add(hs);
         highlightedSectionStack.Push(hs);
         lastPoppedSection = null;
     }
 }
예제 #2
0
 public HtmlElement(int offset, int nesting, bool isEnd, HighlightingColor color)
 {
     this.Offset  = offset;
     this.Nesting = nesting;
     this.IsEnd   = isEnd;
     this.Color   = color;
 }
예제 #3
0
 /// <summary>
 /// Gets whether the color is empty (has no effect on a VisualLineTextElement).
 /// For example, the C# "Punctuation" is an empty color.
 /// </summary>
 bool IsEmptyColor(HighlightingColor color)
 {
     if (color == null)
     {
         return(true);
     }
     return(color.Background == null && color.Foreground == null &&
            color.FontStyle == null && color.FontWeight == null);
 }
예제 #4
0
        /// <summary>
        /// Applies the properties from the HighlightingColor to the specified text segment.
        /// </summary>
        public void SetHighlighting(int offset, int length, HighlightingColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }
            if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null)
            {
                // Optimization: don't split the HighlightingState when we're not changing
                // any property. For example, the "Punctuation" color in C# is
                // empty by default.
                return;
            }
            int startIndex = GetIndexForOffset(offset);
            int endIndex   = GetIndexForOffset(offset + length);

            for (int i = startIndex; i < endIndex; i++)
            {
                HighlightingState state = stateChanges[i];
                if (color.Foreground != null)
                {
                    state.Foreground = color.Foreground.Value;
                }
                if (color.Background != null)
                {
                    state.Background = color.Background.Value;
                }
                if (color.FontStyle != null)
                {
                    state.Style = color.FontStyle;
                }
                if (color.FontWeight != null)
                {
                    state.Weight = color.FontWeight;
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Applies the properties from the HighlightingColor to the specified text segment.
 /// </summary>
 public void SetHighlighting(int offset, int length, HighlightingColor color)
 {
     if (color == null)
         throw new ArgumentNullException("color");
     if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null) {
         // Optimization: don't split the HighlightingState when we're not changing
         // any property. For example, the "Punctuation" color in C# is
         // empty by default.
         return;
     }
     int startIndex = GetIndexForOffset(offset);
     int endIndex = GetIndexForOffset(offset + length);
     for (int i = startIndex; i < endIndex; i++) {
         HighlightingState state = stateChanges[i];
         if (color.Foreground != null)
             state.Foreground = color.Foreground.Value;
         if (color.Background != null)
             state.Background = color.Background.Value;
         if (color.FontStyle != null)
             state.Style = color.FontStyle;
         if (color.FontWeight != null)
             state.Weight = color.FontWeight;
     }
 }
예제 #6
0
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     element.TextRunProperties = color.Apply(element.TextRunProperties);
 }
예제 #7
0
 /// <summary>
 /// Gets whether the color is empty (has no effect on a VisualLineTextElement).
 /// For example, the C# "Punctuation" is an empty color.
 /// </summary>
 bool IsEmptyColor(HighlightingColor color)
 {
     if (color == null)
         return true;
     return color.Background == null && color.Foreground == null
         && color.FontStyle == null && color.FontWeight == null;
 }
예제 #8
0
 /// <summary>
 /// Applies a highlighting color to a visual line element.
 /// </summary>
 protected virtual void ApplyColorToElement(VisualLineElement element, HighlightingColor color)
 {
     element.TextRunProperties = color.Apply(element.TextRunProperties);
 }
예제 #9
0
 void PushColor(HighlightingColor color)
 {
     if (highlightedLine == null)
         return;
     if (color == null) {
         highlightedSectionStack.Push(null);
     } else if (lastPoppedSection != null && lastPoppedSection.Color == color
                && lastPoppedSection.Offset + lastPoppedSection.Length == position + lineStartOffset)
     {
         highlightedSectionStack.Push(lastPoppedSection);
         lastPoppedSection = null;
     } else {
         HighlightedSection hs = new HighlightedSection {
             Offset = position + lineStartOffset,
             Color = color
         };
         highlightedLine.Sections.Add(hs);
         highlightedSectionStack.Push(hs);
         lastPoppedSection = null;
     }
 }