ttf2eot
Advanced tools
Comparing version 1.2.0 to 1.3.0
117
index.js
@@ -9,2 +9,3 @@ /* | ||
var ByteBuffer = require('./lib/byte_buffer.js'); | ||
@@ -90,11 +91,11 @@ /** | ||
function strbuf(str) { | ||
var b = new Buffer (str.length + 4); | ||
var b = new ByteBuffer(new Array(str.length + 4)); | ||
b.writeUInt16LE (str.length, 0); | ||
b.setUint16 (0, str.length, true); | ||
for (var i = 0; i < str.length; i += 2) { | ||
b.writeUInt16LE (str.readUInt16BE (i), i+2); | ||
b.setUint16 (i+2, str.getUint16 (i), true); | ||
} | ||
b.writeUInt16LE (0, b.length - 2); | ||
b.setUint16 (b.length - 2, 0, true); | ||
@@ -104,16 +105,23 @@ return b; | ||
function ttf2eot(buf) { | ||
var out = new Buffer (SIZEOF.EOT_PREFIX) | ||
// Takes TTF font on input and returns ByteBuffer with EOT font | ||
// | ||
// Params: | ||
// | ||
// - arr(Array|Uint8Array) | ||
// | ||
function ttf2eot(arr) { | ||
var buf = new ByteBuffer(arr); | ||
var out = new ByteBuffer(new Array(SIZEOF.EOT_PREFIX)) | ||
, i, j; | ||
out.fill(0); | ||
out.writeUInt32LE(buf.length, EOT_OFFSET.FONT_LENGTH); | ||
out.writeUInt32LE(MAGIC.EOT_VERSION, EOT_OFFSET.VERSION); | ||
out.writeUInt8(MAGIC.EOT_CHARSET, EOT_OFFSET.CHARSET); | ||
out.writeUInt16LE(MAGIC.EOT_MAGIC, EOT_OFFSET.MAGIC); | ||
out.setUint32(EOT_OFFSET.FONT_LENGTH, buf.length, true); | ||
out.setUint32(EOT_OFFSET.VERSION, MAGIC.EOT_VERSION, true); | ||
out.setUint8(EOT_OFFSET.CHARSET, MAGIC.EOT_CHARSET); | ||
out.setUint16(EOT_OFFSET.MAGIC, MAGIC.EOT_MAGIC, true); | ||
var familyName = '' | ||
, subfamilyName = '' | ||
, fullName = '' | ||
, versionString = '' | ||
var familyName = [] | ||
, subfamilyName = [] | ||
, fullName = [] | ||
, versionString = [] | ||
; | ||
@@ -126,14 +134,14 @@ | ||
var numTables = buf.readUInt16BE (SFNT_OFFSET.NUMTABLES); | ||
var numTables = buf.getUint16 (SFNT_OFFSET.NUMTABLES); | ||
for (i = 0; i < numTables; ++i) | ||
{ | ||
var data = buf.slice (SIZEOF.SFNT_HEADER + i*SIZEOF.SFNT_TABLE_ENTRY); | ||
var data = new ByteBuffer(buf, SIZEOF.SFNT_HEADER + i*SIZEOF.SFNT_TABLE_ENTRY); | ||
var tableEntry = { | ||
tag: data.toString ('ascii', SFNT_OFFSET.TABLE_TAG, SFNT_OFFSET.TABLE_TAG + 4), | ||
offset: data.readUInt32BE (SFNT_OFFSET.TABLE_OFFSET), | ||
length: data.readUInt32BE (SFNT_OFFSET.TABLE_LENGTH) | ||
tag: data.toString (SFNT_OFFSET.TABLE_TAG, SFNT_OFFSET.TABLE_TAG + 4), | ||
offset: data.getUint32 (SFNT_OFFSET.TABLE_OFFSET), | ||
length: data.getUint32 (SFNT_OFFSET.TABLE_LENGTH) | ||
}; | ||
var table = buf.slice (tableEntry.offset, tableEntry.offset + tableEntry.length); | ||
var table = new ByteBuffer(buf, tableEntry.offset, tableEntry.length); | ||
@@ -144,15 +152,15 @@ if (tableEntry.tag === 'OS/2') { | ||
for (j = 0; j < 10; ++j) { | ||
out.writeUInt8 (table.readUInt8 (SFNT_OFFSET.OS2_FONT_PANOSE + j), EOT_OFFSET.FONT_PANOSE + j); | ||
out.setUint8 (EOT_OFFSET.FONT_PANOSE + j, table.getUint8 (SFNT_OFFSET.OS2_FONT_PANOSE + j)); | ||
} | ||
/*jshint bitwise:false */ | ||
out.writeUInt8 (table.readUInt16BE (SFNT_OFFSET.OS2_FS_SELECTION) & 0x01, EOT_OFFSET.ITALIC); | ||
out.writeUInt32LE (table.readUInt16BE (SFNT_OFFSET.OS2_WEIGHT), EOT_OFFSET.WEIGHT); | ||
out.setUint8 (EOT_OFFSET.ITALIC, table.getUint16 (SFNT_OFFSET.OS2_FS_SELECTION) & 0x01); | ||
out.setUint32 (EOT_OFFSET.WEIGHT, table.getUint16 (SFNT_OFFSET.OS2_WEIGHT), true); | ||
for (j = 0; j < 4; ++j) { | ||
out.writeUInt32LE (table.readUInt32BE (SFNT_OFFSET.OS2_UNICODE_RANGE + j*4), EOT_OFFSET.UNICODE_RANGE + j*4); | ||
out.setUint32 (EOT_OFFSET.UNICODE_RANGE + j*4, table.getUint32 (SFNT_OFFSET.OS2_UNICODE_RANGE + j*4), true); | ||
} | ||
for (j = 0; j < 2; ++j) { | ||
out.writeUInt32LE (table.readUInt32BE (SFNT_OFFSET.OS2_CODEPAGE_RANGE + j*4), EOT_OFFSET.CODEPAGE_RANGE + j*4); | ||
out.setUint32 (EOT_OFFSET.CODEPAGE_RANGE + j*4, table.getUint32 (SFNT_OFFSET.OS2_CODEPAGE_RANGE + j*4), true); | ||
} | ||
@@ -163,3 +171,3 @@ | ||
haveHead = true; | ||
out.writeUInt32LE (table.readUInt32BE (SFNT_OFFSET.HEAD_CHECKSUM_ADJUSTMENT), EOT_OFFSET.CHECKSUM_ADJUSTMENT); | ||
out.setUint32 (EOT_OFFSET.CHECKSUM_ADJUSTMENT, table.getUint32 (SFNT_OFFSET.HEAD_CHECKSUM_ADJUSTMENT), true); | ||
@@ -171,20 +179,20 @@ } else if (tableEntry.tag === 'name') { | ||
var nameTable = { | ||
format: table.readUInt16BE (SFNT_OFFSET.NAMETABLE_FORMAT) | ||
, count: table.readUInt16BE (SFNT_OFFSET.NAMETABLE_COUNT) | ||
, stringOffset: table.readUInt16BE (SFNT_OFFSET.NAMETABLE_STRING_OFFSET) | ||
format: table.getUint16 (SFNT_OFFSET.NAMETABLE_FORMAT) | ||
, count: table.getUint16 (SFNT_OFFSET.NAMETABLE_COUNT) | ||
, stringOffset: table.getUint16 (SFNT_OFFSET.NAMETABLE_STRING_OFFSET) | ||
}; | ||
for (j = 0; j < nameTable.count; ++j) { | ||
var nameRecord = table.slice (SIZEOF.SFNT_NAMETABLE + j*SIZEOF.SFNT_NAMETABLE_ENTRY); | ||
var nameRecord = new ByteBuffer(table, SIZEOF.SFNT_NAMETABLE + j*SIZEOF.SFNT_NAMETABLE_ENTRY); | ||
var name = { | ||
platformID: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_PLATFORM_ID) | ||
, encodingID: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_ENCODING_ID) | ||
, languageID: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_LANGUAGE_ID) | ||
, nameID: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_NAME_ID) | ||
, length: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_LENGTH) | ||
, offset: nameRecord.readUInt16BE (SFNT_OFFSET.NAME_OFFSET) | ||
platformID: nameRecord.getUint16 (SFNT_OFFSET.NAME_PLATFORM_ID) | ||
, encodingID: nameRecord.getUint16 (SFNT_OFFSET.NAME_ENCODING_ID) | ||
, languageID: nameRecord.getUint16 (SFNT_OFFSET.NAME_LANGUAGE_ID) | ||
, nameID: nameRecord.getUint16 (SFNT_OFFSET.NAME_NAME_ID) | ||
, length: nameRecord.getUint16 (SFNT_OFFSET.NAME_LENGTH) | ||
, offset: nameRecord.getUint16 (SFNT_OFFSET.NAME_OFFSET) | ||
}; | ||
if (name.platformID === 3 && name.encodingID === 1 && name.languageID === MAGIC.LANGUAGE_ENGLISH) { | ||
var s = strbuf (table.slice (nameTable.stringOffset + name.offset, nameTable.stringOffset + name.offset + name.length)); | ||
var s = strbuf (new ByteBuffer(table, nameTable.stringOffset + name.offset, name.length)); | ||
@@ -215,19 +223,28 @@ switch (name.nameID) { | ||
out = Buffer.concat ([ | ||
out, | ||
familyName, | ||
subfamilyName, | ||
versionString, | ||
fullName, | ||
new Buffer([0, 0]) // padding | ||
]); | ||
// Calculate final length | ||
var len = | ||
out.length + | ||
familyName.length + | ||
subfamilyName.length + | ||
versionString.length + | ||
fullName.length + | ||
2 + | ||
buf.length; | ||
out.writeUInt32LE(out.length + buf.length, EOT_OFFSET.LENGTH); // Calculate overall length | ||
// Create final buffer with the the same array type as input one. | ||
var eot = new ByteBuffer(Array.isArray(arr) ? new Array(len) : new Uint8Array(len)); | ||
return Buffer.concat ([ | ||
out, | ||
buf | ||
]); | ||
eot.writeBytes(out.buffer); | ||
eot.writeBytes(familyName.buffer); | ||
eot.writeBytes(subfamilyName.buffer); | ||
eot.writeBytes(versionString.buffer); | ||
eot.writeBytes(fullName.buffer); | ||
eot.writeBytes([0, 0]); | ||
eot.writeBytes(buf.buffer); | ||
eot.setUint32(EOT_OFFSET.LENGTH, len, true); // Calculate overall length | ||
return eot; | ||
} | ||
module.exports = ttf2eot; |
{ | ||
"name" : "ttf2eot", | ||
"version" : "1.2.0", | ||
"version" : "1.3.0", | ||
@@ -15,10 +15,11 @@ "description" : "Convert TTF font to EOT", | ||
"bugs" : { "url": "https://github.com/fontello/ttf2eot/issues" }, | ||
"licenses" : [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/fontello/ttf2eot/raw/master/LICENSE" | ||
} | ||
], | ||
"dependencies" : { "argparse": "~0.1.12" }, | ||
"dependencies" : { "argparse": "~0.1.15" }, | ||
"license" : { | ||
"type": "MIT", | ||
"url": "https://github.com/fontello/ttf2eot/blob/master/LICENSE" | ||
}, | ||
"repository" : { | ||
@@ -33,11 +34,4 @@ "type": "git", | ||
"ttf2eot": "./ttf2eot.js" | ||
}, | ||
"licenses" : [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/fontello/ttf2eot/raw/master/LICENSE" | ||
} | ||
] | ||
} | ||
} | ||
@@ -5,6 +5,7 @@ ttf2eot | ||
ttf2eot converts TTF fonts to EOT format. That can be useful for different | ||
webfont generation tools. This is node.js port of | ||
[ttf2eot](http://code.google.com/p/ttf2eot/). | ||
webfont generation tools. | ||
This is node.js port of [ttf2eot](http://code.google.com/p/ttf2eot/). | ||
Usage | ||
@@ -22,3 +23,3 @@ ----- | ||
``` bash | ||
ttf2eot fontello.ttf fontello.oet | ||
ttf2eot fontello.ttf fontello.eot | ||
``` | ||
@@ -29,3 +30,3 @@ | ||
``` bash | ||
ttf2eot < fontello.ttf > fontello.oet | ||
ttf2eot < fontello.ttf > fontello.eot | ||
``` | ||
@@ -32,0 +33,0 @@ |
@@ -40,11 +40,11 @@ #!/usr/bin/env node | ||
var ttf, size; | ||
var input, size; | ||
try { | ||
if (args.infile) { | ||
ttf = fs.readFileSync(args.infile); | ||
input = fs.readFileSync(args.infile); | ||
} else { | ||
size = fs.fstatSync(process.stdin.fd).size; | ||
ttf = new Buffer(size); | ||
fs.readSync(process.stdin.fd, ttf, 0, size, 0); | ||
input = new Buffer(size); | ||
fs.readSync(process.stdin.fd, input, 0, size, 0); | ||
} | ||
@@ -56,3 +56,4 @@ } catch(e) { | ||
var eot = ttf2eot(ttf); | ||
var ttf = new Uint8Array(input); | ||
var eot = new Buffer(ttf2eot(ttf).buffer); | ||
@@ -59,0 +60,0 @@ if (args.outfile) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22795
11
413
55
0
Updatedargparse@~0.1.15