From 9c8f0fad7b1414284563433e6732d576f1a8c106 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 25 Jan 2024 14:47:24 +0700 Subject: [PATCH 1/4] chore(web): drops svg, eot --- web/src/engine/dom-utils/src/stylesheets.ts | 22 +-------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/web/src/engine/dom-utils/src/stylesheets.ts b/web/src/engine/dom-utils/src/stylesheets.ts index dfcaaccb2e..c409a91aec 100644 --- a/web/src/engine/dom-utils/src/stylesheets.ts +++ b/web/src/engine/dom-utils/src/stylesheets.ts @@ -88,7 +88,7 @@ export class StylesheetManager { const fontKey = fd.family; let source: string; - let i, ttf='', woff='', eot='', svg='', fList=[]; + let i, ttf='', woff='', fList=[]; // TODO: 22 Aug 2014: check that font path passed from cloud is actually used! @@ -118,8 +118,6 @@ export class StylesheetManager { if(fList[i].toLowerCase().indexOf('.otf') > 0) ttf=fList[i]; if(fList[i].toLowerCase().indexOf('.ttf') > 0) ttf=fList[i]; if(fList[i].toLowerCase().indexOf('.woff') > 0) woff=fList[i]; - if(fList[i].toLowerCase().indexOf('.eot') > 0) eot=fList[i]; - if(fList[i].toLowerCase().indexOf('.svg') > 0) svg=fList[i]; } // Font path qualified to support page-relative fonts (build 347) @@ -131,14 +129,6 @@ export class StylesheetManager { woff = fontPathRoot+woff; } - if(eot != '' && (eot.indexOf('/') < 0)) { - eot = fontPathRoot+eot; - } - - if(svg != '' && (svg.indexOf('/') < 0)) { - svg = fontPathRoot+svg; - } - // Build the font-face definition according to the browser being used var s='@font-face {\nfont-family:' + fd.family + ';\nfont-style:normal;\nfont-weight:normal;\n'; @@ -155,16 +145,10 @@ export class StylesheetManager { source = "url('"+ttf+"') format('truetype')"; } } else { - var s0 = []; - if(os == DeviceSpec.OperatingSystem.Android) { // Android 4.2 and 4.3 have bugs in their rendering for some scripts // with embedded ttf or woff. svg mostly works so is a better initial // choice on the Android browser. - if(svg != '') { - source = "url('"+svg+"') format('svg')"; - } - if(woff != '') { source = "url('"+woff+"') format('woff')"; } @@ -180,10 +164,6 @@ export class StylesheetManager { if(ttf != '') { source = "url('"+ttf+"') format('truetype')"; } - - if(svg != '') { - source = "url('"+svg+"') format('svg')"; - } } } From 3d68ba370d335462ec0187f840b1083b49d83e26 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 25 Jan 2024 14:47:56 +0700 Subject: [PATCH 2/4] chore(web): post-drop logic simplification --- web/src/engine/dom-utils/src/stylesheets.ts | 23 +++++---------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/web/src/engine/dom-utils/src/stylesheets.ts b/web/src/engine/dom-utils/src/stylesheets.ts index c409a91aec..b3a6de3800 100644 --- a/web/src/engine/dom-utils/src/stylesheets.ts +++ b/web/src/engine/dom-utils/src/stylesheets.ts @@ -145,25 +145,12 @@ export class StylesheetManager { source = "url('"+ttf+"') format('truetype')"; } } else { - if(os == DeviceSpec.OperatingSystem.Android) { - // Android 4.2 and 4.3 have bugs in their rendering for some scripts - // with embedded ttf or woff. svg mostly works so is a better initial - // choice on the Android browser. - if(woff != '') { - source = "url('"+woff+"') format('woff')"; - } + if(woff != '') { + source = "url('"+woff+"') format('woff')"; + } - if(ttf != '') { - source = "url('"+ttf+"') format('truetype')"; - } - } else { - if(woff != '') { - source = "url('"+woff+"') format('woff')"; - } - - if(ttf != '') { - source = "url('"+ttf+"') format('truetype')"; - } + if(ttf != '') { + source = "url('"+ttf+"') format('truetype')"; } } From 4f2c82d91506ef0be5d81e6d80c8e8714ba3debb Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 25 Jan 2024 15:03:09 +0700 Subject: [PATCH 3/4] fix(web): promise-clearing on error, encoding of font URIs --- web/src/engine/dom-utils/src/stylesheets.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/src/engine/dom-utils/src/stylesheets.ts b/web/src/engine/dom-utils/src/stylesheets.ts index b3a6de3800..e97dd63030 100644 --- a/web/src/engine/dom-utils/src/stylesheets.ts +++ b/web/src/engine/dom-utils/src/stylesheets.ts @@ -142,15 +142,15 @@ export class StylesheetManager { if(this.doCacheBusting) { ttf = this.cacheBust(ttf); } - source = "url('"+ttf+"') format('truetype')"; + source = "url('"+encodeURI(ttf)+"') format('truetype')"; } } else { if(woff != '') { - source = "url('"+woff+"') format('woff')"; + source = "url('"+encodeURI(woff)+"') format('woff')"; } if(ttf != '') { - source = "url('"+ttf+"') format('truetype')"; + source = "url('"+encodeURI(ttf)+"') format('truetype')"; } } @@ -176,7 +176,10 @@ export class StylesheetManager { const fontFace = new FontFace(fd.family, source); const loadPromise = fontFace.load(); this.fontPromises.push(loadPromise); - loadPromise.then(() => this.fontPromises = this.fontPromises.filter((entry) => entry != loadPromise)); + + const clearPromise = () => this.fontPromises = this.fontPromises.filter((entry) => entry != loadPromise); + loadPromise.then(clearPromise); + loadPromise.catch(clearPromise); this.linkStylesheet(sheet); From 330dd17b5211b53b4130b900aa46a69f77bbf5e1 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Mon, 29 Jan 2024 15:55:44 +0700 Subject: [PATCH 4/4] fix(web): should not link in empty sheets --- web/src/engine/dom-utils/src/stylesheets.ts | 11 +++++++---- web/src/engine/osk/src/visualKeyboard.ts | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/engine/dom-utils/src/stylesheets.ts b/web/src/engine/dom-utils/src/stylesheets.ts index e97dd63030..827320cad3 100644 --- a/web/src/engine/dom-utils/src/stylesheets.ts +++ b/web/src/engine/dom-utils/src/stylesheets.ts @@ -29,6 +29,10 @@ export class StylesheetManager { } linkStylesheet(sheet: HTMLStyleElement) { + if(!(sheet instanceof HTMLLinkElement) && !sheet.innerHTML) { + return; + } + this.linkedSheets.push(sheet); this.linkNode.appendChild(sheet); } @@ -51,6 +55,7 @@ export class StylesheetManager { } else { const promise = new ManagedPromise(); sheetElem.addEventListener('load', () => promise.resolve()); + sheetElem.addEventListener('error', () => promise.reject()); promises.push(promise.corePromise); } } @@ -174,12 +179,10 @@ export class StylesheetManager { * For now, we're using this solely to detect when the font has been succesfully loaded. */ const fontFace = new FontFace(fd.family, source); - const loadPromise = fontFace.load(); - this.fontPromises.push(loadPromise); const clearPromise = () => this.fontPromises = this.fontPromises.filter((entry) => entry != loadPromise); - loadPromise.then(clearPromise); - loadPromise.catch(clearPromise); + const loadPromise = fontFace.load().then(clearPromise).catch(clearPromise); + this.fontPromises.push(loadPromise); this.linkStylesheet(sheet); diff --git a/web/src/engine/osk/src/visualKeyboard.ts b/web/src/engine/osk/src/visualKeyboard.ts index 8da40a6852..1a5822703c 100644 --- a/web/src/engine/osk/src/visualKeyboard.ts +++ b/web/src/engine/osk/src/visualKeyboard.ts @@ -1358,8 +1358,10 @@ export default class VisualKeyboard extends EventEmitter implements Ke if (activeKeyboard != null && typeof (activeKeyboard.oskStyling) == 'string') // KMEW-129 customStyle = customStyle + activeKeyboard.oskStyling; - this.styleSheet = createStyleSheet(customStyle); //Build 360 - this.styleSheetManager.linkStylesheet(this.styleSheet); + if(customStyle) { + this.styleSheet = createStyleSheet(customStyle); //Build 360 + this.styleSheetManager.linkStylesheet(this.styleSheet); + } // Once any related fonts are loaded, we can re-adjust key-cap scaling. this.styleSheetManager.allLoadedPromise().then(() => this.refreshLayout());