Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Mar 5, 2018
1 parent b74f2cc commit ec1b5d9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
2 changes: 2 additions & 0 deletions cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ if( argv.version ) {
if(!whitelist.isEmpty()) {
fontface.setUnicodeRange( whitelist.getWhitelistAsUnicodes());
}
fontface.writeCSSFiles();
fontface.output();
} catch(e) {
console.log("GlyphHangerFontFace Error: ", e);
Expand All @@ -134,6 +135,7 @@ if( argv.version ) {

try {
fontface.setUnicodeRange( whitelist.getWhitelistAsUnicodes());
fontface.writeCSSFiles();
fontface.output();
} catch(e) {
console.log("GlyphHangerFontFace Error: ", e);
Expand Down
2 changes: 1 addition & 1 deletion src/GlyphHangerFontFace.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GlyphHangerFontFace {
content.push(` src: ${this.getSrcDescriptor(ttfPath, outputDir || parsePath(ttfPath).dir)};`);
}

if( this.unicodeRange.trim() ) {
if( this.unicodeRange && this.unicodeRange.trim() ) {
content.push(` unicode-range: ${this.unicodeRange};`);
}

Expand Down
33 changes: 0 additions & 33 deletions test/cmdTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,36 +239,3 @@ describe( "CLI (css)", function() {
}`) > - 1);
});
});

//
// TODO glyphhanger --subset=*.ttf (file format conversion)
// DONE glyphhanger --subset=*.ttf --whitelist=ABCD (reduce to whitelist characters)
// TODO glyphhanger --subset=*.ttf --US_ASCII (reduce to US_ASCII characters)
// TODO glyphhanger --subset=*.ttf --US_ASCII --whitelist=ABCD (reduce to US_ASCII union with whitelist)

describe( "CLI (subset)", function() {
it( "Produced a file", function () {
// due to some unknown permission issue, this test fails on travis
if(process.env.TRAVIS) {
this.skip();
}

this.timeout( 10000 );

var fontPath = "test/fonts/sourcesanspro-regular.ttf";
// console.log( "__dirname:", __dirname );

let output = childProcess.execSync(`node cmd.js --whitelist=ABC --subset=${fontPath} --formats=ttf`, {
cwd: path.resolve(__dirname, "..")
});

// console.log( "childProcess output: ", output.toString() );

var subsetPath = fontPath.split( ".ttf" ).join( "-subset.ttf" );
// console.log("old fontPath: ", fontPath, " new fontpath: ", subsetPath);

var subset = fs.existsSync( subsetPath );
assert.ok( subset );
fs.unlinkSync( subsetPath );
});
});
56 changes: 56 additions & 0 deletions test/cmdTestSubset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var assert = require( "assert" );
var path = require( "path" );
var childProcess = require( "child_process" );
var fs = require( "fs" );

// TODO glyphhanger --subset=*.ttf (file format conversion)
// DONE glyphhanger --subset=*.ttf --whitelist=ABCD (reduce to whitelist characters)
// TODO glyphhanger --subset=*.ttf --US_ASCII (reduce to US_ASCII characters)
// TODO glyphhanger --subset=*.ttf --US_ASCII --whitelist=ABCD (reduce to US_ASCII union with whitelist)

describe( "CLI (subset)", function() {
it( "--subset --whitelist", function () {
// due to some unknown permission issue, this test fails on travis
if(process.env.TRAVIS) {
this.skip();
}

this.timeout( 10000 );

var fontPath = "test/fonts/sourcesanspro-regular.ttf";

let output = childProcess.execSync(`node cmd.js --whitelist=ABC --subset=${fontPath} --formats=ttf`, {
cwd: path.resolve(__dirname, "..")
});

var subsetPath = fontPath.split( ".ttf" ).join( "-subset.ttf" );

assert.ok( fs.existsSync( subsetPath ) );
fs.unlinkSync( subsetPath );
});

it( "--subset --whitelist --css", function () {
// due to some unknown permission issue, this test fails on travis
if(process.env.TRAVIS) {
this.skip();
}

this.timeout( 10000 );

var fontPath = "test/fonts/sourcesanspro-regular.ttf";

let output = childProcess.execSync(`node cmd.js --whitelist=ABC --subset=${fontPath} --formats=ttf --css`, {
cwd: path.resolve(__dirname, "..")
});

var subsetPath = fontPath.split( ".ttf" ).join( "-subset.ttf" );
assert.ok( fs.existsSync( subsetPath ) );
fs.unlinkSync( subsetPath );

var cssPath = fontPath.split( ".ttf" ).join( ".css" );
console.log( cssPath );

assert.ok( fs.existsSync( cssPath ) );
fs.unlinkSync( cssPath );
});
});

0 comments on commit ec1b5d9

Please sign in to comment.