diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs
index 02dfbe71e95..daef1dd91d5 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Windows.Media;
@@ -460,12 +460,19 @@ TextRunCache textRunCache
double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;
- ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, "paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize");
- ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, realMaxFontRenderingEmSize, "paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize");
+ if ( paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize < 0
+ || paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize > realMaxFontRenderingEmSize)
+ {
+ throw new ArgumentOutOfRangeException("paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize", SR.Format(SR.ParameterMustBeBetween, 0, realMaxFontRenderingEmSize));
+ }
+
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.Indent, Constants.RealInfiniteWidth, "paragraphProperties.Indent");
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.LineHeight, Constants.RealInfiniteWidth, "paragraphProperties.LineHeight");
- ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultIncrementalTab, "paragraphProperties.DefaultIncrementalTab");
- ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultIncrementalTab, Constants.RealInfiniteWidth, "paragraphProperties.DefaultIncrementalTab");
+ if ( paragraphProperties.DefaultIncrementalTab < 0
+ || paragraphProperties.DefaultIncrementalTab > Constants.RealInfiniteWidth)
+ {
+ throw new ArgumentOutOfRangeException("paragraphProperties.DefaultIncrementalTab", SR.Format(SR.ParameterMustBeBetween, 0, Constants.RealInfiniteWidth));
+ }
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/Strings.resx b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/Strings.resx
index 186693ac403..c7ba9f99a84 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/Strings.resx
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/Strings.resx
@@ -1816,6 +1816,15 @@
Page number cannot be negative.
+
+ Parameter must be greater than or equal to zero.
+
+
+ The parameter value must be between '{0}' and '{1}'.
+
+
+ The parameter value must be greater than zero.
+
Token is not valid.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.cs.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.cs.xlf
index ba6aa8c7ff7..e21e5ab6c41 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.cs.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.cs.xlf
@@ -2517,6 +2517,21 @@
Číslo stránky nemůže být záporné.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Nalezena nesprávná forma {0} při analýze řetězce {1}.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.de.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.de.xlf
index 4b1756317e7..8d9f2c12fb8 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.de.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.de.xlf
@@ -2517,6 +2517,21 @@
Die Seitenzahl kann nicht negativ sein.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Beim Analysieren der Zeichenfolge "{1}" wurde die ungültige Form "{0}" gefunden.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.es.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.es.xlf
index 8487c54bc06..a91d92f45fb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.es.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.es.xlf
@@ -2517,6 +2517,21 @@
El número de página no puede ser negativo.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Se encontró un formato incorrecto "{0}" al analizar la cadena "{1}".
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.fr.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.fr.xlf
index 615026eeac9..1430b50fdcc 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.fr.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.fr.xlf
@@ -2517,6 +2517,21 @@
Le numéro de page ne peut pas être négatif.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Forme '{0}' incorrecte trouvée durant l'analyse de la chaîne '{1}'.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.it.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.it.xlf
index b31798433f9..205a68e1f59 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.it.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.it.xlf
@@ -2517,6 +2517,21 @@
Il numero di pagina non può essere negativo.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.È stato trovato un formato non corretto '{0}' durante l'analisi della stringa '{1}'.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ja.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ja.xlf
index 0cc18516807..d022e53a7cf 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ja.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ja.xlf
@@ -2517,6 +2517,21 @@
ページ番号は負の数にできません。
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.'{1}' 文字列の解析中に無効なフォーム '{0}' が見つかりました。
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ko.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ko.xlf
index 14f62b234d1..2bc81249a33 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ko.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ko.xlf
@@ -2517,6 +2517,21 @@
페이지 번호는 음수일 수 없습니다.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.'{1}' 문자열을 구문 분석하는 동안 잘못된 '{0}' 형식이 검색되었습니다.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pl.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pl.xlf
index aca84fad3a8..cb88c9f41ba 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pl.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pl.xlf
@@ -2517,6 +2517,21 @@
Numer strony nie może być ujemny.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Znaleziono nieprawidłową formę „{0}” podczas analizy ciągu „{1}”.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pt-BR.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pt-BR.xlf
index fa7d3b07dbf..a9f59f8f210 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pt-BR.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.pt-BR.xlf
@@ -2517,6 +2517,21 @@
O número da página não pode ser negativo.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.Forma incorreta de '{0}' encontrada na análise da cadeia de caracteres '{1}'.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ru.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ru.xlf
index 281be405ed7..fd7470933ae 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ru.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.ru.xlf
@@ -2517,6 +2517,21 @@
Номер страницы не может быть отрицательным.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.При синтаксическом анализе строки "{1}" обнаружена неправильная форма "{0}".
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.tr.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.tr.xlf
index 53e3a858840..a46e9c86d98 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.tr.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.tr.xlf
@@ -2517,6 +2517,21 @@
Sayfa numarası negatif olamaz.
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.'{1}' dizesi ayrıştırılırken yanlış '{0}' biçimi bulundu.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hans.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hans.xlf
index 6ada1fd2f64..c53967479a1 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hans.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hans.xlf
@@ -2517,6 +2517,21 @@
页码不能为负数。
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.解析“{1}”字符串时发现格式“{0}”错误。
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hant.xlf b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hant.xlf
index 8d935d25dd8..8e19f0d49ee 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hant.xlf
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/Resources/xlf/Strings.zh-Hant.xlf
@@ -2517,6 +2517,21 @@
頁碼不能為負數。
+
+ Parameter must be greater than or equal to zero.
+ Parameter must be greater than or equal to zero.
+
+
+
+ The parameter value must be between '{0}' and '{1}'.
+ The parameter value must be between '{0}' and '{1}'.
+
+
+
+ The parameter value must be greater than zero.
+ The parameter value must be greater than zero.
+
+ Incorrect form '{0}' found parsing '{1}' string.剖析 '{1}' 字串時發現不正確的格式 '{0}'。
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/D3DImage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/D3DImage.cs
index cc67ca22bb1..1b07292d651 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/D3DImage.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/D3DImage.cs
@@ -55,8 +55,15 @@ public D3DImage() : this(96.0, 96.0)
public D3DImage(double dpiX, double dpiY)
{
- ArgumentOutOfRangeException.ThrowIfNegative(dpiX);
- ArgumentOutOfRangeException.ThrowIfNegative(dpiY);
+ if (dpiX < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(dpiX), SR.ParameterCannotBeNegative);
+ }
+
+ if (dpiY < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(dpiY), SR.ParameterCannotBeNegative);
+ }
_canWriteEvent = new ManualResetEvent(true);
_availableCallback = Callback;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs
index dc042cda7aa..15d649af395 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs
@@ -270,7 +270,9 @@ private static void ValidateCulture(CultureInfo culture)
private static void ValidateFontSize(double emSize)
{
- ArgumentOutOfRangeException.ThrowIfNegativeOrZero(emSize);
+ if (emSize <= 0)
+ throw new ArgumentOutOfRangeException(nameof(emSize), SR.ParameterMustBeGreaterThanZero);
+
ArgumentOutOfRangeException.ThrowIfGreaterThan(emSize, MaxFontEmSize);
ArgumentOutOfRangeException.ThrowIfEqual(emSize, double.NaN);
}
@@ -1223,7 +1225,8 @@ public double LineHeight
{
set
{
- ArgumentOutOfRangeException.ThrowIfNegative(value);
+ if (value < 0)
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ParameterCannotBeNegative);
_defaultParaProps.SetLineHeight(value);
InvalidateMetrics();
@@ -1246,7 +1249,8 @@ public double MaxTextWidth
{
set
{
- ArgumentOutOfRangeException.ThrowIfNegative(value);
+ if (value < 0)
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ParameterCannotBeNegative);
_maxTextWidth = value;
InvalidateMetrics();
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs
index 5c3b4d47e4b..b1209ec2a3b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
@@ -19,7 +19,7 @@ namespace System.Windows.Media.TextFormatting
{
///
/// A specialized TextSymbols implemented by TextFormatter to produces
- /// a collection of TextCharacterShape each represents a collection of
+ /// a collection of TextCharacterShape – each represents a collection of
/// character glyphs from distinct physical typeface.
///
public class TextCharacters : TextRun, ITextSymbols, IShapeableTextCollector
@@ -119,7 +119,10 @@ TextRunProperties textRunProperties
throw new ArgumentNullException("textRunProperties.CultureInfo");
}
- ArgumentOutOfRangeException.ThrowIfNegativeOrZero(textRunProperties.FontRenderingEmSize, "textRunProperties.FontRenderingEmSize");
+ if (textRunProperties.FontRenderingEmSize <= 0)
+ {
+ throw new ArgumentOutOfRangeException("textRunProperties.FontRenderingEmSize", SR.ParameterMustBeGreaterThanZero);
+ }
_characterBufferReference = characterBufferReference;
_length = length;
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Interop/D3DImage.Tests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Interop/D3DImage.Tests.cs
new file mode 100644
index 00000000000..a624f78d908
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Interop/D3DImage.Tests.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Windows.Interop;
+
+public sealed class D3DImageTests
+{
+ [Fact]
+ public void Constructor_NaN_Dpi_DoesNotThrow()
+ {
+ // NaN DPI should not throw - it passes through the "< 0" check
+ // because NaN < 0 is false per IEEE 754.
+ _ = new D3DImage(double.NaN, double.NaN);
+ }
+
+ [Fact]
+ public void Constructor_NegativeDpiX_ThrowsArgumentOutOfRangeException()
+ {
+ Assert.Throws(() => new D3DImage(-1.0, 96.0));
+ }
+
+ [Fact]
+ public void Constructor_NegativeDpiY_ThrowsArgumentOutOfRangeException()
+ {
+ Assert.Throws(() => new D3DImage(96.0, -1.0));
+ }
+
+ [Fact]
+ public void Constructor_ValidDpi_DoesNotThrow()
+ {
+ _ = new D3DImage(96.0, 96.0);
+ }
+}
diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Media/FormattedText.Tests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Media/FormattedText.Tests.cs
new file mode 100644
index 00000000000..c35264939e8
--- /dev/null
+++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationCore.Tests/System/Windows/Media/FormattedText.Tests.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Globalization;
+
+namespace System.Windows.Media;
+
+public sealed class FormattedTextTests
+{
+ private static FormattedText CreateFormattedText(string text = "Test")
+ {
+ return new FormattedText(
+ text,
+ CultureInfo.InvariantCulture,
+ FlowDirection.LeftToRight,
+ new Typeface("Arial"),
+ 12.0,
+ System.Windows.Media.Brushes.Black,
+ 1.0);
+ }
+
+ [Fact]
+ public void LineHeight_SetNaN_DoesNotThrow()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ ft.LineHeight = double.NaN;
+ }
+
+ [Fact]
+ public void LineHeight_SetNegative_ThrowsArgumentOutOfRangeException()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ Assert.Throws(() => ft.LineHeight = -1.0);
+ }
+
+ [Fact]
+ public void LineHeight_SetZero_DoesNotThrow()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ ft.LineHeight = 0.0;
+ }
+
+ [Fact]
+ public void MaxTextWidth_SetNaN_DoesNotThrow()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ ft.MaxTextWidth = double.NaN;
+ }
+
+ [Fact]
+ public void MaxTextWidth_SetNegative_ThrowsArgumentOutOfRangeException()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ Assert.Throws(() => ft.MaxTextWidth = -1.0);
+ }
+
+ [Fact]
+ public void MaxTextWidth_SetZero_DoesNotThrow()
+ {
+ FormattedText ft = CreateFormattedText();
+
+ ft.MaxTextWidth = 0.0;
+ }
+}