Exemplo n.º 1
0
 def open(self, from_disk=False):
     if not from_disk and self.defconFont:
         return self.defconFont
     else:
         if os.path.exists(self.get_path()):
             if self.file_format in ["UFO", "VFB"]:
                 if self.file_format == "VFB":
                     kit.makedirs(self.get_directory())
                     input_path = self.get_path()
                     self._path = None
                     self._filename = os.path.basename(input_path)
                     self.file_format = "UFO"
                     subprocess.call([
                         "vfb2ufo",
                         "-fo",
                         input_path,
                         self.get_path(),
                     ])
                 self.defconFont = kit.patched.defcon.Font(self.get_path())
                 print("[OPENED]", self.get_path())
                 return self.defconFont
             else:
                 raise SystemExit("`{}` is not supported by defcon.".format(
                     self.get_path()))
         else:
             raise SystemExit("`{}` is missing.".format(self.get_path()))
Exemplo n.º 2
0
 def _copy(self, into_temp=True, whole_directory=False):
     if whole_directory:
         permanent = self.get_directory(temp=False)
         temp = self.get_directory()
     else:
         permanent = self.get_path(temp=False)
         temp = self.get_path()
     if into_temp:
         kit.makedirs(self.get_directory())
         kit.copy(permanent, temp)
         print("[COPIED INTO TEMP]", permanent, "=>", temp)
     else:
         kit.makedirs(self.get_directory(temp=False))
         kit.copy(temp, permanent)
         print("[COPIED OUT OF TEMP]", temp, "=>", permanent)
Exemplo n.º 3
0
 def prepare(self, whole_directory=False):
     for f in self.file_group:
         if os.path.exists(f.get_path(temp=False)):
             if os.path.exists(f.get_path()):
                 print("[TEMP FILE ALREADY EXISTS]", f.get_path())
                 continue
             else:
                 f.copy_into_temp(whole_directory=whole_directory)
         else:
             try:
                 kit.makedirs(f.get_directory())
                 f.generate()
                 print("[GENERATED]", f.get_path())
             except NotImplementedError:
                 pass
Exemplo n.º 4
0
 def reset_directory(self, name, temp=False):
     path = self.directories[name]
     if temp:
         path = self.temp(path)
     kit.remove(path)
     kit.makedirs(path)
Exemplo n.º 5
0
    def generate(self):

        self.goadb_trimmed = kit.Goadb(self.project, product=self)
        self.goadb_trimmed.prepare()

        if self.file_format == "OTF" and self.style.file_format == "UFO":

            defconFont = self.style.open()
            defconFont.info.postscriptFontName = self.full_name_postscript
            defconFont.lib["public.glyphOrder"] = self.goadb_trimmed.names
            for k in ["com.schriftgestaltung.glyphOrder", "com.schriftgestaltung.font.glyphOrder"]:
                defconFont.lib.pop(k, None)
            for i in """
                versionMajor
                versionMinor
                copyright
                familyName
                styleName
                styleMapFamilyName
                styleMapStyleName
                postscriptWeightName
                openTypeHeadCreated
                openTypeNamePreferredFamilyName
                openTypeNamePreferredSubfamilyName
                openTypeNameDesigner
                openTypeOS2WeightClass
                openTypeOS2WidthClass
            """.split():
                setattr(defconFont.info, i, None)
            defconFont.groups.clear()
            defconFont.kerning.clear()
            self.style.save()

            if self.project.options["run_checkoutlines"] or self.project.options["run_autohint"]:
                options = {
                    "doOverlapRemoval": self.project.options["run_checkoutlines"],
                    "doAutoHint": self.project.options["run_autohint"],
                    "allowDecimalCoords": False,
                }
                kit.patched.updateInstance(options, self.style.get_path())

        elif self.file_format == "TTF":

            # subprocess.call([
            #     "osascript", "-l", "JavaScript",
            #     kit.relative_to_package("data/generate_ttf.js"),
            #     os.path.abspath(self.style.get_path()),
            # ])

            self.style.file_format = "TTF" #TODO: Should restore the original file format afterwards. Or the styles should just seperate.

            while not os.path.exists(self.style.get_path()):
                print(
                    "\n[PROMPT] Input file {} is missing. Try again? [Y/n]: ".format(self.style.get_path()),
                    end = "",
                )
                if raw_input().upper().startswith("N"):
                    return

        kit.makedirs(self.get_directory())

        arguments = [
            "-f", self.style.get_path(),
            "-o", self.get_path(),
            "-mf", self.project.fmndb.get_path(),
            "-gf", self.goadb_trimmed.get_path(),
            "-ga",
            "-overrideMenuNames",
            "-shw",
        ]
        if self.project.options["use_mac_name_records"]:
            arguments.append("-useMacNames")
        else:
            arguments.append("-omitMacNames")
        if not self.project.args.test:
            arguments.append("-r")
        if self.project.options["do_style_linking"] and (self.is_bold or self.is_italic):
            if self.is_bold:
                arguments.append("-b")
            if self.is_italic:
                arguments.append("-i")
        else:
            arguments.extend(["-osbOn", "6"])
        if self.project.options["use_os_2_version_4"]:
            for digit, boolean in [
                ("7", self.project.options["prefer_typo_metrics"]),
                ("8", self.project.options["is_width_weight_slope_only"]),
                ("9", self.is_oblique),
            ]:
                arguments.append("-osbOn" if boolean else "-osbOff")
                arguments.append(digit)

        subprocess.call(["makeotf"] + arguments)

        if os.path.exists(self.get_path()):

            self.built = True
            print("[FONT SUCCESSFULLY BUILT]", self.get_path())

            font = fontTools.ttLib.TTFont(self.get_path(), recalcTimestamp=True)
            dirty = False
            for table_tag in [
                "STAT", # Introduced by Glyphs.
            ]:
                if table_tag in font:
                    del font[table_tag]
                    dirty = True
            if hasattr(self, "postprocess"):
                font = self.postprocess(font)
                dirty = True
            if dirty:
                font.save(self.get_path(), reorderTables=False)
                print("[FONT POSTPROCESSED]", self.get_path())

        if self.built:

            self.copy_out_of_temp()

            output_dir = self.project.directories["output"]
            if os.path.isdir(output_dir):
                kit.copy(
                    self.get_path(),
                    os.path.join(output_dir, self.filename_with_extension),
                )
                print("[COPIED TO OUPUT DIRECTORY]", self.get_path())
Exemplo n.º 6
0
    def generate(self):

        self.goadb_trimmed = kit.Goadb(self.project, product=self)
        self.goadb_trimmed.prepare()
        style_file_format_backup = None

        if self.file_format == "OTF" and self.style.file_format == "UFO":

            font = self.style.open()
            font.info.postscriptFontName = self.full_name_postscript
            font.lib["public.glyphOrder"] = self.goadb_trimmed.names
            for glyph in font:
                glyph.unicodes = []
            font.groups.clear()
            font.kerning.clear()
            self.style.save()

            # from afdko/makeinstancesufo.py:

            options = self.Options(
                doNormalize = self.project.options["do_normalize"],
                doOverlapRemoval = self.project.options["run_checkoutlines"],
                doAutoHint = self.project.options["run_autohint"],
                no_round = False,
            )
            instancePath = self.style.get_path()
            if options.doNormalize:
                logger.info("Applying UFO normalization...")
                normalizeUFO(
                    instancePath,
                    outputPath = None,
                    onlyModified = True,
                    writeModTimes = False,
                )
            if options.doOverlapRemoval or options.doAutoHint:
                logger.info("Applying post-processing...")
                updateInstance(instancePath, options)
            if not options.doOverlapRemoval:
                validateLayers(instancePath)
            if options.doOverlapRemoval or options.doAutoHint:
                if options.doNormalize:
                    normalizeUFO(
                        instancePath,
                        outputPath = None,
                        onlyModified = False,
                        writeModTimes = False,
                    )

        elif self.file_format == "TTF":
            self.style.open()
            tt_font = ufo2ft.compileTTF(
                self.style.open(),
                removeOverlaps = self.project.options["run_checkoutlines"],
            )
            style_file_format_backup = self.style.file_format
            self.style.file_format = "TTF"
            tt_font.save(self.style.get_path())
            print(f"Converted PostScript outlines into TrueType: `{self.style.get_path()}`")

        kit.makedirs(self.get_directory())

        arguments = [
            "-f", self.style.get_path(),
            "-o", self.get_path(),
            "-mf", self.project.fmndb.get_path(),
            "-gf", self.goadb_trimmed.get_path(),
            "-ga",
            "-overrideMenuNames",
        ]
        if self.project.options["run_autohint"]:
            arguments.append("-shw")
        else:
            arguments.append("-nshw")
        if self.project.options["use_mac_name_records"]:
            arguments.append("-useMacNames")
        else:
            arguments.append("-omitMacNames")
        if not self.project.args.test:
            arguments.append("-r")
        if self.project.options["do_style_linking"] and (self.is_bold or self.is_italic):
            if self.is_bold:
                arguments.append("-b")
            if self.is_italic:
                arguments.append("-i")
        else:
            arguments.extend(["-osbOn", "6"])
        if self.project.options["use_os_2_version_4"]:
            for digit, boolean in [
                ("7", self.project.options["prefer_typo_metrics"]),
                ("8", self.project.options["is_width_weight_slope_only"]),
                ("9", self.is_oblique),
            ]:
                arguments.append("-osbOn" if boolean else "-osbOff")
                arguments.append(digit)

        subprocess.call(["makeotf"] + arguments)

        if style_file_format_backup:
            self.style.file_format = style_file_format_backup

        if os.path.exists(self.get_path()):

            self.built = True
            print("[FONT SUCCESSFULLY BUILT]", self.get_path())

            self.font = fontTools.ttLib.TTFont(self.get_path(), recalcTimestamp=True)
            dirty = False
            for table_tag in [
                "STAT",  # Introduced by Glyphs.
            ]:
                if table_tag in self.font:
                    del self.font[table_tag]
                    dirty = True
            if hasattr(self, "postprocess"):
                self.font = self.postprocess()
                dirty = True
            if dirty:
                self.font.save(self.get_path(), reorderTables=False)
                print("[FONT POSTPROCESSED]", self.get_path())

        if self.built:

            self.copy_out_of_temp()

            output_dir = self.project.directories["output"]
            if os.path.isdir(output_dir):
                kit.copy(
                    self.get_path(),
                    os.path.join(output_dir, self.filename_with_extension),
                )
                print("[COPIED TO OUPUT DIRECTORY]", self.get_path())