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; }
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")) ? FontWeights.Bold : FontWeights.Normal; if (element.HasAttribute("italic")) color.FontStyle = XmlConvert.ToBoolean(element.GetAttribute("italic")) ? FontStyles.Italic : FontStyles.Normal; if (element.HasAttribute("color")) color.Foreground = ParseColor(element.GetAttribute("color")); if (element.HasAttribute("bgcolor")) color.Background = ParseColor(element.GetAttribute("bgcolor")); return color; }
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", V2Loader.FontWeightConverter.ConvertToInvariantString(color.FontWeight.Value).ToLowerInvariant()); if (color.FontStyle != null) writer.WriteAttributeString("fontStyle", V2Loader.FontStyleConverter.ConvertToInvariantString(color.FontStyle.Value).ToLowerInvariant()); }
static XshdColor ParseColorAttributes(XmlReader reader) { XshdColor color = new XshdColor(); SetPosition(color, reader); IXmlLineInfo position = reader as IXmlLineInfo; color.Foreground = ParseColor(position, reader.GetAttribute("foreground")); color.Background = ParseColor(position, reader.GetAttribute("background")); color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight")); color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle")); return color; }