I am currently trying to settle on a font-type in a preloader SVG-image. As of now I am trying to use a Google/Meriweather-font (or Markazi), that works perfect on my PC (fetches installed OS-font):
- whereas my webhotel/remote SVG renders it like this on my laptop:
… thus falling back an ugly Times New Roman-font.
I use the (quite standard) loading.js/Vanilla JS script with a little SVG-variation:
pc.script.createLoadingScreen(function (app) {
var showSplash = function () {
// splash wrapper
var wrapper = document.createElement('div');
wrapper.id = 'application-splash-wrapper';
document.body.appendChild(wrapper);
// splash
var splash = document.createElement('div');
splash.id = 'application-splash';
wrapper.appendChild(splash);
splash.style.display = 'none';
var container = document.createElement('div');
container.id = 'progress-bar-container';
splash.appendChild(container);
var bar = document.createElement('div');
bar.id = 'progress-bar';
container.appendChild(bar);
};
var hideSplash = function () {
var splash = document.getElementById('application-splash-wrapper');
splash.parentElement.removeChild(splash);
};
var setProgress = function (value) {
var bar = document.getElementById('progress-bar');
if(bar) {
value = Math.min(1, Math.max(0, value));
bar.style.width = value * 100 + '%';
}
};
var createCss = function () {
var css = [
'body {',
' background-color: #283538;',
'}',
'#application-splash-wrapper {',
' position: absolute;',
' top: 0;',
' left: 0;',
' height: 100%;',
' width: 100%;',
' background-image: radial-gradient(#102030, #000000 , #101020);',
'}',
'#application-splash {',
' position: absolute;',
' top: calc(2% - 4px);',
' width: 86%;',
' left: 7%;',
'}',
'#application-splash img {',
' width: 86%;',
' margin: 0px auto;',
' display: block;',
'}',
'#progress-bar-container {',
' margin: 20px auto 0 auto;',
' height: 4px;',
' width: 100%;',
' background-image: linear-gradient(to left,#d0e3db, #f8f9e1 , #eef2c8);',
'}',
'#progress-bar {',
' width: 0%;',
' height: 100%;',
' background-color: #fff;',
'}',
'@media (max-width: 600px) {',
' #application-splash {',
' top: calc(2% - 4px);',
' width: 86%;',
' left: 7%;',
' }',
'}'
].join("\n");
var style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
document.head.appendChild(style);
};
createCss();
showSplash();
// Use an image from the assets in the project via the asset registry
// More information: http://developer.playcanvas.com/en/api/pc.AssetRegistry.html
app.on('preload:start', function() {
var splash = document.getElementById('application-splash');
var logoAsset = app.assets.find('SplashSVG2.svg');
if (logoAsset) {
var logo = document.createElement('img');
logo.src = logoAsset.getFileUrl();
// Insert DOM before the progress bar
if (splash.childNodes.length > 0) {
splash.insertBefore(logo, splash.childNodes[0]);
} else {
splash.appendChild(logo);
}
logo.onload = function () {
splash.style.display = 'block';
};
}
});
app.on('preload:end', function () {
app.off('preload:progress');
});
app.on('preload:progress', setProgress);
app.on('start', hideSplash);
});
Q: Can I load an external google-font to be used within the SVG-file at browser DOM-execution, and prevent the fall-back?
PS: Have been trying to break the issue myself (A modern font loading strategy with the vanilla JS FontFaceSet.load() method | Go Make Things), but I am still too inexperienced in Vanilla JS.
Hope you can help (perhaps @Leonidas ? )