def makeUnknownTables():
    from testCaseGeneratorLib.woff import knownTableTags

    header, directory, tableData = defaultSFNTTestData(flavor="TTF")
    # adjust the header
    header["numTables"] += len(dummyTables)
    # adjust the offsets
    shift = len(dummyTables) * sfntDirectoryEntrySize
    for entry in directory:
        entry["offset"] += shift
    # store the data
    sorter = [(entry["offset"], entry["length"]) for entry in directory]
    offset, length = max(sorter)
    offset = offset + length
    data = "\0" * 4
    checksum = calcTableChecksum(None, data)
    for tag in dummyTables:
        tableData[tag] = data
        entry = dict(
            tag=tag,
            offset=offset,
            length=4,
            checksum=checksum
        )
        directory.append(entry)
        offset += 4

    tags = [e["tag"] for e in directory]
    assert not set(tags) < set(knownTableTags)

    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
def makeTableDirectoryAscending1():
    header, directory, tableData = defaultSFNTTestData()
    # adjust the header
    header["numTables"] += len(dummyTables)
    # adjust the offsets
    shift = len(dummyTables) * sfntDirectoryEntrySize
    for entry in directory:
        entry["offset"] += shift
    # store the data
    sorter = [(entry["offset"], entry["length"]) for entry in directory]
    offset, length = max(sorter)
    offset = offset + length
    data = "\0" * 4
    checksum = calcTableChecksum(None, data)
    for tag in dummyTables:
        tableData[tag] = data
        entry = dict(
            tag=tag,
            offset=offset,
            length=4,
            checksum=checksum
        )
        directory.append(entry)
        offset += 4
    # compile
    data = packSFNT(header, directory, tableData)
    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
def makeInvalidChecksum1():
    header, directory, tableData = defaultSFNTTestData()
    # change the OS/2 checksum
    for entry in directory:
        if entry["tag"] == "OS/2":
            entry["checksum"] = 0
    data = packSFNT(header, directory, tableData)
    return data
Пример #7
0
def makeInvalidBlocks2():
    header, directory, tableData = defaultSFNTTestData()
    # shift each table up four bytes
    for entry in directory:
        entry["offset"] -= 4
    # compile
    data = packSFNT(header, directory, tableData)
    return data
def makeInvalidBlocks2():
    header, directory, tableData = defaultSFNTTestData()
    # shift each table up four bytes
    for entry in directory:
        entry["offset"] -= 4
    # compile
    data = packSFNT(header, directory, tableData)
    return data
def makeInvalidDirectoryOrder1():
    header, directory, tableData = defaultSFNTTestData()
    # reverse the entries
    entries = [(entry["tag"], entry) for entry in directory]
    directory = [entry for tag, entry in reversed(sorted(entries))]
    # compile
    data = packSFNT(header, directory, tableData, sortDirectory=False)
    return data
Пример #10
0
def makeInvalidChecksum1():
    header, directory, tableData = defaultSFNTTestData()
    # change the OS/2 checksum
    for entry in directory:
        if entry["tag"] == "OS/2":
            entry["checksum"] = 0
    data = packSFNT(header, directory, tableData)
    return data
Пример #11
0
def makeInvalidDirectoryOrder1():
    header, directory, tableData = defaultSFNTTestData()
    # reverse the entries
    entries = [(entry["tag"], entry) for entry in directory]
    directory = [entry for tag, entry in reversed(sorted(entries))]
    # compile
    data = packSFNT(header, directory, tableData, sortDirectory=False)
    return data
def makeInvalidBlocks3():
    header, directory, tableData = defaultSFNTTestData()
    # extend the length of the final table by four bytes
    entries = [(entry["offset"], entry) for entry in directory]
    entry = sorted(entries)[-1][1]
    entry["length"] += 4
    # compile
    data = packSFNT(header, directory, tableData)
    return data
Пример #13
0
def makeInvalidBlocks3():
    header, directory, tableData = defaultSFNTTestData()
    # extend the length of the final table by four bytes
    entries = [(entry["offset"], entry) for entry in directory]
    entry = sorted(entries)[-1][1]
    entry["length"] += 4
    # compile
    data = packSFNT(header, directory, tableData)
    return data
def makeKnownTables():
    from testCaseGeneratorLib.woff import knownTableTags

    header, directory, tableData = defaultSFNTTestData(flavor="TTF")

    tags = [e["tag"] for e in directory]
    assert set(tags) < set(knownTableTags)

    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
Пример #15
0
def makeInvalidBlocks1():
    header, directory, tableData = defaultSFNTTestData()
    # slice four bytes off of the head table
    tableData["head"] = tableData["head"][:-4]
    # move the other tables up by four bytes
    entries = [(entry["offset"], entry) for entry in directory]
    assert sorted(entries)[0][1]["tag"] == "head"
    for o, entry in sorted(entries[1:]):
        entry["offset"] -= 4
    # compile
    data = packSFNT(header, directory, tableData)
    return data
Пример #16
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 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
Пример #18
0
def makeInvalidPadding4():
    header, directory, tableData = defaultSFNTTestData()
    entries = [(entry["offset"], entry) for entry in directory]
    # pad the tables
    for o, entry in sorted(entries):
        tag = entry["tag"]
        data = tableData[tag]
        tableData[tag] = padData(data)
    # add four bogus bytes to the last table
    entry = sorted(entries)[-1][1]
    tag = entry["tag"]
    tableData[tag] += "\0" * 4
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
def makeInvalidPadding4():
    header, directory, tableData = defaultSFNTTestData()
    entries = [(entry["offset"], entry) for entry in directory]
    # pad the tables
    for o, entry in sorted(entries):
        tag = entry["tag"]
        data = tableData[tag]
        tableData[tag] = padData(data)
    # add four bogus bytes to the last table
    entry = sorted(entries)[-1][1]
    tag = entry["tag"]
    tableData[tag] += "\0" * 4
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
Пример #20
0
def makeInvalidChecksum2():
    header, directory, tableData = defaultSFNTTestData()
    # grab the data
    data = tableData["head"]
    # gab the original value
    origValue = data[8:12]
    # pack a new value
    newValue = struct.pack(">L", 0)
    # make sure that this really is a new value
    assert origValue != newValue
    # store the new data
    newData = data[:8] + newValue + data[12:]
    tableData["head"] = newData
    # compile
    data = packSFNT(header, directory, tableData, calcCheckSum=False)
    return data
def makeInvalidChecksum2():
    header, directory, tableData = defaultSFNTTestData()
    # grab the data
    data = tableData["head"]
    # gab the original value
    origValue = data[8:12]
    # pack a new value
    newValue = struct.pack(">L", 0)
    # make sure that this really is a new value
    assert origValue != newValue
    # store the new data
    newData = data[:8] + newValue + data[12:]
    tableData["head"] = newData
    # compile
    data = packSFNT(header, directory, tableData, calcCheckSum=False)
    return data
Пример #22
0
def makeInvalidPadding3():
    header, directory, tableData = defaultSFNTTestData()
    # shift the offsets for every table after head
    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"] += 4
    # pad the tables
    for tag, data in tableData.items():
        if tag == "head":
            tableData[tag] = padData(data) + ("\0" * 4)
        else:
            tableData[tag] = padData(data)
    # compile
    data = packSFNT(header, directory, tableData, applyPadding=False)
    return data
def makeGlyfBBox1(calcBBoxes=True, composite=False):
    font = getTTFont(sfntTTFSourcePath, recalcBBoxes=calcBBoxes)
    glyf = font["glyf"]
    hmtx = font["hmtx"]
    for name in ("bbox1", "bbox2"):
        pen = TTGlyphPen(None)
        if name == "bbox1":
            pen.moveTo((0, 0))
            pen.lineTo((0, 1000))
            pen.lineTo((1000, 1000))
            pen.lineTo((1000, 0))
            pen.closePath()
        else:
            pen.moveTo((0, 0))
            pen.qCurveTo((500, 750), (600, 500), (500, 250), (0, 0))
            pen.closePath()
        glyph = pen.glyph()
        if not calcBBoxes:
            glyph.recalcBounds(glyf)
            glyph.xMax -= 100
        glyf.glyphs[name] = glyph
        hmtx.metrics[name] = (0, 0)
        glyf.glyphOrder.append(name)

    if composite:
        name = "bbox3"
        pen = TTGlyphPen(glyf.glyphOrder)
        pen.addComponent("bbox1", [1, 0, 0, 1, 0, 0])
        pen.addComponent("bbox2", [1, 0, 0, 1, 1000, 0])
        glyph = pen.glyph()
        glyph.recalcBounds(glyf)
        glyf.glyphs[name] = glyph
        hmtx.metrics[name] = (0, 0)
        glyf.glyphOrder.append(name)

    tableData = getSFNTData(font)[0]
    font.close()
    del font
    header, directory, tableData = defaultSFNTTestData(tableData=tableData, flavor="TTF")
    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
def makeGlyfBBox2(bbox):
    font = getTTFont(sfntTTFSourcePath, recalcBBoxes=False)
    glyf = font["glyf"]
    hmtx = font["hmtx"]

    name = "bbox1"
    glyph = getTableModule('glyf').Glyph()
    glyph.numberOfContours = 0
    glyph.xMin = glyph.xMax = glyph.yMin = glyph.yMax = bbox
    glyph.data = sstruct.pack(getTableModule('glyf').glyphHeaderFormat, glyph)
    glyf.glyphs[name] = glyph
    hmtx.metrics[name] = (0, 0)
    glyf.glyphOrder.append(name)

    tableData = getSFNTData(font)[0]
    font.close()
    del font

    header, directory, tableData = defaultSFNTTestData(tableData=tableData, flavor="TTF")
    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
Пример #25
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
Пример #26
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
Пример #27
0
def makeTableDirectoryAscending1():
    header, directory, tableData = defaultSFNTTestData()
    # adjust the header
    header["numTables"] += len(dummyTables)
    # adjust the offsets
    shift = len(dummyTables) * sfntDirectoryEntrySize
    for entry in directory:
        entry["offset"] += shift
    # store the data
    sorter = [(entry["offset"], entry["length"]) for entry in directory]
    offset, length = max(sorter)
    offset = offset + length
    data = "\0" * 4
    checksum = calcTableChecksum(None, data)
    for tag in dummyTables:
        tableData[tag] = data
        entry = dict(tag=tag, offset=offset, length=4, checksum=checksum)
        directory.append(entry)
        offset += 4
    # compile
    data = packSFNT(header, directory, tableData)
    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
Пример #29
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
Пример #30
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
Пример #31
0
def makeInvalidRangeShift1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, rangeShift=0)
    return data
Пример #32
0
def makeValidSFNT1():
    header, directory, tableData = defaultSFNTTestData()
    data = packSFNT(header, directory, tableData)
    return data
Пример #33
0
def makeValidSFNT2():
    header, directory, tableData = defaultSFNTTestData(flavor="TTF")
    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data
def makeInvalidRangeShift1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, rangeShift=0)
    return data
def makeInvalidEntrySelector1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, entrySelector=0)
    return data
def makeInvalidSearchRange1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, searchRange=0)
    return data
Пример #37
0
def makeInvalidSearchRange1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, searchRange=0)
    return data
Пример #38
0
def makeInvalidEntrySelector1():
    header, directory, tableData = defaultSFNTTestData()
    # compile
    data = packSFNT(header, directory, tableData, entrySelector=0)
    return data
def makeValidSFNT1():
    header, directory, tableData = defaultSFNTTestData()
    data = packSFNT(header, directory, tableData)
    return data
def makeValidSFNT2():
    header, directory, tableData = defaultSFNTTestData(flavor="TTF")
    data = packSFNT(header, directory, tableData, flavor="TTF")
    return data