This way is a very weak method, because It is letter’s width dependent. And If a font family doesn’t maintain constant letter width then my code is trash. This only works with my font.
Tip: What I do, is a trick add variable(your text) + NewLine() then the TextObject has width and height, if you try to get TextObject.width() it works, I don’t know way but works