Skip to content

Commit

Permalink
Merge pull request #391 from SixLabors/defect/390
Browse files Browse the repository at this point in the history
Fix NullReferenceException in UniversalShaper
  • Loading branch information
JimBobSquarePants authored Mar 13, 2024
2 parents d24a330 + 58676e0 commit 5d76f69
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/SixLabors.Fonts/GlyphShapingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class GlyphShapingData
/// <summary>
/// Initializes a new instance of the <see cref="GlyphShapingData"/> class.
/// </summary>
/// <param name="textRun">The text run.</param>
public GlyphShapingData(TextRun textRun) => this.TextRun = textRun;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
44 changes: 44 additions & 0 deletions tests/SixLabors.Fonts.Tests/Issues/Issues_388_390.cs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d76f69

Please sign in to comment.