Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
edb2b11
Add --suffix option
zk-phi Feb 20, 2021
c8c7827
Support empty suffix
zk-phi Feb 20, 2021
2ba45e8
Add workflow to sync fork
zk-phi Mar 6, 2021
659f4e3
Link to Sara’s article from the readme.
zachleat Mar 8, 2021
b3f648b
Update all dependencies, need a minor release.
zachleat Mar 11, 2021
f80463d
Ignore the lock
zachleat Mar 11, 2021
db41117
Adds changelog
zachleat Mar 11, 2021
61d9483
Update URLs.
zachleat Mar 15, 2021
5460e82
v4.0.1
zachleat Mar 15, 2021
d61132a
Update author
zachleat Mar 15, 2021
3df6147
Update upstream branch
zk-phi Mar 17, 2021
281f6f6
Merge pull request #2 from zachleat/master
zk-phi Mar 17, 2021
5e57767
Add the readme link to Unicode Range Interchange
zachleat Jun 7, 2021
4e7bb95
Use my fork of spider-pig
zk-phi Jul 1, 2021
28d21ee
Merge remote-tracking branch 'upstream/master'
zk-phi Jul 1, 2021
e71b6bd
Use pip to install brotli and zopfli
mathieudutour Aug 3, 2021
fc4049e
Removes fs-extra dep.
zachleat Dec 6, 2021
d99ecf8
Updates spider-pig to fix chromium on arm64 dependency.
zachleat Dec 6, 2021
6b27380
v5.0.0 includes dependency major version bumps, notably upgrading pup…
zachleat Dec 6, 2021
d980bd5
Merge pull request #6 from mathieudutour/patch-1
zachleat Dec 13, 2021
2ab73db
Adds `--output` to the docs
nhoizey Dec 13, 2021
ef6485b
Merge pull request #9 from nhoizey/patch-1
zachleat Dec 13, 2021
33f4ea7
Update spider-pig
zk-phi Feb 15, 2025
7d38043
Merge remote-tracking branch 'zachleat/master'
zk-phi Feb 15, 2025
a2d5bc9
Use my fork of spider-pig (again)
zk-phi Feb 15, 2025
7a6c1bf
Revert "Use my fork of spider-pig (again)"
zk-phi Feb 15, 2025
8733e1d
Remove auto-pr workflow
zk-phi Mar 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
test/fonts/ignored
test/fonts/ignored
package-lock.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
v4.0.0

* Requires Node 10+ (Node 8 is EOL)
* A bunch of major release bumps of dependencies
* Fixes the `(node:1077) Warning` console output documented at the end of https://www.sarasoueidan.com/blog/glyphhanger/
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ pip install fonttools

```sh
# Additional installation for --flavor=woff2
git clone https://github.com/google/brotli
cd brotli
python setup.py install
pip install brotli

# Additional installation for --flavor=woff --with-zopfli
git clone https://github.com/anthrotype/py-zopfli
cd py-zopfli
git submodule update --init --recursive
python setup.py install
pip install zopfli
```

If you want to read an in-depth tutorial on the installation steps above, please read [How I set up Glyphhanger on macOS for optimizing and converting font files for the Web](https://www.sarasoueidan.com/blog/glyphhanger/) by Sara Soueidan.

## Usage

_Related: operate on existing `unicode-range` values with [Unicode Range Interchange](https://www.zachleat.com/unicode-range-interchange/) ([read the blog post](https://www.zachleat.com/web/unicode-range-interchange/))._

### Find the glyphs in a local file or url

```sh
Expand All @@ -47,7 +46,7 @@ glyphhanger ./test.html --string
glyphhanger http://example.com

# multiple URLs, optionally using HTTPS
glyphhanger https://google.com https://www.filamentgroup.com
glyphhanger https://google.com https://www.zachleat.com

# show results for each font-family on the page
glyphhanger ./test.html --json
Expand Down Expand Up @@ -145,6 +144,15 @@ Writing CSS file: LatoLatin-Regular.css
}
```

#### Specify output directory for any files created with `--output`

```sh
> glyphhanger --subset=*.ttf --output=some/other/path

Subsetting LatoLatin-Regular.ttf to LatoLatin-Regular-subset.woff (was 145.06 KB, now 2.88 KB)
Subsetting LatoLatin-Regular.ttf to LatoLatin-Regular-subset.woff2 (was 145.06 KB, now 2.24 KB)
```

### Whitelist Characters

```sh
Expand Down Expand Up @@ -233,17 +241,16 @@ echo "this is a test" | glyphhanger --jsdom

## Testing

* Build Status: [![Build Status](https://travis-ci.org/filamentgroup/glyphhanger.svg?branch=master)](https://travis-ci.org/filamentgroup/glyphhanger)

`npm test` will run the tests.

Or, alternatively `npx mocha`.

## Enhancement Queue

* [Top Voted Issues 👍](https://github.com/filamentgroup/glyphhanger/issues?q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc)
* [Top Voted Issues 👍](https://github.com/zachleat/glyphhanger/issues?q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc)
* Archived: [Voted Issues from `filamentgroup/glyphhanger`](https://github.com/filamentgroup/glyphhanger/issues?q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc)

## Alternatives to GlyphHanger

* [unicode-ranger from Jeremy Wagner](https://github.com/malchata/unicode-ranger)
* [subfont from Peter Müller](https://www.npmjs.com/package/subfont)
* [subfont from Peter Müller](https://www.npmjs.com/package/subfont)
1 change: 1 addition & 0 deletions cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if( argv.jsdom ) {

var subset = new GlyphHangerSubset();
subset.setOutputDirectory(argv.output);
subset.setOutputSuffix(argv.suffix);

if( argv.formats ) {
subset.setFormats( argv.formats );
Expand Down
38 changes: 18 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
{
"name": "glyphhanger",
"version": "3.2.0",
"version": "5.0.0",
"description": "A tool to ease webfont subsetting.",
"main": "src/GlyphHanger.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/filamentgroup/glyphhanger.git"
"url": "git+https://github.com/zachleat/glyphhanger.git"
},
"author": {
"name": "Zach Leatherman",
"email": "zach@filamentgroup.com",
"url": "https://filamentgroup.com"
"email": "zachleatherman@gmail.com",
"url": "https://zachleat.com/"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/filamentgroup/glyphhanger/issues"
"url": "https://github.com/zachleat/glyphhanger/issues"
},
"homepage": "https://github.com/filamentgroup/glyphhanger#readme",
"homepage": "https://github.com/zachleat/glyphhanger#readme",
"bin": {
"glyphhanger": "./cmd.js"
},
"dependencies": {
"@zachleat/spider-pig": "^1.0.3",
"chalk": "^2.3.0",
"@zachleat/spider-pig": "^3.0.0",
"chalk": "^4.1.0",
"characterset": "^1.3.0",
"connect": "^3.6.6",
"debug": "^3.1.0",
"filesize": "^3.5.11",
"fs-extra": "^5.0.0",
"get-stdin": "^6.0.0",
"glob": "^7.1.2",
"jsdom": "^13.0.0",
"minimist": "^1.2.0",
"connect": "^3.7.0",
"debug": "^4.3.3",
"filesize": "^6.1.0",
"get-stdin": "^8.0.0",
"glob": "^7.2.0",
"jsdom": "^15.2.1",
"minimist": "^1.2.5",
"parse-filepath": "^1.0.2",
"rsvp": "^4.7.0",
"serve-static": "^1.13.2",
"shelljs": "^0.7.8"
"serve-static": "^1.14.1",
"shelljs": "^0.8.4"
},
"devDependencies": {
"mocha": "^4.0.1"
"mocha": "^8.3.1"
}
}
7 changes: 4 additions & 3 deletions src/GlyphHangerEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const chalk = require( "chalk" );
const path = require( "path" );
const fs = require( "fs-extra" );
const fs = require( "fs" );
const fsp = fs.promises;
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const puppeteer = require("puppeteer");
Expand All @@ -15,8 +16,8 @@ class EnvironmentScripts {
}

async read() {
this.characterset = await fs.readFile(this.charactersetPath, "utf-8");
this.glyphhanger = await fs.readFile(this.glyphhangerPath, "utf-8");
this.characterset = await fsp.readFile(this.charactersetPath, "utf8");
this.glyphhanger = await fsp.readFile(this.glyphhangerPath, "utf8");
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/GlyphHangerFontFace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const parsePath = require("parse-filepath");
const fs = require("fs-extra");
const fs = require("fs");
const path = require( "path" );
const pkg = require("../package.json");

Expand Down Expand Up @@ -78,10 +78,12 @@ ${content.join("\n")}
let outputDir = this.subset.getOutputDirectory();
for( let filePath of paths ) {
let parsed = parsePath(filePath);
let outputFile = path.join( outputDir || parsed.dir, parsed.name + ".css" );
let dir = outputDir || parsed.dir;
let outputFile = path.join( dir, parsed.name + ".css" );
console.log("Writing CSS file:", outputFile);
fs.outputFileSync(outputFile, `/* This file was automatically generated by GlyphHanger ${pkg.version} */
${this.toString(filePath, outputDir)}`, {"encoding": "utf-8"});
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(outputFile, `/* This file was automatically generated by GlyphHanger ${pkg.version} */
${this.toString(filePath, outputDir)}`, {"encoding": "utf8"});
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/GlyphHangerSubset.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class GlyphHangerSubset {
return this.outputDirectory;
}

setOutputSuffix( suffix ) {
if( suffix != null ) {
this.outputSuffix = suffix;
}
}

getOutputSuffix() {
return this.outputSuffix;
}

setFontFilesGlob( ttfFilesGlob ) {
this.fontPaths = glob.sync( ttfFilesGlob );
}
Expand Down Expand Up @@ -84,7 +94,8 @@ class GlyphHangerSubset {

getFilenameFromTTFPath( ttfPath, format, useZopfli ) {
var fontPath = parsePath( ttfPath );
var outputFilename = fontPath.name + "-subset" + ( useZopfli ? ".zopfli" : "" ) + ( format ? "." + format : fontPath.ext );
var suffix = this.getOutputSuffix();;
var outputFilename = fontPath.name + (suffix == null ? "-subset" : suffix) + ( useZopfli ? ".zopfli" : "" ) + ( format ? "." + format : fontPath.ext );
return outputFilename;
}

Expand Down
2 changes: 1 addition & 1 deletion src/GlyphHangerWhitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GlyphHangerWhitelist {
}

if( presets.LATIN ) {
cs = cs.union( CharacterSet.parseUnicodeRange("U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD" ));
cs = cs.union( CharacterSet.parseUnicodeRange("U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD" ));
}

if( typeof chars === "string" ) {
Expand Down