/// <summary> /// Initializes a new TextEntity class. /// </summary> /// <param name="text">The Text.</param> /// <param name="font">The Font.</param> /// <param name="color">The Color.</param> /// <param name="wrapWidth">The Wordwrap Width.</param> public TextEntity(string text, OpenGLFont font, Color color, int wrapWidth = 0) { if (wrapWidth > 0) { text = text.WordWrap(wrapWidth); } var gdiFont = OpenGLHelper.ConvertFont(font); Id = text.GetHashCode() + gdiFont.GetHashCode() + color.GetHashCode(); _text = text; _font = gdiFont; _color = color; }
/// <summary> /// Measures the string. /// </summary> /// <param name="text">The String.</param> /// <param name="font">The Font.</param> /// <returns>Vector2.</returns> public Vector2 MeasureString(string text, IFont font) { var oglFont = font as OpenGLFont; if (oglFont == null) { throw new ArgumentException("Expected a OpenGLFont as resource."); } System.Drawing.Font gdiFont = OpenGLHelper.ConvertFont(oglFont); Size result = TextRenderer.MeasureText(text, gdiFont); return(new Vector2(result.Width, result.Height)); }