Re: Last call comments on WOFF (6)

On Feb 9, 2011, at 15:59, Chris Lilley wrote:

> On Wednesday, January 12, 2011, 4:16:26 PM, Bert wrote:
> 
> BB> 6) A context-free grammar for WOFF in the spec would have been nice,  
> BB> even if there are long-distance dependencies a CFG cannot express  
> BB> (such as that some number must correspond to the number of bytes  
> BB> somewhere else). A grammar gives a concise view of the structure of a
> BB> file, better than the English text can, and thus helps programmers.
> 
> Do you have specific suggestions for a formal language which
> 
> a) could express this, with more precision than the prose, and
> b) developers have indicated a desire to see and use

ABNF, the standard grammar notation for RFCs (see RFC 2234) would be a good choice. The beginning of a WOFF grammar could be something like this:

    WOFF-file           = WOFF-header TableDirectory FontTables
                          ExtendedMetadata PrivateData
    WOFF-header         = signature flavor length numTables reserved
                          totalSfntSize majorVersion minorVersion
                          metaOffset metaLength metaOrigLength
                          privOffset privLength
    signature           = "wOFF"
    flavor              = UInt32   ; "sfnt version"
    length              = UInt32
    ...
    TableDirectory      = 1*TableDirectoryEntry
    TableDirectoryEntry = tag offset compLength origLength origChecksum
    tag                 = Unit32   ; 4-byte sfnt table identifier
    offset              = UInt32
    compLength          = UInt32
    ...
    FontTables          = 1*FontDataTable
    FontDataTable       = 1*UInt32 ; (compLength + 3)/4 UInt32's
    ...
    UInt32              = 4OCTET   ; unsigned big endian number
    UInt16              = 2OCTET
    ...
    etc.

(The "..." just indicate that I skipped things, they are not part of the grammar.) As a Context-Free Grammar, this indeed doesn't express that the length of a table must be equal to a <compLength> elsewhere or that the <offset> must be the offset in bytes of some later table, but that can be added in comments, possibly referring to section numbers for more detail. Together that would give a programmer a good starting point to organize his code, as well as a compact reference of all fields in a WOFF file.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Saturday, 26 March 2011 12:15:28 UTC