diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..22762c3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Main Process", + "type": "node", + "request": "launch", + "cwd": "${workspaceRoot}", + "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", + "windows": { + "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" + }, + "args" : ["."] + } + ] + } \ No newline at end of file diff --git a/fixtures/TheGodfather-v2.ttf b/fixtures/foo.ttf similarity index 100% rename from fixtures/TheGodfather-v2.ttf rename to fixtures/foo.ttf diff --git a/lib/__tests__/font.test.ts b/lib/__tests__/font.test.ts index 7040792..42eab17 100644 --- a/lib/__tests__/font.test.ts +++ b/lib/__tests__/font.test.ts @@ -20,3 +20,9 @@ it('should have an extension', () => { const svg = new WOFF2(fontPath) expect(svg.ext).toBe('woff2') }) + +it('should have a human font name', () => { + expect(fc.fontNameHuman).not.toBeUndefined() + expect(fc.fontNameHuman).not.toEqual(null) + fc.cleanup() +}) diff --git a/lib/css.ts b/lib/css.ts new file mode 100644 index 0000000..9c658bc --- /dev/null +++ b/lib/css.ts @@ -0,0 +1,26 @@ +import { + Font +} from './font' +import * as fs from 'fs' + +export class CSS extends Font { + + export () { + const nameWithoutExt = this.nameWithoutExt + const fontNameHuman = this.fontNameHuman + + const cssOutput = ` +@font-face { + font-family:"${fontNameHuman}"; + src:url("${nameWithoutExt}.woff2") format("woff2"),url("${nameWithoutExt}.woff") format("woff"),url("${nameWithoutExt}.otf") format("opentype"); + font-style:normal;font-weight:400; + } + ` + fs.writeFileSync(this.outFile, cssOutput) + } + + get ext() { + return 'css' + } + +} diff --git a/lib/font-collection.ts b/lib/font-collection.ts index 4e17ee0..5b56cef 100644 --- a/lib/font-collection.ts +++ b/lib/font-collection.ts @@ -2,6 +2,7 @@ import { Font } from './font' import { TTF } from './ttf' import { WOFF } from './woff' import { WOFF2 } from './woff2' +import { CSS } from './css' import * as rimraf from 'rimraf' @@ -20,6 +21,7 @@ export class FontCollection extends Font { new TTF(path).export() new WOFF(path).export() new WOFF2(path).export() + new CSS(path).export() this.cleanupOrphansIfNecessary() } diff --git a/lib/font.ts b/lib/font.ts index 50286fd..b992728 100644 --- a/lib/font.ts +++ b/lib/font.ts @@ -22,11 +22,16 @@ export class Font { } } - export () { + readFont () { const inBuffer = fs.readFileSync(this.ttfPath) - const font = FontEditorCore.Font.create(inBuffer, { + return FontEditorCore.Font.create(inBuffer, { type: 'ttf' }) + } + + export () { + + const font = this.readFont() const outBuffer = font.write({ type: this.ext, @@ -65,6 +70,10 @@ export class Font { return path.parse(this.basename).name } + get fontNameHuman () { + return this.readFont().data.name.fullName || this.nameWithoutExt + } + get isTTF () { return path.parse(this.filePath).ext === '.ttf' }