-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c6b2c8
commit 51c0eaf
Showing
5 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Continuous integration | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: [stable] | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build | ||
run: cargo build --release | ||
|
||
- name: Test | ||
run: cargo test --release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
[package] | ||
name = "subsetter" | ||
version = "0.1.0" | ||
authors = ["Laurenz <[email protected]>"] | ||
edition = "2021" | ||
description = "Reduces the size and coverage of OpenType fonts." | ||
repository = "https://github.com/typst/subsetter" | ||
readme = "README.md" | ||
license = "MIT OR Apache-2.0" | ||
categories = ["compression", "encoding"] | ||
keywords = ["subsetting", "OpenType", "PDF"] | ||
|
||
[dev-dependencies] | ||
ttf-parser = "0.15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# subsetter | ||
Reduces the size and coverage of OpenType fonts. | ||
|
||
Supports both TrueType and CFF outlines. | ||
|
||
## Example | ||
In the example below, we remove all glyphs except the ones with IDs 68, 69, 70. | ||
Those correspond to the letters 'a', 'b' and 'c'. | ||
|
||
```rust | ||
use subsetter::{subset, Profile}; | ||
|
||
// Read the raw font data. | ||
let data = std::fs::read("fonts/NotoSans-Regular.ttf")?; | ||
|
||
// Keep only three glyphs and the OpenType tables | ||
// required for embedding the font in a PDF file. | ||
let glyphs = &[68, 69, 70]; | ||
let profile = Profile::pdf(glyphs); | ||
let sub = subset(&data, 0, profile)?; | ||
|
||
// Write the resulting file. | ||
std::fs::write("target/Noto-Small.ttf", sub)?; | ||
``` | ||
|
||
Notably, this subsetter does not really remove glyphs, just their outlines. This | ||
means that you don't have to worry about changed glyphs IDs. However, it also | ||
means that the resulting font won't always be as small as possible. To somewhat | ||
remedy this, this crate sometimes at least zeroes out unused data that it cannot | ||
fully remove. This helps if the font gets compressed, for example when embedding | ||
it in a PDF file. | ||
|
||
In the above example, the original font was 375 KB (188 KB zipped) while the | ||
resulting font is 36 KB (5 KB zipped). | ||
|
||
## Limitations | ||
Currently, the library only subsets static outline fonts. Furthermore, it is | ||
designed for use cases where text was already mapped to glyphs. Possible future | ||
work includes: | ||
|
||
- The option to pass variation coordinates which would make the subsetter create | ||
a static instance of a variable font. | ||
- Subsetting of bitmap, color and SVG tables. | ||
- A profile which takes a char set instead of a glyph set and subsets the | ||
layout tables. | ||
|
||
## Safety and Dependencies | ||
This crate forbids unsafe code and has zero dependencies. | ||
|
||
## License | ||
This crate is dual-licensed under the MIT and Apache 2.0 licenses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters