1818
1919using System ;
2020using System . Globalization ;
21+ using System . Linq ;
2122using System . Runtime . Serialization ;
2223using System . Text ;
2324using System . Windows ;
@@ -36,9 +37,12 @@ public class HighlightingColor : ISerializable, IFreezable, ICloneable, IEquatab
3637 internal static readonly HighlightingColor Empty = FreezableHelper . FreezeAndReturn ( new HighlightingColor ( ) ) ;
3738
3839 string name ;
40+ FontFamily fontFamily = null ;
41+ int ? fontSize ;
3942 FontWeight ? fontWeight ;
4043 FontStyle ? fontStyle ;
4144 bool ? underline ;
45+ bool ? strikethrough ;
4246 HighlightingBrush foreground ;
4347 HighlightingBrush background ;
4448 bool frozen ;
@@ -57,6 +61,34 @@ public string Name {
5761 }
5862 }
5963
64+ /// <summary>
65+ /// Gets/sets the font family. Null if the highlighting color does not change the font style.
66+ /// </summary>
67+ public FontFamily FontFamily {
68+ get {
69+ return fontFamily ;
70+ }
71+ set {
72+ if ( frozen )
73+ throw new InvalidOperationException ( ) ;
74+ fontFamily = value ;
75+ }
76+ }
77+
78+ /// <summary>
79+ /// Gets/sets the font size. Null if the highlighting color does not change the font style.
80+ /// </summary>
81+ public int ? FontSize {
82+ get {
83+ return fontSize ;
84+ }
85+ set {
86+ if ( frozen )
87+ throw new InvalidOperationException ( ) ;
88+ fontSize = value ;
89+ }
90+ }
91+
6092 /// <summary>
6193 /// Gets/sets the font weight. Null if the highlighting color does not change the font weight.
6294 /// </summary>
@@ -99,6 +131,20 @@ public bool? Underline {
99131 }
100132 }
101133
134+ /// <summary>
135+ /// Gets/sets the strikethrough flag. Null if the strikethrough status does not change the font style.
136+ /// </summary>
137+ public bool ? Strikethrough {
138+ get {
139+ return strikethrough ;
140+ }
141+ set {
142+ if ( frozen )
143+ throw new InvalidOperationException ( ) ;
144+ strikethrough = value ;
145+ }
146+ }
147+
102148 /// <summary>
103149 /// Gets/sets the foreground color applied by the highlighting.
104150 /// </summary>
@@ -148,8 +194,14 @@ protected HighlightingColor(SerializationInfo info, StreamingContext context)
148194 this . FontStyle = ( FontStyle ? ) new FontStyleConverter ( ) . ConvertFromInvariantString ( info . GetString ( "Style" ) ) ;
149195 if ( info . GetBoolean ( "HasUnderline" ) )
150196 this . Underline = info . GetBoolean ( "Underline" ) ;
197+ if ( info . GetBoolean ( "HasStrikethrough" ) )
198+ this . Strikethrough = info . GetBoolean ( "Strikethrough" ) ;
151199 this . Foreground = ( HighlightingBrush ) info . GetValue ( "Foreground" , typeof ( HighlightingBrush ) ) ;
152200 this . Background = ( HighlightingBrush ) info . GetValue ( "Background" , typeof ( HighlightingBrush ) ) ;
201+ if ( info . GetBoolean ( "HasFamily" ) )
202+ this . FontFamily = new FontFamily ( info . GetString ( "Family" ) ) ;
203+ if ( info . GetBoolean ( "HasSize" ) )
204+ this . FontSize = info . GetInt32 ( "Size" ) ;
153205 }
154206
155207 /// <summary>
@@ -170,8 +222,16 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
170222 info . AddValue ( "HasUnderline" , this . Underline . HasValue ) ;
171223 if ( this . Underline . HasValue )
172224 info . AddValue ( "Underline" , this . Underline . Value ) ;
225+ if ( this . Strikethrough . HasValue )
226+ info . AddValue ( "Strikethrough" , this . Strikethrough . Value ) ;
173227 info . AddValue ( "Foreground" , this . Foreground ) ;
174228 info . AddValue ( "Background" , this . Background ) ;
229+ info . AddValue ( "HasFamily" , this . FontFamily != null ) ;
230+ if ( this . FontFamily != null )
231+ info . AddValue ( "Family" , this . FontFamily . FamilyNames . FirstOrDefault ( ) ) ;
232+ info . AddValue ( "HasSize" , this . FontSize . HasValue ) ;
233+ if ( this . FontSize . HasValue )
234+ info . AddValue ( "Size" , this . FontSize . Value . ToString ( ) ) ;
175235 }
176236
177237 /// <summary>
@@ -202,6 +262,14 @@ public virtual string ToCss()
202262 b . Append ( Underline . Value ? "underline" : "none" ) ;
203263 b . Append ( "; " ) ;
204264 }
265+ if ( Strikethrough != null ) {
266+ if ( Underline == null )
267+ b . Append ( "text-decoration: " ) ;
268+
269+ b . Remove ( b . Length - 1 , 1 ) ;
270+ b . Append ( Strikethrough . Value ? " line-through" : " none" ) ;
271+ b . Append ( "; " ) ;
272+ }
205273 return b . ToString ( ) ;
206274 }
207275
@@ -254,8 +322,9 @@ public virtual bool Equals(HighlightingColor other)
254322 if ( other == null )
255323 return false ;
256324 return this . name == other . name && this . fontWeight == other . fontWeight
257- && this . fontStyle == other . fontStyle && this . underline == other . underline
258- && object . Equals ( this . foreground , other . foreground ) && object . Equals ( this . background , other . background ) ;
325+ && this . fontStyle == other . fontStyle && this . underline == other . underline && this . strikethrough == other . strikethrough
326+ && object . Equals ( this . foreground , other . foreground ) && object . Equals ( this . background , other . background )
327+ && object . Equals ( this . fontFamily , other . fontFamily ) && object . Equals ( this . FontSize , other . FontSize ) ;
259328 }
260329
261330 /// <inheritdoc/>
@@ -271,6 +340,10 @@ public override int GetHashCode()
271340 hashCode += 1000000033 * foreground . GetHashCode ( ) ;
272341 if ( background != null )
273342 hashCode += 1000000087 * background . GetHashCode ( ) ;
343+ if ( fontFamily != null )
344+ hashCode += 1000000123 * fontFamily . GetHashCode ( ) ;
345+ if ( fontSize != null )
346+ hashCode += 1000000167 * fontSize . GetHashCode ( ) ;
274347 }
275348 return hashCode ;
276349 }
@@ -292,12 +365,19 @@ public void MergeWith(HighlightingColor color)
292365 this . background = color . background ;
293366 if ( color . underline != null )
294367 this . underline = color . underline ;
368+ if ( color . strikethrough != null )
369+ this . strikethrough = color . strikethrough ;
370+ if ( color . fontFamily != null )
371+ this . fontFamily = color . fontFamily ;
372+ if ( color . fontSize != null )
373+ this . fontSize = color . fontSize ;
295374 }
296375
297376 internal bool IsEmptyForMerge {
298377 get {
299378 return fontWeight == null && fontStyle == null && underline == null
300- && foreground == null && background == null ;
379+ && strikethrough == null && foreground == null && background == null
380+ && fontFamily == null && fontSize == null ;
301381 }
302382 }
303383 }
0 commit comments