Browse Source
Previously `IFormattedTextImpl` had `SetForegroundBrush` which set mutable state. Make `FormattedText` fully mutable (before it was kinda mutable, kinda immutable) and create immutable `IFormattedTextImpl`s on demand.scenegraph-after-breakage
23 changed files with 374 additions and 437 deletions
@ -0,0 +1,21 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public class FormattedTextStyleSpan |
|||
{ |
|||
public FormattedTextStyleSpan( |
|||
int startIndex, |
|||
int length, |
|||
IBrush foregroundBrush = null) |
|||
{ |
|||
StartIndex = startIndex; |
|||
Length = length; |
|||
ForegroundBrush = foregroundBrush; |
|||
} |
|||
|
|||
public int StartIndex { get; } |
|||
public int Length { get; } |
|||
public IBrush ForegroundBrush { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
|
|||
namespace Avalonia.Media |
|||
{ |
|||
public class Typeface |
|||
{ |
|||
public Typeface( |
|||
string fontFamilyName, |
|||
double fontSize, |
|||
FontStyle style = FontStyle.Normal, |
|||
FontWeight weight = FontWeight.Normal) |
|||
{ |
|||
if (fontSize <= 0) |
|||
{ |
|||
throw new ArgumentException("Font size must be > 0."); |
|||
} |
|||
|
|||
if (weight <= 0) |
|||
{ |
|||
throw new ArgumentException("Font weight must be > 0."); |
|||
} |
|||
|
|||
FontFamilyName = fontFamilyName; |
|||
FontSize = fontSize; |
|||
Style = style; |
|||
Weight = weight; |
|||
} |
|||
|
|||
public string FontFamilyName { get; } |
|||
public double FontSize { get; } |
|||
public FontStyle Style { get; } |
|||
public FontWeight Weight { get; } |
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class FormattedTextTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_FontSize_0() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new FormattedText( |
|||
"foo", |
|||
"Ariel", |
|||
0, |
|||
Size.Infinity)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_FontWeight_0() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new FormattedText( |
|||
"foo", |
|||
"Ariel", |
|||
12, |
|||
Size.Infinity, |
|||
fontWeight: 0)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using Avalonia.Media; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests.Media |
|||
{ |
|||
public class TypefaceTests |
|||
{ |
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_FontSize_0() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new Typeface("foo", 0)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Should_Be_Thrown_If_FontWeight_0() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => new Typeface("foo", 12, weight: 0)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue