Beispiel #1
0
def build(
    documentPath,
    outputUFOFormatVersion=2,
    roundGeometry=True,
    verbose=True,
    logPath=None,
    progressFunc=None,
):
    """

		Simple builder for UFO designspaces.

	"""
    from mutatorMath.ufo.document import DesignSpaceDocumentReader
    import os, glob
    if os.path.isdir(documentPath):
        # process all *.designspace documents in this folder
        todo = glob.glob(os.path.join(documentPath, "*.designspace"))
    else:
        # process the
        todo = [documentPath]
    results = []
    for path in todo:
        reader = DesignSpaceDocumentReader(path,
                                           ufoVersion=outputUFOFormatVersion,
                                           roundGeometry=roundGeometry,
                                           verbose=verbose,
                                           logPath=logPath,
                                           progressFunc=progressFunc)
        reader.process()
        results.append(reader.results)
    reader = None
    return results
def test_apply_instance_data(tmpdir, instance_names):
    font = glyphsLib.GSFont(TESTFILE_PATH)
    instance_dir = "instances"
    designspace = glyphsLib.to_designspace(font, instance_dir=instance_dir)
    path = str(tmpdir / (font.familyName + '.designspace'))
    write_designspace_and_UFOs(designspace, path)
    builder = DesignSpaceDocumentReader(designspace.path, ufoVersion=3)
    if instance_names is None:
        # generate all instances
        builder.process()
        include_filenames = None
    else:
        # generate only selected instances
        for name in instance_names:
            builder.readInstance(("stylename", name))
        # make relative filenames from paths returned by MutatorMath
        include_filenames = {os.path.relpath(instance_path, str(tmpdir))
                             for instance_path in builder.results.values()}

    ufos = apply_instance_data(designspace.path,
                               include_filenames=include_filenames)

    for filename in include_filenames or ():
        assert os.path.isdir(str(tmpdir / filename))
    assert len(ufos) == len(builder.results)
    assert isinstance(ufos[0], defcon.Font)
Beispiel #3
0
def build(
		documentPath,
		outputUFOFormatVersion=2,
		roundGeometry=True,
		verbose=True,
		logPath=None,
		progressFunc=None,
		):
	"""

		Simple builder for UFO designspaces.

	"""
	from mutatorMath.ufo.document import DesignSpaceDocumentReader
	import os, glob
	if os.path.isdir(documentPath):
		# process all *.designspace documents in this folder
		todo = glob.glob(os.path.join(documentPath, "*.designspace"))
	else:
		# process the 
		todo = [documentPath]
	results = []
	for path in todo:
		reader = DesignSpaceDocumentReader(
				path,
		        ufoVersion=outputUFOFormatVersion,
		        roundGeometry=roundGeometry,
		        verbose=verbose,
		        logPath=logPath,
				progressFunc=progressFunc
		        )
		reader.process()
		results.append(reader.results)
	reader = None
	return results
Beispiel #4
0
def go(docName,logFile,ufoVersion=3,roundGeometry=True):
    testRoot = app.config['UPLOAD_DIR']
    documentPath = os.path.join(testRoot, docName)
    sourcePath =testRoot
    instancePath = testRoot
    logPath = os.path.join(testRoot, logFile)
    doc = DesignSpaceDocumentReader(documentPath, ufoVersion, roundGeometry=roundGeometry, verbose=True, logPath=logPath)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
    close() #doc.close() ?? #It might be a bug on mutatorMath. There is no known inbuilt way of doing this. Ex: doc.Close() or doc.Flush() etc.https://github.com/LettError/MutatorMath/issues/10 
Beispiel #5
0
def build(
		documentPath=None,
		outputUFOFormatVersion=2,
		roundGeometry=True,
		verbose=True,
		logPath=None):
	"""

		Simple builder for UFO designspaces.

	"""
	from mutatorMath.ufo.document import DesignSpaceDocumentReader
	import os
	if documentPath is None:
		documentPath = os.path.join(os.getcwd(), "designspace.xml")
	if not os.path.exists(documentPath):
		print("Can not find document at \"%s\""%documentPath)
		return 0
	reader = DesignSpaceDocumentReader(
			documentPath,
	        ufoVersion=outputUFOFormatVersion,
	        roundGeometry=True,
	        verbose=verbose,
	        logPath=logPath)
	results = reader.process()
	return results
Beispiel #6
0
    def generate_temp_masters(self, designspace_path):
        """Makes a new designspace file and generates instances at the
           same location as the masters that have a subset of the glyphset"""
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        logfile = tempfile.NamedTemporaryFile(delete=True).name
        temp_ds_path, master_paths = self.build_temp_designspace(
            designspace_path)
        logger.info("Generating temp UFO master(s)...")
        ds_doc_reader = DesignSpaceDocumentReader(temp_ds_path,
                                                  ufoVersion=2,
                                                  roundGeometry=True,
                                                  verbose=False,
                                                  logPath=logfile)
        ds_doc_reader.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
        # Delete temp designspace file
        if os.path.exists(temp_ds_path):
            os.remove(temp_ds_path)
        base_folder = os.path.dirname(os.path.abspath(designspace_path))
        master_paths = [os.path.join(base_folder, p) for p in master_paths]
        return master_paths
Beispiel #7
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    if not args:
        args = ["-u"]

    mkot_options = ''

    if '-u' in args:
        print(__usage__)
        return
    if '-h' in args:
        print(__help__)
        return
    if '--mkot' in args:
        index = args.index('--mkot')
        args.pop(index)
        mkot_options = parse_makeotf_options(args.pop(index))

    (dsPath,) = args
    glyphSetsDiffer, master_paths = testGlyphSetsCompatible(dsPath)

    if glyphSetsDiffer:
        allowDecimalCoords = False
        logFile = tempfile.NamedTemporaryFile(delete=True).name
        tempDSPath, master_paths = buildTempDesignSpace(dsPath)
        print("Generating temp UFO master(s)...")
        ds_doc_reader = DesignSpaceDocumentReader(
            tempDSPath, ufoVersion=2, roundGeometry=(not allowDecimalCoords),
            verbose=False, logPath=logFile)
        ds_doc_reader.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    print("Building local otf's for master font paths...")
    curDir = os.getcwd()
    dsDir = os.path.dirname(dsPath)
    for master_path in master_paths:
        master_path = os.path.join(dsDir, master_path)
        masterDir = os.path.dirname(master_path)
        ufoName = os.path.basename(master_path)
        if ufoName.endswith(kTempUFOExt):
            otfName = ufoName[:-len(kTempUFOExt)]
            # copy the features.fea file from the original UFO master
            fea_file_path_from = os.path.join(
                master_path[:-len(kTempUFOExt)] + '.ufo', kFeaturesFile)
            fea_file_path_to = os.path.join(master_path, kFeaturesFile)
            if os.path.exists(fea_file_path_from):
                shutil.copyfile(fea_file_path_from, fea_file_path_to)
        else:
            otfName = os.path.splitext(ufoName)[0]
        otfName = otfName + ".otf"
        os.chdir(masterDir)
        cmd = "makeotf -f \"%s\" -o \"%s\" -r -nS %s 2>&1" % (
            ufoName, otfName, mkot_options)
        log = runShellCmd(cmd)
        if ("FATAL" in log) or ("Failed to build" in log):
            print(log)

        if "Built" not in str(log):
            print("Error building OTF font for", master_path, log)
            print("makeotf cmd was '%s' in %s." % (cmd, masterDir))
        else:
            print("Built OTF font for", master_path)
            compatibilizePaths(otfName)
            if ufoName.endswith(kTempUFOExt):
                shutil.rmtree(ufoName)
        os.chdir(curDir)

    if glyphSetsDiffer and os.path.exists(tempDSPath):
        os.remove(tempDSPath)
Beispiel #8
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    if not args:
        args = ["-u"]

    mkot_options = ''

    if '-u' in args:
        print(__usage__)
        return
    if '-h' in args:
        print(__help__)
        return
    if '--mkot' in args:
        index = args.index('--mkot')
        args.pop(index)
        mkot_options = parse_makeotf_options(args.pop(index))

    (dsPath,) = args
    glyphSetsDiffer, master_paths = testGlyphSetsCompatible(dsPath)

    if glyphSetsDiffer:
        allowDecimalCoords = False
        logFile = tempfile.NamedTemporaryFile(delete=True).name
        tempDSPath, master_paths = buildTempDesignSpace(dsPath)
        print("Generating temp UFO master(s)...")
        ds_doc_reader = DesignSpaceDocumentReader(
            tempDSPath, ufoVersion=2, roundGeometry=(not allowDecimalCoords),
            verbose=False, logPath=logFile)
        ds_doc_reader.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    print("Building local otf's for master font paths...")
    curDir = os.getcwd()
    dsDir = os.path.dirname(dsPath)
    for master_path in master_paths:
        master_path = os.path.join(dsDir, master_path)
        masterDir = os.path.dirname(master_path)
        ufoName = os.path.basename(master_path)
        if ufoName.endswith(kTempUFOExt):
            otfName = ufoName[:-len(kTempUFOExt)]
            # copy the features.fea file from the original UFO master
            fea_file_path_from = os.path.join(
                master_path[:-len(kTempUFOExt)] + '.ufo', kFeaturesFile)
            fea_file_path_to = os.path.join(master_path, kFeaturesFile)
            if os.path.exists(fea_file_path_from):
                shutil.copyfile(fea_file_path_from, fea_file_path_to)
        else:
            otfName = os.path.splitext(ufoName)[0]
        otfName = otfName + ".otf"
        os.chdir(masterDir)
        cmd = "makeotf -nshw -f \"%s\" -o \"%s\" -r -nS %s 2>&1" % (
            ufoName, otfName, mkot_options)
        log = runShellCmd(cmd)
        if ("FATAL" in log) or ("Failed to build" in log):
            print(log)

        if "Built" not in str(log):
            print("Error building OTF font for", master_path, log)
            print("makeotf cmd was '%s' in %s." % (cmd, masterDir))
        else:
            print("Built OTF font for", master_path)
            compatibilizePaths(otfName)
            if ufoName.endswith(kTempUFOExt):
                shutil.rmtree(ufoName)
        os.chdir(curDir)

    if glyphSetsDiffer and os.path.exists(tempDSPath):
        os.remove(tempDSPath)
Beispiel #9
0
from designSpaceDocument import DesignSpaceDocument, SourceDescriptor, InstanceDescriptor, AxisDescriptor
from mutatorMath.ufo.document import DesignSpaceDocumentWriter, DesignSpaceDocumentReader

path = u"/Users/SO/Desktop/Typemade/TypeDesign/FB/Amstelvar/Amstelvar-SO/sources/Amstelvar-Roman-so.designspace"
doc = DesignSpaceDocumentReader(path, ufoVersion=3)
doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)
print 'done'