Example #1
0
 def generate(self):
     WriteFeaturesKernFDK.kKernFeatureFileName = self.filename_with_extension
     WriteFeaturesKernFDK.KernDataClass(
         font=self.style.open(),
         folderPath=self.style.get_directory(),
     )
     if hasattr(self, "postprocess"):
         kern_path = self.get_path()
         if os.path.exists(kern_path):
             with open(kern_path) as f:
                 self.content = f.read()
             dist, kern = self.postprocess()
             kit.remove(kern_path)
             if dist:
                 with open(os.path.join(self.get_directory(), "dist.fea"),
                           "w") as f:
                     f.write(dist)
             if kern:
                 with open(kern_path, "w") as f:
                     f.write(kern)
Example #2
0
    def build(self):

        self.reset_directory("intermediates")

        if self.options["prepare_masters"]:

            # self.reset_directory("masters", temp=True)

            for master in self.family.masters:
                master.prepare()
                if hasattr(master, "postprocess"):
                    master.postprocess()
                    master.refresh_groups()

            for master in self.family.masters:
                master.save()

        if self.options["prepare_styles"]:

            # self.reset_directory("styles", temp=True)

            self.family.prepare_styles()

        if self.options["prepare_features"]:

            # self.reset_directory("features", temp=True)

            if self.family.styles[0].file_format == "UFO":
                reference_font = self.products[0].style.open()
                self.family.info.unitsPerEm = reference_font.info.unitsPerEm
            elif self.family.styles[0].file_format == "OTF":
                reference_font = fontTools.ttLib.TTFont(
                    self.products[0].style.get_path())
                self.family.info.unitsPerEm = reference_font["head"].unitsPerEm

            self.feature_classes = kit.FeatureClasses(self)
            self.feature_tables = kit.FeatureTables(self)
            self.feature_languagesystems = kit.FeatureLanguagesystems(self)
            self.feature_gsub = kit.FeatureGSUB(self)
            self.feature_gpos = kit.FeatureGPOS(self)

            self.feature_classes.prepare()
            self.feature_tables.prepare()
            self.feature_languagesystems.prepare()
            self.feature_gsub.prepare()
            self.feature_gpos.prepare()

            for product in (i for i in self.products
                            if i.file_format == "OTF"):

                self.feature_kern = kit.FeatureKern(self, style=product.style)
                self.feature_mark = kit.FeatureMark(self, style=product.style)
                self.feature_matches = kit.FeatureMatches(self,
                                                          style=product.style)
                self.feature_OS2_extension = kit.FeatureOS2Extension(
                    self, style=product.style)
                self.feature_name_extension = kit.FeatureNameExtension(
                    self, style=product.style)
                self.features_references = kit.FeatureReferences(
                    self, style=product.style)
                self.features_references._extension = ""

                if self.options["prepare_kerning"]:
                    self.feature_kern.prepare()
                if self.options["prepare_mark_positioning"]:
                    self.feature_mark.prepare()
                if self.options["match_mI_variants"]:
                    self.feature_matches.prepare()
                self.feature_OS2_extension.prepare()
                self.feature_name_extension.prepare()
                self.features_references.prepare()

        if self.options["compile"]:

            # self.reset_directory("products", temp=True)

            self.fmndb.prepare()

            for product in self.products:
                product.generate()

            products_built = [i for i in self.products if i.built]

        client_data = self.family.get_client_data()

        if client_data.name == "Google Fonts" and not self.args.test:

            with open(kit.relative_to_package("data/template-OFL.txt")) as f:
                template = f.read()
            with open(kit.relative_to_cwd("OFL.txt"), "w") as f:
                f.write(template.format(client_data.tables["name"][0]))

            file_format_to_paths = collections.defaultdict(list)
            for product in products_built:
                file_format_to_paths[product.file_format].append(
                    product.get_path(temp=False))
            for file_format, paths in list(file_format_to_paths.items()):
                archive_filename = "{}-{}-{}.zip".format(
                    self.family.name_postscript,
                    self.fontrevision.replace(".", ""),
                    file_format,
                )
                archive_path = os.path.join(self.directories["products"],
                                            archive_filename)
                kit.remove(archive_path)
                subprocess.call(["zip", "-j", archive_path] + paths)
                print("[ZIPPED]", archive_path)
                subprocess.call(["ttx", "-fq"] + paths)
                print("[TTX DUMPED]")
                for path in paths:
                    kit.remove(path)
                    print("[REMOVED]", path)
Example #3
0
 def reset_directory(self, name, temp=False):
     path = self.directories[name]
     if temp:
         path = self.temp(path)
     kit.remove(path)
     kit.makedirs(path)