Skip to content

Commit 3a21143

Browse files
Merge pull request #477 from SixLabors/js/fix-474
Fix ligature caret offset determination
2 parents d11ff41 + 8b2d3f8 commit 3a21143

File tree

7 files changed

+43
-10
lines changed

7 files changed

+43
-10
lines changed

src/SixLabors.Fonts/Tables/AdvancedTypographic/GlyphDefinitionTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public static GlyphDefinitionTable Load(BigEndianBinaryReader reader)
125125

126126
ushort glyphClassDefOffset = reader.ReadUInt16();
127127
ushort attachListOffset = reader.ReadUInt16();
128-
ushort ligatureCaretListOffset = reader.ReadUInt16();
129-
ushort markAttachClassDefOffset = reader.ReadUInt16();
128+
ushort ligatureCaretListOffset = reader.ReadOffset16();
129+
ushort markAttachClassDefOffset = reader.ReadOffset16();
130130
ushort markGlyphSetsDefOffset = 0;
131131
uint itemVarStoreOffset = 0;
132132

src/SixLabors.Fonts/Tables/AdvancedTypographic/LigatureCaretList.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ public static LigatureCaretList Load(BigEndianBinaryReader reader, long offset)
2222
// ----------|--------------------------------|--------------------------------------------------------------------------------------------------------
2323
reader.Seek(offset, SeekOrigin.Begin);
2424

25-
ushort coverageOffset = reader.ReadUInt16();
25+
ushort coverageOffset = reader.ReadOffset16();
2626
ushort ligGlyphCount = reader.ReadUInt16();
2727

2828
using Buffer<ushort> ligGlyphOffsetsBuffer = new(ligGlyphCount);
2929
Span<ushort> ligGlyphOffsets = ligGlyphOffsetsBuffer.GetSpan();
3030
reader.ReadUInt16Array(ligGlyphOffsets);
3131

32-
var ligatureCaretList = new LigatureCaretList()
32+
LigatureCaretList ligatureCaretList = new()
3333
{
34-
CoverageTable = CoverageTable.Load(reader, offset + coverageOffset)
34+
CoverageTable = CoverageTable.Load(reader, offset + coverageOffset),
35+
LigatureGlyphs = new LigatureGlyph[ligGlyphCount]
3536
};
3637

37-
ligatureCaretList.LigatureGlyphs = new LigatureGlyph[ligGlyphCount];
3838
for (int i = 0; i < ligatureCaretList.LigatureGlyphs.Length; i++)
3939
{
40-
ligatureCaretList.LigatureGlyphs[i] = LigatureGlyph.Load(reader, ligGlyphOffsets[i]);
40+
ligatureCaretList.LigatureGlyphs[i] = LigatureGlyph.Load(reader, offset + ligGlyphOffsets[i]);
4141
}
4242

4343
return ligatureCaretList;

src/SixLabors.Fonts/Tables/AdvancedTypographic/LigatureGlyph.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ public static LigatureGlyph Load(BigEndianBinaryReader reader, long offset)
1212
reader.Seek(offset, SeekOrigin.Begin);
1313

1414
ushort caretCount = reader.ReadUInt16();
15-
var ligatureGlyph = new LigatureGlyph()
15+
return new LigatureGlyph()
1616
{
1717
CaretValueOffsets = reader.ReadUInt16Array(caretCount)
1818
};
19-
20-
return ligatureGlyph;
2119
}
2220
}
Lines changed: 3 additions & 0 deletions
Loading
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Text;
5+
6+
namespace SixLabors.Fonts.Tests.Issues;
7+
8+
public class Issues_474
9+
{
10+
[Fact]
11+
public void Test_Issue_474()
12+
{
13+
StringBuilder stringBuilder = new();
14+
stringBuilder.AppendLine("Latin: The quick brown fox jumps over the lazy dog.");
15+
string text = stringBuilder.ToString();
16+
17+
FontCollection fontCollection = new();
18+
string serviceNow = fontCollection.Add(TestFonts.ServiceNowWoff2).Name;
19+
20+
FontFamily mainFontFamily = fontCollection.Get(serviceNow);
21+
Font mainFont = mainFontFamily.CreateFont(30, FontStyle.Regular);
22+
23+
// There are too many metrics to validate here so we just ensure no exceptions are thrown
24+
// and the rendering looks correct by inspecting the snapshot.
25+
TextLayoutTestUtilities.TestLayout(
26+
text,
27+
new TextOptions(mainFont),
28+
includeGeometry: false);
29+
}
30+
}

tests/SixLabors.Fonts.Tests/TestFonts.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ public static class TestFonts
291291

292292
public static string SofiaSansCondensedLight => GetFullPath("SofiaSansCondensed-ExtraLight-Regular.ttf");
293293

294+
public static string ServiceNowWoff2 => GetFullPath("ServiceNow-Sans-Text-Bold-unmastered-1.1.woff");
295+
294296
public static Stream TwemojiMozillaData() => OpenStream(TwemojiMozillaFile);
295297

296298
public static Stream SegoeuiEmojiData() => OpenStream(SegoeuiEmojiFile);

0 commit comments

Comments
 (0)