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'])
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'])
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'])
pnum = [ gsubPnum[n] for n in num ] 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)
numWidth = numFont['glyf']['zero']['advanceWidth'] 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)