Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/SixLabors.Fonts/GlyphShapingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public GlyphShapingData(GlyphShapingData data, bool clearFeatures = false)
this.Features.AddRange(data.Features);
}

this.AppliedFeatures.AddRange(data.AppliedFeatures);
foreach (Tag feature in data.AppliedFeatures)
{
this.AppliedFeatures.Add(feature);
}

this.Bounds = data.Bounds;
}
Expand Down Expand Up @@ -124,7 +127,7 @@ public GlyphShapingData(GlyphShapingData data, bool clearFeatures = false)
/// <summary>
/// Gets or sets the collection of applied features.
/// </summary>
public List<Tag> AppliedFeatures { get; set; } = new();
public HashSet<Tag> AppliedFeatures { get; set; } = new();

/// <summary>
/// Gets or sets the shaping bounds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public static bool ApplyLookupList(
int index,
int count)
{
bool hasChanged = false;
SkippingGlyphIterator iterator = new(fontMetrics, collection, index, lookupFlags);
int currentCount = collection.Count;

Expand All @@ -62,7 +61,7 @@ public static bool ApplyLookupList(
iterator.Index = index;
iterator.Increment(sequenceIndex);
GSub.LookupTable lookup = table.LookupList.LookupTables[lookupIndex];
hasChanged |= lookup.TrySubstitution(fontMetrics, table, collection, feature, iterator.Index, count - (iterator.Index - index));
_ = lookup.TrySubstitution(fontMetrics, table, collection, feature, iterator.Index, count - (iterator.Index - index));

// Account for substitutions changing the length of the collection.
if (collection.Count != currentCount)
Expand All @@ -72,7 +71,7 @@ public static bool ApplyLookupList(
}
}

return hasChanged;
return true;
}

public static bool ApplyLookupList(
Expand All @@ -85,7 +84,6 @@ public static bool ApplyLookupList(
int index,
int count)
{
bool hasChanged = false;
SkippingGlyphIterator iterator = new(fontMetrics, collection, index, lookupFlags);
foreach (SequenceLookupRecord lookupRecord in records)
{
Expand All @@ -94,10 +92,10 @@ public static bool ApplyLookupList(
iterator.Index = index;
iterator.Increment(sequenceIndex);
LookupTable lookup = table.LookupList.LookupTables[lookupIndex];
hasChanged |= lookup.TryUpdatePosition(fontMetrics, table, collection, feature, iterator.Index, count - (iterator.Index - index));
_ = lookup.TryUpdatePosition(fontMetrics, table, collection, feature, iterator.Index, count - (iterator.Index - index));
}

return hasChanged;
return true;
}

public static bool MatchInputSequence(SkippingGlyphIterator iterator, Tag feature, ushort increment, ushort[] sequence, Span<int> matches)
Expand Down Expand Up @@ -222,7 +220,7 @@ public static bool CheckAllCoverages(
CoverageTable[] lookahead)
{
// Check that there are enough context glyphs.
if (index - backtrack.Length < 0 || input.Length + lookahead.Length > count)
if (index < backtrack.Length || input.Length + lookahead.Length > count)
{
return false;
}
Expand Down Expand Up @@ -253,7 +251,8 @@ public static void ApplyAnchor(
int index,
AnchorTable baseAnchor,
MarkRecord markRecord,
int baseGlyphIndex)
int baseGlyphIndex,
Tag feature)
{
GlyphShapingData baseData = collection[baseGlyphIndex];
AnchorXY baseXY = baseAnchor.GetAnchor(fontMetrics, baseData, collection);
Expand All @@ -264,18 +263,21 @@ public static void ApplyAnchor(
markData.Bounds.X = baseXY.XCoordinate - markXY.XCoordinate;
markData.Bounds.Y = baseXY.YCoordinate - markXY.YCoordinate;
markData.MarkAttachment = baseGlyphIndex;
markData.AppliedFeatures.Add(feature);
}

public static void ApplyPosition(
GlyphPositioningCollection collection,
int index,
ValueRecord record)
ValueRecord record,
Tag feature)
{
GlyphShapingData current = collection[index];
current.Bounds.Width += record.XAdvance;
current.Bounds.Height += record.YAdvance;
current.Bounds.X += record.XPlacement;
current.Bounds.Y += record.YPlacement;
current.AppliedFeatures.Add(feature);
}

public static bool IsMarkGlyph(FontMetrics fontMetrics, ushort glyphId, GlyphShapingData shapingData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override bool TryUpdatePosition(
if (coverage > -1)
{
ValueRecord record = this.valueRecord;
AdvancedTypographicUtils.ApplyPosition(collection, index, record);
AdvancedTypographicUtils.ApplyPosition(collection, index, record, feature);

return true;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public override bool TryUpdatePosition(
if (coverage > -1)
{
ValueRecord record = this.valueRecords[coverage];
AdvancedTypographicUtils.ApplyPosition(collection, index, record);
AdvancedTypographicUtils.ApplyPosition(collection, index, record, feature);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public override bool TryUpdatePosition(
if (pairSet.TryGetPairValueRecord(glyphId2, out PairValueRecord pairValueRecord))
{
ValueRecord record1 = pairValueRecord.ValueRecord1;
AdvancedTypographicUtils.ApplyPosition(collection, index, record1);
AdvancedTypographicUtils.ApplyPosition(collection, index, record1, feature);

ValueRecord record2 = pairValueRecord.ValueRecord2;
AdvancedTypographicUtils.ApplyPosition(collection, index + 1, record2);
AdvancedTypographicUtils.ApplyPosition(collection, index + 1, record2, feature);

return true;
}
Expand Down Expand Up @@ -285,10 +285,10 @@ public override bool TryUpdatePosition(
Class2Record class2Record = class1Record.Class2Records[classDef2];

ValueRecord record1 = class2Record.ValueRecord1;
AdvancedTypographicUtils.ApplyPosition(collection, index, record1);
AdvancedTypographicUtils.ApplyPosition(collection, index, record1, feature);

ValueRecord record2 = class2Record.ValueRecord2;
AdvancedTypographicUtils.ApplyPosition(collection, index + 1, record2);
AdvancedTypographicUtils.ApplyPosition(collection, index + 1, record2, feature);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override bool TryUpdatePosition(

MarkRecord markRecord = this.markArrayTable.MarkRecords[markIndex];
AnchorTable baseAnchor = this.baseArrayTable.BaseRecords[baseIndex].BaseAnchorTables[markRecord.MarkClass];
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, baseGlyphIndex);
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, baseGlyphIndex, feature);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public override bool TryUpdatePosition(

MarkRecord markRecord = this.markArrayTable.MarkRecords[markIndex];
AnchorTable baseAnchor = ligatureAttach.ComponentRecords[compIndex].LigatureAnchorTables[markRecord.MarkClass];
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, baseGlyphIndex);
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, baseGlyphIndex, feature);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public override bool TryUpdatePosition(

MarkRecord markRecord = this.mark1ArrayTable.MarkRecords[mark1Index];
AnchorTable baseAnchor = this.mark2ArrayTable.Mark2Records[mark2Index].MarkAnchorTable[markRecord.MarkClass];
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, prevIdx);
AdvancedTypographicUtils.ApplyAnchor(fontMetrics, collection, index, baseAnchor, markRecord, prevIdx, feature);

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Images/ReferenceOutput/Issue_451_A-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Images/ReferenceOutput/Issue_451_B-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Images/ReferenceOutput/Issue_451_C-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
47 changes: 47 additions & 0 deletions tests/SixLabors.Fonts.Tests/Issues/Issues_451.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Numerics;

namespace SixLabors.Fonts.Tests.Issues;

public class Issues_451
{
private readonly FontFamily berry = new FontCollection().Add(TestFonts.VeryBerryProRegular);

[Fact]
public void Issue_451_A()
{
Font font = this.berry.CreateFont(85);
TextLayoutTestUtilities.TestLayout(
"The",
new TextOptions(font)
{
Origin = new Vector2(0, 50),
});
}

[Fact]
public void Issue_451_B()
{
Font font = this.berry.CreateFont(85);
TextLayoutTestUtilities.TestLayout(
"Th",
new TextOptions(font)
{
Origin = new Vector2(0, 50),
});
}

[Fact]
public void Issue_451_C()
{
Font font = this.berry.CreateFont(85);
TextLayoutTestUtilities.TestLayout(
"The quick brown fox jumps over the lazy dog",
new TextOptions(font)
{
Origin = new Vector2(0, 50),
});
}
}
2 changes: 2 additions & 0 deletions tests/SixLabors.Fonts.Tests/TestFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@

public static string CharisSILRegular => GetFullPath("CharisSIL-Regular.ttf");

public static string VeryBerryProRegular => GetFullPath("VeryBerryProRegular.ttf");

public static Stream TwemojiMozillaData() => OpenStream(TwemojiMozillaFile);

public static Stream SegoeuiEmojiData() => OpenStream(SegoeuiEmojiFile);
Expand Down Expand Up @@ -312,7 +314,7 @@

private static string GetFullPath(string path)
{
string root = Path.GetDirectoryName(new Uri(typeof(TestFonts).GetTypeInfo().Assembly.CodeBase).LocalPath);

Check warning on line 317 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, macos-latest, net7.0, 7.0.x, true, -x64, false)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

Check warning on line 317 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, macos-latest, net6.0, 6.0.x, -x64, false)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

Check warning on line 317 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

Check warning on line 317 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

string[] paths = new[]
{
Expand Down
Loading