Changeset 625
- Timestamp:
- 09/21/09 22:50:50 (1 year ago)
- Files:
-
- applications/WOFFValidator/woffValidator.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
applications/WOFFValidator/woffValidator.py
r622 r625 1697 1697 tables = unpackTableData(data) 1698 1698 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 1700 1704 searchRange, entrySelector, rangeShift = getSearchRange(numTables) 1701 1705 sfntDirectoryData = dict( … … 1706 1710 rangeShift=rangeShift 1707 1711 ) 1708 sfntDirectory = sstruct.pack(sfntDirectoryFormat, sfntDirectoryData) 1709 # create the SFNT directory 1712 directory = sstruct.pack(sfntDirectoryFormat, sfntDirectoryData) 1710 1713 sfntEntries = {} 1711 1714 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"] 1714 1720 sfntEntry = SFNTDirectoryEntry() 1715 sfntEntry.tag = tag 1721 sfntEntry.tag = entry["tag"] 1722 sfntEntry.checkSum = entry["origChecksum"] 1716 1723 sfntEntry.offset = offset 1717 1724 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) 1727 1729 for tag, sfntEntry in sorted(sfntEntries.items()): 1728 sfntDirectory += sfntEntry.toString()1729 # c ompile the table checksums1730 tags = tables.keys()1730 directory += sfntEntry.toString() 1731 # calculate 1732 tags = sfntEntries.keys() 1731 1733 checksums = numpy.zeros(len(tags) + 1, numpy.int32) 1732 for index, entry in enumerate(directory):1733 checksums[index] = sfntEntries[ entry["tag"]].checkSum1734 # add the directory checksum1735 checksums[-1] = calcChecksum(None, sfntDirectory)1736 # sum1734 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) 1737 1739 checksum = numpy.add.reduce(checksums) 1738 # do the required translation1739 1740 checkSumAdjustment = numpy.array(0xb1b0afbaL - 0x100000000L, numpy.int32) - checksum 1740 # done1741 1741 return checkSumAdjustment 1742 1742
