Add code for validating OpenType GLYF table entries#12375
Add code for validating OpenType GLYF table entries#12375mitchellh merged 3 commits intoghostty-org:mainfrom
Conversation
We want to have this for the glyph protocol so that we can validate passed glyf data in libghostty without having to link freetype or anything like that.
Also fixes a logic bug where we weren't counting the length of x coordinates and y coordinates correctly when we had repeated flags.
There was a problem hiding this comment.
From the spec
If a glyph has zero contours, no additional glyph data beyond the header is required. A glyph with zero contours may have additional data, however; in particular, it may have instructions that operate on phantom points.
This test should pass:
test "glyf: zero-contour glyph can be header-only" {
const testing = std.testing;
const header: Glyf.Entry.Header = .{
.numberOfContours = 0,
.xMin = 0,
.yMin = 0,
.xMax = 0,
.yMax = 0,
};
const glyph = try Glyf.Entry.init(std.mem.asBytes(&header));
try testing.expectEqual(@sizeOf(Glyf.Entry.Header), try glyph.size());
}|
Haha yeah I actually realized I had written that bug while I was going to sleep last night and going back over the spec in my head- adding a test (and if need be, a fix) for it was on my todo list for today. |
|
I realize for the purpose of the glyph protocol its a silly glyph cause its... empty... but it is valid. 🤷 |
|
But actually, no that test is incorrect-- the additional data after the header is a few bytes still since it has to encode the instructions length. At least 2 extra bytes for the 16-bit
|
|
It is confusing, and semantically for our use case it probably doesn't matter. I read this:
As meaning the instructions part was optional. |
|
Yep, see my edits on my last reply. I'll make a fix for it in an hour or so. |
This code was motivated by the need for the glyph protocol handler (#12352) to be able to validate the provided
glyfpayload, without having to link freetype or anything (because libghostty-vt needs to be static). As such it's written specifically to meet those needs, but in such a way that it can be expanded if we find a need for more in-depth inspection ofglyfs in the future.