Ejemplo n.º 1
0
	def mergeThings(self, out, lst):
		masterModel = None
		origTTFs = None
		if None in lst:
			if allNone(lst):
				if out is not None:
					raise FoundANone(self, got=lst)
				return

			# temporarily subset the list of master ttfs to the ones for which
			# master values are not None
			origTTFs = self.ttfs
			if self.ttfs:
				self.ttfs = subList([v is not None for v in lst], self.ttfs)

			masterModel = self.model
			model, lst = masterModel.getSubModel(lst)
			self.setModel(model)

		super(VariationMerger, self).mergeThings(out, lst)

		if masterModel:
			self.setModel(masterModel)
		if origTTFs:
			self.ttfs = origTTFs
Ejemplo n.º 2
0
    def mergeThings(self, out, lst):
        masterModel = None
        if None in lst:
            if allNone(lst):
                assert out is None, (out, lst)
                return
            masterModel = self.model
            model, lst = masterModel.getSubModel(lst)
            self.setModel(model)

        super(VariationMerger, self).mergeThings(out, lst)

        if masterModel:
            self.setModel(masterModel)
Ejemplo n.º 3
0
	def mergeThings(self, out, lst):
		masterModel = None
		if None in lst:
			if allNone(lst):
				assert out is None, (out, lst)
				return
			masterModel = self.model
			model, lst = masterModel.getSubModel(lst)
			self.setModel(model)

		super(VariationMerger, self).mergeThings(out, lst)

		if masterModel:
			self.setModel(masterModel)
Ejemplo n.º 4
0
    def mergeThings(self, out, lst):
        masterModel = None
        if None in lst:
            if allNone(lst):
                if out is not None:
                    raise FoundANone(self, got=lst)
                return
            masterModel = self.model
            model, lst = masterModel.getSubModel(lst)
            self.setModel(model)

        super(VariationMerger, self).mergeThings(out, lst)

        if masterModel:
            self.setModel(masterModel)
Ejemplo n.º 5
0
def merge(merger, self, lst):
    if self is None:
        assert allNone(lst), (lst)
        return

    self.classDefs = {}
    # We only care about the .classDefs
    self = self.classDefs
    lst = [l.classDefs for l in lst]

    allKeys = set()
    allKeys.update(*[l.keys() for l in lst])
    for k in allKeys:
        allValues = nonNone(l.get(k) for l in lst)
        assert allEqual(allValues), allValues
        if not allValues:
            self[k] = None
        else:
            self[k] = allValues[0]
Ejemplo n.º 6
0
def merge(merger, self, lst):
	if self is None:
		assert allNone(lst), (lst)
		return

	self.classDefs = {}
	# We only care about the .classDefs
	self = self.classDefs
	lst = [l.classDefs for l in lst]

	allKeys = set()
	allKeys.update(*[l.keys() for l in lst])
	for k in allKeys:
		allValues = nonNone(l.get(k) for l in lst)
		assert allEqual(allValues), allValues
		if not allValues:
			self[k] = None
		else:
			self[k] = allValues[0]
Ejemplo n.º 7
0
def merge(merger, self, lst):
    if self is None:
        if not allNone(lst):
            raise VarLibMergeError(lst)
        return

    lst = [l.classDefs for l in lst]
    self.classDefs = {}
    # We only care about the .classDefs
    self = self.classDefs

    allKeys = set()
    allKeys.update(*[l.keys() for l in lst])
    for k in allKeys:
        allValues = nonNone(l.get(k) for l in lst)
        if not allEqual(allValues):
            raise VarLibMergeError(allValues)
        if not allValues:
            self[k] = None
        else:
            self[k] = allValues[0]
Ejemplo n.º 8
0
def merge(merger, self, lst):
	if self is None:
		if not allNone(lst):
			raise NotANone(merger, expected=None, got=lst)
		return

	lst = [l.classDefs for l in lst]
	self.classDefs = {}
	# We only care about the .classDefs
	self = self.classDefs

	allKeys = set()
	allKeys.update(*[l.keys() for l in lst])
	for k in allKeys:
		allValues = nonNone(l.get(k) for l in lst)
		if not allEqual(allValues):
			raise ShouldBeConstant(merger, expected=allValues[0], got=lst, stack=["." + k])
		if not allValues:
			self[k] = None
		else:
			self[k] = allValues[0]
Ejemplo n.º 9
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)
Ejemplo n.º 10
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.

		assert allEqual(allClasses), allClasses
		if not 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)