textMetricsTest: insert canvas in DOM

This commit is contained in:
kkapsner 2020-03-15 13:43:41 +01:00
parent 736aeb371d
commit dd6fbc6c1f
1 changed files with 4 additions and 0 deletions

View File

@ -43,6 +43,7 @@
async function testMeasureText(){ async function testMeasureText(){
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
document.body.appendChild(canvas);
const node = document.createElement("span"); const node = document.createElement("span");
document.body.appendChild(node); document.body.appendChild(node);
const context = canvas.getContext("2d"); const context = canvas.getContext("2d");
@ -74,9 +75,12 @@
propertyDataIndex += 1; propertyDataIndex += 1;
if (textMetric.width !== domRect.width){ if (textMetric.width !== domRect.width){
differences += 1; differences += 1;
console.log("difference at", char, "(", charCodePoint, ")", "with", font);
console.log(textMetric.width, "!==", domRect.width);
} }
}); });
}); });
document.body.removeChild(canvas);
document.body.removeChild(node); document.body.removeChild(node);
document.querySelector("#measureText .differences").textContent = document.querySelector("#measureText .differences").textContent =