Home > Software engineering >  Parse WOFF2 DirectoryEntry Flags not working
Parse WOFF2 DirectoryEntry Flags not working

Time:09-16

I think this might be the best place to ask stupid questions… so here we are:

I’m currently writing a pretty simple woff2 parser to get some information about the font. I got woff and otf parsing working but woff2 gives me headaches.

I’m struggling parsing the the TableDictionaryEntries. As stated in the specification the flags are UInt8. The first 6 bits represents the index in a list of table names.

So I’m doing the following: (I’m new to all that bitwise stuff)

let tables = [
 'cmap',
 'head',
 ...
] // size 64

let flags = binary.getUInt8(); // gets me the next 8bits as UInt8
// 00001101 or 10000010 or 10101011 or 01110100

let tableNameIndex = (flags << 2) >> 2
// 00001101 or 00000010 or 00101011 or 00110100
// some libraries do flags & 0x3f but that seems to be the same


let tableName = tables[Int(tableNameIndex)]

But I think I do something wrong. I have double names in the TableDirectory — thats not right… Maybe I mess something up with bigEdian or something like that?

CodePudding user response:

Thats it. transformLength was not set so I got a alignment issue.

  • Related