Skip to content

Font API and object-level shaping - #16

Merged
hasanzakeri merged 2 commits into
mainfrom
feat/phase5-font
Apr 26, 2026
Merged

hasanzakeri merged 2 commits into
mainfrom
feat/phase5-font

Conversation

@hasanzakeri

Copy link
Copy Markdown
Owner

Summary

This PR adds the object-oriented shaping API: load fonts from path or bytes, configure axis variations and point size, shape a Buffer, and work with the resulting GlyphInfo / GlyphPosition data. Buffers can be recycled through GlyphBuffer.clear(), and serialized output can be matched to the high-level shape() helper for the cases we cover in tests.

What’s included

  • Font — load via path (Font(path)) or Font.from_bytes, optional face_index, units_per_em, set_variations (string or Variation list), set_point_size, and shape(buffer, features=…) with string or Feature list.
  • GlyphBuffer, GlyphInfo, GlyphPosition — length, index access, iteration as (info, pos) pairs, glyph_infos / glyph_positions getters, and serialize(font) for HarfRust-style glyph strings.
  • Safety / UX — clear errors when the buffer’s direction is still invalid before shaping, and explicit consumption semantics for Buffer (after shape) and GlyphBuffer (after clear()) to match the owned-container design.
  • Tests — construction, shaping, iteration, feature and variation options, point size, serialize parity with pyharfrust.shape, and buffer consumption / recycling.

- Added `Font` class for loading and managing font data, including methods for creating instances from file paths and byte arrays.
- Introduced `GlyphBuffer`, `GlyphInfo`, and `GlyphPosition` classes to handle glyph shaping and positioning, providing a structured way to access glyph information.
- Updated `__init__.py` to include new classes in the module's public API.
- Enhanced `Buffer` class with methods for handling glyph data and serialization.
- Added comprehensive tests for the new font and glyph functionalities, ensuring correct behavior and integration with existing components.
- Updated `test_glyph_info_fields` to assert additional properties of glyph information, including cluster values for multiple glyphs.
- Introduced `test_from_bytes_matches_from_path` to verify that font data loaded from bytes matches that loaded from a file path.
- Adjusted error handling in `test_features_wrong_type` to ensure proper feature validation.
@hasanzakeri
hasanzakeri merged commit ffef3f7 into main Apr 26, 2026
2 checks passed
@hasanzakeri
hasanzakeri deleted the feat/phase5-font branch April 26, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant