public static Size GetTextPixelSize(string pText, TextStyle pTextStyle) { if (pTextStyle.Format == null) { pTextStyle.Initialize(D2DStatic.StringFactory); } using (TextLayout layout = StringFactory.CreateTextLayout(pText, pTextStyle.Format, 9999, 9999)) { return(new Size(layout.Metrics.Width, layout.Metrics.Height)); } }