Пример #1
0
def interpolate(rfonts, master_dir, out_dir, designspace_path,
                    instance_data, italic=False, debug=False):
    """Create MutatorMath designspace and generate instances.
    Returns instance UFOs, or unused instance data if debug is True.
    """

    print('>>> Writing masters')
    for font in rfonts:
        font.save(os.path.join(
            master_dir, font.info.postscriptFullName + '.ufo'))

    writer = DesignSpaceDocumentWriter(designspace_path)
    base_family = add_masters_to_writer(writer, rfonts)
    instance_files = add_instances_to_writer(
        writer, base_family, instance_data, italic, out_dir)
    writer.save()

    print('>>> Building instances')
    build(designspace_path)

    instance_ufos = []
    for path, data in instance_files:
        ufo = OpenFont(path)
        for attr in data:
            if attr.pop('name') == 'panose':
                ufo.info.openTypeOS2Panose = map(int, attr.pop('value'))
        set_redundant_data(ufo)
        instance_ufos.append(ufo)

    if debug:
        return clear_data(instance_data)
    return instance_ufos
Пример #2
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
Пример #3
0
def interpolate(rfonts, master_dir, out_dir, designspace_path,
                instance_data, italic=False, debug=False):
    """Create MutatorMath designspace and generate instances.
    Returns instance UFOs, or unused instance data if debug is True.
    """

    print('>>> Writing masters')
    for font in rfonts:
        font.save(os.path.join(
            master_dir, build_postscript_name(
                font.info.familyName, font.info.styleName) + '.ufo'))

    writer = DesignSpaceDocumentWriter(designspace_path)
    base_family = add_masters_to_writer(writer, rfonts)
    instance_files = add_instances_to_writer(
        writer, base_family, instance_data, italic, out_dir)
    writer.save()

    print('>>> Building instances')
    build(designspace_path)

    instance_ufos = []
    for path, data in instance_files:
        ufo = OpenFont(path)
        set_custom_params(ufo, data=data)
        set_redundant_data(ufo)
        ufo.save()
        instance_ufos.append(ufo)

    if debug:
        return clear_data(instance_data)
    return instance_ufos
Пример #4
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
Пример #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
Пример #6
0
    def __init__(self, project):
        self.project = project

        # remove existing .designspace file
        if os.path.exists(self.project.designspace_path):
            os.remove(self.project.designspace_path)

        # create fresh .designspace file
        self.doc_writer = DesignSpaceDocumentWriter(self.project.designspace_path, verbose=True)
Пример #7
0
    def __init__(self, project):
        self.project = project

        # remove existing .designspace file
        if os.path.exists(self.project.designspace_path):
            os.remove(self.project.designspace_path)

        # create fresh .designspace file
        self.doc_writer = DesignSpaceDocumentWriter(self.project.designspace_path, verbose=True)
Пример #8
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
Пример #9
0
class DesignSpaceMaker(object):

    axes      = []
    masters   = []
    instances = []
    neutral   = None

    def __init__(self, project):
        self.project = project

        # remove existing .designspace file
        if os.path.exists(self.project.designspace_path):
            os.remove(self.project.designspace_path)

        # create fresh .designspace file
        self.doc_writer = DesignSpaceDocumentWriter(self.project.designspace_path, verbose=True)

    def add_masters(self, verbose=False):

        if verbose: print('\tadding masters...')

        for master in self.masters:
            ufo_path = os.path.join(self.project.ufos_folder, '%s.ufo' % master)

            # check if master exists
            if os.path.exists(ufo_path):

                # make Location
                L = {}
                for i in range(len(self.axes)):
                    axis  = self.axes[i]
                    param = self.masters[master][i]
                    L[axis] = param

                # add neutral
                if master == self.neutral:
                    if verbose: print('\t\tadding %s [neutral]...' % master)
                    self.doc_writer.addSource(
                        ufo_path, master, location=L,
                        copyInfo=True, copyGroups=True,
                        copyLib=False, copyFeatures=False)

                # add deltas
                else:
                    if verbose: print('\t\tadding %s...' % master)
                    self.doc_writer.addSource(ufo_path, master, location=L)

    def add_instances(self, verbose=False):

        if verbose: print('\tadding instances...')

        for instance in self.instances:
            ufo_filename = '%s.ufo' % instance.replace(' ', '-')
            ufo_path = os.path.join(self.project.instances_folder, ufo_filename)

            # make Location
            L = {}
            for i in range(len(self.axes)):
                axis  = self.axes[i]
                param = self.instances[instance][i]
                L[axis] = param

            # add instance
            if verbose: print('\t\tadding %s...' % instance)
            self.doc_writer.startInstance(
                    fileName=ufo_path,
                    familyName='Untitled',
                    styleName=instance,
                    location=L)
            self.doc_writer.endInstance()

    def save(self, verbose=False):
        if verbose: print('creating .designspace file...')
        # add masters
        self.add_masters(verbose)
        # add instances
        self.add_instances(verbose)
        if verbose: print('\tsaving file %s...' % self.project.designspace_path, end=' ')
        # save designspace file
        self.doc_writer.save()
        if verbose: print(os.path.exists(self.project.designspace_path))
        if verbose: print('...done.\n')
Пример #10
0
src = {
    "sources/Amstelvar-NewSpaceNames/Italic",
}

src_dir = "sources/1-drawings"
master_dir = "master_ufo"
instance_dir = "instances"

# Copy sources to temporary 1-drawings
for source in src:
    copy_tree(source, src_dir)

# use a temporary designspace to build instances with mutator math
familyName = "Amstelvar"
tmpDesignSpace = "tmp.designspace"
doc = DesignSpaceDocumentWriter(tmpDesignSpace)
# sources
doc.addSource(path="sources/1-drawings/Amstelvar-Italic.ufo",
              name="Amstelvar-Italic.ufo",
              location=dict(wght=0, wdth=0, opsz=0),
              styleName="Italic",
              familyName=familyName,
              copyLib=False,
              copyGroups=False,
              copyInfo=False,
              copyFeatures=False,
              muteKerning=False,
              muteInfo=False,
              mutedGlyphNames=None)

# axes
Пример #11
0
    shutil.rmtree("instances", ignore_errors=True)
if os.path.exists("master_ttf"):
    shutil.rmtree("master_ttf", ignore_errors=True)
if os.path.exists("master_ufo"):
    shutil.rmtree("master_ufo", ignore_errors=True)
if os.path.exists("master_ttf_interpolatable"):
    shutil.rmtree("master_ttf_interpolatable", ignore_errors=True)

src_dir = "1-drawings"
master_dir = "master_ufo"
instance_dir = "instances"

# use a temporary designspace to build instances with mutator math
familyName = "RobotoDelta"
tmpDesignSpace = "tmp.designspace"
doc = DesignSpaceDocumentWriter(tmpDesignSpace)
# sources
doc.addSource(path="1-drawings/RobotoDelta-Regular.ufo",
              name="RobotoDelta-Regular.ufo",
              location=dict(XYOPQ=0, XTRA=0, YTLC=0, YTUC=0, YTAS=0, YTDE=0),
              styleName="Regular",
              familyName=familyName,
              copyLib=False,
              copyGroups=False,
              copyInfo=False,
              copyFeatures=False,
              muteKerning=False,
              muteInfo=False,
              mutedGlyphNames=None)
doc.addSource(path="1-drawings/RobotoDelta-XOPQmin-YOPQmin.ufo",
              name="RobotoDelta-XOPQmin-YOPQmin.ufo",
Пример #12
0
def generate_designspace(family, path):

    def normalize_path(path):
        return os.path.join(family['working_directory'], path)

    doc = DesignSpaceDocumentWriter(normalize_path(path))

    for i, master in enumerate(family['masters']):

        doc.addSource(

            path = normalize_path(master['path']),
            name = 'master-' + master['name'],
            location = {'weight': master['interpolation_value']},

            copyLib    = True if i == 0 else False,
            copyGroups = True if i == 0 else False,
            copyInfo   = True if i == 0 else False,

            # muteInfo = False,
            # muteKerning = False,
            # mutedGlyphNames = None,

        )

    for style in family['styles']:

        doc.startInstance(
            name = 'instance-' + style['name'],
            location = {'weight': style['interpolation_value']},
            familyName = family['output_name'],
            styleName = style['name'],
            fileName = normalize_path(style['path']),
            postScriptFontName = style['output_full_name_postscript'],
            # styleMapFamilyName = None,
            # styleMapStyleName = None,
        )

        doc.writeInfo()

        if family['has_kerning']:
            doc.writeKerning()

        doc.endInstance()

    doc.save()
Пример #13
0
def testGeometry(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3, path4, path5 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'geometryTest.designspace')
    logPath = os.path.join(rootPath,"geometryTest.log")
    try:
        testLogFile = open(logPath, 'w')
        testLogFile.close()
    except:
        print "Can't make a logfile."

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
            path1,
            name="master_1", 
            location=dict(width=0), 
            copyLib=True,
            copyGroups=True,
            copyInfo=True, 
            copyFeatures=True,
            )
    doc.addSource(
            path2,
            name="master_2", 
            location=dict(width=1000), 
            copyLib=False,
            copyGroups=False,
            copyInfo=False, 
            copyFeatures=False,
            )
    doc.startInstance(fileName=path3,
            familyName="TestInstance",
            styleName="Regular",
            location=dict(width=500)
            )
    doc.endInstance()
    doc.startInstance(fileName=path4,
            familyName="TestInstance",
            styleName="Anisotropic1",
            location=dict(width=(0, 1000))
            )
    doc.endInstance()
    doc.startInstance(fileName=path5,
            familyName="TestInstance",
            styleName="Anisotropic2",
            location=dict(width=(1000, 0))
            )
    doc.endInstance()
    doc.save()

    # execute the designspace.
    doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=False, makeInfo=True)

    r1 = Font(path3)
    assert r1['glyphOne'].bounds == (0, 0, 300, 300)

    r2 = Font(path4)
    assert r2['glyphOne'].bounds == (0, 0, 100, 500)

    r3 = Font(path5)
    assert r3['glyphOne'].bounds == (0, 0, 500, 100)

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True
Пример #14
0
def testGeometry(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3, path4, path5 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'geometryTest.designspace')

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
            path1,
            name="master_1", 
            location=dict(width=0), 
            copyLib=True,
            copyGroups=True,
            copyInfo=True, 
            copyFeatures=True,
            )
    doc.addSource(
            path2,
            name="master_2", 
            location=dict(width=1000), 
            copyLib=False,
            copyGroups=False,
            copyInfo=False, 
            copyFeatures=False,
            )
    doc.startInstance(fileName=path3,
            familyName="TestInstance",
            styleName="Regular",
            location=dict(width=500)
            )
    doc.endInstance()
    doc.startInstance(fileName=path4,
            familyName="TestInstance",
            styleName="Anisotropic1",
            location=dict(width=(0, 1000))
            )
    doc.endInstance()
    doc.startInstance(fileName=path5,
            familyName="TestInstance",
            styleName="Anisotropic2",
            location=dict(width=(1000, 0))
            )
    doc.endInstance()
    doc.save()

    # execute the designspace.
    doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=False, makeInfo=True)

    r1 = Font(path3)
    assert r1['glyphOne'].bounds == (0, 0, 300, 300)

    r2 = Font(path4)
    assert r2['glyphOne'].bounds == (0, 0, 100, 500)

    r3 = Font(path5)
    assert r3['glyphOne'].bounds == (0, 0, 500, 100)

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True
Пример #15
0
def testOuroborosKerning(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'kerningTest.designspace')

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
        path1,
        name="master_1",
        location=dict(width=0),
        copyLib=True,
        copyGroups=True,
        copyInfo=True,
        copyFeatures=True,
    )
    doc.addSource(
        path2,
        name="master_2",
        location=dict(width=1000),
        copyLib=False,
        copyGroups=False,
        copyInfo=False,
        copyFeatures=False,
    )
    doc.startInstance(fileName=path3,
                      familyName="TestInstance",
                      styleName="Regular",
                      location=dict(width=100))
    doc.writeKerning(location=dict(width=500))
    doc.endInstance()
    doc.save()

    # execute the designspace. Kerning errors should be tripped by the
    doc = DesignSpaceDocumentReader(documentPath,
                                    2,
                                    roundGeometry=True,
                                    verbose=True,
                                    progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True

    def test1():
        """
Пример #16
0
src = {
    "sources",
}

src_dir = "sources/1-drawings"
master_dir = "master_ufo"
instance_dir = "instances"

# Copy sources to temporary 1-drawings
for source in src:
    copy_tree(source, src_dir)

# use a temporary designspace to build instances with mutator math
familyName = "Lexend"
tmpDesignSpace = "tmp.designspace"
doc = DesignSpaceDocumentWriter(tmpDesignSpace)
# sources
doc.addSource(path="sources/1-drawings/Lexend-Regular.ufo",
              name="Lexend-Regular.ufo",
              location=dict(wdth=100),
              styleName="Regular",
              familyName=familyName,
              copyLib=True,
              copyGroups=True,
              copyInfo=True,
              copyFeatures=True,
              muteKerning=False,
              muteInfo=False,
              mutedGlyphNames=None)

# axes
Пример #17
0
class DesignSpaceMaker(object):

    axes      = []
    masters   = []
    instances = []
    neutral   = None

    def __init__(self, project):
        self.project = project

        # remove existing .designspace file
        if os.path.exists(self.project.designspace_path):
            os.remove(self.project.designspace_path)

        # create fresh .designspace file
        self.doc_writer = DesignSpaceDocumentWriter(self.project.designspace_path, verbose=True)

    def add_masters(self, verbose=False):

        if verbose: print '\tadding masters...'

        for master in self.masters:
            ufo_path = os.path.join(self.project.ufos_folder, '%s.ufo' % master)

            # check if master exists
            if os.path.exists(ufo_path):

                # make Location
                L = {}
                for i in range(len(self.axes)):
                    axis  = self.axes[i]
                    param = self.masters[master][i]
                    L[axis] = param

                # add neutral
                if master == self.neutral:
                    if verbose: print '\t\tadding %s [neutral]...' % master
                    self.doc_writer.addSource(
                        ufo_path, master, location=L,
                        copyInfo=True, copyGroups=True,
                        copyLib=False, copyFeatures=False)

                # add deltas
                else:
                    if verbose: print '\t\tadding %s...' % master
                    self.doc_writer.addSource(ufo_path, master, location=L)

    def add_instances(self, verbose=False):

        if verbose: print '\tadding instances...'

        for instance in self.instances:
            ufo_filename = '%s.ufo' % instance.replace(' ', '-')
            ufo_path = os.path.join(self.project.instances_folder, ufo_filename)

            # make Location
            L = {}
            for i in range(len(self.axes)):
                axis  = self.axes[i]
                param = self.instances[instance][i]
                L[axis] = param

            # add instance
            if verbose: print '\t\tadding %s...' % instance
            self.doc_writer.startInstance(
                    fileName=ufo_path,
                    familyName='Untitled',
                    styleName=instance,
                    location=L)
            self.doc_writer.endInstance()

    def save(self, verbose=False):
        if verbose: print 'creating .designspace file...'
        # add masters
        self.add_masters(verbose)
        # add instances
        self.add_instances(verbose)
        if verbose: print '\tsaving file %s...' % self.project.designspace_path,
        # save designspace file
        self.doc_writer.save()
        if verbose: print os.path.exists(self.project.designspace_path)
        if verbose: print '...done.\n'
Пример #18
0
def testMutingOptions(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    # path1 and path2 are masters. path3 is the instance
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'mutingTest.designspace')

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(path1,
                  name="master_1",
                  location=dict(width=0),
                  copyLib=True,
                  copyGroups=True,
                  copyInfo=True,
                  copyFeatures=True,
                  muteKerning=True)
    doc.addSource(
        path2,
        name="master_2",
        location=dict(width=1000),
        copyLib=False,
        copyGroups=False,
        copyInfo=False,
        copyFeatures=False,
        muteInfo=True,
        mutedGlyphNames=['glyphThree']  # mute glyphThree in master 1
    )
    doc.startInstance(fileName=path3,
                      familyName="TestInstance",
                      styleName="Regular",
                      location=dict(width=500))
    doc.writeGlyph('glyphFour', mute=True)  # mute glyphFour in the instance
    doc.writeKerning()
    doc.writeInfo()
    doc.endInstance()
    doc.save()

    # execute the designspace.
    doc = DesignSpaceDocumentReader(documentPath,
                                    2,
                                    roundGeometry=True,
                                    verbose=True,
                                    progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    # look at the results
    m1 = Font(path1)
    m2 = Font(path2)
    r = Font(path3)
    #
    # the glyphThree master was muted in the second master
    # so the instance glyphThree should be the same as the first master:
    assert r['glyphThree'].bounds == m1['glyphThree'].bounds
    # we muted glyphFour in the instance.
    # so it should not be part of the instance UFO:
    assert "glyphFour" not in r
    # font.info is muted for master2, so the instance has to have the values from master 1
    assert r.info.unitsPerEm == m1.info.unitsPerEm
    # kerning is muted for master1, so the instance has to have the kerning from master 2
    assert r.kerning[('glyphOne', 'glyphOne')] == m2.kerning[('glyphOne',
                                                              'glyphOne')]

    if cleanUp:
        # remove the mess
        try:
            shutil.rmtree(path1)
            shutil.rmtree(path2)
            shutil.rmtree(path3)
        except:
            pass

    return True
Пример #19
0
def testOuroborosKerning(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'kerningTest.designspace')

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
            path1,
            name="master_1", 
            location=dict(width=0), 
            copyLib=True,
            copyGroups=True,
            copyInfo=True, 
            copyFeatures=True,
            )
    doc.addSource(
            path2,
            name="master_2", 
            location=dict(width=1000), 
            copyLib=False,
            copyGroups=False,
            copyInfo=False, 
            copyFeatures=False,
            )
    doc.startInstance(fileName=path3,
            familyName="TestInstance",
            styleName="Regular",
            location=dict(width=100)
            )
    doc.writeKerning(location=dict(width=500))
    doc.endInstance()
    doc.save()

    # execute the designspace. Kerning errors should be tripped by the 
    doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True


    def test1():
        """
Пример #20
0
def testOuroborosKerning(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'kerningTest.designspace')
    logPath = os.path.join(rootPath,"kerningTest.log")
    try:
        testLogFile = open(logPath, 'w')
        testLogFile.close()
    except:
        print "Can't make a logfile."

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
            path1,
            name="master_1", 
            location=dict(width=0), 
            copyLib=True,
            copyGroups=True,
            copyInfo=True, 
            copyFeatures=True,
            )
    doc.addSource(
            path2,
            name="master_2", 
            location=dict(width=1000), 
            copyLib=False,
            copyGroups=False,
            copyInfo=False, 
            copyFeatures=False,
            )
    doc.startInstance(fileName=path3,
            familyName="TestInstance",
            styleName="Regular",
            location=dict(width=100)
            )
    doc.writeKerning(location=dict(width=500))
    doc.endInstance()
    doc.save()

    # execute the designspace. Kerning errors should be tripped by the 
    doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    # did we log the error?
    report = u"""invalidInstance.ufo:\nThese kerning pairs failed validation and have been removed:\nglyphOne, public.kern2.@MMK_R_two (-400) conflicts with public.kern1.@MMK_L_one, glyphThree (-250)\npublic.kern1.@MMK_L_one, glyphThree (-250) conflicts with glyphOne, public.kern2.@MMK_R_two (-400)"""
    log = open(logPath, 'r')
    logText = log.read()
    log.close()
    #print logText
    #assert report in logText

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True
Пример #21
0
def makeInstances(stepsWeight, stepsWidth):
    doc = DesignSpaceDocumentWriter(designSpacePath, verbose=True)

    doc.addSource(os.path.join(mutatorSansFolder,
                               "MutatorSansLightCondensed.ufo"),
                  name="LightCondensed",
                  location=dict(weight=0, width=0),
                  copyInfo=True,
                  familyName="MutatorSans",
                  styleName="LightCondensed")

    doc.addSource(os.path.join(mutatorSansFolder, "MutatorSansLightWide.ufo"),
                  name="LightWide",
                  location=dict(weight=0, width=1))

    doc.addSource(os.path.join(mutatorSansFolder,
                               "MutatorSansBoldCondensed.ufo"),
                  name="BoldCondensed",
                  location=dict(weight=1, width=0))

    doc.addSource(os.path.join(mutatorSansFolder, "MutatorSansBoldWide.ufo"),
                  name="BoldWide",
                  location=dict(weight=1, width=1))

    for i in range(stepsWeight):
        wt = i * 1.0 / (stepsWeight - 1)
        for j in range(stepsWidth):
            wd = j * 1.0 / (stepsWidth - 1)
            doc.startInstance(fileName=os.path.join(
                ufosFolder, "MutatorSansInstance_%s-%s.ufo" %
                (int(wt * 1000), int(wd * 1000))),
                              familyName="MutatorSansExample",
                              styleName="%s-%s" %
                              (int(wt * 1000), int(wd * 1000)),
                              location=dict(weight=wt, width=wd))
            doc.endInstance()

    doc.save()

    doc = DesignSpaceDocumentReader(designSpacePath,
                                    3,
                                    roundGeometry=True,
                                    verbose=False)
    doc.process(makeGlyphs=True, makeKerning=False, makeInfo=False)
Пример #22
0
def testMutingOptions(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    # path1 and path2 are masters. path3 is the instance
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'mutingTest.designspace')
    logPath = os.path.join(rootPath,"mutingTest.log")

    try:
        testLogFile = open(logPath, 'w')
        testLogFile.close()
    except:
        print "Can't make a logfile."

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
            path1,
            name="master_1", 
            location=dict(width=0), 
            copyLib=True,
            copyGroups=True,
            copyInfo=True, 
            copyFeatures=True,
            muteKerning=True
            )
    doc.addSource(
            path2,
            name="master_2", 
            location=dict(width=1000), 
            copyLib=False,
            copyGroups=False,
            copyInfo=False, 
            copyFeatures=False,
            muteInfo=True,
            mutedGlyphNames=['glyphThree']  # mute glyphThree in master 1
            )
    doc.startInstance(fileName=path3,
            familyName="TestInstance",
            styleName="Regular",
            location=dict(width=500)
            )
    doc.writeGlyph('glyphFour', mute=True)  # mute glyphFour in the instance
    doc.writeKerning()
    doc.writeInfo()
    doc.endInstance()
    doc.save()

    # execute the designspace. 
    doc = DesignSpaceDocumentReader(documentPath, 2, roundGeometry=True, verbose=True, logPath=logPath, progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    # look at the results
    m1 = Font(path1)
    m2 = Font(path2)
    r = Font(path3)
    # 
    # the glyphThree master was muted in the second master
    # so the instance glyphThree should be the same as the first master:
    assert r['glyphThree'].bounds == m1['glyphThree'].bounds
    # we muted glyphFour in the instance.
    # so it should not be part of the instance UFO:
    assert "glyphFour" not in r
    # font.info is muted for master2, so the instance has to have the values from master 1
    assert r.info.unitsPerEm == m1.info.unitsPerEm
    # kerning is muted for master1, so the instance has to have the kerning from master 2
    assert r.kerning[('glyphOne', 'glyphOne')] == m2.kerning[('glyphOne', 'glyphOne')]

    if cleanUp:
        # remove the mess
        try:
            shutil.rmtree(path1)
            shutil.rmtree(path2)
            shutil.rmtree(path3)
        except:
            pass

    return True
Пример #23
0
def testOuroborosKerning(rootPath, cleanUp=True):
    # that works, let's do it via MutatorMath
    path1, path2, path3 = makeTestFonts(rootPath)
    documentPath = os.path.join(rootPath, 'kerningTest.designspace')
    logPath = os.path.join(rootPath, "kerningTest.log")
    try:
        testLogFile = open(logPath, 'w')
        testLogFile.close()
    except:
        print "Can't make a logfile."

    doc = DesignSpaceDocumentWriter(documentPath, verbose=True)
    doc.addSource(
        path1,
        name="master_1",
        location=dict(width=0),
        copyLib=True,
        copyGroups=True,
        copyInfo=True,
        copyFeatures=True,
    )
    doc.addSource(
        path2,
        name="master_2",
        location=dict(width=1000),
        copyLib=False,
        copyGroups=False,
        copyInfo=False,
        copyFeatures=False,
    )
    doc.startInstance(fileName=path3,
                      familyName="TestInstance",
                      styleName="Regular",
                      location=dict(width=100))
    doc.writeKerning(location=dict(width=500))
    doc.endInstance()
    doc.save()

    # execute the designspace. Kerning errors should be tripped by the
    doc = DesignSpaceDocumentReader(documentPath,
                                    2,
                                    roundGeometry=True,
                                    verbose=True,
                                    logPath=logPath,
                                    progressFunc=testingProgressFunc)
    doc.process(makeGlyphs=True, makeKerning=True, makeInfo=True)

    # did we log the error?
    report = u"""invalidInstance.ufo:\nThese kerning pairs failed validation and have been removed:\nglyphOne, public.kern2.@MMK_R_two (-400) conflicts with public.kern1.@MMK_L_one, glyphThree (-250)\npublic.kern1.@MMK_L_one, glyphThree (-250) conflicts with glyphOne, public.kern2.@MMK_R_two (-400)"""
    log = open(logPath, 'r')
    logText = log.read()
    log.close()
    #print logText
    #assert report in logText

    if cleanUp:
        # remove the mess
        shutil.rmtree(path1)
        shutil.rmtree(path2)
        shutil.rmtree(path3)

    return True