google / woff2

MIT License
1.52k stars 188 forks source link

Don't zero out glyf table bits #140

Closed davelab6 closed 3 years ago

davelab6 commented 3 years ago

@lorp mentioned to me today he had a chat with Garret and Vlad in the ATypI hang out room that there's a bug in woff2_decompress when writing bit 6; the bits the spec says are reserved for 0 are forced back to 0, but they should not be, as in practice they are used.

eg, bit 7 may also used for storing other curve orders (cubics).

So, if we keep the bits roundtripping, we won't need to update all the woff2 tooling if those bits do get used.

davelab6 commented 3 years ago

Ah, duplicate of https://github.com/google/woff2/issues/117

anthrotype commented 3 years ago

it's not possible to roundtrip because there's no place to store that bit in woff2, it's lost as soon as the glyf table is transformed. the decoder can only guess (either force it to always be set, or check for overlaps and set it accordingly but it'd be too expensive).

vlevantovsky commented 3 years ago

it's not possible to roundtrip because there's no place to store that bit in woff2, it's lost as soon as the glyf table is transformed.

I believe WOFF2 does have a place (see flagStream[]) to store that bit, it may be just the way the decoder got implemented to "optimize" for bits that are "unused.

anthrotype commented 3 years ago

Hm, but the flagStream (an array of u8 bytes) is for specifying the variable-length encoding of X and Y coordinates (besides the on- vs off-curve flag)

see https://www.w3.org/TR/WOFF2/#triplet_decoding

The most significant bit of a flag indicates whether the point is on- or off-curve point, the remaining seven bits of the flag determine the format of X and Y coordinate values and specify 128 possible combinations of indices that have been assigned taking into consideration typical statistical distribution of data found in TrueType fonts...

vlevantovsky commented 3 years ago

Ahh, you're right - I thought that the triplet encoding format has a provision to encode the original flags value. I just re-read the triplet encoding description and realize it redefine all the original flags beyond the on/off-curve bit.

Lorp commented 3 years ago

Thanks for the clarification and pointers to the flags spec @anthrotype!