Handwrite

repository·dev·Indexed 19 days ago

https://github.com/yashlamba/handwrite

A tool that converts handwriting samples into custom .ttf font files, allowing users to type in their own handwriting style using standard word processors. It includes a CLI for automating the pipeline from sample sheets to fonts via PNG and SVG conversion, and requires fontforge and Potrace as system dependencies.

Tokens
1.5K
Snippets
7
Records
11
Agent score
66%

What's inside handwrite

  1. Overview of Handwrite

    dev
    Handwrite is a tool that generates a custom font based on a sample of your handwriting. This allows you to type assignments or documents that appear to be handwritten, making them compatible with standard text editors and word processors like Microsoft Word and LibreOffice Writer. It is designed to make handwritten assignments more efficient and is particularly helpful for individuals with dysgraphia.
  2. Generate a font using the Handwrite CLI

    dev

    Once you have your .jpg sample, you can generate a .ttf font file using the handwrite command.

    Prerequisites You must have the following installed on your system:

    • handwrite
    • potrace
    • fontforge

    Basic Usage Run the command with the path to your image and the desired output directory: handwrite [PATH TO IMAGE] [OUTPUT DIRECTORY]

    Advanced Usage

    • Custom Configuration: Pass a custom JSON configuration file using the --config [CONFIG FILE] flag.
    • Argument Precedence: If you provide metadata (such as filename, family, or style) directly as CLI arguments, these will override any values found in the provided config file.
    • Default Config: If no --config argument is provided, the tool uses the default config file.

    Output The generated font will be located at: [OUTPUT DIRECTORY]/[OUTPUT FONT NAME].ttf.

    handwrite path/to/your_sample.jpg ./output_folder
    
    # Using a custom config file
    handwrite path/to/your_sample.jpg ./output_folder --config my_config.json
  3. How to use Handwrite

    dev
    To generate your custom handwriting font, you follow a simple process of filling out a form with your handwriting samples. Once the form is processed, Handwrite produces a font file that can be installed on your system and used in any application that supports custom fonts.
  4. Create a handwritten sample for font generation

    dev

    To generate a font from your handwriting, you must first create a physical sample using the provided template:

    1. Print the sample form.
    2. Fill out the form manually using a pen.
    3. Scan the completed form using a scanner or a mobile scanning app (like Adobe Scan).
    4. Save the resulting scan as a .jpg image on your system.
  5. Install system dependencies for Handwrite

    dev

    Before installing handwrite, you must install the following system-level dependencies:

    1. fontforge: Required for font manipulation.
    2. Potrace: Required for tracing bitmap images into vector graphics.

    Ensure these are installed and available in your system's PATH before proceeding with the pip install.

  6. Use the Handwrite CLI to generate a font from a sample sheet

    dev

    The Handwrite CLI automates the pipeline of converting a handwriting sample sheet into a usable font file (.ttf). The process follows three stages: converting the sheet to PNGs, converting PNGs to SVGs, and finally converting SVGs to a TTF font.

    By default, the CLI uses a temporary directory for intermediate files and a default.json configuration file located in the package directory. You can specify a custom directory for intermediate files, a custom configuration file, and metadata for the resulting font (filename, family, and style).

    python -m handwrite.cli <input_path> <output_directory> [options]
    
    # Example: Generate a font named 'MyHand' with family 'MyHandwriting'
    python -m handwrite.cli sample_sheet.png ./output_font --filename MyHand.ttf --family MyHandwriting --style Regular
  7. Use SHEETtoPNG to convert sheets to PNG images

    dev

    The SHEETtoPNG function (located in the handwrite.sheettopng module) is used to convert sheet data into PNG image files. This function is part of the handwrite library's capabilities for generating handwriting-style images from structured input.

    from handwrite.sheettopng import SHEETtoPNG
    
    # Usage of SHEETtoPNG goes here
  8. Use PNGtoSVG to convert PNG images to SVG

    dev

    The PNGtoSVG class in the handwrite.pngtosvg module provides functionality to convert PNG images into SVG format. This is likely used as part of a handwriting reconstruction or vectorization pipeline within the handwrite library.

    from handwrite.pngtosvg import PNGtoSVG
    
    # Initialize the converter
    converter = PNGtoSVG()
    # Further usage depends on the specific implementation of the class
  9. Handwrite CLI arguments and options reference

    dev

    The Handwrite CLI accepts the following positional arguments and optional flags to control the font generation process.

    Positional Arguments:
      input_path          Path to sample sheet
      output_directory    Directory Path to save font output
    
    Optional Arguments:
      --directory          Generate additional files to this path (Temp by default)
      --config             Use custom configuration file
      --filename           Font File name
      --family             Font Family name
      --style              Font Style name