From 03f36c4283a99e45c5de8aea357b42ee72e9cf12 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 13 Mar 2024 16:15:27 +1000 Subject: [PATCH 1/2] Fix #390 --- src/SixLabors.Fonts/GlyphShapingData.cs | 1 + .../Shapers/UniversalShaper.cs | 2 +- .../SixLabors.Fonts.Tests/Issues/Issues_390.cs | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs diff --git a/src/SixLabors.Fonts/GlyphShapingData.cs b/src/SixLabors.Fonts/GlyphShapingData.cs index 042bfdbf..f5b9f2f2 100644 --- a/src/SixLabors.Fonts/GlyphShapingData.cs +++ b/src/SixLabors.Fonts/GlyphShapingData.cs @@ -17,6 +17,7 @@ internal class GlyphShapingData /// /// Initializes a new instance of the class. /// + /// The text run. public GlyphShapingData(TextRun textRun) => this.TextRun = textRun; /// diff --git a/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/UniversalShaper.cs b/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/UniversalShaper.cs index 5a55edec..d2575439 100644 --- a/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/UniversalShaper.cs +++ b/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/UniversalShaper.cs @@ -143,7 +143,7 @@ private static void SetupSyllables(IGlyphShapingCollection collection, int index } // Assign rphf feature - int limit = substitutionCollection[match.StartIndex].UniversalShapingEngineInfo!.Category == "R" + int limit = substitutionCollection[match.StartIndex + index].UniversalShapingEngineInfo!.Category == "R" ? 1 : Math.Min(3, match.EndIndex - match.StartIndex); diff --git a/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs b/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs new file mode 100644 index 00000000..b4ff1e73 --- /dev/null +++ b/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs @@ -0,0 +1,17 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +#if OS_WINDOWS +namespace SixLabors.Fonts.Tests.Issues; +public class Issues_390 +{ + [Fact] + public void UniversalShaper_NullReferenceException() + { + const string s = " 꿹ꓴ/ꥀ냘"; + FontFamily fontFamily = SystemFonts.Get("Arial"); + Font font = new(fontFamily, 10f); + _ = TextMeasurer.MeasureBounds(s, new TextOptions(font)); + } +} +#endif From 58676e05e27d8b75bd5689c5e6a1081b02623de7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 13 Mar 2024 16:24:33 +1000 Subject: [PATCH 2/2] Add tests for 388 --- .../Issues/Issues_388_390.cs | 44 +++++++++++++++++++ .../Issues/Issues_390.cs | 17 ------- 2 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 tests/SixLabors.Fonts.Tests/Issues/Issues_388_390.cs delete mode 100644 tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs diff --git a/tests/SixLabors.Fonts.Tests/Issues/Issues_388_390.cs b/tests/SixLabors.Fonts.Tests/Issues/Issues_388_390.cs new file mode 100644 index 00000000..d60f3401 --- /dev/null +++ b/tests/SixLabors.Fonts.Tests/Issues/Issues_388_390.cs @@ -0,0 +1,44 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +#if OS_WINDOWS +using SixLabors.Fonts.Unicode; + +namespace SixLabors.Fonts.Tests.Issues; +public class Issues_388_390 +{ + [Fact] + public void UniversalShaper_NullReferenceException_388() + { + CodePoint taiLeCharacter = new(0x195C); // ᥜ + CodePoint sundaneseCharacter = new(0x1B9B); // ᮛ + CodePoint tifinaghCharacter = new(0x2D43); // ⵃ + CodePoint chamCharacter = new(0xAA43); // ꩃ + + CodePoint latainCharacter = new(0x0041); // A + CodePoint hiraganaCharacter = new(0x3042); // あ + + FontFamily fontFamily = SystemFonts.Get("Yu Gothic"); + Font font = fontFamily.CreateFont(20.0F); + TextOptions textOption = new(font); + + _ = TextMeasurer.MeasureBounds($"{latainCharacter}{taiLeCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{hiraganaCharacter}{taiLeCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{latainCharacter}{sundaneseCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{hiraganaCharacter}{sundaneseCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{latainCharacter}{tifinaghCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{hiraganaCharacter}{tifinaghCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{latainCharacter}{chamCharacter}", textOption); + _ = TextMeasurer.MeasureBounds($"{hiraganaCharacter}{chamCharacter}", textOption); + } + + [Fact] + public void UniversalShaper_NullReferenceException_390() + { + const string s = " 꿹ꓴ/ꥀ냘"; + FontFamily fontFamily = SystemFonts.Get("Arial"); + Font font = new(fontFamily, 10f); + _ = TextMeasurer.MeasureBounds(s, new TextOptions(font)); + } +} +#endif diff --git a/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs b/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs deleted file mode 100644 index b4ff1e73..00000000 --- a/tests/SixLabors.Fonts.Tests/Issues/Issues_390.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -#if OS_WINDOWS -namespace SixLabors.Fonts.Tests.Issues; -public class Issues_390 -{ - [Fact] - public void UniversalShaper_NullReferenceException() - { - const string s = " 꿹ꓴ/ꥀ냘"; - FontFamily fontFamily = SystemFonts.Get("Arial"); - Font font = new(fontFamily, 10f); - _ = TextMeasurer.MeasureBounds(s, new TextOptions(font)); - } -} -#endif