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
10 changes: 8 additions & 2 deletions src/SixLabors.Fonts/Tables/General/Svg/SvgTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ private SvgTable(byte[] tableData, uint svgDocIndexOffset, uint tableBaseOffset,
/// Loads the SVG table from the specified binary reader.
/// </summary>
/// <param name="reader">The binary reader positioned at the start of the SVG table.</param>
/// <returns>The <see cref="SvgTable"/>.</returns>
public static SvgTable Load(BigEndianBinaryReader reader)
/// <returns>The <see cref="SvgTable"/>, or <see langword="null"/> if the table is not valid in the font.</returns>
public static SvgTable? Load(BigEndianBinaryReader reader)
{
// HEADER
// | Type | Name | Description |
Expand All @@ -99,6 +99,12 @@ public static SvgTable Load(BigEndianBinaryReader reader)
// | Entry[numEntries] | entries | Array of SVG Document Index Entries(sorted by startGlyphID).|
reader.Seek(svgDocIndexOffset, SeekOrigin.Begin);
ushort numEntries = reader.ReadUInt16();
if (numEntries == 0)
{
// The spec says the number of entries must be non-zero.
return null;
}

SvgDocumentIndexEntry[] entries = new SvgDocumentIndexEntry[numEntries];

// SVG Document Index Entry
Expand Down
3 changes: 3 additions & 0 deletions tests/Fonts/Issues/Issue534.ttf
Git LFS file not shown
17 changes: 17 additions & 0 deletions tests/SixLabors.Fonts.Tests/Issues/Issues_534.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.Fonts.Tests.Issues;

public class Issues_534
{
[Fact]
public void ShouldLoadFontWithSvgTableHavingZeroEntries()
{
Font font = TestFonts.GetFont(TestFonts.Issues.Issue534, 12);

FontRectangle size = TextMeasurer.MeasureBounds("ABCabc123", new TextOptions(font));

Assert.NotEqual(FontRectangle.Empty, size);
}
}
2 changes: 2 additions & 0 deletions tests/SixLabors.Fonts.Tests/TestFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ public static class Issues
public static string Issue512 => GetFullPath("Issues/Issue512.otf");

public static string Issue514 => GetFullPath("Issues/Issue514.ttf");

public static string Issue534 => GetFullPath("Issues/Issue534.ttf");
}

/// <summary>
Expand Down
Loading