Skip to content

Commit

Permalink
Merge pull request #20 from matthewgonzalez/feature/output-css
Browse files Browse the repository at this point in the history
generate css file
  • Loading branch information
briangonzalez authored Nov 27, 2017
2 parents 38c4204 + 60bd170 commit 4460e5e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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" : ["."]
}
]
}
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/__tests__/font.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
26 changes: 26 additions & 0 deletions lib/css.ts
Original file line number Diff line number Diff line change
@@ -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'
}

}
2 changes: 2 additions & 0 deletions lib/font-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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()
}
Expand Down
13 changes: 11 additions & 2 deletions lib/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit 4460e5e

Please sign in to comment.