Metadata-Version: 2.4
Name: ufo_gleaner
Version: 0.2.0
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Requires-Dist: cffi
License-File: LICENSE
Summary: High-performance UFO/GLIF parser for Python written in Rust
Keywords: font design,UFO
Author-email: Knut Nergaard <knut.nergaard@gmail.com>
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/knutnergaard/SMufoLib

# ufo-gleaner

[![PyPI - Version](https://img.shields.io/pypi/v/ufo-gleaner?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/ufo-gleaner/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ufo-gleaner?logo=python&logoColor=white&style=for-the-badge)](https://www.python.org)



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

## Usage

### Install

Install with pip:

```bash
python -m pip install ufo-gleaner
```

### Eager Gleaner

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

```python
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:

```python
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:

```python
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()
```
