This provides a function to calculate the width in pixels of a given string for a given font. For example, if we have a label "label", a string "s", and a font "f", we can use moebius92.FontMetrics.FontWidth to determine the width of the label, if we want to fit the entire string onto a single line:
label:SetWidth(moebius92.FontMetric.FontWidth(f, Turbine.UI.FontStyle.None, false, s));
The arguments to FontWidth are: font, font style, markup enabled?, and text.
Currently, font style is ignored (outlined characters don't actually seem to take up more space (or they do - but labels won't require more space for them)).
Markup enabled simply indicates whether or not to ignore markups when calculating the font length.
The actual width is calculated by adding together the widths of the characters in the string ("width" table for the font), adding an optional amount of space if required by the first character in the string ("head" table for the font), and modifying the width by the amount of space needed or not needed by the last character in the string ("tail" table for the font). These values are stored by Font ID in moebius92.FontMetrics.fontWidth.
(Technically the way the tail of a string is handled is slightly more complicated - Qs in TrajanPro have fairly long tails, such that they can actually extend past the character that follows them. moebius92.FontMetrics.FontWidth will handle this correctly.)
Currently only handles characters between 0x30 and 0x7F (basic ASCII) - higher unicode characters will use the default width. Also, when it encounters UTF-8 unicode characters, it only pays attention to the head byte to determine the number of bytes in the character. I.e., if it encounter "\195" it'll assume the next byte is part of a two byte UTF-8 character, regardless of whether or not the next byte has the correct high order bits. Which is to say, make sure you get your UTF-8 correct in any string that you give to FontWidth, or else it may return an incorrect result.