Example #1
0
def doit(args):
    global logger
    logger = args.logger

    designspace_path = args.designspace_path
    instance_font_name = args.instanceName
    instance_attr = args.instanceAttr
    instance_val = args.instanceVal
    output_path_prefix = args.output
    calc_glyphs = args.forceInterpolation
    build_folder = args.folder
    round_instances = args.roundInstances

    if instance_font_name and (instance_attr or instance_val):
        args.logger.log('--instanceName is mutually exclusive with --instanceAttr or --instanceVal','S')
    if (instance_attr and not instance_val) or (instance_val and not instance_attr):
        args.logger.log('--instanceAttr and --instanceVal must be used together', 'S')
    if (build_folder and (instance_font_name or instance_attr or instance_val
                          or output_path_prefix or calc_glyphs)):
        args.logger.log('--folder cannot be used with options: -i, -a, -v, -o, --forceInterpolation', 'S')

    args.logger.log('Interpolating master UFOs from designspace', 'P')
    if not build_folder:
        if not os.path.isfile(designspace_path):
            args.logger.log('A designspace file (not a folder) is required', 'S')
        reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3,
                                           roundGeometry=round_instances,
                                           progressFunc=progress_func)
        # assignment to an internal object variable is a kludge, probably should use subclassing instead
        reader._instanceWriterClass = InstanceWriterCF(output_path_prefix, calc_glyphs, args.weightfix)
        if calc_glyphs:
            args.logger.log('Interpolating glyphs where an instance font location matches a master', 'P')
        if instance_font_name or instance_attr:
            key_attr = instance_attr if instance_val else 'name'
            key_val = instance_val if instance_attr else instance_font_name
            reader.readInstance((key_attr, key_val))
        else:
            reader.readInstances()
    else:
        # The below uses a utility function that's part of mutatorMath
        #  It will accept a folder and processes all designspace files there
        args.logger.log('Interpolating glyphs where an instance font location matches a master', 'P')
        build_designspace(designspace_path,
                          outputUFOFormatVersion=3, roundGeometry=round_instances,
                          progressFunc=progress_func)

    if not severe_error:
        args.logger.log('Done', 'P')
    else:
        args.logger.log('Done with severe error', 'S')
    def run_from_designspace(self,
                             designspace_path,
                             interpolate=False,
                             masters_as_instances=False,
                             instance_data=None,
                             interpolate_binary_layout=False,
                             **kwargs):
        """Run toolchain from a MutatorMath design space document.

        Args:
            designspace_path: Path to designspace document.
            interpolate: If True output instance fonts, otherwise just masters.
            masters_as_instances: If True, output master fonts as instances.
            instance_data: Data to be applied to instance UFOs, as returned from
                glyphsLib's parsing function (ignored unless interpolate is True).
            interpolate_binary_layout: Interpolate layout tables from compiled
                master binaries.
            kwargs: Arguments passed along to run_from_ufos.

        Raises:
            TypeError: "variable" output is incompatible with arguments
                "interpolate", "masters_as_instances", and
                "interpolate_binary_layout".
        """

        if "variable" in kwargs.get("output", ()):
            for argname in ("interpolate", "masters_as_instances",
                            "interpolate_binary_layout"):
                if locals()[argname]:
                    raise TypeError(
                        '"%s" argument incompatible with "variable" output' %
                        argname)

        from glyphsLib.interpolation import apply_instance_data
        from mutatorMath.ufo import build as build_designspace
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        ufos = []
        if not interpolate or masters_as_instances:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos.extend(reader.getSourcePaths())
        if interpolate:
            logger.info('Interpolating master UFOs from designspace')
            results = build_designspace(designspace_path,
                                        outputUFOFormatVersion=3)
            if instance_data is not None:
                ufos.extend(apply_instance_data(instance_data))
            else:
                for result in results:
                    ufos.extend(result.values())

        interpolate_layout_from = (designspace_path
                                   if interpolate_binary_layout else None)

        self.run_from_ufos(ufos,
                           designspace_path=designspace_path,
                           is_instance=(interpolate or masters_as_instances),
                           interpolate_layout_from=interpolate_layout_from,
                           **kwargs)
Example #3
0
    def run_from_designspace(
            self, designspace_path, interpolate=False, **kwargs):
        """Run toolchain from a MutatorMath design space document to OpenType
        binaries.
        """

        if interpolate:
            print('>> Interpolating master UFOs from design space')
            results = build_designspace(
                designspace_path, outputUFOFormatVersion=3)
            ufos = []
            for result in results:
                ufos.extend(result.values())
        else:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos = reader.getSourcePaths()
        self.run_from_ufos(ufos, is_instance=True, **kwargs)
Example #4
0
    def run_from_designspace(self,
                             designspace_path,
                             interpolate=False,
                             masters_as_instances=False,
                             instance_data=None,
                             interpolate_binary_layout=False,
                             **kwargs):
        """Run toolchain from a MutatorMath design space document.

        Args:
            designspace_path: Path to designspace document.
            interpolate: If True output instance fonts, otherwise just masters.
            masters_as_instances: If True, output master fonts as instances.
            instance_data: Data to be applied to instance UFOs, as returned from
                glyphsLib's parsing function.
            interpolate_binary_layout: Interpolate layout tables from compiled
                master binaries.
            kwargs: Arguments passed along to run_from_ufos.
        """

        from glyphsLib.interpolation import apply_instance_data
        from mutatorMath.ufo import build as build_designspace
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        ufos = []
        if not interpolate or masters_as_instances:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos.extend(reader.getSourcePaths())
        if interpolate:
            logger.info('Interpolating master UFOs from designspace')
            results = build_designspace(designspace_path,
                                        outputUFOFormatVersion=3)
            if instance_data is not None:
                ufos.extend(apply_instance_data(instance_data))
            else:
                for result in results:
                    ufos.extend(result.values())

        interpolate_layout_from = (designspace_path
                                   if interpolate_binary_layout else None)

        self.run_from_ufos(ufos,
                           designspace_path=designspace_path,
                           is_instance=(interpolate or masters_as_instances),
                           interpolate_layout_from=interpolate_layout_from,
                           **kwargs)
Example #5
0
    def run_from_designspace(
            self, designspace_path, interpolate=False, **kwargs):
        """Run toolchain from a MutatorMath design space document to OpenType
        binaries.
        """

        if interpolate:
            print('>> Interpolating master UFOs from design space')
            results = build_designspace(
                designspace_path, outputUFOFormatVersion=3)
            ufos = []
            for result in results:
                ufos.extend(result.values())
        else:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos = reader.getSourcePaths()
        self.run_from_ufos(ufos, is_instance=True, **kwargs)
Example #6
0
    def run_from_designspace(
            self, designspace_path, interpolate=False,
            masters_as_instances=False, instance_data=None,
            interpolate_binary_layout=False, **kwargs):
        """Run toolchain from a MutatorMath design space document.

        Args:
            designspace_path: Path to designspace document.
            interpolate: If True output instance fonts, otherwise just masters.
            masters_as_instances: If True, output master fonts as instances.
            instance_data: Data to be applied to instance UFOs, as returned from
                glyphsLib's parsing function.
            interpolate_binary_layout: Interpolate layout tables from compiled
                master binaries.
            kwargs: Arguments passed along to run_from_ufos.
        """

        from glyphsLib.interpolation import apply_instance_data
        from mutatorMath.ufo import build as build_designspace
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        ufos = []
        if not interpolate or masters_as_instances:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos.extend(reader.getSourcePaths())
        if interpolate:
            self.info('Interpolating master UFOs from designspace')
            results = build_designspace(
                designspace_path, outputUFOFormatVersion=3)
            if instance_data is not None:
                ufos.extend(apply_instance_data(instance_data))
            else:
                for result in results:
                    ufos.extend(result.values())

        interpolate_layout_from = (
            designspace_path if interpolate_binary_layout else None)

        self.run_from_ufos(
            ufos, designspace_path=designspace_path,
            is_instance=(interpolate or masters_as_instances),
            interpolate_layout_from=interpolate_layout_from, **kwargs)
Example #7
0
    def run_from_designspace(
            self, designspace_path, interpolate=False,
            masters_as_instances=False, **kwargs):
        """Run toolchain from a MutatorMath design space document to OpenType
        binaries.
        """
        from mutatorMath.ufo import build as build_designspace
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        ufos = []
        if not interpolate or masters_as_instances:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos.extend(reader.getSourcePaths())
        if interpolate:
            print('>> Interpolating master UFOs from design space')
            results = build_designspace(
                designspace_path, outputUFOFormatVersion=3)
            for result in results:
                ufos.extend(result.values())
        self.run_from_ufos(
            ufos, is_instance=(interpolate or masters_as_instances), **kwargs)
Example #8
0
    def run_from_designspace(self,
                             designspace_path,
                             interpolate=False,
                             masters_as_instances=False,
                             instance_data=None,
                             interpolate_binary_layout=False,
                             round_instances=False,
                             **kwargs):
        """Run toolchain from a MutatorMath design space document.

        Args:
            designspace_path: Path to designspace document.
            interpolate: If True output instance fonts, otherwise just masters.
            masters_as_instances: If True, output master fonts as instances.
            instance_data: Data to be applied to instance UFOs, as returned from
                glyphsLib's parsing function (ignored unless interpolate is True).
            interpolate_binary_layout: Interpolate layout tables from compiled
                master binaries.
            round_instances: apply integer rounding when interpolating with
                MutatorMath.
            kwargs: Arguments passed along to run_from_ufos.

        Raises:
            TypeError: "variable" output is incompatible with arguments
                "interpolate", "masters_as_instances", and
                "interpolate_binary_layout".
        """

        if "variable" in kwargs.get("output", ()):
            for argname in ("interpolate", "masters_as_instances",
                            "interpolate_binary_layout"):
                if locals()[argname]:
                    raise TypeError(
                        '"%s" argument incompatible with "variable" output' %
                        argname)

        from glyphsLib.interpolation import apply_instance_data
        from mutatorMath.ufo import build as build_designspace
        from mutatorMath.ufo.document import DesignSpaceDocumentReader

        ufos = []
        if not interpolate or masters_as_instances:
            reader = DesignSpaceDocumentReader(designspace_path, ufoVersion=3)
            ufos.extend(reader.getSourcePaths())
        if interpolate:
            logger.info('Interpolating master UFOs from designspace')
            _, ilocs = self._designspace_locations(designspace_path)
            for ipath in ilocs.keys():
                # mutatorMath does not remove the existing instance UFOs
                # so we do it ourselves, or else strange things happen...
                # https://github.com/googlei18n/fontmake/issues/372
                if ipath.endswith(".ufo") and os.path.isdir(ipath):
                    logger.debug("Removing %s" % ipath)
                    shutil.rmtree(ipath)
            results = build_designspace(designspace_path,
                                        outputUFOFormatVersion=3,
                                        roundGeometry=round_instances)
            if instance_data is not None:
                ufos.extend(apply_instance_data(instance_data))
            else:
                for result in results:
                    ufos.extend(result.values())

        interpolate_layout_from = (designspace_path
                                   if interpolate_binary_layout else None)

        self.run_from_ufos(ufos,
                           designspace_path=designspace_path,
                           is_instance=(interpolate or masters_as_instances),
                           interpolate_layout_from=interpolate_layout_from,
                           **kwargs)