I once did the same thing for SpriteFont, you only have to adapt the "textWidth" function so it returns the width based on the characters in the sprite instead of using that javascript function (which indeed use 12pt Arial for its calculation; the font used by the DestText object).
2 ways to do that, depending on your need.
If your spritefont is monospaced, it's much easier. The "textWidth" function should return len(Function.Param(0)) * (characterWidth + characterSpacing).
However, if some characters have different width, you'll have to use the SpriteFont.TextWidth expression. You can either use a dedicated SpriteFont to "measure" text, or create a temporary one to do it.
Here's an edited version using a SpriteFont.