https://github.com/adrientetar/kotlin-ufo
A library to read/write UFO fonts
https://github.com/adrientetar/kotlin-ufo
fonts kotlin-jvm
Last synced: about 2 months ago
JSON representation
A library to read/write UFO fonts
- Host: GitHub
- URL: https://github.com/adrientetar/kotlin-ufo
- Owner: adrientetar
- License: apache-2.0
- Created: 2023-05-29T15:54:50.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-02-26T01:07:56.000Z (4 months ago)
- Last Synced: 2026-02-26T06:24:32.310Z (4 months ago)
- Topics: fonts, kotlin-jvm
- Language: Kotlin
- Homepage:
- Size: 223 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
kotlin-ufo
==========
**A library to read/write [UFO fonts]**
[](https://kotlinlang.org/)
[](LICENSE.txt)
[](https://central.sonatype.com/artifact/io.github.adrientetar/kotlin-ufo)
[](https://codecov.io/gh/adrientetar/kotlin-ufo)
With this library, one can read and write [UFO fonts], which in turn allows using the [fontmake] compiler.
UFO 3 is supported, as well as UFOZ (ZIP-compressed UFO). UFO 2 import is supported.
Maven library
-------------
```kotlin
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.adrientetar:kotlin-ufo:1.2.0")
}
```
Usage
-----
### Read
```kotlin
import com.google.common.truth.Truth.assertThat
import io.github.adrientetar.ufo.UFOReader
import java.nio.file.Paths
val path = Paths.get("/usr/share/MyFont-Regular.ufo")
val reader = UFOReader(path)
val info = reader.readFontInfo()
assertThat(info.familyName).isEqualTo("My Font")
assertThat(info.styleName).isEqualTo("Regular")
```
### Write
```kotlin
import io.github.adrientetar.ufo.FontInfoValues
import io.github.adrientetar.ufo.UFOWriter
import java.nio.file.Paths
val path = Paths.get("/usr/share/MyFont-Regular.ufo")
val info = FontInfoValues().apply {
familyName = "My Font"
styleName = "Regular"
}
val writer = UFOWriter(path)
writer.writeMetaInfo()
writer.writeFontInfo(info)
```
### Round-trip
Read all layers from one UFO and write them to another, using the
`UFOFormatWriter` interface to target either `.ufo` or `.ufoz`:
```kotlin
import io.github.adrientetar.ufo.*
import java.nio.file.Paths
val input = Paths.get("MyFont-Regular.ufo")
val output = Paths.get("MyFont-Regular.ufoz")
val reader = UFOReader(input)
// UFOFormatWriter lets you write to .ufo or .ufoz interchangeably
val writer: UFOFormatWriter = UFOZWriter.open(output)
writer.use {
it.writeMetaInfo()
it.writeFontInfo(reader.readFontInfo())
it.writeLayers(reader.readLayers())
it.writeGroups(reader.readGroups())
it.writeKerning(reader.readKerning())
it.writeLib(reader.readLib())
it.writeFeatures(reader.readFeatures())
}
```
See [the tests](/src/test/kotlin/io/github/adrientetar/ufo) for more sample code.
Supported features
------------------
| Feature | Status |
|---------|--------|
| `metainfo.plist` | ✅ Read/Write |
| `fontinfo.plist` | ✅ Read/Write (comprehensive) |
| `groups.plist` | ✅ Read/Write (with kerning group helpers) |
| `kerning.plist` | ✅ Read/Write |
| `lib.plist` | ✅ Read/Write (with `public.glyphOrder`) |
| `features.fea` | ✅ Read/Write |
| `layercontents.plist` | ✅ Read/Write (multiple layers) |
| `glyphs/` | ✅ Read/Write (all GLIF elements) |
| `images/` directory | ✅ Read/Write (PNG images) |
| `data/` directory | ✅ Read/Write (arbitrary data) |
| `UFOFormatWriter` | ✅ Shared interface for UFO/UFOZ writing |
| `readLayers()` / `readGlyphs(layerName)` | ✅ Full round-trip layer support |
**GLIF support:** advance, unicode, anchor, outline (contour, component, point), lib, note, image, guideline, and identifier attributes.
Build
-----
You need JDK 11 or later installed.
To build this library, run `./gradlew jar`.
[UFO fonts]: https://unifiedfontobject.org/
[fontmake]: https://github.com/googlefonts/fontmake
[jimfs]: https://github.com/google/jimfs