Comparing version 0.0.4 to 0.0.5
@@ -40,24 +40,22 @@ "use strict"; | ||
} | ||
const codeMap = {}; | ||
// 兼容 woff2 的解析 | ||
yield woff2.init(); | ||
const unicodeSet = new Set(); | ||
for (let i = 0; i < source.length; i++) { | ||
const s = source[i]; | ||
if (codeMap[s]) { | ||
const c = source.charCodeAt(i); | ||
if (unicodeSet.has(c)) { | ||
continue; | ||
} | ||
codeMap[s] = source.charCodeAt(i); | ||
unicodeSet.add(c); | ||
} | ||
// 兼容 woff2 的解析 | ||
yield woff2.init(); | ||
const unicodeSet = Object.values(codeMap); | ||
const sourceBuffer = yield fs.promises.readFile(fontpath); | ||
const font = Font.create(sourceBuffer, { | ||
type: path.extname(fontpath).replace('.', ''), | ||
subset: unicodeSet, | ||
subset: Array.from(unicodeSet), | ||
}); | ||
const map = {}; | ||
// 保证传进来的字符的编码顺序 | ||
for (let i = 0; i < unicodeSet.length; i++) { | ||
const fonts = font.find({ | ||
unicode: [unicodeSet[i]], | ||
}); | ||
let i = 0; | ||
for (let code of unicodeSet) { | ||
const fonts = font.find({ unicode: [code] }); | ||
const glyf = fonts[0]; | ||
@@ -68,2 +66,3 @@ const sourceUnicode = glyf.unicode[0]; | ||
map[String.fromCharCode(sourceUnicode)] = unicode; | ||
i++; | ||
} | ||
@@ -70,0 +69,0 @@ const output = {}; |
@@ -5,3 +5,3 @@ const path = require('path'); | ||
const fontpath = path.resolve(__dirname, '..', 'fonts', 'SourceHanSansCN-Regular.ttf'); | ||
const source = '的一了是我不在人们有来他这上着个地到大里说去子得也和那要下看天时过出小么起你都把好还多没为又可家学只以主会样年想能生同老中从自面前头到它后然走很像见两用她国动进成回什边作对开而已些现山民候经发工向事命给长水几义三声于高正妈手知理眼志点心战二问但身方实吃做叫当住听革打呢真党全才四已所敌之最光产情路分总条白话东席次亲如被花口放儿常西气五第使写军吧文运在果怎定许快明行因别飞外树物活部门无往船望新带队先力完间却站代员机更九您每风级跟笑啊孩万少直意夜比阶连车重便斗马哪化太指变社似士者干石满决百原拿群究各六本思解立河爸村八难早论吗根共让相研今其书坐接应关信觉死步反处记将千找争领或师结块跑谁草越字加脚紧爱等习阵怕月青半火法题建赶位唱海七女任件感准张团屋爷离色脸片科倒睛利世病刚且由送切星晚表够整认响雪流未场该并底深刻平伟忙提确近亮轻讲农古黑告界拉名呀土清阳照办史改历转画造嘴此治北必服雨穿父内识验传业菜爬睡兴'; | ||
const source = '12310的一了'; | ||
fontsub | ||
@@ -20,4 +20,4 @@ .genSubsetFont({ | ||
fs.writeFileSync('test/subset.woff', res.output.woff); | ||
console.log(fontsub.convert('呼吸科的朱倩倩一门心思的赚钱,开源节流节省的不是一般。在其他科室,只要转科医生用心,带教老师多多少少的会给点辛苦费,管饭、买水都是常规。刚入职的转科医生,就靠着一点死工资苦吧苦的死熬,也不是没钱吃饭,带教医生管饭、买水也是一种对转科医生的肯定和认可。', res.map)); | ||
console.log(fontsub.convert('12340呼吸科的朱倩倩一门心思的赚钱,开源节流节省的不是一般。在其他科室,只要转科医生用心,带教老师多多少少的会给点辛苦费,管饭、买水都是常规。刚入职的转科医生,就靠着一点死工资苦吧苦的死熬,也不是没钱吃饭,带教医生管饭、买水也是一种对转科医生的肯定和认可。', res.map)); | ||
}); | ||
//# sourceMappingURL=test.js.map |
{ | ||
"name": "fontsub", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "import font file and export .ttf ", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -44,26 +44,24 @@ import fs = require('fs') | ||
const codeMap = {} | ||
// 兼容 woff2 的解析 | ||
await woff2.init() | ||
const unicodeSet = new Set() | ||
for (let i = 0; i < source.length; i++) { | ||
const s = source[i] | ||
if (codeMap[s]) { | ||
const c = source.charCodeAt(i) | ||
if (unicodeSet.has(c)) { | ||
continue | ||
} | ||
codeMap[s] = source.charCodeAt(i) | ||
unicodeSet.add(c) | ||
} | ||
// 兼容 woff2 的解析 | ||
await woff2.init() | ||
const unicodeSet = Object.values(codeMap) | ||
const sourceBuffer = await fs.promises.readFile(fontpath) | ||
const font = Font.create(sourceBuffer, { | ||
type: path.extname(fontpath).replace('.', ''), | ||
subset: unicodeSet, | ||
subset: Array.from(unicodeSet), | ||
}) | ||
const map = {} | ||
// 保证传进来的字符的编码顺序 | ||
for (let i = 0; i < unicodeSet.length; i++) { | ||
const fonts = font.find({ | ||
unicode: [unicodeSet[i]], | ||
}) | ||
let i = 0 | ||
for (let code of unicodeSet) { | ||
const fonts = font.find({ unicode: [code] }) | ||
@@ -75,2 +73,3 @@ const glyf = fonts[0] | ||
map[String.fromCharCode(sourceUnicode)] = unicode | ||
i++ | ||
} | ||
@@ -77,0 +76,0 @@ |
@@ -10,4 +10,3 @@ const path = require('path') | ||
) | ||
const source = | ||
'的一了是我不在人们有来他这上着个地到大里说去子得也和那要下看天时过出小么起你都把好还多没为又可家学只以主会样年想能生同老中从自面前头到它后然走很像见两用她国动进成回什边作对开而已些现山民候经发工向事命给长水几义三声于高正妈手知理眼志点心战二问但身方实吃做叫当住听革打呢真党全才四已所敌之最光产情路分总条白话东席次亲如被花口放儿常西气五第使写军吧文运在果怎定许快明行因别飞外树物活部门无往船望新带队先力完间却站代员机更九您每风级跟笑啊孩万少直意夜比阶连车重便斗马哪化太指变社似士者干石满决百原拿群究各六本思解立河爸村八难早论吗根共让相研今其书坐接应关信觉死步反处记将千找争领或师结块跑谁草越字加脚紧爱等习阵怕月青半火法题建赶位唱海七女任件感准张团屋爷离色脸片科倒睛利世病刚且由送切星晚表够整认响雪流未场该并底深刻平伟忙提确近亮轻讲农古黑告界拉名呀土清阳照办史改历转画造嘴此治北必服雨穿父内识验传业菜爬睡兴' | ||
const source = '12310的一了' | ||
fontsub | ||
@@ -28,3 +27,3 @@ .genSubsetFont({ | ||
fontsub.convert( | ||
'呼吸科的朱倩倩一门心思的赚钱,开源节流节省的不是一般。在其他科室,只要转科医生用心,带教老师多多少少的会给点辛苦费,管饭、买水都是常规。刚入职的转科医生,就靠着一点死工资苦吧苦的死熬,也不是没钱吃饭,带教医生管饭、买水也是一种对转科医生的肯定和认可。', | ||
'12340呼吸科的朱倩倩一门心思的赚钱,开源节流节省的不是一般。在其他科室,只要转科医生用心,带教老师多多少少的会给点辛苦费,管饭、买水都是常规。刚入职的转科医生,就靠着一点死工资苦吧苦的死熬,也不是没钱吃饭,带教医生管饭、买水也是一种对转科医生的肯定和认可。', | ||
res.map | ||
@@ -31,0 +30,0 @@ ) |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
2
4
16554970
19
255