Skip to content

Commit debb381

Browse files
committed
feat: add unglyph unified font glyph manipulation library
- Implement comprehensive font glyph management system - Add font parsing using fontkit with undio integration - Add font creation using opentype.js with SVG rendering - Add GlyphManager class with CRUD operations and batch processing - Include factory functions for consistent API design - Add comprehensive TypeScript type definitions - Support OTF font export with expandable architecture - Include complete test suite demonstrating font workflow - Add English-only codebase following project conventions - Update project documentation and package structure
1 parent c07c6fe commit debb381

13 files changed

Lines changed: 1316 additions & 4 deletions

File tree

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
![GitHub](https://img.shields.io/github/license/bysages/typography)
44
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)
55

6-
> Typography toolkit featuring Unicode confusables detection and string normalization
6+
> Typography toolkit featuring Unicode confusables detection, OCR capabilities, and font glyph manipulation
77
88
## Packages
99

1010
This is a monorepo that contains the following packages:
1111

1212
- **[unconfusables](./packages/unconfusables/README.md)** - Unicode confusables detection and string normalization library
13-
- **[unocr](./packages/unocr/README.md)** - Unified OCR library with multi-driver support for Tesseract.js
13+
- **[unocr](./packages/unocr/README.md)** - Unified OCR library with multi-driver support for Tesseract.js and AI models
14+
- **[unglyph](./packages/unglyph/README.md)** - Unified font glyph manipulation library with simple API for parsing, creating, and modifying fonts
1415

1516
## Quick Start
1617

@@ -47,6 +48,47 @@ const ocr = createOCRManager({
4748
const result = await ocr.recognize(imageBuffer);
4849
const text = toString(result);
4950
console.log(text); // Extracted text
51+
52+
// Font manipulation with unglyph
53+
import {
54+
parseFont,
55+
createFont,
56+
createGlyphManager,
57+
renderGlyph,
58+
} from "unglyph";
59+
60+
// Parse existing font
61+
const font = parseFont(fontBuffer);
62+
console.log(`Font: ${font.familyName}, ${font.glyphCount} glyphs`);
63+
64+
// Create custom font
65+
const manager = createGlyphManager();
66+
manager.add({
67+
unicode: 65, // 'A'
68+
name: "A",
69+
advanceWidth: 600,
70+
path: {
71+
commands: [
72+
{ type: "M", x: 300, y: 0 },
73+
{ type: "L", x: 100, y: 700 },
74+
{ type: "L", x: 500, y: 700 },
75+
{ type: "L", x: 300, y: 0 },
76+
],
77+
},
78+
});
79+
80+
const newFont = createFont(manager.list(), {
81+
familyName: "MyFont",
82+
styleName: "Regular",
83+
unitsPerEm: 1000,
84+
});
85+
86+
// Render glyph to SVG
87+
const svg = renderGlyph(manager.findByUnicode(65), {
88+
size: 100,
89+
color: "#2563eb",
90+
padding: 20,
91+
});
5092
```
5193

5294
### Development
@@ -66,6 +108,9 @@ node playground/unconfusables.ts
66108

67109
# Test unocr functionality
68110
node playground/unocr/tesseract.ts
111+
112+
# Test unglyph functionality
113+
node playground/unglyph.ts
69114
```
70115

71116
## Contributing

0 commit comments

Comments
 (0)