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

feat(developer): Add more non-printing characters #9846

Merged
merged 20 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion common/web/types/src/kmx/kmx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class KMXFile {
public static readonly VERSION_80 = 0x00000800;
public static readonly VERSION_90 = 0x00000900;
public static readonly VERSION_100 = 0x00000A00;
public static readonly VERSION_110 = 0x00000B00;
public static readonly VERSION_120 = 0x00000C00;
public static readonly VERSION_130 = 0x00000D00;
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't add these because we don't have files with these version numbers

public static readonly VERSION_140 = 0x00000E00;
public static readonly VERSION_150 = 0x00000F00;

Expand Down Expand Up @@ -457,4 +460,4 @@ export class KMXFile {
throw "COMP_KEYBOARD size is "+this.COMP_KEYBOARD.size()+" but should be "+KMXFile.COMP_KEYBOARD_SIZE+" bytes";
}
}
}
}
4 changes: 4 additions & 0 deletions developer/src/kmc-kmn/src/kmw-compiler/compiler-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ export function IsKeyboardVersion14OrLater(): boolean {
export function IsKeyboardVersion15OrLater(): boolean {
return fk.fileVersion >= KMX.KMXFile.VERSION_150;
}

export function IsKeyboardVersion17OrLater(): boolean {
return fk.fileVersion >= KMX.KMXFile.VERSION_170;
}
28 changes: 25 additions & 3 deletions developer/src/kmc-kmn/src/kmw-compiler/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { KMX } from "@keymanapp/common-types";

export enum TRequiredKey {
K_LOPT='K_LOPT', K_BKSP='K_BKSP', K_ENTER='K_ENTER'
}; // I4447
Expand All @@ -8,9 +10,9 @@ export const
// See also builder.js: specialCharacters; web/source/osk/oskKey.ts: specialCharacters
export const
CSpecialText10: string = '*Shift*\0*Enter*\0*Tab*\0*BkSp*\0*Menu*\0*Hide*\0*Alt*\0*Ctrl*\0*Caps*\0' +
'*ABC*\0*abc*\0*123*\0*Symbol*\0*Currency*\0*Shifted*\0*AltGr*\0*TabLeft*',
'*ABC*\0*abc*\0*123*\0*Symbol*\0*Currency*\0*Shifted*\0*AltGr*\0*TabLeft*\0',
// these names were added in Keyman 14
CSpecialText14: string = '*LTREnter*\0*LTRBkSp*\0*RTLEnter*\0*RTLBkSp*\0*ShiftLock*\0*ShiftedLock*\0*ZWNJ*\0*ZWNJiOS*\0*ZWNJAndroid*',
CSpecialText14: string = '*LTREnter*\0*LTRBkSp*\0*RTLEnter*\0*RTLBkSp*\0*ShiftLock*\0*ShiftedLock*\0*ZWNJ*\0*ZWNJiOS*\0*ZWNJAndroid*\0',
CSpecialText14ZWNJ: string = '*ZWNJ*\0*ZWNJiOS*\0*ZWNJAndroid*',
CSpecialText14Map: string[][] = [
['*LTREnter*', '*Enter*'],
Expand All @@ -21,9 +23,29 @@ export const
['*ShiftedLock*', '*Shifted*'],
['*ZWNJ*', '<|>'],
['*ZWNJiOS*', '<|>'],
['*ZWNJAndroid*', '<|>']
['*ZWNJAndroid*', '<|>'],
],
// these names were added in Keyman 17
CSpecialText17: string = '*Sp*\0*NBSp*\0*NarNBSp*\0*EnQ*\0*EmQ*\0*EnSp*\0*EmSp*\0*PunctSp*\0' +
'*ThSp*\0*HSp*\0*ZWSp*\0*ZWJ*\0*WJ*\0*CGJ*\0*LTRM*\0*RTLM*\0*SH*\0*HTab*\0',
CSpecialText17ZWNJ: string = '*ZWNJGeneric*',
CSpecialText17Map: string[][] = [
['*ZWNJGeneric*', '<|>']
];

// Map for checking minimum versions and Special Text
export const CSpecialText = new Map<number, string>([
[KMX.KMXFile.VERSION_100, CSpecialText10],
[KMX.KMXFile.VERSION_110, CSpecialText10],
[KMX.KMXFile.VERSION_120, CSpecialText10],
[KMX.KMXFile.VERSION_130, CSpecialText10],
darcywong00 marked this conversation as resolved.
Show resolved Hide resolved
[KMX.KMXFile.VERSION_140, CSpecialText14 + CSpecialText10],
[KMX.KMXFile.VERSION_150, CSpecialText14 + CSpecialText10],
[KMX.KMXFile.VERSION_160, CSpecialText14 + CSpecialText10],
[KMX.KMXFile.VERSION_170, CSpecialText17 + CSpecialText14 + CSpecialText10]
]);
export const CSpecialTextMinVer = KMX.KMXFile.VERSION_100;
export const CSpecialTextMaxVer = KMX.KMXFile.VERSION_170;

// These correspond to TSS_ values in kmx.ts
export const
Expand Down
30 changes: 24 additions & 6 deletions developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KMX, Osk, TouchLayout, TouchLayoutFileReader, TouchLayoutFileWriter } from "@keymanapp/common-types";
import { callbacks, IsKeyboardVersion14OrLater, IsKeyboardVersion15OrLater } from "./compiler-globals.js";
import { callbacks, fk, IsKeyboardVersion14OrLater, IsKeyboardVersion15OrLater, IsKeyboardVersion17OrLater } from "./compiler-globals.js";
import { JavaScript_Key } from "./javascript-strings.js";
import { TRequiredKey, CRequiredKeys, CSpecialText10, CSpecialText14, CSpecialText14ZWNJ, CSpecialText14Map } from "./constants.js";
import { TRequiredKey, CRequiredKeys, CSpecialText, CSpecialText14Map, CSpecialText17Map, CSpecialTextMinVer, CSpecialTextMaxVer } from "./constants.js";
import { KeymanWebTouchStandardKeyNames, KMWAdditionalKeyNames, VKeyNames } from "./keymanweb-key-codes.js";
import { KmwCompilerMessages } from "./messages.js";

Expand Down Expand Up @@ -144,9 +144,9 @@ function CheckKey(
// Keyman versions before 14 do not support '*special*' labels on non-special keys.
// ZWNJ use, however, is safe because it will be transformed in function
// TransformSpecialKeys14 to '<|>', which does not require the custom OSK font.
if((CSpecialText10.includes(FText) || CSpecialText14.includes(FText)) &&
!CSpecialText14ZWNJ.includes(FText) &&
!IsKeyboardVersion14OrLater() &&
const mapVersion = (fk.fileVersion > CSpecialTextMaxVer ? CSpecialTextMaxVer : fk.fileVersion < CSpecialTextMinVer ? CSpecialTextMinVer : fk.fileVersion);
darcywong00 marked this conversation as resolved.
Show resolved Hide resolved
const specialText = CSpecialText.get(mapVersion);
if(specialText.includes(FText) &&
darcywong00 marked this conversation as resolved.
Show resolved Hide resolved
!([TouchLayout.TouchLayoutKeySp.special, TouchLayout.TouchLayoutKeySp.specialActive].includes(FKeyType))) {
callbacks.reportMessage(KmwCompilerMessages.Warn_TouchLayoutSpecialLabelOnNormalKey({
keyId: FId,
Expand Down Expand Up @@ -199,6 +199,22 @@ function TransformSpecialKeys14(FDebug: boolean, sLayoutFile: string): string {
return sLayoutFile;
}

function TransformSpecialKeys17(FDebug: boolean, sLayoutFile: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit WET, based on TransformSpecialKeys14 (ll 188-202)

// Rewrite Special key labels that are only supported in Keyman 17+
// This code is a little ugly but effective.
if(!IsKeyboardVersion17OrLater()) {
for(let i = 0; i < CSpecialText17Map.length; i++) {
// Assumes the JSON output format will not change
if(FDebug) {
sLayoutFile = sLayoutFile.replaceAll('"text": "'+CSpecialText17Map[i][0]+'"', '"text": this._v>16 ? "'+CSpecialText17Map[i][0]+'" : "'+CSpecialText17Map[i][1]+'"');
} else {
sLayoutFile = sLayoutFile.replaceAll('"text":"'+CSpecialText17Map[i][0]+'"', '"text":this._v>16?"'+CSpecialText17Map[i][0]+'":"'+CSpecialText17Map[i][1]+'"');
}
}
Comment on lines +207 to +214
Copy link
Member

Choose a reason for hiding this comment

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

We are using a multidimensional array here instead of a map, due to the conversion from Delphi. One day should clean this up

}
return sLayoutFile;
}

export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFile: string, sVKDictionary: string, displayMap: Osk.PuaMap): VLFOutput { // I4060 // I4139
let FDictionary: string[] = sVKDictionary.split(/\s+/);

Expand Down Expand Up @@ -282,8 +298,10 @@ export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFil

sLayoutFile = TransformSpecialKeys14(FDebug, sLayoutFile);

sLayoutFile = TransformSpecialKeys17(FDebug, sLayoutFile);

return {
output: sLayoutFile,
result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
},
{
"id": "K_X",
"text": "*Enter*"
"text": "*Enter*",
"sp": "1"
},
{
"id": "K_C",
Expand Down Expand Up @@ -665,4 +666,4 @@
],
"displayUnderlying": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
{
"id": "K_X",
"text": "*Enter*"
"text": "*Enter*",
darcywong00 marked this conversation as resolved.
Show resolved Hide resolved
},
{
"id": "K_C",
Expand Down Expand Up @@ -665,4 +665,4 @@
],
"displayUnderlying": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
},
{
"id": "K_X",
"text": "*Enter*"
"text": "*Enter*",
"sp": "1"
},
{
"id": "K_C",
Expand Down Expand Up @@ -665,4 +666,4 @@
],
"displayUnderlying": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@
],
"displayUnderlying": false
}
}
}
35 changes: 29 additions & 6 deletions developer/src/tike/xml/layoutbuilder/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ $(function() {
}
this.lookupKeyNames.sort();

// Defines the PUA code mapping for the various 'special' modifier/control keys on keyboards.
// This is lifted directly from visualKeyboard.ts and must be kept in sync. See also CompileKeymanWeb.pas: CSpecialText10
// Defines the PUA code mapping for the various 'special' modifier/control/non-printing keys on keyboards.
// This is lifted directly from specialCharacters.ts and must be kept in sync. See also CompileKeymanWeb.pas: CSpecialText10
this.specialCharacters = {
'*Shift*': 8,
'*Enter*': 5,
Expand Down Expand Up @@ -586,16 +586,39 @@ $(function() {
'*RAltShift*': 0x68,
'*LCtrlShift*': 0x69,
'*RCtrlShift*': 0x70,
// Following codes introduced in Keyman 14.0
// Added in Keyman 14.0
'*LTREnter*': 0x05, // Default alias of '*Enter*'.
'*LTRBkSp*': 0x04, // Default alias of '*BkSp*'.
'*RTLEnter*': 0x71,
'*RTLBkSp*': 0x72,
'*ShiftLock*': 0x73,
'*ShiftedLock*': 0x74,
'*ZWNJ*': 0x75, // * If this one is specified, auto-detection will kick in.
'*ZWNJiOS*': 0x75, // The iOS version will be used by default, but the
'*ZWNJAndroid*': 0x76, // Android platform has its own default glyph.
'*LTREnter*': 5, // * Forces LTR shaping for the Enter/BkSp keys regardless
'*LTRBkSp*': 4, // of layout's directionality.
// Added in Keyman 17.0.
// Reference: https://github.com/silnrsi/font-symchar/blob/v4.000/documentation/encoding.md
'*ZWNJGeneric*': 0x79, // Generic version of ZWNJ (no override)
'*Sp*': 0x80, // Space
'*NBSp*': 0x82, // No-break Space
'*NarNBSp*': 0x83, // Narrow No-break Space
'*EnQ*': 0x84, // En Quad
'*EmQ*': 0x85, // Em Quad
'*EnSp*': 0x86, // En Space
'*EmSp*': 0x87, // Em Space
// TODO: Skipping #-per-em-space
'*PunctSp*': 0x8c, // Punctuation Space
'*ThSp*': 0x8d, // Thin Space
'*HSp*': 0x8e, // Hair Space
'*ZWSp*': 0x81, // Zero Width Space
'*ZWJ*': 0x77, // Zero Width Joiner
'*WJ*': 0x78, // Word Joiner
'*CGJ*': 0x7a, // Combining Grapheme Joiner
'*LTRM*': 0x90, // Left-to-right Mark
'*RTLM*': 0x91, // Right-to-left Mark
'*SH*': 0xa1, // Soft Hyphen
'*HTab*': 0xa2, // Horizontal Tabulation
// TODO: Skipping size references
};

this.specialKeyNames = Object.entries(this.specialCharacters).map(ch => ch[0]);
Expand Down Expand Up @@ -711,4 +734,4 @@ $(function() {
return r;
};

}.bind(builder));
}.bind(builder));
Binary file modified developer/src/tike/xml/layoutbuilder/keymanweb-osk.ttf
Binary file not shown.