示例#1
0
def build_masters(filename, master_dir, designspace_instance_dir=None):
    """Write and return UFOs from the masters defined in a .glyphs file.

    If `designspace_instance_dir` is provided, a designspace document will be
    written alongside the master UFOs, though no instances will be built.
    """

    ufos, instance_data = load_to_ufos(filename, include_instances=True)
    if designspace_instance_dir is not None:
        build_designspace(ufos, master_dir, designspace_instance_dir,
                          instance_data)
    else:
        for ufo in ufos:
            write_ufo(ufo, master_dir)
    return ufos
示例#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
示例#3
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
示例#4
0
 def build_designspace(self, masters, instances):
     master_dir = tempfile.mkdtemp()
     designspace, _ = build_designspace(masters, master_dir,
                                        os.path.join(master_dir, "out"),
                                        instances)
     with open(designspace, mode="r", encoding="utf-8") as f:
         result = f.readlines()
     shutil.rmtree(master_dir)
     return result
示例#5
0
    def test_designspace_name(self):
        master_dir = tempfile.mkdtemp()
        try:
            designspace_path, _ = build_designspace([
                makeMaster("Family Name", "Regular", weight=100),
                makeMaster("Family Name", "Bold", weight=190),
            ], master_dir, os.path.join(master_dir, "out"), {})
            # no shared base style name, only write the family name
            self.assertEqual(os.path.basename(designspace_path),
                             "FamilyName.designspace")

            designspace_path, _ = build_designspace([
                makeMaster("Family Name", "Italic", weight=100),
                makeMaster("Family Name", "Bold Italic", weight=190),
            ], master_dir, os.path.join(master_dir, "out"), {})
            # 'Italic' is the base style; append to designspace name
            self.assertEqual(os.path.basename(designspace_path),
                             "FamilyName-Italic.designspace")
        finally:
            shutil.rmtree(master_dir)
示例#6
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.
    """

    ufos, instance_data = load_to_ufos(
        filename, include_instances=True, family_name=family_name)
    if designspace_instance_dir is not None:
        build_designspace(ufos, master_dir, designspace_instance_dir,
                          instance_data)
    else:
        for ufo in ufos:
            write_ufo(ufo, master_dir)
    return ufos
示例#7
0
 def expect_designspace(self, masters, instances, expectedFile):
     master_dir = tempfile.mkdtemp()
     designspace, _ = build_designspace(
         masters, master_dir, os.path.join(master_dir, "out"), instances)
     with open(designspace, mode="r", encoding="utf-8") as f:
         actual = f.readlines()
     path, _ = os.path.split(__file__)
     expectedPath = os.path.join(path, "data", expectedFile)
     with open(expectedPath, mode="r", encoding="utf-8") as f:
         expected = f.readlines()
     if actual != expected:
         for line in difflib.unified_diff(
                 expected, actual,
                 fromfile=expectedPath, tofile=designspace):
             sys.stderr.write(line)
         self.fail("*.designspace file is different from expected")
     shutil.rmtree(master_dir)