Пример #1
0
def merge(self, m, tables):

    assert len(tables) == len(m.duplicateGlyphsPerFont)
    for i, (table, dups) in enumerate(zip(tables, m.duplicateGlyphsPerFont)):
        if not dups: continue
        assert (table is not None and table is not NotImplemented
                ), "Have duplicates to resolve for font %d but no GSUB: %s" % (
                    i + 1, dups)
        synthFeature = None
        synthLookup = None
        for script in table.table.ScriptList.ScriptRecord:
            if script.ScriptTag == 'DFLT': continue  # XXX
            for langsys in [script.Script.DefaultLangSys] + [
                    l.LangSys for l in script.Script.LangSysRecord
            ]:
                if langsys is None: continue  # XXX Create!
                feature = [
                    v for v in langsys.FeatureIndex if v.FeatureTag == 'locl'
                ]
                assert len(feature) <= 1
                if feature:
                    feature = feature[0]
                else:
                    if not synthFeature:
                        synthFeature = otTables.FeatureRecord()
                        synthFeature.FeatureTag = 'locl'
                        f = synthFeature.Feature = otTables.Feature()
                        f.FeatureParams = None
                        f.LookupCount = 0
                        f.LookupListIndex = []
                        langsys.FeatureIndex.append(synthFeature)
                        langsys.FeatureIndex.sort(key=lambda v: v.FeatureTag)
                        table.table.FeatureList.FeatureRecord.append(
                            synthFeature)
                        table.table.FeatureList.FeatureCount += 1
                    feature = synthFeature

                if not synthLookup:
                    subtable = otTables.SingleSubst()
                    subtable.mapping = dups
                    synthLookup = otTables.Lookup()
                    synthLookup.LookupFlag = 0
                    synthLookup.LookupType = 1
                    synthLookup.SubTableCount = 1
                    synthLookup.SubTable = [subtable]
                    if table.table.LookupList is None:
                        # mtiLib uses None as default value for LookupList,
                        # while feaLib points to an empty array with count 0
                        # TODO: make them do the same
                        table.table.LookupList = otTables.LookupList()
                        table.table.LookupList.Lookup = []
                        table.table.LookupList.LookupCount = 0
                    table.table.LookupList.Lookup.append(synthLookup)
                    table.table.LookupList.LookupCount += 1

                feature.Feature.LookupListIndex[:0] = [synthLookup]
                feature.Feature.LookupCount += 1

    DefaultTable.merge(self, m, tables)
    return self
Пример #2
0
def merge(self, m, tables):

    assert len(tables) == len(m.duplicateGlyphsPerFont)
    for i, (table, dups) in enumerate(zip(tables, m.duplicateGlyphsPerFont)):
        if not dups: continue
        assert (
            table is not None and table is not NotImplemented
        ), "Have duplicates to resolve for font %d but no GSUB" % (i + 1)
        lookupMap = dict((id(v), v) for v in table.table.LookupList.Lookup)
        featureMap = dict(
            (id(v), v) for v in table.table.FeatureList.FeatureRecord)
        synthFeature = None
        synthLookup = None
        for script in table.table.ScriptList.ScriptRecord:
            if script.ScriptTag == 'DFLT': continue  # XXX
            for langsys in [script.Script.DefaultLangSys] + [
                    l.LangSys for l in script.Script.LangSysRecord
            ]:
                feature = [
                    featureMap[v] for v in langsys.FeatureIndex
                    if featureMap[v].FeatureTag == 'locl'
                ]
                assert len(feature) <= 1
                if feature:
                    feature = feature[0]
                else:
                    if not synthFeature:
                        synthFeature = otTables.FeatureRecord()
                        synthFeature.FeatureTag = 'locl'
                        f = synthFeature.Feature = otTables.Feature()
                        f.FeatureParams = None
                        f.LookupCount = 0
                        f.LookupListIndex = []
                        langsys.FeatureIndex.append(id(synthFeature))
                        featureMap[id(synthFeature)] = synthFeature
                        langsys.FeatureIndex.sort(
                            key=lambda v: featureMap[v].FeatureTag)
                        table.table.FeatureList.FeatureRecord.append(
                            synthFeature)
                        table.table.FeatureList.FeatureCount += 1
                    feature = synthFeature

                if not synthLookup:
                    subtable = otTables.SingleSubst()
                    subtable.mapping = dups
                    synthLookup = otTables.Lookup()
                    synthLookup.LookupFlag = 0
                    synthLookup.LookupType = 1
                    synthLookup.SubTableCount = 1
                    synthLookup.SubTable = [subtable]
                    table.table.LookupList.Lookup.append(synthLookup)
                    table.table.LookupList.LookupCount += 1

                feature.Feature.LookupListIndex[:0] = [id(synthLookup)]
                feature.Feature.LookupCount += 1

    DefaultTable.merge(self, m, tables)
    return self
Пример #3
0
def doit(args) :
    infont = args.ifont
    for tag, version in (('Silf', 5), ('Glat', 3)) :
        dat = infont.getTableData(tag)
        newdat = compressGr(dat, version)
        table = DefaultTable(tag)
        table.decompile(newdat, infont)
        infont[tag] = table
    return infont
Пример #4
0
def merge(self, m, tables):

	assert len(tables) == len(m.duplicateGlyphsPerFont)
	for i,(table,dups) in enumerate(zip(tables, m.duplicateGlyphsPerFont)):
		if not dups: continue
		if table is None or table is NotImplemented:
			# Checks whether the dups are equivalent or not.
			# Discard gid if its shape is not equal to that of oldgid.
			for oldgid, gid in dups.items():
				if not isGlyphSame(m.fonts, oldgid, gid):
					oldgname, oldidx = getGlyphNameAndFontIndex(oldgid)
					gname, idx = getGlyphNameAndFontIndex(gid)
					log.warn("%s:<%s> is dropped and replaced by %s:<%s>" % (m.fontfiles[idx], gname, m.fontfiles[oldidx], oldgname))
			continue
		lookupMap = {id(v):v for v in table.table.LookupList.Lookup}
		featureMap = {id(v):v for v in table.table.FeatureList.FeatureRecord}
		synthFeature = None
		synthLookup = None
		for script in table.table.ScriptList.ScriptRecord:
			if script.ScriptTag == 'DFLT': continue # XXX
			for langsys in [script.Script.DefaultLangSys] + [l.LangSys for l in script.Script.LangSysRecord]:
				if langsys is None: continue # XXX Create!
				feature = [featureMap[v] for v in langsys.FeatureIndex if featureMap[v].FeatureTag == 'locl']
				assert len(feature) <= 1
				if feature:
					feature = feature[0]
				else:
					if not synthFeature:
						synthFeature = otTables.FeatureRecord()
						synthFeature.FeatureTag = 'locl'
						f = synthFeature.Feature = otTables.Feature()
						f.FeatureParams = None
						f.LookupCount = 0
						f.LookupListIndex = []
						langsys.FeatureIndex.append(id(synthFeature))
						featureMap[id(synthFeature)] = synthFeature
						langsys.FeatureIndex.sort(key=lambda v: featureMap[v].FeatureTag)
						table.table.FeatureList.FeatureRecord.append(synthFeature)
						table.table.FeatureList.FeatureCount += 1
					feature = synthFeature

				if not synthLookup:
					subtable = otTables.SingleSubst()
					subtable.mapping = dups
					synthLookup = otTables.Lookup()
					synthLookup.LookupFlag = 0
					synthLookup.LookupType = 1
					synthLookup.SubTableCount = 1
					synthLookup.SubTable = [subtable]
					table.table.LookupList.Lookup.append(synthLookup)
					table.table.LookupList.LookupCount += 1

				feature.Feature.LookupListIndex[:0] = [id(synthLookup)]
				feature.Feature.LookupCount += 1

	DefaultTable.merge(self, m, tables)
	return self
Пример #5
0
def merge(self, m, tables):

	assert len(tables) == len(m.duplicateGlyphsPerFont)
	for i,(table,dups) in enumerate(zip(tables, m.duplicateGlyphsPerFont)):
		if not dups: continue
		assert (table is not None and table is not NotImplemented), "Have duplicates to resolve for font %d but no GSUB: %s" % (i + 1, dups)
		synthFeature = None
		synthLookup = None
		for script in table.table.ScriptList.ScriptRecord:
			if script.ScriptTag == 'DFLT': continue # XXX
			for langsys in [script.Script.DefaultLangSys] + [l.LangSys for l in script.Script.LangSysRecord]:
				if langsys is None: continue # XXX Create!
				feature = [v for v in langsys.FeatureIndex if v.FeatureTag == 'locl']
				assert len(feature) <= 1
				if feature:
					feature = feature[0]
				else:
					if not synthFeature:
						synthFeature = otTables.FeatureRecord()
						synthFeature.FeatureTag = 'locl'
						f = synthFeature.Feature = otTables.Feature()
						f.FeatureParams = None
						f.LookupCount = 0
						f.LookupListIndex = []
						langsys.FeatureIndex.append(synthFeature)
						langsys.FeatureIndex.sort(key=lambda v: v.FeatureTag)
						table.table.FeatureList.FeatureRecord.append(synthFeature)
						table.table.FeatureList.FeatureCount += 1
					feature = synthFeature

				if not synthLookup:
					subtable = otTables.SingleSubst()
					subtable.mapping = dups
					synthLookup = otTables.Lookup()
					synthLookup.LookupFlag = 0
					synthLookup.LookupType = 1
					synthLookup.SubTableCount = 1
					synthLookup.SubTable = [subtable]
					if table.table.LookupList is None:
						# mtiLib uses None as default value for LookupList,
						# while feaLib points to an empty array with count 0
						# TODO: make them do the same
						table.table.LookupList = otTables.LookupList()
						table.table.LookupList.Lookup = []
						table.table.LookupList.LookupCount = 0
					table.table.LookupList.Lookup.append(synthLookup)
					table.table.LookupList.LookupCount += 1

				feature.Feature.LookupListIndex[:0] = [synthLookup]
				feature.Feature.LookupCount += 1

	DefaultTable.merge(self, m, tables)
	return self
Пример #6
0
def merge(self, m, tables):
	DefaultTable.merge(self, m, tables)
	if self.version < 2:
		# bits 8 and 9 are reserved and should be set to zero
		self.fsType &= ~0x0300
	if self.version >= 3:
		# Only one of bits 1, 2, and 3 may be set. We already take
		# care of bit 1 implications in mergeOs2FsType. So unset
		# bit 2 if bit 3 is already set.
		if self.fsType & 0x0008:
			self.fsType &= ~0x0004
	return self
def merge(self, m, tables):
	DefaultTable.merge(self, m, tables)
	if self.version < 2:
		# bits 8 and 9 are reserved and should be set to zero
		self.fsType &= ~0x0300
	if self.version >= 3:
		# Only one of bits 1, 2, and 3 may be set. We already take
		# care of bit 1 implications in mergeOs2FsType. So unset
		# bit 2 if bit 3 is already set.
		if self.fsType & 0x0008:
			self.fsType &= ~0x0004
	return self
Пример #8
0
def merge(self, m, tables):

	assert len(tables) == len(m.duplicateGlyphsPerFont)
	for i,(table,dups) in enumerate(zip(tables, m.duplicateGlyphsPerFont)):
		if not dups: continue
		assert (table is not None and table is not NotImplemented), "Have duplicates to resolve for font %d but no GSUB" % (i + 1)
		lookupMap = {id(v):v for v in table.table.LookupList.Lookup}
		featureMap = {id(v):v for v in table.table.FeatureList.FeatureRecord}
		synthFeature = None
		synthLookup = None
		for script in table.table.ScriptList.ScriptRecord:
			if script.ScriptTag == 'DFLT': continue # XXX
			for langsys in [script.Script.DefaultLangSys] + [l.LangSys for l in script.Script.LangSysRecord]:
				if langsys is None: continue # XXX Create!
				feature = [featureMap[v] for v in langsys.FeatureIndex if featureMap[v].FeatureTag == 'locl']
				assert len(feature) <= 1
				if feature:
					feature = feature[0]
				else:
					if not synthFeature:
						synthFeature = otTables.FeatureRecord()
						synthFeature.FeatureTag = 'locl'
						f = synthFeature.Feature = otTables.Feature()
						f.FeatureParams = None
						f.LookupCount = 0
						f.LookupListIndex = []
						langsys.FeatureIndex.append(id(synthFeature))
						featureMap[id(synthFeature)] = synthFeature
						langsys.FeatureIndex.sort(key=lambda v: featureMap[v].FeatureTag)
						table.table.FeatureList.FeatureRecord.append(synthFeature)
						table.table.FeatureList.FeatureCount += 1
					feature = synthFeature

				if not synthLookup:
					subtable = otTables.SingleSubst()
					subtable.mapping = dups
					synthLookup = otTables.Lookup()
					synthLookup.LookupFlag = 0
					synthLookup.LookupType = 1
					synthLookup.SubTableCount = 1
					synthLookup.SubTable = [subtable]
					table.table.LookupList.Lookup.append(synthLookup)
					table.table.LookupList.LookupCount += 1

				feature.Feature.LookupListIndex[:0] = [id(synthLookup)]
				feature.Feature.LookupCount += 1

	DefaultTable.merge(self, m, tables)
	return self
Пример #9
0
def merge(self, m, tables):
	for i,table in enumerate(tables):
		for g in table.glyphs.values():
			if i:
				# Drop hints for all but first font, since
				# we don't map functions / CVT values.
				g.removeHinting()
			# Expand composite glyphs to load their
			# composite glyph names.
			if g.isComposite():
				g.expand(table)
	return DefaultTable.merge(self, m, tables)
def merge(self, m, tables):
	for i,table in enumerate(tables):
		for g in table.glyphs.values():
			if i:
				# Drop hints for all but first font, since
				# we don't map functions / CVT values.
				g.removeHinting()
			# Expand composite glyphs to load their
			# composite glyph names.
			if g.isComposite():
				g.expand(table)
	return DefaultTable.merge(self, m, tables)
Пример #11
0
def BuildRawHdmx(font):
	head_ = font['head']
	os_2_ = font['OS/2']
	maxp_ = font['maxp']
	hmtx_ = font['hmtx']

	head_.flags |= headFlagInstructionsMayAlterAdvanceWidth

	numGlyphs = maxp_.numGlyphs
	recordSize = 4 * ((2 + numGlyphs + 3) // 4)
	pad = (recordSize - 2 - numGlyphs) * b"\0"
	deviceRecords = []

	upm = head_.unitsPerEm
	widthHw = os_2_.xAvgCharWidth
	for ppem in range(ppemMin, ppemMax + 1):
		ppemHw = widthHw * ppem / upm
		if type(ppemHw) == int:
			continue
		d, i = math.modf(ppemHw)
		if (d <= 1/3):
			ppemHw = int(i)
		else:
			ppemHw = int(i) + 1

		widths = []
		for name in font.getGlyphOrder():
			width = hmtx_[name][0]
			widths.append(math.ceil(width / widthHw) * ppemHw)
		record = bytes([ ppem, max(widths) ] + widths) + pad
		deviceRecords.append(record)

	hdmxHeader = sstruct.pack(hdmxHeaderFormat, SimpleNamespace(version = 0, numRecords = len(deviceRecords), recordSize = recordSize))
	
	hdmx_ = DefaultTable('hdmx')
	hdmx_.data = hdmxHeader + b''.join(deviceRecords)
	font['hdmx'] = hdmx_
Пример #12
0
from fontTools.ttLib.tables.DefaultTable import DefaultTable

font_path = "myfont.ttf"
output_path = "myfont_patched.ttf"

table_tag = "DSIG"


# Get raw table data from the source font

font = TTFont(font_path)
raw_data = font.getTableData(table_tag)


# Do something with the raw table data
# This example just sets an empty DSIG table.

raw_data = b"\0\0\0\1\0\0\0\0"


# Write the data back to the font

# We could re-use the existing table when the source and target font are
# identical, but let's make a new empty table to be more universal.
table = DefaultTable(table_tag)
table.data = raw_data

# Add the new table back into the source font and save under a new name.
font[table_tag] = table
font.save(output_path)
Пример #13
0
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables.DefaultTable import DefaultTable

font_path = "myfont.ttf"
output_path = "myfont_patched.ttf"

table_tag = "DSIG"

# Get raw table data from the source font

font = TTFont(font_path)
raw_data = font.getTableData(table_tag)

# Do something with the raw table data
# This example just sets an empty DSIG table.

raw_data = b"\0\0\0\1\0\0\0\0"

# Write the data back to the font

# We could re-use the existing table when the source and target font are
# identical, but let's make a new empty table to be more universal.
table = DefaultTable(table_tag)
table.data = raw_data

# Add the new table back into the source font and save under a new name.
font[table_tag] = table
font.save(output_path)