Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common/web): improve null handling and initialisation of KvkFileWriter #12810

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions common/web/types/src/kvk/kvk-file-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ export default class KvkFileWriter {
header: {
identifier: BUILDER_KVK_HEADER_IDENTIFIER,
version: BUILDER_KVK_HEADER_VERSION,
associatedKeyboard: {len:0,str:''},
associatedKeyboard: {len:1,str:''},
flags: source.header.flags,
ansiFont:{
color: VISUAL_KEYBOARD_TEXT_COLOR,
size: source.header.ansiFont.size,
name: {len:0,str:''}
name: {len:1,str:''}
},
unicodeFont:{
color: VISUAL_KEYBOARD_TEXT_COLOR,
size: source.header.unicodeFont.size,
name: {len:0,str:''}
name: {len:1,str:''}
},
},
keyCount: source.keys.length,
keys:[]
};

this.setString(binary.header.associatedKeyboard, source.header.associatedKeyboard);
this.setString(binary.header.ansiFont.name, source.header.ansiFont.name);
this.setString(binary.header.unicodeFont.name, source.header.unicodeFont.name);
this.setString(binary.header.associatedKeyboard, source.header.associatedKeyboard || '');
this.setString(binary.header.ansiFont.name, source.header.ansiFont.name || '');
this.setString(binary.header.unicodeFont.name, source.header.unicodeFont.name || '');

for(let sourceKey of source.keys) {
const binaryKey: BUILDER_KVK_KEY = {
flags: sourceKey.flags,
vkey: sourceKey.vkey,
shift: sourceKey.shift,
text: { len: 0, str: '' },
text: { len: 1, str: '' },
bitmapSize: sourceKey.bitmap ? sourceKey.bitmap.byteLength : 0,
bitmapData: sourceKey.bitmap ? Array.from(sourceKey.bitmap) : []
};
Expand Down
108 changes: 54 additions & 54 deletions common/web/types/tests/kvk/kvk-file-writer.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,60 +68,60 @@ describe('Test of KVK-File-Writer', () => {
const binary: BUILDER_KVK_FILE = writer['build'](vk);
checkBuilderKvkFile(binary, vk);
});
// it('can handle a null associatedKeyboard', () => {
// const vk_associatedKeyboard: string = null;
// const vk = initVisualKeyboard([
// initVisualKeyboardKey(0),
// initVisualKeyboardKey(1),
// initVisualKeyboardKey(2),
// ],
// undefined,
// BUILDER_KVK_HEADER_FLAGS.kvkhNone,
// vk_associatedKeyboard,
// DEFAULT_KVK_FONT,
// DEFAULT_KVK_FONT,
// undefined,
// );
// const writer = new KvkFileWriter;
// const binary: BUILDER_KVK_FILE = writer['build'](vk);
// checkBuilderKvkFile(binary, vk);
// });
// it('can handle a null ansiFont name', () => {
// const vk_ansiFont_name: string = null;
// const vk = initVisualKeyboard([
// initVisualKeyboardKey(0),
// initVisualKeyboardKey(1),
// initVisualKeyboardKey(2),
// ],
// undefined,
// BUILDER_KVK_HEADER_FLAGS.kvkhNone,
// "associatedKeyboard",
// { name: vk_ansiFont_name, size: -12 },
// DEFAULT_KVK_FONT,
// undefined,
// );
// const writer = new KvkFileWriter;
// const binary: BUILDER_KVK_FILE = writer['build'](vk);
// checkBuilderKvkFile(binary, vk);
// });
// it('can handle a null unicodeFont name', () => {
// const vk_unicodeFont_name: string = null;
// const vk = initVisualKeyboard([
// initVisualKeyboardKey(0),
// initVisualKeyboardKey(1),
// initVisualKeyboardKey(2),
// ],
// undefined,
// BUILDER_KVK_HEADER_FLAGS.kvkhNone,
// "associatedKeyboard",
// DEFAULT_KVK_FONT,
// { name: vk_unicodeFont_name, size: -12 },
// undefined,
// );
// const writer = new KvkFileWriter;
// const binary: BUILDER_KVK_FILE = writer['build'](vk);
// checkBuilderKvkFile(binary, vk);
// });
it('can handle a null associatedKeyboard', () => {
const vk_associatedKeyboard: string = null;
const vk = initVisualKeyboard([
initVisualKeyboardKey(0),
initVisualKeyboardKey(1),
initVisualKeyboardKey(2),
],
undefined,
BUILDER_KVK_HEADER_FLAGS.kvkhNone,
vk_associatedKeyboard,
DEFAULT_KVK_FONT,
DEFAULT_KVK_FONT,
undefined,
);
const writer = new KvkFileWriter;
const binary: BUILDER_KVK_FILE = writer['build'](vk);
checkBuilderKvkFile(binary, vk);
});
it('can handle a null ansiFont name', () => {
const vk_ansiFont_name: string = null;
const vk = initVisualKeyboard([
initVisualKeyboardKey(0),
initVisualKeyboardKey(1),
initVisualKeyboardKey(2),
],
undefined,
BUILDER_KVK_HEADER_FLAGS.kvkhNone,
"associatedKeyboard",
{ name: vk_ansiFont_name, size: -12 },
DEFAULT_KVK_FONT,
undefined,
);
const writer = new KvkFileWriter;
const binary: BUILDER_KVK_FILE = writer['build'](vk);
checkBuilderKvkFile(binary, vk);
});
it('can handle a null unicodeFont name', () => {
const vk_unicodeFont_name: string = null;
const vk = initVisualKeyboard([
initVisualKeyboardKey(0),
initVisualKeyboardKey(1),
initVisualKeyboardKey(2),
],
undefined,
BUILDER_KVK_HEADER_FLAGS.kvkhNone,
"associatedKeyboard",
DEFAULT_KVK_FONT,
{ name: vk_unicodeFont_name, size: -12 },
undefined,
);
const writer = new KvkFileWriter;
const binary: BUILDER_KVK_FILE = writer['build'](vk);
checkBuilderKvkFile(binary, vk);
});
it('can handle a null vkey', () => {
const vkk_vkey: number = null;
const vk = initVisualKeyboard([
Expand Down
Loading