예제 #1
0
def buildMarkArray(marks, glyphMap):
    """{"acute": (markClass, otTables.Anchor)} --> otTables.MarkArray"""
    self = ot.MarkArray()
    self.MarkRecord = []
    for mark in sorted(marks.keys(), key=glyphMap.__getitem__):
        markClass, anchor = marks[mark]
        markrec = buildMarkRecord(markClass, anchor)
        self.MarkRecord.append(markrec)
    self.MarkCount = len(self.MarkRecord)
    return self
예제 #2
0
 def setMarkArray_(self, marks, markClassIDs, subtable):
     """Helper for MarkBasePosBuilder and MarkLigPosBuilder."""
     subtable.MarkArray = otTables.MarkArray()
     subtable.MarkArray.MarkCount = len(marks)
     subtable.MarkArray.MarkRecord = []
     for mark in subtable.MarkCoverage.glyphs:
         markClassName, markAnchor = self.marks[mark]
         markrec = otTables.MarkRecord()
         markrec.Class = markClassIDs[markClassName]
         markrec.MarkAnchor = markAnchor
         subtable.MarkArray.MarkRecord.append(markrec)
예제 #3
0
def _MarkBasePosFormat1_merge(self, lst, merger, Mark='Mark', Base='Base'):
    self.ClassCount = max(l.ClassCount for l in lst)

    MarkCoverageGlyphs, MarkRecords = \
     _merge_GlyphOrders(merger.font,
          [getattr(l, Mark+'Coverage').glyphs for l in lst],
          [getattr(l, Mark+'Array').MarkRecord for l in lst])
    getattr(self, Mark + 'Coverage').glyphs = MarkCoverageGlyphs

    BaseCoverageGlyphs, BaseRecords = \
     _merge_GlyphOrders(merger.font,
          [getattr(l, Base+'Coverage').glyphs for l in lst],
          [getattr(getattr(l, Base+'Array'), Base+'Record') for l in lst])
    getattr(self, Base + 'Coverage').glyphs = BaseCoverageGlyphs

    # MarkArray
    records = []
    for g, glyphRecords in zip(MarkCoverageGlyphs, zip(*MarkRecords)):
        allClasses = [r.Class for r in glyphRecords if r is not None]

        # TODO Right now we require that all marks have same class in
        # all masters that cover them.  This is not required.
        #
        # We can relax that by just requiring that all marks that have
        # the same class in a master, have the same class in every other
        # master.  Indeed, if, say, a sparse master only covers one mark,
        # that mark probably will get class 0, which would possibly be
        # different from its class in other masters.
        #
        # We can even go further and reclassify marks to support any
        # input.  But, since, it's unlikely that two marks being both,
        # say, "top" in one master, and one being "top" and other being
        # "top-right" in another master, we shouldn't do that, as any
        # failures in that case will probably signify mistakes in the
        # input masters.

        if not allEqual(allClasses):
            raise allClasses(self, allClasses)
            rec = None
        else:
            rec = ot.MarkRecord()
            rec.Class = allClasses[0]
            allAnchors = [
                None if r is None else r.MarkAnchor for r in glyphRecords
            ]
            if allNone(allAnchors):
                anchor = None
            else:
                anchor = ot.Anchor()
                anchor.Format = 1
                merger.mergeThings(anchor, allAnchors)
            rec.MarkAnchor = anchor
        records.append(rec)
    array = ot.MarkArray()
    array.MarkRecord = records
    array.MarkCount = len(records)
    setattr(self, Mark + "Array", array)

    # BaseArray
    records = []
    for g, glyphRecords in zip(BaseCoverageGlyphs, zip(*BaseRecords)):
        if allNone(glyphRecords):
            rec = None
        else:
            rec = getattr(ot, Base + 'Record')()
            anchors = []
            setattr(rec, Base + 'Anchor', anchors)
            glyphAnchors = [[] if r is None else getattr(r, Base + 'Anchor')
                            for r in glyphRecords]
            for l in glyphAnchors:
                l.extend([None] * (self.ClassCount - len(l)))
            for allAnchors in zip(*glyphAnchors):
                if allNone(allAnchors):
                    anchor = None
                else:
                    anchor = ot.Anchor()
                    anchor.Format = 1
                    merger.mergeThings(anchor, allAnchors)
                anchors.append(anchor)
        records.append(rec)
    array = getattr(ot, Base + 'Array')()
    setattr(array, Base + 'Record', records)
    setattr(array, Base + 'Count', len(records))
    setattr(self, Base + 'Array', array)