コード例 #1
0
    def save(self):
        if self.save_to_default_layer:
            self.defcon_font.save()
        else:
            if self.ufo_format <= UFOFormatVersion.FORMAT_2_0:
                # Up-convert the UFO to format 3
                warnings.warn("The UFO was up-converted to format 3.")
                self.ufo_format = UFOFormatVersion.FORMAT_3_0

                with UFOWriter(self.defcon_font.path,
                               formatVersion=self.ufo_format) as writer:
                    writer.getGlyphSet()
                    writer.writeLayerContents()

            writer = UFOWriter(self.defcon_font.path,
                               formatVersion=self.ufo_format)
            writer.layerContents[PROCD_GLYPHS_LAYER_NAME] = PROCD_GLYPHS_LAYER
            layers = self.defcon_font.layers
            layer = layers[PROCD_GLYPHS_LAYER_NAME]
            glyph_set = writer.getGlyphSet(layerName=PROCD_GLYPHS_LAYER_NAME,
                                           defaultLayer=False)
            if self.font_format == "PFC":
                libs = {}
                for f in layers.defaultLayer._glyphs.items():
                    libs[f[0]] = f[1].lib
                for g in layer._glyphs.items():
                    g[1].lib = libs[g[0]]
            writer.writeLayerContents(layers.layerOrder)
            layer.save(glyph_set)

        if self.font_type == UFO_FONT_TYPE:
            ufotools.regenerate_glyph_hashes(self.ufo_font_hash_data)
            # Write the hash data, if it has changed.
            self.ufo_font_hash_data.close()

        elif self.font_type == TYPE1_FONT_TYPE:
            args = ['tx', '-t1']
            if self.font_format == 'PFB':
                args.append('-pfb')
            if not run_shell_command(args +
                                     [self.temp_ufo_path, self.font_path]):
                raise FocusFontError('Failed to convert UFO font to Type 1.')

        else:
            temp_cff_path = get_temp_file_path()
            if not run_shell_command([
                    'tx', '-cff', '+S', '+b', '-std', self.temp_ufo_path,
                    temp_cff_path
            ],
                                     suppress_output=True):
                raise FocusFontError('Failed to convert UFO font to CFF.')

            if self.font_type == CFF_FONT_TYPE:
                shutil.copy2(temp_cff_path, self.font_path)

            else:  # OTF_FONT_TYPE
                if not run_shell_command(
                    ['sfntedit', '-a', f'CFF={temp_cff_path}', self.font_path
                     ]):
                    raise FocusFontError('Failed to add CFF table to OTF.')
コード例 #2
0
ファイル: test_utils.py プロジェクト: ystallonne/afdko
def generalizeCFF(otfPath, do_sfnt=True):
    """
    Adapted from similar routine in 'buildmasterotfs'. This uses
    temp files for both tx output and sfntedit output instead of
    overwriting 'otfPath', and also provides an option to skip
    the sfntedit step (so 'otfPath' can be either a .otf file or
    a .cff file).
    """
    tmp_tx_path = get_temp_file_path()
    out_path = get_temp_file_path()
    shutil.copyfile(otfPath, out_path, follow_symlinks=True)

    if not run_shell_command(
        ['tx', '-cff', '+b', '-std', '-no_opt', otfPath, tmp_tx_path]):
        raise Exception

    if do_sfnt:

        if not run_shell_command(
            ['sfntedit', '-a', f'CFF ={tmp_tx_path}', out_path]):
            raise Exception

        return out_path

    else:

        return tmp_tx_path
コード例 #3
0
def generalizeCFF(otfPath):
    tempFilePath = get_temp_file_path()

    if not run_shell_command(
        ['tx', '-cff', '+b', '-std', '-no_opt', otfPath, tempFilePath]):
        raise ShellCommandError

    if not run_shell_command(
        ['sfntedit', '-a', 'CFF ={}'.format(tempFilePath), otfPath]):
        raise ShellCommandError
コード例 #4
0
    def open(self, use_hash_map):
        font_path = self.font_path

        if self.font_format == 'UFO':
            self.font_type = UFO_FONT_TYPE
            ufotools.validateLayers(font_path)
            self.defcon_font = defcon.Font(font_path)
            self.ufo_format = self.defcon_font.ufoFormatVersionTuple
            self.use_hash_map = use_hash_map
            self.ufo_font_hash_data = ufotools.UFOFontData(
                font_path,
                self.use_hash_map,
                programName=ufotools.kCheckOutlineName)
            self.ufo_font_hash_data.readHashMap()

        else:
            print("Converting to temp UFO font...")
            self.temp_ufo_path = temp_path = get_temp_dir_path('font.ufo')

            if not run_shell_command(['tx', '-ufo', font_path, temp_path]):
                raise FocusFontError('Failed to convert input font to UFO.')

            try:
                self.defcon_font = defcon.Font(temp_path)
            except UFOLibError:
                raise

            if self.font_format == 'OTF':
                self.font_type = OTF_FONT_TYPE
            elif self.font_format == 'CFF':
                self.font_type = CFF_FONT_TYPE
            else:
                self.font_type = TYPE1_FONT_TYPE

        return self.defcon_font
コード例 #5
0
ファイル: checkoutlinesufo.py プロジェクト: spiratype/afdko
    def save(self):
        if self.save_to_default_layer:
            self.defcon_font.save()
        else:
            """
            XXX A real hack here XXX
            RoboFont did not support layers (UFO3 feature) until version 3.
            So in order to allow editing (in RF 1.x) UFOs that contain
            a processed glyphs layer, checkoutlinesufo generates UFOs that
            are structured like UFO3, but advertise themselves as UFO2.
            To achieve this, the code below hacks ufoLib to surgically save
            only the processed layer.
            This hack is only performed if the original UFO is format 2.

            NOTE: this is deprecated and will be removed from AFDKO.
            """
            writer = UFOWriter(
                self.defcon_font.path, formatVersion=self.ufo_format)
            writer.layerContents[
                PROCD_GLYPHS_LAYER_NAME] = PROCD_GLYPHS_LAYER
            layers = self.defcon_font.layers
            layer = layers[PROCD_GLYPHS_LAYER_NAME]

            if self.ufo_format == UFOFormatVersion.FORMAT_2_0:
                # Override the UFO's formatVersion. This disguises a UFO2 to
                # be seen as UFO3 by ufoLib, thus enabling it to write the
                # layer without raising an error.
                warn_txt = ("Using a ‘hybrid’ UFO2-as-UFO3 is deprecated and "
                            "will be removed from AFDKO by the end of 2020. "
                            "This behavior (hack) was primarily to support "
                            "older versions of RoboFont which did not support "
                            "UFO3/layers. RoboFont 3 now supports UFO3 so the "
                            "hack is no longer required. Please update your "
                            "toolchain as needed.")
                warnings.warn(warn_txt, category=FutureWarning)
                writer._formatVersion = UFOFormatVersion.FORMAT_3_0

            glyph_set = writer.getGlyphSet(
                layerName=PROCD_GLYPHS_LAYER_NAME, defaultLayer=False)
            writer.writeLayerContents(layers.layerOrder)

            if self.ufo_format == UFOFormatVersion.FORMAT_2_0:
                # Restore the UFO's formatVersion to the original value.
                # This makes the glif files be set to format 1 instead of 2.
                glyph_set.ufoFormatVersionTuple = UFOFormatVersion.FORMAT_2_0

            layer.save(glyph_set)

        if self.font_type == UFO_FONT_TYPE:
            ufotools.regenerate_glyph_hashes(self.ufo_font_hash_data)
            # Write the hash data, if it has changed.
            self.ufo_font_hash_data.close()

        elif self.font_type == TYPE1_FONT_TYPE:
            args = ['tx', '-t1']
            if self.font_format == 'PFB':
                args.append('-pfb')
            if not run_shell_command(
                    args + [self.temp_ufo_path, self.font_path]):
                raise FocusFontError('Failed to convert UFO font to Type 1.')

        else:
            temp_cff_path = get_temp_file_path()
            if not run_shell_command([
                    'tx', '-cff', '+S', '+b', '-std',
                    self.temp_ufo_path, temp_cff_path], suppress_output=True):
                raise FocusFontError('Failed to convert UFO font to CFF.')

            if self.font_type == CFF_FONT_TYPE:
                copy2(temp_cff_path, self.font_path)

            else:  # OTF_FONT_TYPE
                if not run_shell_command([
                        'sfntedit', '-a',
                        f'CFF={temp_cff_path}', self.font_path]):
                    raise FocusFontError('Failed to add CFF table to OTF.')
コード例 #6
0
ファイル: checkoutlinesufo.py プロジェクト: ystallonne/afdko
    def save(self):
        if self.save_to_default_layer:
            self.defcon_font.save()
        else:
            """
            XXX A real hack here XXX
            RoboFont did not support layers (UFO3 feature) until version 3.
            So in order to allow editing (in RF 1.x) UFOs that contain
            a processed glyphs layer, checkoutlinesufo generates UFOs that
            are structured like UFO3, but advertise themselves as UFO2.
            To achieve this, the code below hacks ufoLib to surgically save
            only the processed layer.
            This hack is only performed if the original UFO is format 2.
            """
            writer = UFOWriter(self.defcon_font.path,
                               formatVersion=self.ufo_format)
            writer.layerContents[PROCD_GLYPHS_LAYER_NAME] = PROCD_GLYPHS_LAYER
            layers = self.defcon_font.layers
            layer = layers[PROCD_GLYPHS_LAYER_NAME]

            if self.ufo_format == 2:
                # Override the UFO's formatVersion. This disguises a UFO2 to
                # be seen as UFO3 by ufoLib, thus enabling it to write the
                # layer without raising an error.
                writer._formatVersion = 3

            glyph_set = writer.getGlyphSet(layerName=PROCD_GLYPHS_LAYER_NAME,
                                           defaultLayer=False)
            writer.writeLayerContents(layers.layerOrder)

            if self.ufo_format == 2:
                # Restore the UFO's formatVersion to the original value.
                # This makes the glif files be set to format 1 instead of 2.
                glyph_set.ufoFormatVersion = self.ufo_format

            layer.save(glyph_set)

        if self.font_type == UFO_FONT_TYPE:
            ufotools.regenerate_glyph_hashes(self.ufo_font_hash_data)
            # Write the hash data, if it has changed.
            self.ufo_font_hash_data.close()

        elif self.font_type == TYPE1_FONT_TYPE:
            args = ['tx', '-t1']
            if self.font_format == 'PFB':
                args.append('-pfb')
            if not run_shell_command(args +
                                     [self.temp_ufo_path, self.font_path]):
                raise FocusFontError('Failed to convert UFO font to Type 1.')

        else:
            temp_cff_path = get_temp_file_path()
            if not run_shell_command([
                    'tx', '-cff', '+S', '+b', '-std', self.temp_ufo_path,
                    temp_cff_path
            ],
                                     suppress_output=True):
                raise FocusFontError('Failed to convert UFO font to CFF.')

            if self.font_type == CFF_FONT_TYPE:
                copy2(temp_cff_path, self.font_path)

            else:  # OTF_FONT_TYPE
                if not run_shell_command(
                    ['sfntedit', '-a', f'CFF={temp_cff_path}', self.font_path
                     ]):
                    raise FocusFontError('Failed to add CFF table to OTF.')
コード例 #7
0
ファイル: fdkutils_test.py プロジェクト: ystallonne/afdko
def test_run_shell_command(cmd, rslt):
    assert run_shell_command(cmd) is rslt