Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
delphiactual committed Jun 12, 2024
1 parent c420a02 commit 74a6c7a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/generate-custom-glyph-enums.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { loadSync } from 'opentype.js';
import { webfont } from 'webfont';
import { writeFile } 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 acc: Record<string, number> = {};

const woffFile = './DIM-custom-font/DIM-Symbols.woff';
const woff2File = './output/DIMSymbols.woff2';
const TAG = "CUSTOM-GLYPHS"

webfont({
files: './DIM-custom-font/SVGs/',
Expand All @@ -24,18 +22,18 @@ webfont({
descent: '150',
})
.then((result) => {
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(result.svg!), { ts: 0 }).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 = loadSync(woffFile);

// no need to keep this temp file
unlinkSync(woffFile);

for (let i = 0; i < font.glyphs.length; i++) {
const glyph = font.glyphs.get(i);
if (glyph.name && glyph.unicode) {
Expand All @@ -51,6 +49,9 @@ webfont({

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.`)
})
.catch((error) => {
throw error;
Expand Down

0 comments on commit 74a6c7a

Please sign in to comment.