Skip to content

Commit

Permalink
Merge pull request #9056 from keymanapp/chore/developer/cleanup-displ…
Browse files Browse the repository at this point in the history
…ay-underlying-flag

chore(developer): cleanup displayUnderlying flag in kmw compiler 🗜
  • Loading branch information
mcdurdin authored Jun 23, 2023
2 parents 6928188 + a67abad commit 2222e87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
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
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

0 comments on commit 2222e87

Please sign in to comment.