Exemple #1
0
def fix(file):
    dirname = args.dirname if os.path.exists(args.dirname) \
        else os.path.join(os.path.dirname(file), args.dirname)
    basename = os.path.basename(file)

    if not os.path.exists(dirname):
        os.mkdir(dirname)

    logger.name = basename

    with open(file, 'rb') as f:
        header = f.read(4)

    font = TTCollection(file, **options) if header == b'ttcf' \
        else TTFont(file, **options)

    repair(font)

    font.save(os.path.join(dirname, basename))
Exemple #2
0
def run(path, options):
    with open(path, 'rb') as f:
        header = f.read(4)

    if header == b'ttcf' and options.face_index == -1:
        extension = '.ttc'
        font = TTCollection(path)
    else:
        extension = '.ttf'
        font = TTFont(path, fontNumber=options.face_index)

    if options.output and not os.path.isdir(options.output):
        output = options.output
    else:
        output = makeOutputFileName(path, outputDir=options.output,
                                    extension=extension,
                                    overWrite=options.overwrite)

    otf_to_ttf(font,
               post_format=options.post_format,
               max_err=options.max_error,
               reverse_direction=options.reverse_direction)
    font.save(output)
Exemple #3
0
			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_

if __name__ == "__main__":
	parser = argparse.ArgumentParser()
	parser.add_argument('-i', '--input', required = True)
	parser.add_argument('-o', '--output', required = True)
	args = parser.parse_args()

	try:
		ttc = TTCollection(args.input, recalcBBoxes = False)
		for font in ttc:
			BuildRawHdmx(font)
		ttc.save(args.output)
	except TTLibError:
		font = TTFont(args.input, recalcBBoxes = False)
		BuildRawHdmx(font)
		font.save(args.output)
Exemple #4
0
import sys
from fontTools.ttLib import TTFont, TTCollection

import common

if __name__ == "__main__":
    param = common.ParamFromArgument(sys.argv[1])

    ttc = TTCollection(param['font'], recalcBBoxes=False)
    font = ttc[0]
    del font['vhea']
    del font['vmtx']
    font_head = font['head']

    ref = TTFont(param['reference'])
    ref_head = ref['head']
    scale = font_head.unitsPerEm / ref_head.unitsPerEm

    font_head.yMin = round(ref_head.yMin * scale)
    font_head.yMax = round(ref_head.yMax * scale)

    ttc.save(param['out'])