Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing anchor table format 2 #238

Merged
merged 8 commits into from
Feb 26, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static AnchorTable Load(BigEndianBinaryReader reader, long offset)
return anchorFormat switch
{
1 => AnchorFormat1.Load(reader),
_ => throw new NotSupportedException($"anchorFormat {anchorFormat} not supported. Should be '1'.")
2 => AnchorFormat2.Load(reader),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As somebody who knows nothing about fonts, making these error messages more descriptive might be helpful too. If I knew that my font format wasn't supported, I'd just pick a different one.

 3 => throw new NotSupportedException($"Variable fonts (format 3) are not supported. Read: https://docs.sixlabors.com/articles/fonts/anchorTableFormats.html")
 _ => throw new NotSupportedException($"Fonts using anchor table format {anchorFormat} are not supported. Read: https://docs.sixlabors.com/articles/fonts/anchorTableFormats.html")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't link to docs from exception messages. The maintenance burden of tracking URL changes would be too much.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair enough, was just a thought

_ => throw new NotSupportedException($"anchorFormat {anchorFormat} not supported. Should be '1' or `2`.")
};
}

Expand All @@ -72,5 +73,33 @@ public static AnchorFormat1 Load(BigEndianBinaryReader reader)
return new AnchorFormat1(xCoordinate, yCoordinate);
}
}

internal sealed class AnchorFormat2 : AnchorTable
{
// TODO: actually use the anchorPointIndex.
private readonly ushort anchorPointIndex;

public AnchorFormat2(short xCoordinate, short yCoordinate, ushort anchorPointIndex)
: base(xCoordinate, yCoordinate) => this.anchorPointIndex = anchorPointIndex;

public static AnchorFormat2 Load(BigEndianBinaryReader reader)
{
// +--------------+------------------------+------------------------------------------------+
// | Type | Name | Description |
// +==============+========================+================================================+
// | uint16 | anchorFormat | Format identifier, = 1 |
// +--------------+------------------------+------------------------------------------------+
// | int16 | xCoordinate | Horizontal value, in design units. |
// +--------------+------------------------+------------------------------------------------+
// | int16 | yCoordinate | Vertical value, in design units. |
// +--------------+------------------------+------------------------------------------------+
// | uint16 + anchorPoint | Index to glyph contour point +
// +--------------+------------------------+------------------------------------------------+
short xCoordinate = reader.ReadInt16();
short yCoordinate = reader.ReadInt16();
ushort anchorPointIndex = reader.ReadUInt16();
return new AnchorFormat2(xCoordinate, yCoordinate, anchorPointIndex);
}
}
}
}