public Size Measure(string text, double fontSize, Typeface typeface, double maxWidth) { if (htmlElement == null) { htmlElement = Document.CreateElement("div"); Bridge.Html5.Window.Body.AppendChild(htmlElement); } htmlElement.SetHtmlStyleProperty("position", "absolute"); htmlElement.SetHtmlStyleProperty("visibility", "hidden"); htmlElement.SetHtmlFontSize(fontSize, converter); htmlElement.SetHtmlFontFamily(typeface.FontFamily, converter); htmlElement.SetHtmlFontStretch(typeface.Stretch, converter); htmlElement.SetHtmlFontStyle(typeface.Style, converter); htmlElement.SetHtmlFontWeight(typeface.Weight, converter); if (maxWidth.IsNaN() || double.IsInfinity(maxWidth)) { htmlElement.SetHtmlTextWrapping(TextWrapping.NoWrap, converter); htmlElement.ClearHtmlStyleProperty("max-width"); } else { htmlElement.SetHtmlTextWrapping(TextWrapping.Wrap, converter); htmlElement.SetHtmlStyleProperty("max-width", converter.ToPixelString(maxWidth)); } htmlElement.InnerHTML = converter.ToHtmlContentString(text.DefaultIfNullOrEmpty("A")); (int width, int height) = htmlElement.Dimensions; return(new Size(text.IsNullOrEmpty() ? 0 : width + 2, height)); }