From a2aef99c3ed565fe3b41c78e2fca32e168a85a57 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 17 Mar 2022 10:15:40 +1100 Subject: [PATCH] fix(web): font size on key preview Font size adjustment needed an override for the key preview to prevent it using the base key font size as a starting point. --- web/source/osk/browser/keytip.ts | 2 +- web/source/osk/oskKey.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/source/osk/browser/keytip.ts b/web/source/osk/browser/keytip.ts index 7874abbf0e..d19621d1b2 100644 --- a/web/source/osk/browser/keytip.ts +++ b/web/source/osk/browser/keytip.ts @@ -86,7 +86,7 @@ namespace com.keyman.osk.browser { height: 1.6 * xHeight + 'px' // as opposed to the canvas height of 2.3 * xHeight. }; - kts.fontSize = key.key.getIdealFontSize(vkbd, scaleStyle); + kts.fontSize = key.key.getIdealFontSize(vkbd, scaleStyle, true); } this.label.textContent = kc.textContent; diff --git a/web/source/osk/oskKey.ts b/web/source/osk/oskKey.ts index d156c07b27..feb108645d 100644 --- a/web/source/osk/oskKey.ts +++ b/web/source/osk/oskKey.ts @@ -300,7 +300,14 @@ namespace com.keyman.osk { return metrics; } - getIdealFontSize(vkbd: VisualKeyboard, style: {height?: string, fontFamily?: string, fontSize: string}): string { + /** + * Calculate the font size required for a key cap, scaling to fit longer text + * @param vkbd + * @param style specification for the desired base font size + * @param override if true, don't use the font spec from the button, just use the passed in spec + * @returns font size as a style string + */ + getIdealFontSize(vkbd: VisualKeyboard, style: {height?: string, fontFamily?: string, fontSize: string}, override?: boolean): string { let buttonStyle = getComputedStyle(this.btn); let keyWidth = parseFloat(buttonStyle.width); let emScale = 1; @@ -316,7 +323,7 @@ namespace com.keyman.osk { // Recompute the new width for use in autoscaling calculations below, just in case. emScale = vkbd.getKeyEmFontSize(); keyWidth = this.getKeyWidth(vkbd); - } else { + } else if(!override) { // When available, just use computedStyle instead. style = buttonStyle; }