Skip to content

Commit

Permalink
feat: support index.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kekee000 committed Oct 14, 2020
1 parent aa54155 commit 21e27b7
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 19 deletions.
424 changes: 424 additions & 0 deletions index.d.ts

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fonteditor-core",
"version": "2.1.2",
"version": "2.1.3",
"description": "fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.",
"keywords": [
"sfnt",
Expand Down Expand Up @@ -60,11 +60,13 @@
"url": "git://github.com/kekee000/fonteditor-core.git"
},
"files": [
"index.d.ts",
"lib",
"src",
"woff2"
],
"main": "./lib/main.js",
"module": "./src/main.js",
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
Expand Down
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import ttftowoff2 from './ttf/ttftowoff2';
import woff2tottf from './ttf/woff2tottf';
import woff2 from '../woff2/index';

export {Font};
export {woff2};

const modules = {
Font,
TTF,
Expand All @@ -46,6 +49,7 @@ const modules = {
};

export default modules;

if (typeof exports !== 'undefined') {
// eslint-disable-next-line import/no-commonjs
module.exports = modules;
Expand Down
2 changes: 1 addition & 1 deletion src/ttf/data/empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
"numTables": 10,
"searchRenge": 128,
"entrySelector": 3,
"rengeShift": 64,
"rangeShift": 64,
"head": {
"version": 1,
"fontRevision": 1,
Expand Down
6 changes: 3 additions & 3 deletions src/ttf/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class Font {
* @param {boolean} options.compound2simple 复合字形转简单字形
*
* woff 读取配置
* @param {Object} options.inflate 解压相关函数
* @param {Function} options.inflate 解压相关函数
*
* svg 读取配置
* @param {boolean} options.combinePath 是否合并成单个字形,仅限于普通svg导入
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class Font {
* @param {Object} options.metadata 字体相关的信息
*
* woff 字体参数
* @param {Object} options.deflate 压缩相关函数
* @param {Function} options.deflate 压缩相关函数
* @return {Buffer|ArrayBuffer|string}
*/
write(options = {}) {
Expand Down Expand Up @@ -192,7 +192,7 @@ export default class Font {
* @see write
*
* @param {ArrayBuffer} buffer 如果提供了buffer数据则使用 buffer数据, 否则转换现有的 font
* @return {Buffer|ArrayBuffer|string}
* @return {string}
*/
toBase64(options, buffer) {
if (!options.type) {
Expand Down
4 changes: 2 additions & 2 deletions src/ttf/otfreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default class OTFReader {
// entrySelector
font.entrySelector = reader.readUint16();

// rengeShift
font.rengeShift = reader.readUint16();
// rangeShift
font.rangeShift = reader.readUint16();

font.tables = new Directory(reader.offset).read(reader, font);

Expand Down
2 changes: 1 addition & 1 deletion src/ttf/ttf2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const GLYPH_TPL = '<glyph glyph-name="${name}" unicode="${unicode}" d="${d}" />'
*
* @param {ttfObject} ttf ttfObject对象
* @param {Object} options 选项
* @param {Object} options.metadata 字体相关的信息
* @param {string} options.metadata 字体相关的信息
* @return {string} svg字符串
*/
function ttfobject2svg(ttf, options) {
Expand Down
4 changes: 2 additions & 2 deletions src/ttf/ttfreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export default class TTFReader {
// entrySelector
ttf.entrySelector = reader.readUint16();

// rengeShift
ttf.rengeShift = reader.readUint16();
// rangeShift
ttf.rangeShift = reader.readUint16();

ttf.tables = new Directory(reader.offset).read(reader, ttf);

Expand Down
4 changes: 2 additions & 2 deletions test/spec/ttf/font.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('读otf数据', function () {
it('test read otf', function () {
assert.equal(font.data.version, 0x1);
assert.equal(font.data.numTables, 9);
assert.equal(font.data.rengeShift, 16);
assert.equal(font.data.rangeShift, 16);
assert.equal(font.data.searchRenge, 128);
});
});
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('写woff2数据', function () {
assert.ok(buffer.byteLength > 1000);
assert.ok(buffer.byteLength < 10000);
});

let font = Font.create(buffer, {
type: 'woff2'
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/ttf/otfreader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('读otf数据', function () {
it('test read otf', function () {
assert.equal(fontObject.version, 'OTTO');
assert.equal(fontObject.numTables, 9);
assert.equal(fontObject.rengeShift, 16);
assert.equal(fontObject.rangeShift, 16);
assert.equal(fontObject.searchRenge, 128);
});

Expand Down
2 changes: 1 addition & 1 deletion test/spec/ttf/ttfreader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('读ttf数据', function () {
it('test read ttf', function () {
assert.equal(fontObject.version, 1);
assert.equal(fontObject.numTables, 15);
assert.equal(fontObject.rengeShift, 112);
assert.equal(fontObject.rangeShift, 112);
assert.equal(fontObject.searchRenge, 128);
});

Expand Down
11 changes: 6 additions & 5 deletions woff2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
* https://github.com/alimilhim/woff2-wasm
* @author mengke01([email protected])
*/
/* eslint-disable fecs-camel-case */

function convertFromVecToUint8Array(vector) {
let arr = [];
const arr = [];
for (let i = 0, l = vector.size(); i < l; i++) {
arr.push(vector.get(i));
}
return new Uint8Array(arr);
}


// eslint-disable-next-line import/no-commonjs
module.exports = {

woff2Module: null,

/**
Expand All @@ -36,7 +37,7 @@ module.exports = {
* @return {Promise}
*/
init(wasmUrl) {
return new Promise((resolve, reject) => {
return new Promise(resolve => {
if (this.woff2Module) {
resolve(this);
return;
Expand Down Expand Up @@ -76,7 +77,7 @@ module.exports = {
* @return {Uint8Array} uint8 array
*/
encode(ttfBuffer) {
let buffer = new Uint8Array(ttfBuffer);
const buffer = new Uint8Array(ttfBuffer);
const woffbuff = this.woff2Module.woff2Enc(buffer, buffer.byteLength);
return convertFromVecToUint8Array(woffbuff);
},
Expand All @@ -88,7 +89,7 @@ module.exports = {
* @return {Uint8Array} uint8 array
*/
decode(woff2Buffer) {
let buffer = new Uint8Array(woff2Buffer);
const buffer = new Uint8Array(woff2Buffer);
const ttfbuff = this.woff2Module.woff2Dec(buffer, buffer.byteLength);
return convertFromVecToUint8Array(ttfbuff);
}
Expand Down

0 comments on commit 21e27b7

Please sign in to comment.