Exemplo n.º 1
0
def build_masters(filename, master_dir, designspace_instance_dir=None,
                  family_name=None):
    """Write and return UFOs from the masters defined in a .glyphs file.

    Args:
        master_dir: Directory where masters are written.
        designspace_instance_dir: If provided, a designspace document will be
            written alongside the master UFOs though no instances will be built.
        family_name: If provided, the master UFOs will be given this name and
            only instances with this name will be included in the designspace.

    Returns:
        A list of master UFOs, and if designspace_instance_dir is provided, a
        path to a designspace and a list of (path, data) tuples with instance
        paths from the designspace and respective data from the Glyphs source.
    """

    ufos, instance_data = load_to_ufos(
        filename, include_instances=True, family_name=family_name)
    if designspace_instance_dir is not None:
        designspace_path, instance_data = build_designspace(
            ufos, master_dir, designspace_instance_dir, instance_data)
        return ufos, designspace_path, instance_data
    else:
        for ufo in ufos:
            write_ufo(ufo, master_dir)
        return ufos
Exemplo n.º 2
0
def build_masters(filename,
                  master_dir,
                  designspace_instance_dir=None,
                  family_name=None,
                  propagate_anchors=True):
    """Write and return UFOs from the masters defined in a .glyphs file.

    Args:
        master_dir: Directory where masters are written.
        designspace_instance_dir: If provided, a designspace document will be
            written alongside the master UFOs though no instances will be built.
        family_name: If provided, the master UFOs will be given this name and
            only instances with this name will be included in the designspace.

    Returns:
        A list of master UFOs, and if designspace_instance_dir is provided, a
        path to a designspace and a list of (path, data) tuples with instance
        paths from the designspace and respective data from the Glyphs source.
    """

    ufos, instance_data = load_to_ufos(filename,
                                       include_instances=True,
                                       family_name=family_name,
                                       propagate_anchors=propagate_anchors)
    if designspace_instance_dir is not None:
        designspace_path, instance_data = build_designspace(
            ufos, master_dir, designspace_instance_dir, instance_data)
        return ufos, designspace_path, instance_data
    else:
        for ufo in ufos:
            write_ufo(ufo, master_dir)
        return ufos
Exemplo n.º 3
0
def build_designspace(masters, master_dir, out_dir, instance_data):
    """Just create MutatorMath designspace without generating instances.

    Returns the path of the resulting designspace document and a list of
    (instance_path, instance_data) tuples which map instance UFO filenames to
    Glyphs data for that instance.
    """
    from mutatorMath.ufo.document import DesignSpaceDocumentWriter

    for font in masters:
        write_ufo(font, master_dir)

    # needed so that added masters and instances have correct relative paths
    tmp_path = os.path.join(master_dir, 'tmp.designspace')
    writer = DesignSpaceDocumentWriter(tmp_path)

    base_family, base_style = add_masters_to_writer(writer, masters)
    instance_files = add_instances_to_writer(
        writer, base_family, instance_data, out_dir)

    basename = '%s%s.designspace' % (
        base_family, ('-' + base_style) if base_style else '')
    writer.path = os.path.join(master_dir, basename.replace(' ', ''))
    writer.save()
    return writer.path, instance_files
def build_designspace(masters, master_dir, out_dir, instance_data):
    """Just create MutatorMath designspace without generating instances.

    Returns the path of the resulting designspace document and a list of
    (instance_path, instance_data) tuples which map instance UFO filenames to
    Glyphs data for that instance.
    """
    # TODO: (jany) check whether this function is still useful
    # No need to build a designspace, we should have it in "instance_data"
    designspace = instance_data['designspace']

    # Move masters and instances to the designated directories
    for font in masters:
        write_ufo(font, master_dir)
        for source in designspace.sources:
            if source.font is font:
                source.path = font.path
    for instance in designspace.instances:
        instance.path = os.path.join(out_dir,
                                     os.path.basename(instance.filename))

    designspace_path = os.path.join(master_dir, designspace.filename)
    designspace.write(designspace_path)

    return designspace_path, InstanceData(designspace)
Exemplo n.º 5
0
def build_designspace(masters, master_dir, out_dir, instance_data):
    """Just create MutatorMath designspace without generating instances.

    Returns the path of the resulting designspace document and a list of
    (instance_path, instance_data) tuples which map instance UFO filenames to
    Glyphs data for that instance.
    """
    from mutatorMath.ufo.document import DesignSpaceDocumentWriter

    for font in masters:
        write_ufo(font, master_dir)

    # needed so that added masters and instances have correct relative paths
    tmp_path = os.path.join(master_dir, 'tmp.designspace')
    writer = DesignSpaceDocumentWriter(tmp_path)

    base_family, base_style = add_masters_to_writer(writer, masters)
    instance_files = add_instances_to_writer(
        writer, base_family, instance_data, out_dir)

    basename = '%s%s.designspace' % (
        base_family, ('-' + base_style) if base_style else '')
    writer.path = os.path.join(master_dir, basename.replace(' ', ''))
    writer.save()
    return writer.path, instance_files
Exemplo n.º 6
0
def build_designspace(masters, master_dir, out_dir, instance_data):
    """Just create MutatorMath designspace without generating instances.

    Returns the path of the resulting designspace document and a list of
    (instance_path, instance_data) tuples which map instance UFO filenames to
    Glyphs data for that instance.
    """
    from mutatorMath.ufo.document import DesignSpaceDocumentWriter

    for font in masters:
        write_ufo(font, master_dir)

    # needed so that added masters and instances have correct relative paths
    tmp_path = os.path.join(master_dir, 'tmp.designspace')
    writer = DesignSpaceDocumentWriter(tmp_path)

    instances = list(filter(is_instance_active, instance_data.get('data', [])))
    regular = find_regular_master(
        masters=masters,
        regularName=instance_data.get('Variation Font Origin'))
    axes = get_axes(masters, regular, instances)
    write_axes(axes, writer)
    add_masters_to_writer(masters, regular, axes, writer)
    base_family = instance_data.get('defaultFamilyName',
                                    regular.info.familyName)
    instance_files = add_instances_to_writer(writer, base_family, axes,
                                             instances, out_dir)

    basename = '%s.designspace' % base_family
    writer.path = os.path.join(master_dir, basename.replace(' ', ''))
    writer.save()
    return writer.path, instance_files
Exemplo n.º 7
0
def build_designspace(masters, master_dir, out_dir, instance_data):
    """Just create MutatorMath designspace without generating instances.

    Returns the path of the resulting designspace document and a list of
    (instance_path, instance_data) tuples which map instance UFO filenames to
    Glyphs data for that instance.
    """
    from mutatorMath.ufo.document import DesignSpaceDocumentWriter

    base_family = masters[0].info.familyName
    assert all(m.info.familyName == base_family for m in masters), \
        'Masters must all have same family'

    for font in masters:
        write_ufo(font, master_dir)

    # needed so that added masters and instances have correct relative paths
    tmp_path = os.path.join(master_dir, 'tmp.designspace')
    writer = DesignSpaceDocumentWriter(tmp_path)

    instances = list(filter(is_instance_active, instance_data.get('data', [])))
    regular = find_regular_master(
        masters=masters,
        regularName=instance_data.get('Variation Font Origin'))
    axes = get_axes(masters, regular, instances)
    write_axes(axes, writer)
    add_masters_to_writer(masters, regular, axes, writer)
    instance_files = add_instances_to_writer(writer, base_family, axes,
                                             instances, out_dir)

    # append base style shared by all masters to designspace file name
    base_style = find_base_style(masters)
    if base_style:
        base_style = "-" + base_style
    ds_name = (base_family + base_style).replace(' ', '') + '.designspace'
    writer.path = os.path.join(master_dir, ds_name)
    writer.save()
    return writer.path, instance_files