@lightningjs/msdf-generator
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -6,4 +6,5 @@ /** | ||
* @param dstDir | ||
* @param charsetFilePath | ||
*/ | ||
export declare function setGeneratePaths(srcDir: string, dstDir: string): void; | ||
export declare function setGeneratePaths(srcDir: string, dstDir: string, charsetFilePath?: string): void; | ||
export interface SdfFontInfo { | ||
@@ -10,0 +11,0 @@ fontName: string; |
@@ -20,2 +20,3 @@ /* | ||
import chalk from 'chalk'; | ||
import { fileURLToPath } from 'url'; | ||
import generateBMFont from 'msdf-bmfont-xml'; | ||
@@ -26,2 +27,3 @@ let fontSrcDir = ''; | ||
let charsetPath = ''; | ||
let presets; | ||
/** | ||
@@ -32,8 +34,10 @@ * Set the paths for the font source and destination directories. | ||
* @param dstDir | ||
* @param charsetFilePath | ||
*/ | ||
export function setGeneratePaths(srcDir, dstDir) { | ||
export function setGeneratePaths(srcDir, dstDir, charsetFilePath) { | ||
fontSrcDir = srcDir; | ||
fontDstDir = dstDir; | ||
overridesPath = path.join(fontSrcDir, 'overrides.json'); | ||
charsetPath = path.join(fontSrcDir, 'charset.txt'); | ||
charsetPath = charsetFilePath ? charsetFilePath : path.join(fontSrcDir, 'charset.config.json'); | ||
presets = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), 'presets.json'), 'utf8')); | ||
} | ||
@@ -75,3 +79,15 @@ /** | ||
if (fs.existsSync(charsetPath)) { | ||
options['charset'] = fs.readFileSync(charsetPath, 'utf8'); | ||
const config = JSON.parse(fs.readFileSync(charsetPath, 'utf8')); | ||
let charset = config.charset; | ||
const presetsToApply = config.presets; | ||
for (let i = 0; i < presetsToApply.length; i++) { | ||
const key = presetsToApply[i]; | ||
if (key && key in presets) { | ||
charset += presets[key]; | ||
} | ||
else { | ||
console.warn(`preset, '${key}' is not available in msdf-generator presets`); | ||
} | ||
} | ||
options['charset'] = charset; | ||
} | ||
@@ -78,0 +94,0 @@ await generateFont(fontPath, fontDstDir, fontNameNoExt, fieldType, options); |
{ | ||
"name": "@lightningjs/msdf-generator", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Converts font files (.ttf, .otf, .woff, .woff2) to SDF format for Lightning 3's renderer, with added font metrics generation for SDF and Canvas Web fonts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -21,2 +21,3 @@ /* | ||
import chalk from 'chalk'; | ||
import { fileURLToPath } from 'url' | ||
import generateBMFont from 'msdf-bmfont-xml'; | ||
@@ -29,2 +30,8 @@ | ||
interface PresetsData { | ||
[key : string]: string | undefined | ||
} | ||
let presets: PresetsData | ||
/** | ||
@@ -35,8 +42,10 @@ * Set the paths for the font source and destination directories. | ||
* @param dstDir | ||
* @param charsetFilePath | ||
*/ | ||
export function setGeneratePaths(srcDir: string, dstDir: string) { | ||
export function setGeneratePaths(srcDir: string, dstDir: string, charsetFilePath?: string ) { | ||
fontSrcDir = srcDir; | ||
fontDstDir = dstDir; | ||
overridesPath = path.join(fontSrcDir, 'overrides.json'); | ||
charsetPath = path.join(fontSrcDir, 'charset.txt'); | ||
charsetPath = charsetFilePath ? charsetFilePath : path.join(fontSrcDir, 'charset.config.json'); | ||
presets = JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), 'presets.json'), 'utf8')) | ||
} | ||
@@ -64,2 +73,7 @@ | ||
interface CharsetConfig{ | ||
charset: string, | ||
presets: string[] | ||
} | ||
/** | ||
@@ -105,3 +119,14 @@ * Generates a font file in the specified field type. | ||
if (fs.existsSync(charsetPath)) { | ||
options['charset'] = fs.readFileSync(charsetPath, 'utf8') | ||
const config:CharsetConfig = JSON.parse(fs.readFileSync(charsetPath, 'utf8')) | ||
let charset = config.charset | ||
const presetsToApply = config.presets | ||
for (let i = 0; i < presetsToApply.length; i++ ){ | ||
const key = presetsToApply[i] | ||
if (key && key in presets) { | ||
charset += presets[key] | ||
} else { | ||
console.warn(`preset, '${key}' is not available in msdf-generator presets`) | ||
} | ||
} | ||
options['charset'] = charset | ||
} | ||
@@ -108,0 +133,0 @@ |
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
646
4
149573
21