From 8ace2341fb6babcb202708c8d887ffb913142a3e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 14:06:05 +0200 Subject: [PATCH] Fix bugs in #505 --- .../Src/Options/NamedColorHighlightingItem.cs | 2 +- .../Highlighting/HighlightingColor.cs | 26 +++++++++++++++---- .../Highlighting/Resources/ModeV2.xsd | 1 - .../Highlighting/Xshd/V2Loader.cs | 2 +- .../Highlighting/Xshd/XshdColor.cs | 10 ++++--- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs index 5bc0f4cd7f..e5176fdc80 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs @@ -70,7 +70,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options public bool Underline { get { - return color.Underline; + return color.Underline == true; } set { throw new NotSupportedException(); diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs index 163444c111..6dfb652d05 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs @@ -86,8 +86,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting } /// - /// Gets/sets the underline flag. Null if the underline status does not change the font style. - /// + /// Gets/sets the underline flag. Null if the underline status does not change the font style. + /// public bool? Underline { get { return underline; @@ -97,7 +97,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting throw new InvalidOperationException(); underline = value; } - } + } /// /// Gets/sets the foreground color applied by the highlighting. @@ -146,6 +146,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight")); if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); + if (info.GetBoolean("HasUnderline")) + this.Underline = info.GetBoolean("Underline"); this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush)); this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush)); } @@ -169,6 +171,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting info.AddValue("HasStyle", this.FontStyle.HasValue); if (this.FontStyle.HasValue) info.AddValue("Style", this.FontStyle.Value.ToString()); + info.AddValue("HasUnderline", this.Underline.HasValue); + if (this.Underline.HasValue) + info.AddValue("Underline", this.Underline.Value); info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); } @@ -196,6 +201,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting b.Append(FontStyle.Value.ToString().ToLowerInvariant()); b.Append("; "); } + if (Underline != null) + { + b.Append("text-decoration: "); + b.Append(Underline.Value ? "underline" : "none"); + b.Append("; "); + } return b.ToString(); } @@ -247,7 +258,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting { if (other == null) return false; - return this.name == other.name && this.fontWeight == other.fontWeight && this.fontStyle == other.fontStyle && object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background); + return this.name == other.name && this.fontWeight == other.fontWeight + && this.fontStyle == other.fontStyle && this.underline == other.underline + && object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background); } /// @@ -282,11 +295,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting this.foreground = color.foreground; if (color.background != null) this.background = color.background; + if (color.underline != null) + this.underline = color.underline; } internal bool IsEmptyForMerge { get { - return fontWeight == null && fontStyle == null && foreground == null && background == null; + return fontWeight == null && fontStyle == null && underline == null + && foreground == null && background == null; } } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd index 1a9c463960..c2e242ac28 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd @@ -24,7 +24,6 @@ - diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs index 70b2539dc8..b9b81d1dec 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs @@ -297,7 +297,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd color.Background = ParseColor(position, reader.GetAttribute("background")); color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight")); color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle")); - color.Underline = reader.GetAttribute("underline") == "true"; + color.Underline = reader.GetBoolAttribute("underline"); return color; } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs index 5213eeee34..a6968508b8 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd /// /// Gets/sets the underline flag /// - public bool Underline { get; set; } + public bool? Underline { get; set; } /// /// Gets/sets the font style. @@ -86,7 +86,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); this.ExampleText = info.GetString("ExampleText"); - this.Underline = info.GetBoolean("Underline"); + if (info.GetBoolean("HasUnderline")) + this.Underline = info.GetBoolean("Underline"); } /// @@ -104,9 +105,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd info.AddValue("Name", this.Name); info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); + info.AddValue("HasUnderline", this.Underline.HasValue); + if (this.Underline.HasValue) + info.AddValue("Underline", this.Underline.Value); info.AddValue("HasWeight", this.FontWeight.HasValue); - if (this.Underline) - info.AddValue("Underline", this.Underline); if (this.FontWeight.HasValue) info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); info.AddValue("HasStyle", this.FontStyle.HasValue);