var lcffonts_log = true; function lcffontsLog (serious, s, ...args) { curstack = new Error().stack; if (serious) tools_log ('lcffonts', curstack, s, ...args); } lcffontsLog (true, 'lcffonts.js (generated from lcffonts.js.template by the server)'); /* this file is used by Lynx to create @runtime the file "lcffonts.js" */ window.postMessage('lynx-fontsloadstarting', "*"); lcffontsLog (lcffonts_log, 'window.postMessage(\'lynx-fontsloadstarting\''); document.fonts.addEventListener("loading", (event) => { lcffontsLog (lcffonts_log, 'loading: event', event); }); document.fonts.addEventListener("loadingerror", (event) => { lcffontsLog (lcffonts_log, 'loadingerror: event', event); }); document.fonts.addEventListener("loadingdone", (event) => { lcffontsLog (lcffonts_log, 'loadingdone: event', event); }); const lcfFontFaces = [ /* Example : new FontFace ( "NotoSans", "url(/loadfont?name=NotoSans-Bold) format('truetype')", { weight: "bold"} ), */ /*$INSERT_HERE THE_FONT_INFO$*/ ]; lcfFontFaces.forEach ( (element) => { lcffontsLog (lcffonts_log, `lcfFontFace: ${element.family} ${element.weight}`); console.log (element); document.fonts.add(element); }); lcffontsLog (lcffonts_log, 'after adding the font faces'); async function loadAll () { for (let i = 0; i < lcfFontFaces.length; i++) { try { await lcfFontFaces[i].load(); } catch (err) { console.log (` *** catch *** loading ${i} ${lcfFontFaces[i].family}`, err, lcfFontFaces[i]); } } } loadAll(); lcffontsLog (lcffonts_log, 'after waiting for the loads the font faces'); function waitForCondition() { return new Promise(resolve => { var start_time = Date.now(); function checkFlag() { let cnt = 0; lcffontsLog (lcffonts_log, `lcfFontFaces.length = ${lcfFontFaces.length} ${start_time}`); for (let i = 0; i < lcfFontFaces.length; i++) { let f = lcfFontFaces[i]; lcffontsLog (lcffonts_log, `${f.family} ${f.status} ${f.loaded}`); if (lcfFontFaces[i].status=='loaded' || lcfFontFaces[i].status=='error') cnt++; } if (cnt==lcfFontFaces.length) { lcffontsLog (lcffonts_log, 'all fontFaces are loaded'); resolve(); } else if (Date.now() > start_time + 8000) { lcffontsLog (true, 'fontloading time out'); resolve(); } else { window.setTimeout(checkFlag, 500); } } checkFlag(); } ); } async function run() { //console.log('===>>> before'); await waitForCondition() //console.log('===>>> after ... '); lcffontsLog (lcffonts_log, `window.postMessage('lynx-fontsloaded')`); window.postMessage('lynx-fontsloaded', "*"); } //console.log('before run'); run(); //console.log('after run');