LibWeb: Implement FontFaceSet.check()

This returns true if the given text can be rendered with the fonts in
the set that are fully loaded.
This commit is contained in:
Tim Ledbetter
2026-03-27 14:19:36 +00:00
committed by Sam Atkins
parent 14a0f00400
commit 657060ccc2
Notes: github-actions[bot] 2026-03-27 15:30:12 +00:00
5 changed files with 66 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const fontFaceSet = document.fonts;
try {
fontFaceSet.check("invalid");
println("Check invalid font: FAIL");
} catch (e) {
println(`Check invalid font: ${e.name === "SyntaxError" ? "PASS" : "FAIL"}`);
}
try {
fontFaceSet.check("revert");
println("Check CSS keyword as font: FAIL");
} catch (e) {
println(`Check CSS keyword as font: ${e.name === "SyntaxError" ? "PASS" : "FAIL"}`);
}
println(`Check non-existent font: ${fontFaceSet.check("10px NonExistentFont") === true ? "PASS" : "FAIL"}`);
const fontFace = new FontFace("Hash Sans", "url(../../../Assets/HashSans.woff)");
fontFaceSet.add(fontFace);
println(`Check unloaded font: ${fontFaceSet.check("1em Hash Sans") === false ? "PASS" : "FAIL"}`);
await fontFace.load();
println(`Check loaded font: ${fontFaceSet.check("1em Hash Sans") === true ? "PASS" : "FAIL"}`);
});
</script>