mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-09 18:35:32 +00:00
fix(developer): add ERROR_FontFileMetaDataIsInvalid error and corresponding test
This commit is contained in:
parent
a090099633
commit
b7bbd759a4
4 changed files with 19 additions and 12 deletions
|
|
@ -16,12 +16,7 @@ export async function getFontFamily(source: Uint8Array) {
|
|||
}
|
||||
|
||||
const buffer = Buffer.from(source);
|
||||
let font = null;
|
||||
try {
|
||||
font = await ttfMeta.promise(buffer);
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
const font = await ttfMeta.promise(buffer);
|
||||
/* c8 ignore next 3 */
|
||||
if(!font) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -64,5 +64,9 @@ export class KeyboardInfoCompilerMessages {
|
|||
static ERROR_FontFileCannotBeRead = SevError | 0x000E;
|
||||
static Error_FontFileCannotBeRead = (o:{filename: string}) => m(this.ERROR_FontFileCannotBeRead,
|
||||
`Font ${def(o.filename)} could not be parsed to extract a font family.`);
|
||||
|
||||
static ERROR_FontFileMetaDataIsInvalid = SevError | 0x000F;
|
||||
static Error_FontFileMetaDataIsInvalid = (o:{filename: string,message:string}) => m(this.ERROR_FontFileMetaDataIsInvalid,
|
||||
`Font ${def(o.filename)} meta data invalid: ${def(o.message)}.`);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -595,8 +595,16 @@ export class KeyboardInfoCompiler implements KeymanCompiler {
|
|||
return null;
|
||||
}
|
||||
|
||||
let fontFamily = null;
|
||||
try {
|
||||
fontFamily = await getFontFamily(fontData)
|
||||
} catch(e) {
|
||||
this.callbacks.reportMessage(KeyboardInfoCompilerMessages.Error_FontFileMetaDataIsInvalid({filename: sourcePath,message: e}));
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = {
|
||||
family: await getFontFamily(fontData),
|
||||
family: fontFamily,
|
||||
source
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -318,9 +318,9 @@ describe('KeyboardInfoCompilerMessages', function () {
|
|||
`ERROR_NoLicenseFound not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
|
||||
});
|
||||
|
||||
// ERROR_FontFileCannotBeRead
|
||||
// ERROR_FontFileMetaDataIsInvalid
|
||||
|
||||
it('should generate ERROR_FontFileCannotBeRead error if font family cannot be obtained from file', async function() {
|
||||
it('should generate ERROR_FontFileMetaDataIsInvalid error if font file meta data throws an error', async function() {
|
||||
const jsFilename = makePathToFixture('font-file-cannot-be-read', 'build', 'khmer_angkor.js');
|
||||
const kpsFilename = makePathToFixture('font-file-cannot-be-read', 'source', 'khmer_angkor.kps');
|
||||
const kmpFilename = makePathToFixture('font-file-cannot-be-read', 'build', 'khmer_angkor.kmp');
|
||||
|
|
@ -341,9 +341,9 @@ describe('KeyboardInfoCompilerMessages', function () {
|
|||
const source = ["font_file_cannot_be_read.ttf"]
|
||||
const result = await compiler['fontSourceToKeyboardInfoFont'](kpsFilename, kmpJsonData, source)
|
||||
assert.isNull(result);
|
||||
assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FontFileCannotBeRead),
|
||||
`ERROR_FontFileCannotBeRead not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
|
||||
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FontFileCannotBeRead).includes(kmpJsonData.files[0].name),
|
||||
assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FontFileMetaDataIsInvalid),
|
||||
`ERROR_FontFileMetaDataIsInvalid not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
|
||||
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FontFileMetaDataIsInvalid).includes(kmpJsonData.files[0].name),
|
||||
kmpJsonData.files[0].name+' not found in the message');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue