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(web): cleanup & segmentation of font style-sheet management #7387

Open
jahorton opened this issue Sep 30, 2022 · 0 comments
Open

chore(web): cleanup & segmentation of font style-sheet management #7387

jahorton opened this issue Sep 30, 2022 · 0 comments
Labels
chore m:osk On Screen Keyboard or Touch Keyboard, all platforms web/
Milestone

Comments

@jahorton
Copy link
Contributor

As of the changes in #7343 and #7360, there are a couple of lingering references to old touch-alias code still found in kmwbase.ts:

export class KeymanBase {
_MasterDocument = null; // Document with controller (to allow iframes to distinguish local/master control)
_HotKeys = []; // Array of document-level hotkey objects
warned = false; // Warning flag (to prevent multiple warnings)
baseFont = 'sans-serif'; // Default font for mapped input elements
appliedFont = ''; // Chain of fonts to be applied to mapped input elements

As it stands, baseFont and appliedFont are still in use - most prominently by the following methods:

  • VisualKeyboard.appendStyleSheet()
  • Which calls VisualKeyboard.addFontStyle()

There's also some setup code to prepare appliedFont for use there, based on the value assigned during engine init to baseFont.

For VisualKeyboard.addFontStyle():

addFontStyle(kfd, ofd): string {
let keymanweb = com.keyman.singleton;
// Get name of font to be applied
var fn = keymanweb.baseFont;
if (typeof (kfd) != 'undefined' && typeof (kfd['family']) != 'undefined') {
fn = kfd['family'];
}
// Unquote font name in base font (if quoted)
fn = fn.replace(/\u0022/g, '');
// Set font family chain for mapped elements and remove any double quotes
var rx = new RegExp('\\s?' + fn + ',?'), ff = keymanweb.appliedFont.replace(/\u0022/g, '');
// Remove base font name from chain if present
ff = ff.replace(rx, '');
ff = ff.replace(/,$/, '');
// Then replace it at the head of the chain
if (ff == '') {
ff = fn;
} else {
ff = fn + ',' + ff;
}
// Re-insert quotes around individual font names
ff = '"' + ff.replace(/\,\s?/g, '","') + '"';
// Add to the stylesheet, quoted, and with !important to override any explicit style
var s = '.keymanweb-font{\nfont-family:' + ff + ' !important;\n}\n';
// Set font family for OSK text
if (typeof (ofd) != 'undefined') {
s = s + '.kmw-key-text{\nfont-family:"' + ofd['family'].replace(/\u0022/g, '').replace(/,/g, '","') + '";\n}\n';
} else if (typeof (kfd) != 'undefined') {
s = s + '.kmw-key-text{\nfont-family:"' + kfd['family'].replace(/\u0022/g, '').replace(/,/g, '","') + '";\n}\n';
}
// Store the current font chain (with quote-delimited font names)
keymanweb.appliedFont = ff;
// Return the style string
return s;

Note that the function accomplishes two separate goals in the same function:

  • Prepares OSK key font formatting.
    • This quite clearly belongs here.
    • This currently does reference baseFont, though there's little reason the OSK can't do an independent, quick check rather than rely on this "semi-global". (In fact, relying on it hurts a goal referenced below - the "own module" bit.)
  • Prepares CSS font formatting for page inputs for browser-based KMW.
    • This... should be separate. There's no need for it to be here.
    • If we're planning to spin the OSK off as its own module (like, for cross-platform keyboard theming), this part should be left out as browser-Web-only.
    • Note: appliedFont is only used for this purpose. The OSK does not need access to this variable otherwise.
@mcdurdin mcdurdin added this to the 17.0 milestone Oct 17, 2022
@mcdurdin mcdurdin modified the milestones: 17.0, Future Dec 9, 2022
@mcdurdin mcdurdin added the m:osk On Screen Keyboard or Touch Keyboard, all platforms label Sep 16, 2023
@keymanapp-test-bot keymanapp-test-bot bot removed the feat label Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore m:osk On Screen Keyboard or Touch Keyboard, all platforms web/
Projects
None yet
Development

No branches or pull requests

2 participants