https://github.com/dcsch/ufokit
Unified Font Object file handling
https://github.com/dcsch/ufokit
Last synced: about 1 year ago
JSON representation
Unified Font Object file handling
- Host: GitHub
- URL: https://github.com/dcsch/ufokit
- Owner: dcsch
- License: mit
- Created: 2017-12-31T01:43:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-11-26T06:50:31.000Z (over 3 years ago)
- Last Synced: 2025-04-22T21:48:50.048Z (about 1 year ago)
- Language: Swift
- Size: 86.9 KB
- Stars: 11
- Watchers: 7
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UFOKit
A Swift library for low-level [Unified Font Object](http://unifiedfontobject.org/)
file handling.
A simple example to render a glyph in a view:
```swift
do {
// Load the font and grab the set of glyphs
let ufoReader = try UFOReader(url: URL(fileURLWithPath: "font.ufo"))
let glyphSet = try ufoReader.glyphSet()
// Use a pen that generates a CGPath from a glyph
let pen = QuartzPen(glyphSet: glyphSet)
// Read the glyph for 'A'
try glyphSet.readGlyph(glyphName: "A", pointPen: pen)
// Render in a simple view
let glyphView = GlyphView(frame: NSRect(x: 0, y: 0, width: 240, height: 480))
glyphView.glyphPath = pen.path
glyphView.bounds = pen.path.boundingBox
PlaygroundPage.current.liveView = glyphView
} catch {
print("Error: \(error)")
}
// A simple view that only renders a CGPath
class GlyphView: NSView {
var glyphPath: CGPath?
override func draw(_ dirtyRect: NSRect) {
guard let context = NSGraphicsContext.current?.cgContext else {
return
}
context.setFillColor(CGColor.white)
context.fill(self.bounds)
if let path = glyphPath {
context.addPath(path)
}
context.setFillColor(CGColor.black)
context.fillPath()
}
}
```
## Useful links
- [Unified Font Object (UFO) specification](http://unifiedfontobject.org/)
- [ufoLib — A low-level UFO reader and writer in Python](https://github.com/unified-font-object/ufoLib)
- [RoboFab](http://robofab.org/)