Forum Discussion
measureSvgTextWidth giving wrong results?
- 5 years ago
Hi, Henry, thank you for you answer!
I didn't say the problem was with getTailoredTextOrDefault. The problem seem to be with measureSvgTextWidth, that returned the wrong size.
I just now figured out what is wrong, so I'll just put here for further reference: one must inform the fontsize unit, either in points (pt) or pixels (px). If only the number is used, although anything else works fine, this function calculates the wrong width (which breaks getTailoredTextOrDefault as well).
So, to further exemplify:
let textProperties = { text: "Microsoft PowerBI!", fontFamily: "sans-serif", fontSize: "24" }; console.log(tms.getTailoredTextOrDefault(textProperties, 100)); // Microsoft PowerBI!Here's a little experiment I've made:
I didn't see any reference to this behaviour in the official document, nor any mention of what is the default unit (if any).
Hi ewaghabi ,
According to your description, the reason that causes the getTailoredTextOrDefault function to use the error is that no specific value is specified in the return value. For details, refer to the official website document for the use of getTailoredTextOrDefault and measureSvgTextWidth.
Here is the official document link.
If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, Henry, thank you for you answer!
I didn't say the problem was with getTailoredTextOrDefault. The problem seem to be with measureSvgTextWidth, that returned the wrong size.
I just now figured out what is wrong, so I'll just put here for further reference: one must inform the fontsize unit, either in points (pt) or pixels (px). If only the number is used, although anything else works fine, this function calculates the wrong width (which breaks getTailoredTextOrDefault as well).
So, to further exemplify:
let textProperties = {
text: "Microsoft PowerBI!",
fontFamily: "sans-serif",
fontSize: "24"
};
console.log(tms.getTailoredTextOrDefault(textProperties, 100)); // Microsoft PowerBI!
Here's a little experiment I've made:
I didn't see any reference to this behaviour in the official document, nor any mention of what is the default unit (if any).