static XshdColor GetColorFromElement(XmlElement element) { if (!element.HasAttribute("bold") && !element.HasAttribute("italic") && !element.HasAttribute("color") && !element.HasAttribute("bgcolor")) { return(null); } XshdColor color = new XshdColor(); if (element.HasAttribute("bold")) { color.FontWeight = XmlConvert.ToBoolean(element.GetAttribute("bold")) ? FontWeight.Bold : FontWeight.Normal; } if (element.HasAttribute("italic")) { color.FontStyle = XmlConvert.ToBoolean(element.GetAttribute("italic")) ? FontStyle.Italic : FontStyle.Normal; } if (element.HasAttribute("color")) { color.Foreground = ParseColor(element.GetAttribute("color")); } if (element.HasAttribute("bgcolor")) { color.Background = ParseColor(element.GetAttribute("bgcolor")); } return(color); }
public object VisitColor(XshdColor color) { HighlightingColor c; if (color.Name != null) { c = _def._colorDict[color.Name]; } else if (color.Foreground == null && color.FontStyle == null && color.FontWeight == null) { return(null); } else { c = new HighlightingColor(); } c.Name = color.Name; c.Foreground = color.Foreground; c.Background = color.Background; c.Underline = color.Underline; c.FontStyle = color.FontStyle; c.FontWeight = color.FontWeight; return(c); }
private static XshdColor ParseColorAttributes(XmlReader reader) { var color = new XshdColor(); SetPosition(color, reader); color.Foreground = ParseColor(reader.GetAttribute("foreground")); color.Background = ParseColor(reader.GetAttribute("background")); color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight")); color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle")); color.Underline = reader.GetBoolAttribute("underline"); return(color); }
static XshdReference <XshdColor> GetColorReference(XmlElement element) { XshdColor color = GetColorFromElement(element); if (color != null) { return(new XshdReference <XshdColor>(color)); } else { return(new XshdReference <XshdColor>()); } }
object IXshdVisitor.VisitColor(XshdColor color) { _writer.WriteStartElement("Color", Namespace); if (color.Name != null) { _writer.WriteAttributeString("name", color.Name); } WriteColorAttributes(color); if (color.ExampleText != null) { _writer.WriteAttributeString("exampleText", color.ExampleText); } _writer.WriteEndElement(); return(null); }
public object VisitColor(XshdColor color) { if (color.Name != null) { if (color.Name.Length == 0) { throw Error(color, "Name must not be the empty string"); } if (_def._colorDict.ContainsKey(color.Name)) { throw Error(color, "Duplicate color name '" + color.Name + "'."); } _def._colorDict.Add(color.Name, new HighlightingColor()); } return(null); }
private void WriteColorAttributes(XshdColor color) { if (color.Foreground != null) { _writer.WriteAttributeString("foreground", color.Foreground.ToString()); } if (color.Background != null) { _writer.WriteAttributeString("background", color.Background.ToString()); } if (color.FontWeight != null) { _writer.WriteAttributeString("fontWeight", color.FontWeight.Value.ToString().ToLowerInvariant()); } if (color.FontStyle != null) { _writer.WriteAttributeString("fontStyle", color.FontStyle.Value.ToString().ToLowerInvariant()); } }