<commit_before>#!/usr/bin/env python3
import fontforge
import os
import ruamel.yaml
import shutil


class FontMaker:
    """
    Usage Example:
        fm = FontMaker('osmaxx_v1_definition.yml')
        fm.create_font()
    """
    def __init__(self, font_config):
        self.config = self.yml_reader(font_config)
        self._base_path = '/home/fonts/osmaxx/svg'
        self.n = fontforge.font()
        self.n.encoding = 'Unicode'

    def yml_reader(self, font_config):
        return ruamel.yaml.load(open(font_config, 'r').read())

    def add_glyph(self, hex_position, svg):
        glyph = self.n.createChar(hex_position)
        glyph.importOutlines(os.path.join(self._base_path, svg))

    def create_font(self):
        for font, definition in self.config.items():
            print("creating {}".format(font))
            self.n.fontname = definition['fontname']
            self.n.familyname = definition['fontname']
            self.n.fullname = definition['fontname']
            self.n.comment = definition['fontname']
            self.n.weight = 'normal'
            for hex_position, glyph in definition['mappings'].items():
                hex_value = int(hex_position, 16)
                print(hex_value, glyph['filename'])
                self.add_glyph(hex_value, glyph['filename'])
            self.n.save('{}.sfd'.format(definition['fontname']))
            export_file_name = '{}'.format(definition['filename'])
            self.n.generate(export_file_name)
            print("generated: ", export_file_name)
            shutil.move(export_file_name, '/out/OSMaxx_v1.ttf')

fm = FontMaker('osmaxx_v1_definition.yml')
fm.create_font()<commit_msg>use more speaking variable name<commit_after>#!/usr/bin/env python3
import fontforge
import os
import ruamel.yaml
import shutil


class FontMaker:
    """
    Usage Example:
        fm = FontMaker('osmaxx_v1_definition.yml')
        fm.create_font()
    """
    def __init__(self, font_config):
        self.config = self.yml_reader(font_config)
        self._base_path = '/home/fonts/osmaxx/svg'
        self.fontforge_font = fontforge.font()
        self.fontforge_font.encoding = 'Unicode'

    def yml_reader(self, font_config):
        return ruamel.yaml.load(open(font_config, 'r').read())

    def add_glyph(self, hex_position, svg):
        glyph = self.fontforge_font.createChar(hex_position)
        glyph.importOutlines(os.path.join(self._base_path, svg))

    def create_font(self):
        for font, definition in self.config.items():
            print("creating {}".format(font))
            self.fontforge_font.fontname = definition['fontname']
            self.fontforge_font.familyname = definition['fontname']
            self.fontforge_font.fullname = definition['fontname']
            self.fontforge_font.comment = definition['fontname']
            self.fontforge_font.weight = 'normal'
            for hex_position, glyph in definition['mappings'].items():
                hex_value = int(hex_position, 16)
                print(hex_value, glyph['filename'])
                self.add_glyph(hex_value, glyph['filename'])
            self.fontforge_font.save('{}.sfd'.format(definition['fontname']))
            export_file_name = '{}'.format(definition['filename'])
            self.fontforge_font.generate(export_file_name)
            print("generated: ", export_file_name)
            shutil.move(export_file_name, '/out/OSMaxx_v1.ttf')

fm = FontMaker('osmaxx_v1_definition.yml')
fm.create_font()
{'fraction_non_alphanumeric': 0.12757437070938216, 'fraction_numerical': 0.003432494279176201, 'mean_word_length': 2.7805405405405406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718349', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1058, 'n_words': 171}