diff --git a/.gitignore b/.gitignore index 38e62aa..0942b0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -test/fonts/ignored \ No newline at end of file +test/fonts/ignored +package-lock.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c984685 --- /dev/null +++ b/CHANGELOG.md @@ -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/ \ No newline at end of file diff --git a/README.md b/README.md index 6d58718..f36e9ef 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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) \ No newline at end of file +* [subfont from Peter Müller](https://www.npmjs.com/package/subfont) diff --git a/cmd.js b/cmd.js index ec2ab86..307d302 100755 --- a/cmd.js +++ b/cmd.js @@ -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 ); diff --git a/package.json b/package.json index b9f610f..bd5f629 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "glyphhanger", - "version": "3.2.0", + "version": "5.0.0", "description": "A tool to ease webfont subsetting.", "main": "src/GlyphHanger.js", "scripts": { @@ -8,39 +8,37 @@ }, "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" } } diff --git a/src/GlyphHangerEnvironment.js b/src/GlyphHangerEnvironment.js index 3d0bed6..8381541 100644 --- a/src/GlyphHangerEnvironment.js +++ b/src/GlyphHangerEnvironment.js @@ -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"); @@ -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"); } } diff --git a/src/GlyphHangerFontFace.js b/src/GlyphHangerFontFace.js index b724f2f..03173f2 100644 --- a/src/GlyphHangerFontFace.js +++ b/src/GlyphHangerFontFace.js @@ -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"); @@ -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"}); } } diff --git a/src/GlyphHangerSubset.js b/src/GlyphHangerSubset.js index ea9c3fa..7621500 100644 --- a/src/GlyphHangerSubset.js +++ b/src/GlyphHangerSubset.js @@ -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 ); } @@ -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; } diff --git a/src/GlyphHangerWhitelist.js b/src/GlyphHangerWhitelist.js index fbaede0..80c5143 100644 --- a/src/GlyphHangerWhitelist.js +++ b/src/GlyphHangerWhitelist.js @@ -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" ) {