From ecdfba020f14857f98e3ba8bdb1a9c9dbc9579fa Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 16 May 2025 13:14:30 +0700 Subject: [PATCH 1/2] fix(web): empty layout fontSize property should default to 1em Fixes: #13908 Fixes: KEYMAN-WEB-RK Cherry-pick-of: #13959 Fun fact: `Number('')` returns 0, not NaN! I thought it would do the latter in #13838, which is what led to the issue this PR addresses. --- web/src/engine/osk/src/views/oskView.ts | 8 ++++++-- web/src/engine/osk/src/visualKeyboard.ts | 7 ++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web/src/engine/osk/src/views/oskView.ts b/web/src/engine/osk/src/views/oskView.ts index cc41e4560a..e6cc137a6d 100644 --- a/web/src/engine/osk/src/views/oskView.ts +++ b/web/src/engine/osk/src/views/oskView.ts @@ -521,11 +521,15 @@ export default abstract class OSKView // Set default OSK font size (Build 344, KMEW-90) // If the layer group specifies a fontsize value, we need // to apply that to the banner as well. - const layerFontSizeRaw = this.vkbd?.layerGroup?.spec.fontsize; + let layerFontSizeRaw = this.vkbd?.layerGroup?.spec.fontsize; + if(layerFontSizeRaw == '') { + layerFontSizeRaw = "1em"; + } // Addresses issue with touch-layouts specifying a unitless fontsize; this // coerces them to `pt` style sizing, like how word-processors present font-size. // - // Returns NaN if not 100% a number. "12px", "12pt", "12%" all return NaN. + // Number() returns NaN if not 100% a number. "12px", "12pt", "12%" all return NaN. + // '' returns 0, though! const fsRaw = Number(layerFontSizeRaw); const layerFontSize = isNaN(fsRaw) ? layerFontSizeRaw : (fsRaw + 'pt'); diff --git a/web/src/engine/osk/src/visualKeyboard.ts b/web/src/engine/osk/src/visualKeyboard.ts index 92c4ac8e89..300b41707f 100644 --- a/web/src/engine/osk/src/visualKeyboard.ts +++ b/web/src/engine/osk/src/visualKeyboard.ts @@ -1113,10 +1113,6 @@ export default class VisualKeyboard extends EventEmitter implements Ke * This function allows us to calculate the font size in those situations. */ getKeyEmFontSize(): ParsedLengthStyle { - if (!this.fontSize) { - return new ParsedLengthStyle('0px'); - } - if (this.device.formFactor == 'desktop') { let keySquareScale = 0.8; // Set in kmwosk.css, is relative. return this.fontSize.scaledBy(keySquareScale); @@ -1313,7 +1309,8 @@ export default class VisualKeyboard extends EventEmitter implements Ke // All existing font-precalculations will need to be reset, as the font // was previously unavailable. this.layerGroup.resetPrecalcFontSizes(); - this.refreshLayout() + // Can trigger when we're not actually layout-ready! + this.refreshLayout(); }); } From 8059970a7aa3e15487204e395ac80e6573f54605 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 16 May 2025 13:58:08 +0700 Subject: [PATCH 2/2] change(web): apply suggestion from code-review Co-authored-by: Marc Durdin --- web/src/engine/osk/src/views/oskView.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/engine/osk/src/views/oskView.ts b/web/src/engine/osk/src/views/oskView.ts index e6cc137a6d..dc17950c50 100644 --- a/web/src/engine/osk/src/views/oskView.ts +++ b/web/src/engine/osk/src/views/oskView.ts @@ -522,7 +522,7 @@ export default abstract class OSKView // If the layer group specifies a fontsize value, we need // to apply that to the banner as well. let layerFontSizeRaw = this.vkbd?.layerGroup?.spec.fontsize; - if(layerFontSizeRaw == '') { + if(layerFontSizeRaw === '') { layerFontSizeRaw = "1em"; } // Addresses issue with touch-layouts specifying a unitless fontsize; this