XGraphics.MeasureString() uses a FormattedText object to measure string width. This is expensive because the FormattedText creates a drawing context underneath the scenes, for any unique text string that gets drawn. A better method is to use the GlyphTypeface method, such a what this blog entry does:
http://incrediblejourneysintotheknown.b ... forth.htmlWhen rendering many pages, this performance is improved significantly by using the following code fix in XGraphics.cs (3213):
#if WPF && !GDI
/* OLD CODE:
FormattedText formattedText = new FormattedText(text, new CultureInfo("en-us"),
FlowDirection.LeftToRight, font.typeface, font.Height, System.Windows.Media.Brushes.Black);
return new XSize(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
* */
GlyphTypeface gTypeface;
if (!font.typeface.TryGetGlyphTypeface(out gTypeface))
throw new InvalidOperationException("No glyphtypeface found");
ushort[] glyphIndexes = new ushort[text.Length];
double[] advanceWidths = new double[text.Length];
double totalWidth = 0;
for (int n = 0; n < text.Length; n++)
{
ushort glyphIndex = gTypeface.CharacterToGlyphMap[text[n]];
glyphIndexes[n] = glyphIndex;
double width = gTypeface.AdvanceWidths[glyphIndex] * font.Size;
advanceWidths[n] = width;
totalWidth += width;
}
return new XSize(totalWidth, gTypeface.Height * font.Size);
#endif