Skip to main content

A tool for converting fonts to NICO Game Framework format fonts.

Project description

NICO Font Tool - Python

PyPI

A tool for converting fonts to NICO Game Framework format fonts.

This is the Python version. The Nim version see: nico-font-tool.

Installation

pip install nico-font-tool

Usage

import logging
import os

import nico_font_tool
from examples import fonts_dir, outputs_dir

logging.basicConfig(level=logging.DEBUG)


def convert_font(
        font_file_name: str,
        outputs_name: str,
        font_size: int = None,
        glyph_offset_x: int = 0,
        glyph_offset_y: int = 0,
        glyph_adjust_width: int = 0,
        glyph_adjust_height: int = 0,
):
    font_file_path = os.path.join(fonts_dir, font_file_name)
    sheet_data, alphabet = nico_font_tool.create_sheet(
        font_file_path,
        font_size,
        glyph_offset_x,
        glyph_offset_y,
        glyph_adjust_width,
        glyph_adjust_height,
    )

    palette_outputs_dir = os.path.join(outputs_dir, 'palette')
    if not os.path.exists(palette_outputs_dir):
        os.makedirs(palette_outputs_dir)
    nico_font_tool.save_palette_png(sheet_data, palette_outputs_dir, outputs_name)
    nico_font_tool.save_dat_file(alphabet, palette_outputs_dir, outputs_name)
    
    rgba_outputs_dir = os.path.join(outputs_dir, 'rgba')
    if not os.path.exists(rgba_outputs_dir):
        os.makedirs(rgba_outputs_dir)
    nico_font_tool.save_rgba_png(sheet_data, rgba_outputs_dir, outputs_name)
    nico_font_tool.save_dat_file(alphabet, rgba_outputs_dir, outputs_name)


def main():
    convert_font(
        font_file_name='quan/quan.ttf',
        outputs_name='quan',
        font_size=8,
        glyph_adjust_width=-1,
    )
    convert_font(
        font_file_name='fusion-pixel-monospaced/fusion-pixel-monospaced.otf',
        outputs_name='fusion-pixel-monospaced',
        font_size=12,
        glyph_offset_y=-1,
        glyph_adjust_width=-1,
        glyph_adjust_height=-1,
    )
    convert_font(
        font_file_name='fusion-pixel-proportional/fusion-pixel-proportional.otf',
        outputs_name='fusion-pixel-proportional',
        font_size=12,
        glyph_offset_y=-1,
        glyph_adjust_width=-1,
        glyph_adjust_height=-1,
    )
    convert_font(
        font_file_name='galmuri/Galmuri9.ttf',
        outputs_name='galmuri9',
        font_size=10,
        glyph_offset_y=1,
        glyph_adjust_width=-1,
        glyph_adjust_height=1,
    )
    convert_font(
        font_file_name='galmuri/Galmuri9.bdf',
        outputs_name='galmuri9-bdf',
        glyph_adjust_width=-1,
    )
    convert_font(
        font_file_name='unifont/unifont-15.0.01.ttf',
        outputs_name='unifont',
        font_size=16,
        glyph_adjust_width=-1,
    )
    convert_font(
        font_file_name='unifont/unifont-15.0.01.bdf',
        outputs_name='unifont-bdf',
        glyph_adjust_width=-1,
    )
    convert_font(
        font_file_name='roboto/Roboto-Regular.ttf',
        outputs_name='roboto',
        font_size=24,
    )


if __name__ == '__main__':
    main()

License

Under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nico-font-tool-0.0.1.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

nico_font_tool-0.0.1-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page