fix font issue

This commit is contained in:
daniel-j 2018-03-14 18:04:50 +01:00
parent cfefbdd76b
commit 0051da9862
6 changed files with 27 additions and 39 deletions

View file

@ -28,8 +28,7 @@
},
"web_accessible_resources": [
"fimfic2epub-logo.png",
"build/fonts/fontawesome-webfont.ttf"
"fimfic2epub-logo.png"
],
"permissions": [

View file

@ -7,7 +7,6 @@ import Sequence from 'run-sequence'
import watch from 'gulp-watch'
import lazypipe from 'lazypipe'
import filter from 'gulp-filter'
import merge from 'merge-stream'
import change from 'gulp-change'
import rename from 'gulp-rename'
import banner from 'gulp-banner'
@ -33,6 +32,8 @@ if (isStandalone) {
webpackConfig.shift()
webpackConfig.shift()
webpackConfig.shift()
} else {
webpackConfig.pop()
}
let watchOpts = {
@ -149,9 +150,7 @@ gulp.task('watch', (done) => {
})
gulp.task('fontawesome', () => {
let copy = gulp.src('node_modules/font-awesome/fonts/fontawesome-webfont.ttf')
.pipe(gulp.dest('extension/build/fonts/'))
let codes = gulp.src('node_modules/font-awesome/scss/_variables.scss')
return gulp.src('node_modules/font-awesome/scss/_variables.scss')
.pipe(change(convertFontAwesomeVars))
.pipe(rename({
basename: 'font-awesome-codes',
@ -159,7 +158,6 @@ gulp.task('fontawesome', () => {
dirname: ''
}))
.pipe(gulp.dest('build/'))
return merge(copy, codes)
})
gulp.task('pack', ['binaries'], (done) => {
sequence(['pack:firefox', 'pack:chrome'], done)

View file

@ -26,7 +26,6 @@
"detect-node": "^2.0.3",
"escape-string-regexp": "^1.0.5",
"file-type": "^7.2.0",
"font-awesome": "4.7.0",
"fonteditor-core": "^1.0.2",
"html-entities": "^1.2.0",
"html-to-text": "^4.0.0",
@ -54,9 +53,9 @@
"babel-register": "^6.26.0",
"binary-loader": "0.0.1",
"del": "^3.0.0",
"es6-event-emitter": "^1.10.2",
"exports-loader": "^0.7.0",
"file-saver": "^1.3.2",
"font-awesome": "4.7.0",
"gulp": "^3.9.1",
"gulp-banner": "^0.1.3",
"gulp-change": "^1.0.0",
@ -69,7 +68,6 @@
"gulp-watch": "^5.0.0",
"gulp-zip": "^4.0.0",
"lazypipe": "^1.0.1",
"merge-stream": "^1.0.1",
"raw-loader": "^0.5.1",
"run-sequence": "^2.2.0",
"standard": "^11.0.0",

View file

@ -1,4 +1,3 @@
/* global chrome */
import JSZip from 'jszip'
import escapeStringRegexp from 'escape-string-regexp'
@ -10,7 +9,7 @@ import isNode from 'detect-node'
import fileType from 'file-type'
import isSvg from 'is-svg'
import sizeOf from 'image-size'
import Emitter from 'es6-event-emitter'
import EventEmitter from 'events'
import { cleanMarkup } from './cleanMarkup'
import fetch from './fetch'
@ -27,7 +26,7 @@ const entities = new XmlEntities()
const trimWhitespace = /^\s*(<br\s*\/?\s*>)+|(<br\s*\/?\s*>)+\s*$/ig
class FimFic2Epub extends Emitter {
class FimFic2Epub extends EventEmitter {
static getStoryId (id) {
if (isNaN(id)) {
let url = URL.parse(id, false, true)
@ -547,7 +546,7 @@ class FimFic2Epub extends Emitter {
// let partsize = 1 / parts
// percent = (part / parts) + percent * partsize
try {
this.trigger('progress', percent, status)
this.emit('progress', percent, status)
} catch (err) {
console.error(err)
}
@ -608,13 +607,8 @@ class FimFic2Epub extends Emitter {
let glyphs = [...this.usedIcons].map((name) => {
return fontAwesomeCodes[name].charCodeAt(0)
})
let fontPath
if (!isNode) {
fontPath = chrome.extension.getURL('build/fonts/fontawesome-webfont.ttf')
} else {
fontPath = require('font-awesome/fonts/fontawesome-webfont.ttf') // resolve the path, see webpack config
}
this.iconsFont = await subsetFont(fontPath, glyphs, {local: isNode})
let fontFile = require('font-awesome/fonts/fontawesome-webfont.ttf')
this.iconsFont = await subsetFont(fontFile, glyphs, {local: isNode})
}
iconsStyle () {

View file

@ -7,13 +7,13 @@ import fileType from 'file-type'
async function subsetFont (fontPath, glyphs, options = {}) {
let data
if (!isNode || !options.local) {
data = await fetch(fontPath, 'arraybuffer')
let fontdata = Buffer.from(fontPath, 'binary')
let type = fileType(fontdata)
if (type && type.mime === 'font/ttf') {
data = fontdata
} else {
let fontdata = Buffer.from(fontPath, 'binary')
let type = fileType(fontdata)
if (type && type.mime === 'font/ttf') {
data = fontdata
if (!isNode || !options.local) {
data = await fetch(fontPath, 'arraybuffer')
} else {
data = await new Promise((resolve, reject) => {
fs.readFile(fontPath, (err, data) => {

View file

@ -1,5 +1,4 @@
import webpack from 'webpack'
import path from 'path'
import nodeExternals from 'webpack-node-externals'
@ -30,6 +29,10 @@ const bundleExtensionConfig = {
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
},
{
test: /\.ttf$/,
use: 'binary-loader'
}
]
},
@ -50,7 +53,6 @@ const bundleExtensionConfig = {
plugins: [
// new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)()
new webpack.NormalModuleReplacementPlugin(/font-awesome\/fonts\/fontawesome-webfont\.ttf/, './false')
],
performance: {
hints: false
@ -92,6 +94,10 @@ const bundleNpmModuleConfig = {
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
},
{
test: /\.ttf$/,
use: 'binary-loader'
}
]
},
@ -108,9 +114,7 @@ const bundleNpmModuleConfig = {
__dirname: false
},
externals: [nodeExternals({whitelist: ['es6-event-emitter', /^babel-runtime/]}), {
'font-awesome/fonts/fontawesome-webfont.ttf': 'require.resolve(\'font-awesome/fonts/fontawesome-webfont.ttf\')'
}],
externals: [nodeExternals({whitelist: [/^babel-runtime/, /fontawesome-webfont\.ttf/]})],
plugins: [],
performance: {
@ -148,16 +152,12 @@ const bundleNpmBinaryConfig = {
}
}]]
}
},
{
test: /\.styl$/,
use: ['raw-loader', 'stylus-loader']
}
]
},
resolve: {
extensions: ['.js', '.json', '.styl'],
extensions: ['.js', '.json'],
modules: [
path.resolve('./src'),
'node_modules'
@ -170,8 +170,7 @@ const bundleNpmBinaryConfig = {
externals: [nodeExternals(), {
'./FimFic2Epub': 'require(\'../dist/fimfic2epub\')',
'../package.json': 'require(\'../package.json\')',
'font-awesome/fonts/fontawesome-webfont.ttf': 'require.resolve(\'font-awesome/fonts/fontawesome-webfont.ttf\')'
'../package.json': 'require(\'../package.json\')'
}],
plugins: [],