- From: Levantovsky, Vladimir <Vladimir.Levantovsky@monotype.com>
- Date: Wed, 9 Dec 2015 23:03:47 +0000
- To: Roderick Sheeter <rsheeter@google.com>, WebFonts WG <public-webfonts-wg@w3.org>
- Message-ID: <9f18fc70dbdd4efc9f8997abbad2065c@wob-maildb-03.agfamonotype.org>
Thank you Rod, this is perfect.
Since the purpose of the pseudo-code is to supplement the spec, this would work just fine. I will add the pseudo-code to the spec and anyone who would be curious to see what the actual code looks like would have to make an effort. ☺
Thank you,
Vlad
From: Roderick Sheeter [mailto:rsheeter@google.com]
Sent: Wednesday, December 09, 2015 5:55 PM
To: WebFonts WG
Subject: Pseudo-code to read 255UInt16
As requested in https://www.w3.org/Fonts/WG/track/actions/191, C-like pseudo-code to read a UIntBase128 follows:
bool ReadUIntBase128( data, *result )
UInt32 accum = 0;
for (i = 0; i < 5; i++) {
UInt8 data_byte = data.getNextUInt8();
// No leading 0's
if (i == 0 && data_byte = 0x80) return false;
// If any of top 7 bits are set then << 7 would overflow
if (accum & 0xFE000000) return false;
*accum = (accum << 7) | (data_byte & 0x7F);
// Spin until most significant bit of data byte is false
if ((data_byte & 0x80) == 0) {
*result = accum;
return true;
}
}
// UIntBase128 sequence exceeds 5 bytes
return false;
}
(pseudo-code may suspiciously resemble actual code in https://github.com/google/woff2/blob/master/src/variable_length.cc)
I wasn't sure how much of the error checking to keep. I noticed the Read255UShort pseudo-code doesn't include things like checking if we actually have a next byte and attempted to match.
Cheers, Rod S.
Received on Wednesday, 9 December 2015 23:05:04 UTC