get floating point width

This commit is contained in:
sawka
2023-02-25 21:11:34 -08:00
parent 472acd8d99
commit 5e68c6b2f7
+2 -2
View File
@@ -1,6 +1,6 @@
let canvasElem = document.createElement("canvas");
function measureText(text : string, textOpts? : {pre? : boolean, mono? : boolean, fontSize? : number|string}) : {width : number, height : number} {
function measureText(text : string, textOpts? : {pre? : boolean, mono? : boolean, fontSize? : number|string}) : DOMRect {
if (textOpts == null) {
textOpts = {};
}
@@ -25,7 +25,7 @@ function measureText(text : string, textOpts? : {pre? : boolean, mono? : boolean
throw new Error("cannot measure text, no #measure div");
}
measureDiv.replaceChildren(textElem);
return {width: textElem.clientWidth, height: textElem.clientHeight};
return measureDiv.getBoundingClientRect()
}
export {measureText};