Skip to content

Commit

Permalink
fix(opentype): remove Node impl
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Sep 26, 2023
1 parent 3e9f482 commit 9753e6b
Showing 1 changed file with 0 additions and 103 deletions.
103 changes: 0 additions & 103 deletions src/libs/opentype.js
Original file line number Diff line number Diff line change
Expand Up @@ -9264,30 +9264,6 @@ const { parseBuffer } = (() => {
return undefined
}

function isBrowser() {
return typeof window !== 'undefined'
}

function nodeBufferToArrayBuffer(buffer) {
var ab = new ArrayBuffer(buffer.length)
var view = new Uint8Array(ab)
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i]
}

return ab
}

function arrayBufferToNodeBuffer(ab) {
var buffer = new Buffer(ab.byteLength)
var view = new Uint8Array(ab)
for (var i = 0; i < buffer.length; ++i) {
buffer[i] = view[i]
}

return buffer
}

function checkArgument(expression, message) {
if (!expression) {
throw message
Expand Down Expand Up @@ -15222,38 +15198,6 @@ vim: set ts=4 sw=4 expandtab:
return buffer
}

/**
* Initiate a download of the OpenType font.
*/
Font.prototype.download = function (fileName) {
var familyName = this.getEnglishName('fontFamily')
var styleName = this.getEnglishName('fontSubfamily')
fileName = fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf'
var arrayBuffer = this.toArrayBuffer()

if (isBrowser()) {
window.URL = window.URL || window.webkitURL

if (window.URL) {
var dataView = new DataView(arrayBuffer)
var blob = new Blob([dataView], { type: 'font/opentype' })

var link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = fileName

var event = document.createEvent('MouseEvents')
event.initEvent('click', true, false)
link.dispatchEvent(event)
} else {
console.warn('Font file could not be downloaded. Try using a different browser.')
}
} else {
var fs = require('fs')
var buffer = arrayBufferToNodeBuffer(arrayBuffer)
fs.writeFileSync(fileName, buffer)
}
}
/**
* @private
*/
Expand Down Expand Up @@ -15734,53 +15678,6 @@ vim: set ts=4 sw=4 expandtab:

// opentype.js

/**
* The opentype library.
* @namespace opentype
*/

// File loaders /////////////////////////////////////////////////////////
/**
* Loads a font from a file. The callback throws an error message as the first parameter if it fails
* and the font as an ArrayBuffer in the second parameter if it succeeds.
* @param {string} path - The path of the file
* @param {Function} callback - The function to call when the font load completes
*/
function loadFromFile(path, callback) {
var fs = require('fs')
fs.readFile(path, function (err, buffer) {
if (err) {
return callback(err.message)
}

callback(null, nodeBufferToArrayBuffer(buffer))
})
}
/**
* Loads a font from a URL. The callback throws an error message as the first parameter if it fails
* and the font as an ArrayBuffer in the second parameter if it succeeds.
* @param {string} url - The URL of the font file.
* @param {Function} callback - The function to call when the font load completes
*/
function loadFromUrl(url, callback) {
var request = new XMLHttpRequest()
request.open('get', url, true)
request.responseType = 'arraybuffer'
request.onload = function () {
if (request.response) {
return callback(null, request.response)
} else {
return callback('Font could not be loaded: ' + request.statusText)
}
}

request.onerror = function () {
callback('Font could not be loaded')
}

request.send()
}

// Table Directory Entries //////////////////////////////////////////////
/**
* Parses OpenType table entries.
Expand Down

0 comments on commit 9753e6b

Please sign in to comment.