Skip to main content

gtfont

Fast string measurement for perfect tables.

gtfont is a Rust-powered Python extension that provides precise text measurement utilities, optimized for building perfectly aligned tables from pandas DataFrames.

This library is designed for use within the greater_tables package, but can also be used standalone.

Features

  • Measure the rendered width of a sentence using system fonts
  • Compute maximum word width in a line
  • Combine both in one efficient call
  • Based on native font rendering for accurate results
  • Blazing-fast Rust backend exposed as a Python module

Installation

pip install gtfont

Python ≥3.8 is required. Pre-built wheels are available for major platforms via PyPI.

Example

from gtfont import FontMeasurer
from matplotlib import font_manager

font_path = font_manager.findfont("Times New Roman", fallback_to_default=True)
font_bytes = Path(font_path).read_bytes()
fm = FontMeasurer(font_bytes)
sentence = "The quick brown fox jumps over the lazy dog."

# Measure sentence width in points
width = fm.measure(sentence, 11)

# Measure max word width
max_word = fm.max_word_width(sentence, 11)

# Both at once
sentence_width, max_word_width = fm.measure_and_max_word(sentence, 11)

Build

maturin build --release --strip

# or 

maturin develop 

Why Rust?

Font measurement is performance-critical. By leveraging pyo3, we combine the safety and speed of Rust with the usability of Python.

License

MIT © Stephen J. Mildenhall

Metadata

Release files for gtfont 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for gtfont 1.0.0
File Interpreter ABI Platform
gtfont-1.0.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details

Release files / gtfont-1.0.0-cp38-abi3-win_amd64.whl

Download URL gtfont-1.0.0-cp38-abi3-win_amd64.whl
Size 2.8 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0787b28a1985608c438ba5bc2e4ff10ad637dac40c7918dc7017f1a97f36a4bf
BLAKE2b-256 checksum
How to use checksums
4ad947a3f63ab79457aed843819772b8ae7bf85777ba10c31a7f955de1276834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page