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

chore(developer): cleanup displayUnderlying flag in kmw compiler 🗜 #9056

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 3 additions & 15 deletions developer/src/kmc-kmn/src/kmw-compiler/visual-keyboard-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ import { FTabStop, nl } from "./compiler-globals.js";
import { CKeymanWebKeyCodes } from "./keymanweb-key-codes.js";
import { RequotedString } from "./write-compiled-keyboard.js";

interface VKFFResult {
result: string;
displayUnderling: boolean;
}

export function VisualKeyboardFromFile(visualKeyboard: VisualKeyboard.VisualKeyboard, debug: boolean): VKFFResult {
let f102 = visualKeyboard.header.flags & KvkFile.BUILDER_KVK_HEADER_FLAGS.kvkh102 ? '1' : '0';

let result = `{F:' 1em "${RequotedString(visualKeyboard.header.unicodeFont.name)}"',K102:${f102}}` +
export function VisualKeyboardFromFile(visualKeyboard: VisualKeyboard.VisualKeyboard, debug: boolean): string {
const f102 = visualKeyboard.header.flags & KvkFile.BUILDER_KVK_HEADER_FLAGS.kvkh102 ? '1' : '0';
return `{F:' 1em "${RequotedString(visualKeyboard.header.unicodeFont.name)}"',K102:${f102}}` +
`;` + VisualKeyboardToKLS(visualKeyboard) +
';' + BuildBKFromKLS(debug);

return {
result: result,
// TODO: this can go in caller, later
displayUnderling: !!(visualKeyboard.header.flags & KvkFile.BUILDER_KVK_HEADER_FLAGS.kvkhDisplayUnderlying)
}
}

function WideQuote(s: string): string {
Expand Down
28 changes: 9 additions & 19 deletions developer/src/kmc-kmn/src/kmw-compiler/write-compiled-keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KMX, CompilerOptions, CompilerCallbacks, KvkFileReader, VisualKeyboard, KmxFileReader, Osk } from "@keymanapp/common-types";
import { KMX, CompilerOptions, CompilerCallbacks, KvkFileReader, VisualKeyboard, KmxFileReader, Osk, KvkFile } from "@keymanapp/common-types";
import { ExpandSentinel, incxstr, xstrlen } from "./util.js";
import { options, nl, FTabStop, setupGlobals, IsKeyboardVersion10OrLater, callbacks, FFix183_LadderLength } from "./compiler-globals.js";
import { JavaScript_ContextMatch, JavaScript_KeyAsString, JavaScript_Name, JavaScript_OutputString, JavaScript_Rules, JavaScript_Shift, JavaScript_ShiftAsString, JavaScript_Store, zeroPadHex } from './javascript-strings.js';
Expand Down Expand Up @@ -54,7 +54,7 @@ export function WriteCompiledKeyboard(callbacks: CompilerCallbacks, kmnfile: str
let vMnemonic: number = 0;
let /*s: string,*/ sRTL: string = "", sHelp: string = "''", sHelpFile: string = "",
sEmbedJS: string = "", sEmbedCSS: string = "";
let sVisualKeyboard: string = "", sFullName: string = "";
let sVisualKeyboardFilename: string = "", sFullName: string = "";
let sBegin_NewContext: string = "", sBegin_PostKeystroke: string = "";
let sLayoutFile: string = "", sVKDictionary: string = "";
let linecomment: string; // I3438
Expand All @@ -81,7 +81,7 @@ export function WriteCompiledKeyboard(callbacks: CompilerCallbacks, kmnfile: str
sHelp = '"'+RequotedString(fsp.dpString)+'"';
}
else if (fsp.dpName == 'VisualKeyboard' || fsp.dwSystemID == KMX.KMXFile.TSS_VISUALKEYBOARD) {
sVisualKeyboard = fsp.dpString;
sVisualKeyboardFilename = fsp.dpString;
}
else if (fsp.dpName == 'EmbedJS' || fsp.dwSystemID == KMX.KMXFile.TSS_KMW_EMBEDJS) {
sEmbedJS = fsp.dpString;
Expand Down Expand Up @@ -190,24 +190,14 @@ export function WriteCompiledKeyboard(callbacks: CompilerCallbacks, kmnfile: str
// layout platform.displayUnderlying property or, if that is not present for
// the given platform, by the OSK property.
let fDisplayUnderlying = false;
let sVisualKeyboard = 'null'; // 'null' as a string is correct

if (sVisualKeyboard != '') {
// TODO: stop reusing sVisualKeyboard for both filename and content
let reader = new KvkFileReader();
let kvk: VisualKeyboard.VisualKeyboard = reader.read(kvkData);
let result = VisualKeyboardFromFile(kvk, options.saveDebug);
if(!result.result) {
// TODO: error
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not possible - VisualKeyboardFromFile always returns a string.

sVisualKeyboard = 'null';
}
else {
sVisualKeyboard = result.result;
}
if (sVisualKeyboardFilename != '') {
const reader = new KvkFileReader();
const kvk: VisualKeyboard.VisualKeyboard = reader.read(kvkData);
fDisplayUnderlying = !!(kvk.header.flags & KvkFile.BUILDER_KVK_HEADER_FLAGS.kvkhDisplayUnderlying);
sVisualKeyboard = VisualKeyboardFromFile(kvk, options.saveDebug);
}
else {
sVisualKeyboard = 'null';
}


const fMnemonic = vMnemonic == 1;

Expand Down