Commit 8ec93d8f authored by Alexandros Georgantas's avatar Alexandros Georgantas

Fonts support added

parent 778adea0
......@@ -16,6 +16,7 @@ class HTMLEPUB {
this.xhtml = []
this.images = []
this.styles = []
this.fonts = []
}
load (items) {
......@@ -38,6 +39,18 @@ class HTMLEPUB {
stream (outputStream) {
const epub = this
const fontsRoot = epub.options.fontsRoot.replace(/\/?$/, '/') // ensure trailing slash
if (fontsRoot !== '') {
fs.readdirSync(fontsRoot).forEach(file => {
const source = `${process.cwd()}/static/fonts/${file}`
const target = `styles/fonts/${file}`
const mimetype = 'application/vnd.ms-opentype'
const id = file
epub.fonts.push({ id, source, mimetype, target })
})
}
return new Promise((resolve, reject) => {
const archive = archiver('zip')
......@@ -99,7 +112,8 @@ class HTMLEPUB {
Promise.all(epub.images.map(appendFile)),
// EPUB/styles/* - the styles
Promise.all(epub.styles.map(appendFile))
Promise.all(epub.styles.map(appendFile)),
Promise.all(epub.fonts.map(appendFile))
]).then(() => {
archive.finalize()
......@@ -201,6 +215,7 @@ class HTMLEPUB {
}
}
$node.attr('href', '../' + target)
})
}
......@@ -330,6 +345,14 @@ class HTMLEPUB {
})
})
this.fonts.forEach(file => {
item.push({
'@id': file.id,
'@href': file.target,
'@media-type': file.mimetype
})
})
return { item }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment