diff --git a/output/DIMSymbols.woff2 b/output/DIMSymbols.woff2 index 87b7a887..03f065dc 100644 Binary files a/output/DIMSymbols.woff2 and b/output/DIMSymbols.woff2 differ diff --git a/package.json b/package.json index 1f99cd83..0042db07 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,6 @@ "@types/node": "^20.14.2", "@types/opentype.js": "^1.3.8", "@types/stringify-object": "^4.0.5", - "@types/svg2ttf": "^5.0.3", - "@types/ttf2woff": "^2.0.4", "@types/ttf2woff2": "^2.0.2", "@typescript-eslint/eslint-plugin": "^7.13.0", "@typescript-eslint/parser": "^7.13.0", @@ -58,8 +56,6 @@ "pretty-quick": "^4.0.0", "resolve-tspaths": "^0.8.19", "stringify-object": "^5.0.0", - "svg2ttf": "^6.0.3", - "ttf2woff": "^3.0.0", "ttf2woff2": "^5.0.0", "typescript": "^5.4.5", "webfont": "^11.2.26" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9685c1cf..18b0d26f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,12 +23,6 @@ devDependencies: '@types/stringify-object': specifier: ^4.0.5 version: 4.0.5 - '@types/svg2ttf': - specifier: ^5.0.3 - version: 5.0.3 - '@types/ttf2woff': - specifier: ^2.0.4 - version: 2.0.4 '@types/ttf2woff2': specifier: ^2.0.2 version: 2.0.2 @@ -86,12 +80,6 @@ devDependencies: stringify-object: specifier: ^5.0.0 version: 5.0.0 - svg2ttf: - specifier: ^6.0.3 - version: 6.0.3 - ttf2woff: - specifier: ^3.0.0 - version: 3.0.0 ttf2woff2: specifier: ^5.0.0 version: 5.0.0 @@ -321,22 +309,12 @@ packages: resolution: {integrity: sha512-TzX5V+njkbJ8iJ0mrj+Vqveep/1JBH4SSA3J2wYrE1eUrOhdsjTBCb0kao4EquSQ8KgPpqY4zSVP2vCPWKBElg==} dev: true - /@types/svg2ttf@5.0.3: - resolution: {integrity: sha512-hL+/A4qMISvDbDTtdY73R0zuvsdc7YRYnV5FyAfKVGk8OsluXu/tCFxop7IB5Sgr+ZCS0hHtFxylD0REmm+abA==} - dev: true - /@types/ttf2woff2@2.0.2: resolution: {integrity: sha512-C9bkZUNpJFp64YD2IO0J2Y0R2EQiM2gvBr2KeVngFOQtKLDyYp7t5biNfkYyBbxDiJXwZFkzBs7jJtpoF0pzlw==} dependencies: '@types/node': 20.14.2 dev: true - /@types/ttf2woff@2.0.4: - resolution: {integrity: sha512-pD66iwSkU5lIMWWTz5sxIMjwM7/qs/EYgE01vqu5C3S1izONHiF1GRy2dWvlKMlC39TfZszP7+OVXgVk3BccOg==} - dependencies: - '@types/node': 20.14.2 - dev: true - /@typescript-eslint/eslint-plugin@7.13.0(@typescript-eslint/parser@7.13.0)(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-FX1X6AF0w8MdVFLSdqwqN/me2hyhuQg4ykN6ZpVhh1ij/80pTvDKclX1sZB9iqex8SjQfVhwMKs3JtnnMLzG9w==} engines: {node: ^18.18.0 || >=20.0.0} @@ -3596,14 +3574,6 @@ packages: pako: 1.0.11 dev: true - /ttf2woff@3.0.0: - resolution: {integrity: sha512-OvmFcj70PhmAsVQKfC15XoKH55cRWuaRzvr2fpTNhTNer6JBpG8n6vOhRrIgxMjcikyYt88xqYXMMVapJ4Rjvg==} - hasBin: true - dependencies: - argparse: 2.0.1 - pako: 1.0.11 - dev: true - /type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} diff --git a/src/generate-custom-glyph-enums.ts b/src/generate-custom-glyph-enums.ts index ed00f0d8..23527fc2 100644 --- a/src/generate-custom-glyph-enums.ts +++ b/src/generate-custom-glyph-enums.ts @@ -1,20 +1,12 @@ -import { loadSync } from 'opentype.js'; +import { parse } from 'opentype.js'; import { webfont } from 'webfont'; -import { writeFile } from './helpers.js'; +import { writeFile, toArrayBuffer } from './helpers.js'; import { infoLog } from './log.js'; -import svg2ttf from 'svg2ttf'; -import ttf2woff2 from 'ttf2woff2'; -import ttf2woff from 'ttf2woff'; import fse from 'fs-extra'; -const { writeFileSync, unlinkSync } = fse; +const { writeFileSync } = fse; const acc: Record = {}; const TAG = 'CUSTOM-GLYPHS'; -const options = { - ts: 0, - description: 'generated by d2ai for Destiny Item Manager', - url: 'http://www.destinyitemmanager.com', -}; const svgFont = await webfont({ files: './DIM-custom-font/SVGs/', @@ -25,19 +17,17 @@ const svgFont = await webfont({ centerHorizontally: true, fontHeight: '960', descent: '150', + formats: ['woff', 'woff2'], }); -const woffFile = './DIM-custom-font/DIM-Symbols.woff'; -const woff2File = './output/DIMSymbols.woff2'; -// loadSync requires .otf or .woff filetype for enumeration -const ttf = Buffer.from(svg2ttf(String(svgFont.svg), options).buffer); -writeFileSync(woffFile, ttf2woff(ttf)); -infoLog(TAG, `TEMP: ${woffFile} saved.`); -// Generate font format to be used by DIM -writeFileSync(woff2File, ttf2woff2(ttf)); -infoLog(TAG, `${woff2File} saved.`); +const font = parse(toArrayBuffer(svgFont.woff!)); -const font = loadSync(woffFile); +// Generate font format to be used by DIM +if (svgFont.woff2) { + const woff2File = './output/DIMSymbols.woff2'; + writeFileSync(woff2File, svgFont.woff2); + infoLog(TAG, `${woff2File} saved.`); +} for (let i = 0; i < font.glyphs.length; i++) { const glyph = font.glyphs.get(i); @@ -54,6 +44,3 @@ const outputEnum = `export const enum DimCustomSymbols {${Object.entries(acc) writeFile('./output/dim-custom-symbols.ts', outputEnum); writeFile('./data/dim-custom-symbols.ts', outputEnum); -// no need to keep this temp file -unlinkSync(woffFile); -infoLog(TAG, `TEMP: ${woffFile} removed.`); diff --git a/src/helpers.ts b/src/helpers.ts index fa689dce..222d67f7 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -196,3 +196,12 @@ function removeArticles(str: string) { } return str; } + +export function toArrayBuffer(buffer: Buffer) { + const arrayBuffer = new ArrayBuffer(buffer.length); + const view = new Uint8Array(arrayBuffer); + for (let i = 0; i < buffer.length; ++i) { + view[i] = buffer[i]; + } + return arrayBuffer; +}