public HtmlElement(int offset, int nesting, bool isEnd, HighlightingColor color) { this.Offset = offset; this.Nesting = nesting; this.IsEnd = isEnd; this.Color = color; }
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; } }
/// <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.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 )); } }
/// <summary> /// Gets whether the color needs to be written out to HTML. /// </summary> public virtual bool ColorNeedsSpanForStyling(HighlightingColor color) { if (color == null) { throw new ArgumentNullException("color"); } return(!string.IsNullOrEmpty(color.ToCss())); }
/// <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); }
/// <summary> /// Writes the HTML attribute for the style to the text writer. /// </summary> public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color) { if (writer == null) { throw new ArgumentNullException("writer"); } if (color == null) { throw new ArgumentNullException("color"); } writer.Write(" style=\""); writer.Write(color.ToCss()); writer.Write("\""); }
/// <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.Background == 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.GetBrush(null); } if (color.Background != null) { state.Background = color.Background.GetBrush(null); } if (color.FontStyle != null) { state.Style = color.FontStyle; } if (color.FontWeight != null) { state.Weight = color.FontWeight; } } }
void Insert(ref int pos, ref int newSectionStart, int insertionEndPos, HighlightingColor color, Stack <int> insertionStack) { if (newSectionStart >= insertionEndPos) { // nothing to insert here return; } while (insertionStack.Peek() <= newSectionStart) { insertionStack.Pop(); } while (insertionStack.Peek() < insertionEndPos) { int end = insertionStack.Pop(); // insert the portion from newSectionStart to end if (end > newSectionStart) { this.Sections.Insert(pos++, new HighlightedSection { Offset = newSectionStart, Length = end - newSectionStart, Color = color }); newSectionStart = end; } } if (insertionEndPos > newSectionStart) { this.Sections.Insert(pos++, new HighlightedSection { Offset = newSectionStart, Length = insertionEndPos - newSectionStart, Color = color }); newSectionStart = insertionEndPos; } }