Skip to main content

High-performance UFO/GLIF parser for Python written in Rust

Project description

ufo-gleaner

PyPI - Version PyPI - Python Version

High-performance UFO/GLIF parser for Python written in Rust

Usage

Install

Install with pip:

python -m pip install ufo-gleaner

Eager Gleaner

Parse all .glif files in one go as a dictionary mapping glyph names to their attributes:

from ufo_gleaner import Gleaner, FileProvider

provider = FileProvider("/path/to/myfont.ufo")
gleaner = Gleaner(provider)

glyphs = gleaner.glean()
print(glyphs["A"]["advance"]["width"])

Lazy Font Object Model

To minimize load time and memory footprint, ufo-gleaner provides a dictionary-like font object with lazy parsing and on-demand access to GLIF files and their attributes:

from ufo_gleaner import Font, FileProvider

provider = FileProvider("/path/to/myfont.ufo")
font = Font(provider)

# Access a single glyph by name
glyph = font["A"]

# Access glyph attributes lazily
anchors = glyph.anchors

Custom Providers

Gleaner can be used with any Python object that implements a read(path: str) -> bytes method, where path is relative to the UFO root. This lets you read from both .ufo directories and .ufoz ZIP archives, for example:

import zipfile
from ufo_gleaner import Gleaner

class UfozProvider:
    def __init__(self, root):
        self.zipfile = zipfile.ZipFile(root, "r")
    
    def read(self, path: str) -> bytes:
        return self.zipfile.read(path)

provider = UfozProvider("/path/to/myfont.ufoz")
gleaner = Gleaner(provider)

glyphs = gleaner.glean()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ufo_gleaner-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (364.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file ufo_gleaner-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ufo_gleaner-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddb7c3a4c48f3f63fdf745984cc18467411ed22e17a39db599a8cf8c17530d83
MD5 cff1ffc74a1ac5e1500a1ee44b61a606
BLAKE2b-256 898e81c0fb1c56646ac5aea1ba37c1d12c2f74adc9bc620d220e4635c5117b4c

See more details on using hashes here.

Supported by

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