diff --git a/samples/DrawWithImageSharp/DrawWithImageSharp.csproj b/samples/DrawWithImageSharp/DrawWithImageSharp.csproj index 8c6e4621..880b2b3d 100644 --- a/samples/DrawWithImageSharp/DrawWithImageSharp.csproj +++ b/samples/DrawWithImageSharp/DrawWithImageSharp.csproj @@ -46,7 +46,7 @@ - + diff --git a/src/SixLabors.Fonts/Tables/AdvancedTypographic/GSub/LookupType5SubTable.cs b/src/SixLabors.Fonts/Tables/AdvancedTypographic/GSub/LookupType5SubTable.cs index 3b91c85f..82a2ef97 100644 --- a/src/SixLabors.Fonts/Tables/AdvancedTypographic/GSub/LookupType5SubTable.cs +++ b/src/SixLabors.Fonts/Tables/AdvancedTypographic/GSub/LookupType5SubTable.cs @@ -150,7 +150,12 @@ public override bool TrySubstitution( return false; } - ClassSequenceRuleSetTable ruleSetTable = this.sequenceRuleSetTables[offset]; + ClassSequenceRuleSetTable? ruleSetTable = this.sequenceRuleSetTables[offset]; + if (ruleSetTable is null) + { + return false; + } + SkippingGlyphIterator iterator = new(fontMetrics, collection, index, this.LookupFlags); foreach (ClassSequenceRuleTable ruleTable in ruleSetTable.SequenceRuleTables) { diff --git a/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/IndicShaper.cs b/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/IndicShaper.cs index 6c212768..b77d1a66 100644 --- a/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/IndicShaper.cs +++ b/src/SixLabors.Fonts/Tables/AdvancedTypographic/Shapers/IndicShaper.cs @@ -52,9 +52,9 @@ public IndicShaper(ScriptClass script, Tag unicodeScriptTag, TextOptions textOpt { this.textOptions = textOptions; - if (IndicConfigurations.ContainsKey(script)) + if (IndicConfigurations.TryGetValue(script, out ShapingConfiguration value)) { - this.indicConfiguration = IndicConfigurations[script]; + this.indicConfiguration = value; } else { diff --git a/src/UnicodeTrieGenerator/Generator.UniversalShapingEngine.cs b/src/UnicodeTrieGenerator/Generator.UniversalShapingEngine.cs index 1b9305f2..18f19e38 100644 --- a/src/UnicodeTrieGenerator/Generator.UniversalShapingEngine.cs +++ b/src/UnicodeTrieGenerator/Generator.UniversalShapingEngine.cs @@ -528,12 +528,13 @@ or 0x2068 if (category != null) { - if (!symbols.ContainsKey(category)) + if (!symbols.TryGetValue(category, out int value)) { - symbols[category] = numSymbols++; + value = numSymbols++; + symbols[category] = value; } - builder.Set(codePoint.Code, (uint)symbols[category]); + builder.Set(codePoint.Code, (uint)value); } if (codePoint.IndicSyllabicCategory == ISC.VowelDependent && codePoint.Decomposition.Any()) diff --git a/tests/SixLabors.Fonts.Tests/Fonts/BNazanin.ttf b/tests/SixLabors.Fonts.Tests/Fonts/BNazanin.ttf new file mode 100644 index 00000000..eb227d7e Binary files /dev/null and b/tests/SixLabors.Fonts.Tests/Fonts/BNazanin.ttf differ diff --git a/tests/SixLabors.Fonts.Tests/Issues/Issues_363.cs b/tests/SixLabors.Fonts.Tests/Issues/Issues_363.cs new file mode 100644 index 00000000..1c56ff75 --- /dev/null +++ b/tests/SixLabors.Fonts.Tests/Issues/Issues_363.cs @@ -0,0 +1,18 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.Fonts.Tests.Issues; + +public class Issues_363 +{ + [Fact] + public void GSubFormat2NUllReferenceException() + { + Font font = new FontCollection().Add(TestFonts.BNazaninFile).CreateFont(12); + + TextOptions textOptions = new(font); + string text = "تست فونت 1234"; + FontRectangle rect = TextMeasurer.MeasureAdvance(text, textOptions); + Assert.NotEqual(default, rect); + } +} diff --git a/tests/SixLabors.Fonts.Tests/TestFonts.cs b/tests/SixLabors.Fonts.Tests/TestFonts.cs index 85ef2fb3..64f486e7 100644 --- a/tests/SixLabors.Fonts.Tests/TestFonts.cs +++ b/tests/SixLabors.Fonts.Tests/TestFonts.cs @@ -245,6 +245,8 @@ public static class TestFonts public static string THSarabunFile => GetFullPath("THSarabun.ttf"); + public static string BNazaninFile => GetFullPath("BNazanin.ttf"); + public static Stream TwemojiMozillaData() => OpenStream(TwemojiMozillaFile); public static Stream SegoeuiEmojiData() => OpenStream(SegoeuiEmojiFile);