Files
ladybird/Tests/LibWeb/Text/input/css/FontFace-arraybuffer-matching.html
Tim Ledbetter 5b584fde1d LibWeb: Register JS-created FontFace objects for font matching
Previously, FontFace objects created via the JS and added to
`document.fonts` were stored in the FontFaceSet but never participated
in font matching during style resolution. We now store both
CSS-connected and JS-created font faces in a unified map on
`FontComputer`, keyed by family name, and include them all as
candidates in the font matching algorithm.
2026-04-05 00:13:35 +02:00

43 lines
1.4 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const fontData = await fetch("../../../Assets/HashSans.woff").then(
response => response.arrayBuffer());
const face = new FontFace("TestFont", fontData);
document.fonts.add(face);
await face.loaded;
const element = document.createElement("span");
element.style.fontFamily = "TestFont, serif";
element.style.fontSize = "20px";
element.textContent = "test";
document.body.appendChild(element);
const fallbackElement = document.createElement("span");
fallbackElement.style.fontFamily = "serif";
fallbackElement.style.fontSize = "20px";
fallbackElement.textContent = "test";
document.body.appendChild(fallbackElement);
// Force layout
document.body.offsetHeight;
const testWidth = element.offsetWidth;
const fallbackWidth = fallbackElement.offsetWidth;
println(`face.status: ${face.status}`);
println(`font matched: ${testWidth !== fallbackWidth}`);
document.fonts.delete(face);
// Force layout after removal
document.body.offsetHeight;
const afterDeleteWidth = element.offsetWidth;
println(`font unmatched after delete: ${afterDeleteWidth === fallbackWidth}`);
});
</script>