示例#1
0
    def gen_stat(self, varfonts):
        if "axisOrder" not in self.config:
            self.config["axisOrder"] = [
                ax.axisTag for ax in varfonts[0]["fvar"].axes
            ]
        if len(varfonts) > 1 and "ital" not in self.config["axisOrder"]:
            # *Are* any italic? Presumably, but test
            if any(font_is_italic(f) for f in varfonts):
                self.config["axisOrder"].append("ital")

        locations = self.config.get("statFormat4", None)
        if locations and 'stat' not in self.config:
            raise ValueError(
                "Cannot add statFormat 4 axisValues since no stat table has been declared."
            )
        if "stylespaceFile" in self.config and self.config["stylespaceFile"]:
            self.gen_stat_stylespace(self.config["stylespaceFile"], varfonts)
        elif "stat" in self.config:
            gen_stat_tables_from_config(self.config["stat"],
                                        varfonts,
                                        locations=locations)
        else:
            gen_stat_tables(varfonts, self.config["axisOrder"])

        for ttFont in varfonts:
            ttFont.save(ttFont.reader.file.name)
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("fonts",
                        nargs="+",
                        help="Variable TTF files which make up a family")
    parser.add_argument("--src",
                        help="use yaml file to build STAT",
                        default=None)
    parser.add_argument(
        "--axis-order",
        nargs="+",
        required=False,
        choices=axis_registry.keys(),
        help="List of space seperated axis tags used to set the STAT table "
        "axis order e.g --axis-order wdth wght ital",
    )
    parser.add_argument(
        "--elided-values",
        nargs="+",
        default=None,
        help="List of space seperated axis_values to elide. "
        "Input must be structed as axis_tag=int,int..."
        "e.g --elided-values wdth=100 wght=400",
    )
    parser.add_argument("--out", "-o", help="Output dir for fonts")
    parser.add_argument("--inplace",
                        action="store_true",
                        default=False,
                        help="Overwrite input files")
    args = parser.parse_args()

    fonts = [TTFont(f) for f in args.fonts]

    if args.src:
        config = yaml.load(open(args.src), Loader=yaml.SafeLoader)
        gen_stat_tables_from_config(config, fonts)
    else:
        if not args.axis_order:
            raise ValueError("axis-order arg is missing")
        elided_values = (parse_elided_values(args.elided_values)
                         if args.elided_values else None)
        gen_stat_tables(fonts, args.axis_order, elided_values)

    if args.out:
        if not os.path.isdir(args.out):
            os.mkdir(args.out)

    for font in fonts:
        if args.out:
            dst = os.path.join(args.out,
                               os.path.basename(font.reader.file.name))
        elif args.inplace:
            dst = font.reader.file.name
        else:
            dst = font.reader.file.name + ".fix"
        if os.path.isfile(dst):
            os.remove(dst)
        print(f"Saving font to {dst}")
        font.save(dst)
示例#3
0
    def gen_stat(self, varfonts):
        if len(varfonts) > 1 and "ital" not in self.config["axisOrder"]:
            # *Are* any italic? Presumably, but test
            if any(font_is_italic(f) for f in varfonts):
                self.config["axisOrder"].append("ital")

        if "stylespaceFile" in self.config and self.config["stylespaceFile"]:
            self.gen_stat_stylespace(self.config["stylespaceFile"], varfonts)
        elif "stat" in self.config:
            gen_stat_tables_from_config(self.config["stat"], varfonts)
        else:
            gen_stat_tables(varfonts, self.config["axisOrder"])

        for ttFont in varfonts:
            ttFont.save(ttFont.reader.file.name)