def compile(self, ttFont):
    if self.data:
        return (struct.pack('>HLL', self.format, self.length, self.numVarSelectorRecords) + self.data)
    uvsDict = self.uvsDict
    uvsList = sorted(uvsDict.keys())
    self.numVarSelectorRecords = len(uvsList)
    offset = (10 + (self.numVarSelectorRecords * 11))
    data = []
    varSelectorRecords = []
    for uvs in uvsList:
        entryList = uvsDict[uvs]
        defList = [entry for entry in entryList if (entry[1] is None)]
        if defList:
            defList = [entry[0] for entry in defList]
            defOVSOffset = offset
            defList.sort()
            lastUV = defList[0]
            cnt = (- 1)
            defRecs = []
            for defEntry in defList:
                cnt += 1
                if ((lastUV + cnt) != defEntry):
                    rec = struct.pack('>3sB', cvtFromUVS(lastUV), (cnt - 1))
                    lastUV = defEntry
                    defRecs.append(rec)
                    cnt = 0
            rec = struct.pack('>3sB', cvtFromUVS(lastUV), cnt)
            defRecs.append(rec)
            numDefRecs = len(defRecs)
            data.append(struct.pack('>L', numDefRecs))
            data.extend(defRecs)
            offset += (4 + (numDefRecs * 4))
        else:
            defOVSOffset = 0
        ndefList = [entry for entry in entryList if (entry[1] is not None)]
        if ndefList:
            nonDefUVSOffset = offset
            ndefList.sort()
            numNonDefRecs = len(ndefList)
            data.append(struct.pack('>L', numNonDefRecs))
            offset += (4 + (numNonDefRecs * 5))
            for (uv, gname) in ndefList:
                gid = ttFont.getGlyphID(gname)
                ndrec = struct.pack('>3sH', cvtFromUVS(uv), gid)
                data.append(ndrec)
        else:
            nonDefUVSOffset = 0
        vrec = struct.pack('>3sLL', cvtFromUVS(uvs), defOVSOffset, nonDefUVSOffset)
        varSelectorRecords.append(vrec)
    data = (bytesjoin(varSelectorRecords) + bytesjoin(data))
    self.length = (10 + len(data))
    headerdata = struct.pack('>HLL', self.format, self.length, self.numVarSelectorRecords)
    self.data = (headerdata + data)
    return self.data
def compile(self, ttFont):
    if self.data:
        return (struct.pack('>HLL', self.format, self.length, self.numVarSelectorRecords) + self.data)
    uvsDict = self.uvsDict
    uvsList = sorted(uvsDict.keys())
    self.numVarSelectorRecords = len(uvsList)
    offset = (10 + (self.numVarSelectorRecords * 11))
    data = []
    varSelectorRecords = []
    for uvs in uvsList:
        entryList = uvsDict[uvs]
        defList = [entry for entry in entryList if (entry[1] is None)]
        if defList:
            defList = [entry[0] for entry in defList]
            defOVSOffset = offset
            defList.sort()
            lastUV = defList[0]
            cnt = (- 1)
            defRecs = []
            for defEntry in defList:
                cnt += 1
                if ((lastUV + cnt) != defEntry):
                    rec = struct.pack('>3sB', cvtFromUVS(lastUV), (cnt - 1))
                    lastUV = defEntry
                    defRecs.append(rec)
                    cnt = 0
            rec = struct.pack('>3sB', cvtFromUVS(lastUV), cnt)
            defRecs.append(rec)
            numDefRecs = len(defRecs)
            data.append(struct.pack('>L', numDefRecs))
            data.extend(defRecs)
            offset += (4 + (numDefRecs * 4))
        else:
            defOVSOffset = 0
        ndefList = [entry for entry in entryList if (entry[1] is not None)]
        if ndefList:
            nonDefUVSOffset = offset
            ndefList.sort()
            numNonDefRecs = len(ndefList)
            data.append(struct.pack('>L', numNonDefRecs))
            offset += (4 + (numNonDefRecs * 5))
            for (uv, gname) in ndefList:
                gid = ttFont.getGlyphID(gname)
                ndrec = struct.pack('>3sH', cvtFromUVS(uv), gid)
                data.append(ndrec)
        else:
            nonDefUVSOffset = 0
        vrec = struct.pack('>3sLL', cvtFromUVS(uvs), defOVSOffset, nonDefUVSOffset)
        varSelectorRecords.append(vrec)
    data = (bytesjoin(varSelectorRecords) + bytesjoin(data))
    self.length = (10 + len(data))
    headerdata = struct.pack('>HLL', self.format, self.length, self.numVarSelectorRecords)
    self.data = (headerdata + data)
    return self.data