-
Notifications
You must be signed in to change notification settings - Fork 80
Description
In src/core/ServerManager.js, preloading of fonts is specifically handled in its method ServerManager._downloadResources, which is quoted as follows, starting from Line 1115:
// start loading fonts:
for (const name of fontResources)
{
const pathStatusData = this._resources.get(name);
pathStatusData.status = ServerManager.ResourceStatus.DOWNLOADING;
this.emit(ServerManager.Event.RESOURCE, {
message: ServerManager.Event.DOWNLOADING_RESOURCE,
resource: name,
});
const pathExtension = pathStatusData.path.toLowerCase().split(".").pop();
try
{
const newFont = await new FontFace(name, `url('${pathStatusData.path}') format('${pathExtension}')`).load();
document.fonts.add(newFont);
++this._nbLoadedResources;
pathStatusData.status = ServerManager.ResourceStatus.DOWNLOADED;
this.emit(ServerManager.Event.RESOURCE, {
message: ServerManager.Event.RESOURCE_DOWNLOADED,
resource: name,
});
if (this._nbLoadedResources === resources.size)
{
this.setStatus(ServerManager.Status.READY);
this.emit(ServerManager.Event.RESOURCE, {
message: ServerManager.Event.DOWNLOAD_COMPLETED,
});
}
}
catch (error)
{
console.error(error);
this.setStatus(ServerManager.Status.ERROR);
pathStatusData.status = ServerManager.ResourceStatus.ERROR;
throw Object.assign(response, {
error: `unable to download resource: ${name}: ${error}`
});
}
}Bug is introduced in Line 1128:
const newFont = await new FontFace(name, `url('${pathStatusData.path}') format('${pathExtension}')`).load();This line tries to use its name in resources as font family name, and the extension as font format. For example, if the font to be preloaded is fonts/OpenSans-Bold.ttf, it attempts to use the full path fonts/OpenSans-Bold.ttf as font family name, which is illegal. The format specified format('ttf') would also be wrong, since format('truetype') is expected in this case.
For an independent project this could be easily fixed, but I have no idea how this should be fixed in the context of PsychoJS and the builder project. I hope this would help.