def makeInvalidPadding5():
    header, directory, tableData = defaultSFNTTestData()
    # pad the tables
    for tag, data in tableData.items():
        if tag == "head":
            assert calcPaddingLength(len(data))
            tableData[tag] = data + ("\x01" * calcPaddingLength(len(data)))
        else:
            tableData[tag] = padData(data)
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
Ejemplo n.º 2
0
def makeInvalidPadding5():
    header, directory, tableData = defaultSFNTTestData()
    # pad the tables
    for tag, data in tableData.items():
        if tag == "head":
            assert calcPaddingLength(len(data))
            tableData[tag] = data + ("\x01" * calcPaddingLength(len(data)))
        else:
            tableData[tag] = padData(data)
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
def makeBitwiseIdenticalNonStandardTable1():
    header, directory, tableData = defaultSFNTTestData()
    # adjust the header
    header["numTables"] += 1
    # store the data
    data = "\0" * 4
    tableData["TEST"] = data
    # offset the directory entries
    for entry in directory:
        entry["offset"] += sfntDirectoryEntrySize
    # find the offset
    entries = [(entry["offset"], entry) for entry in directory]
    entry = max(entries)[1]
    offset = entry["offset"] + entry["length"]
    offset += calcPaddingLength(offset)
    # make the entry
    directory.append(
        dict(
            tag="TEST",
            offset=offset,
            length=4,
            checksum=calcTableChecksum("TEST", data)
        )
    )
    # compile
    data = packSFNT(header, directory, tableData)
    return data
def makeInvalidPadding2():
    header, directory, tableData = defaultSFNTTestData()
    # pad the tables and update their offsets
    entries = [(entry["offset"], entry) for entry in directory]
    for o, entry in sorted(entries):
        tag = entry["tag"]
        data = tableData[tag]
        tableData[tag] = padData(data)
        entry["offset"] += sfntDirectoryEntrySize
    # make a bogus table and insert it
    header["numTables"] += 1
    data = "\01" * 15
    tableData["zzzz"] = data
    offset = entry["offset"] + entry["length"] + calcPaddingLength(entry["length"])
    directory.append(
        dict(
            tag="zzzz",
            offset=offset,
            length=15,
            checksum=calcTableChecksum("zzzz", data)
        )
    )
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
def makeDSIG(flavor="CFF"):
    header, directory, tableData = defaultSFNTTestData(flavor=flavor)
    # adjust the header
    header["numTables"] += 1
    # store the data
    data = "\0" * 4
    tableData["DSIG"] = data
    # offset the directory entries
    for entry in directory:
        entry["offset"] += sfntDirectoryEntrySize
    # find the offset
    entries = [(entry["offset"], entry) for entry in directory]
    entry = max(entries)[1]
    offset = entry["offset"] + entry["length"]
    offset += calcPaddingLength(offset)
    # make the entry
    directory.append(
        dict(
            tag="DSIG",
            offset=offset,
            length=4,
            checksum=calcTableChecksum("DSIG", data)
        )
    )
    # compile
    data = packSFNT(header, directory, tableData, flavor=flavor)
    return data
Ejemplo n.º 6
0
def makeInvalidPadding1():
    header, directory, tableData = defaultSFNTTestData()
    # grab the head table, calculate the padding length
    # and shift the following tables
    headEntry = [entry for entry in directory if entry["tag"] == "head"][0]
    shift = calcPaddingLength(headEntry["length"])
    assert shift
    entries = [(entry["offset"], entry) for entry in directory]
    assert sorted(entries)[0][1]["tag"] == "head"
    for o, entry in sorted(entries)[1:]:
        if entry["tag"] == "head":
            continue
        entry["offset"] -= shift
    # pad the tables
    for tag, data in tableData.items():
        if tag == "head":
            continue
        tableData[tag] = padData(data)
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
def makeBitwiseIdenticalNotRecommendedTableOrder2():
    header, directory, tableData = defaultSFNTTestData()
    # make the new order
    newOrder = "fpgm,LTSH,glyf,cmap,hhea,hmtx,PCLT,post,DSIG,maxp,loca,gasp,VDMX,kern,name,hdmx,prep,OS/2,cvt ,head".split(",")
    newOrder = [tag for tag in newOrder if tag in tableData]
    for tag in sorted(tableData.keys()):
        if tag not in newOrder:
            newOrder.append(tag)
    # reset the offsets
    directoryDict = {}
    for entry in directory:
        directoryDict[entry["tag"]] = entry
    assert set(newOrder) == set(directoryDict.keys())
    offset = sfntDirectorySize + (sfntDirectoryEntrySize * len(directory))
    for tag in newOrder:
        entry = directoryDict[tag]
        entry["offset"] = offset
        offset += entry["length"] + calcPaddingLength(entry["length"])
    directory = [entry for tag, entry in sorted(directoryDict.items())]
    # compile
    data = packSFNT(header, directory, tableData)
    return data
Ejemplo n.º 8
0
def makeBitwiseIdenticalNotRecommendedTableOrder1():
    header, directory, tableData = defaultSFNTTestData(flavor="TTF")
    # make the new order
    newOrder = "CFF ,maxp,hhea,name,post,cmap,OS/2,head".split(",")
    newOrder = [tag for tag in newOrder if tag in tableData]
    for tag in sorted(tableData.keys()):
        if tag not in newOrder:
            newOrder.append(tag)
    # reset the offsets
    directoryDict = {}
    for entry in directory:
        directoryDict[entry["tag"]] = entry
    assert set(newOrder) == set(directoryDict.keys())
    offset = sfntDirectorySize + (sfntDirectoryEntrySize * len(directory))
    for tag in newOrder:
        entry = directoryDict[tag]
        entry["offset"] = offset
        offset += entry["length"] + calcPaddingLength(entry["length"])
    directory = [entry for tag, entry in sorted(directoryDict.items())]
    # compile
    data = packSFNT(header, directory, tableData)
    return data
Ejemplo n.º 9
0
def makeInvalidPadding2():
    header, directory, tableData = defaultSFNTTestData()
    # pad the tables and update their offsets
    entries = [(entry["offset"], entry) for entry in directory]
    for o, entry in sorted(entries):
        tag = entry["tag"]
        data = tableData[tag]
        tableData[tag] = padData(data)
        entry["offset"] += sfntDirectoryEntrySize
    # make a bogus table and insert it
    header["numTables"] += 1
    data = "\01" * 15
    tableData["zzzz"] = data
    offset = entry["offset"] + entry["length"] + calcPaddingLength(
        entry["length"])
    directory.append(
        dict(tag="zzzz",
             offset=offset,
             length=15,
             checksum=calcTableChecksum("zzzz", data)))
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
Ejemplo n.º 10
0
def makeBitwiseIdenticalNonStandardTable1():
    header, directory, tableData = defaultSFNTTestData()
    # adjust the header
    header["numTables"] += 1
    # store the data
    data = "\0" * 4
    tableData["TEST"] = data
    # offset the directory entries
    for entry in directory:
        entry["offset"] += sfntDirectoryEntrySize
    # find the offset
    entries = [(entry["offset"], entry) for entry in directory]
    entry = max(entries)[1]
    offset = entry["offset"] + entry["length"]
    offset += calcPaddingLength(offset)
    # make the entry
    directory.append(
        dict(tag="TEST",
             offset=offset,
             length=4,
             checksum=calcTableChecksum("TEST", data)))
    # compile
    data = packSFNT(header, directory, tableData)
    return data