Exemple #1
0
def ApplyPalt(font):
    for palt in GetLookupPalt(font):
        for sub in palt['subtables']:
            for (n, d) in sub.items():
                glyph = font['glyf'][n]
                if 'dx' in d:
                    Transform(glyph, 1, 0, 0, 1, d['dx'], 0)
                if 'dWidth' in d:
                    ChangeAdvanceWidth(glyph, d['dWidth'])
Exemple #2
0
def ProportionalizeKana(font):
    for palt in GetLookupPalt(font):
        for sub in palt['subtables']:
            for (n, d) in sub.items():
                if any([IsKana(ch) for ch in GetUnicodeScalars(n, font)]):
                    glyph = font['glyf'][n]
                    if 'dx' in d:
                        Transform(glyph, 1, 0, 0, 1, d['dx'], 0)
                    if 'dWidth' in d:
                        ChangeAdvanceWidth(glyph, d['dWidth'])
Exemple #3
0
def ProportionalizeKana(font):
	for palt in GetLookupPalt(font):
		for sub in palt['subtables']:
			for (n, d) in sub.items():
				if re.match('^uni[0-9A-F]{4,5}$', n) and IsKana(int(n[3:], 16)):
					glyph = font['glyf'][n]
					if 'dx' in d:
						Transform(glyph, 1, 0, 0, 1, d['dx'], 0)
					if 'dWidth' in d:
						ChangeAdvanceWidth(glyph, d['dWidth'])
Exemple #4
0
def Dereference(glyph, font):
	if 'references' not in glyph:
		return copy.deepcopy(glyph)

	result = dict(glyph)
	del result['references']
	result['contours'] = []

	for ref in glyph['references']:
		target = font['glyf'][ref['glyph']]
		data = Dereference(target, font) if 'references' in target else copy.deepcopy(target)
		Transform(data, ref['a'], ref['b'], ref['c'], ref['d'], ref['x'], ref['y'])
		result['contours'].extend(data['contours'])

	return result
	version = sys.argv[4]

	isOldstyle = region == 'OSF'
	
	if isOldstyle:
		region2 = 'Oldstyle'
	else:
		region2 = 'Classic' if region == 'CL' else region

	with open("noto/{}/NotoRounded{}-Condensed{}.otd".format('osf' if isOldstyle else 'rounded', 'OSF' if isOldstyle else '', weight), 'rb') as baseFile:
		baseFont = json.loads(baseFile.read().decode('UTF-8', errors='replace'))

	with open("rhr/ResourceHanRounded{}-{}.otd".format(region, weight), 'rb') as asianFile:
		asianFont = json.loads(asianFile.read().decode('UTF-8', errors = 'replace'))

	with open("noto/emoji/NotoEmoji-Regular.otd", 'rb') as emojiFile:
		emojiFont = json.loads(emojiFile.read().decode('UTF-8', errors = 'replace'))

	baseFont['OS_2']['ulCodePageRange1'][encoding] = True
	NameFont(baseFont, region2, weight, version)

	ApplyPalt(asianFont)
	MergeBelow(baseFont, asianFont)
	for _, glyph in emojiFont['glyf'].items():
		Transform(glyph, 1000 / 2048, 0, 0, 1000 / 2048, 0, 0)
	MergeBelow(baseFont, emojiFont)

	outStr = json.dumps(baseFont, ensure_ascii=False)
	with open("nowar/{}-NowarCompactRoundedUI-{}-{}.otd".format(encoding, region, weight), 'w') as outFile:
		outFile.write(outStr)
			onum = [ gsubOnum[n] for n in pnum ]
			tonum = [ gsubOnum[n] for n in num ]

			for n in num + tonum:
				tGlyph = numFont['glyf'][n]
				tWidth = tGlyph['advanceWidth']
				pName = gsubPnum[n]
				pGlyph = numFont['glyf'][pName]
				pWidth = pGlyph['advanceWidth']
				if pWidth > tWidth:
					numFont['glyf'][pName] = copy.deepcopy(tGlyph)
					pGlyph = numFont['glyf'][pName]
					pWidth = tWidth
				if changeWidth != 0:
					ChangeAdvanceWidth(pGlyph, changeWidth)
					Transform(pGlyph, 1, 0, 0, 1, (changeWidth + 1) // 2, 0)

			for n in num + pnum + onum + tonum:
				baseFont['glyf'][n] = numFont['glyf'][n]
			ApplyGsubSingle('pnum', baseFont)

	# merge CJK
	if param.family in [ "Sans", "UI", "WarcraftSans", "WarcraftUI" ]:
		with open("shs/{}.otd".format(configure.GenerateFilename(dep['CJK'])), 'rb') as asianFile:
			asianFont = json.loads(asianFile.read().decode('UTF-8', errors = 'replace'))

		# pre-apply `palt` in UI family
		if "UI" in param.family:
			ApplyPalt(asianFont)

		# pseudo-SC, remap characters
    changeWidth = maxWidth - numWidth if numWidth > maxWidth else 0

    for n in [
            'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
            'eight', 'nine'
    ]:
        glyph = numFont['glyf'][n]
        width = glyph['advanceWidth']
        pGlyph = numFont['glyf'][n + '.lf']
        pWidth = pGlyph['advanceWidth']
        if pWidth < width:
            glyph = pGlyph
            width = pWidth
        if changeWidth != 0:
            ChangeAdvanceWidth(glyph, changeWidth)
            Transform(glyph, 1, 0, 0, 1, (changeWidth + 1) // 2, 0)
        baseFont['glyf'][n] = glyph

    MergeBelow(baseFont, asianFont)
    for _, glyph in emojiFont['glyf'].items():
        Transform(glyph, 1000 / 2048, 0, 0, 1000 / 2048, 0, 0)
    MergeBelow(baseFont, emojiFont)

    # quotes, em-dash and ellipsis
    for u in [0x2014, 0x2018, 0x2019, 0x201C, 0x201D, 0x2026]:
        if str(u) in asianFont['cmap']:
            baseFont['glyf'][baseFont['cmap'][str(u)]] = asianFont['glyf'][
                asianFont['cmap'][str(u)]]

    outStr = json.dumps(baseFont, ensure_ascii=False)
    with open(