Changeset 625

Show
Ignore:
Timestamp:
09/21/09 22:50:50 (1 year ago)
Author:
tal
Message:
Reworked the head checkSumAdjustment calculation. This is now identical to the calculation used in woffLib. This is probably not a good thing. The validator should use a different way of calculating the value.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • applications/WOFFValidator/woffValidator.py

    r622 r625  
    16971697    tables = unpackTableData(data) 
    16981698    numTables = header["numTables"] 
    1699     # compile the SFNT header 
     1699    # sort tables 
     1700    sorter = [] 
     1701    for entry in directory: 
     1702        sorter.append((entry["offset"], entry, tables[entry["tag"]])) 
     1703    # build the sfnt directory 
    17001704    searchRange, entrySelector, rangeShift = getSearchRange(numTables) 
    17011705    sfntDirectoryData = dict( 
     
    17061710        rangeShift=rangeShift 
    17071711    ) 
    1708     sfntDirectory = sstruct.pack(sfntDirectoryFormat, sfntDirectoryData) 
    1709     # create the SFNT directory 
     1712    directory = sstruct.pack(sfntDirectoryFormat, sfntDirectoryData) 
    17101713    sfntEntries = {} 
    17111714    offset = sfntDirectorySize + (sfntDirectoryEntrySize * numTables) 
    1712     for entry in directory: 
    1713         tag = entry["tag"] 
     1715    for index, entry, data in sorted(sorter): 
     1716        if entry["tag"] == "head": 
     1717            checksum = calcChecksum("head", data) 
     1718        else: 
     1719            checksum = entry["origChecksum"] 
    17141720        sfntEntry = SFNTDirectoryEntry() 
    1715         sfntEntry.tag = tag 
     1721        sfntEntry.tag = entry["tag"] 
     1722        sfntEntry.checkSum = entry["origChecksum"] 
    17161723        sfntEntry.offset = offset 
    17171724        sfntEntry.length = entry["origLength"] 
    1718         # set the checkSumAdjustment to 0 
    1719         if tag == "head": 
    1720             checksum = calcChecksum(tag, tables[tag]) 
    1721         # use the original checksum 
    1722         else: 
    1723             checksum = entry["origChecksum"] 
    1724         sfntEntry.checkSum = checksum 
    1725         sfntEntries[tag] = sfntEntry 
    1726     # add the compiled entries to the directory 
     1725        sfntEntries[entry["tag"]] = sfntEntry 
     1726        offset += entry["origLength"] 
     1727        if entry["origLength"] % 4: 
     1728            offset += 4 - (entry["origLength"] % 4) 
    17271729    for tag, sfntEntry in sorted(sfntEntries.items()): 
    1728         sfntDirectory += sfntEntry.toString() 
    1729     # compile the table checksums 
    1730     tags = tables.keys() 
     1730        directory += sfntEntry.toString() 
     1731    # calculate 
     1732    tags = sfntEntries.keys() 
    17311733    checksums = numpy.zeros(len(tags) + 1, numpy.int32) 
    1732     for index, entry in enumerate(directory): 
    1733         checksums[index] = sfntEntries[entry["tag"]].checkSum 
    1734     # add the directory checksum 
    1735     checksums[-1] = calcChecksum(None, sfntDirectory) 
    1736     # sum 
     1734    for index, tag in enumerate(tags): 
     1735        checksums[index] = sfntEntries[tag].checkSum 
     1736    directoryEnd = sfntDirectorySize + (len(tags) * sfntDirectoryEntrySize) 
     1737    assert directoryEnd == len(directory) 
     1738    checksums[-1] = calcChecksum(None, directory) 
    17371739    checksum = numpy.add.reduce(checksums) 
    1738     # do the required translation 
    17391740    checkSumAdjustment = numpy.array(0xb1b0afbaL - 0x100000000L, numpy.int32) - checksum 
    1740     # done 
    17411741    return checkSumAdjustment 
    17421742