From 47b23cec713f823b64bb129042e77be3832f543d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 23 Apr 2015 23:43:05 +0100 Subject: [PATCH] Prevent text measuring as NaN. When text is right-aligned, WidthIncludingTrailingWhitespace seems to return null. Worked around that but I think the layout code is wrong now. --- Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs b/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs index c8a108d824..b51cb627ea 100644 --- a/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs +++ b/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs @@ -120,9 +120,15 @@ namespace Perspex.Direct2D1.Media public Size Measure() { - return new Size( - this.TextLayout.Metrics.WidthIncludingTrailingWhitespace, - this.TextLayout.Metrics.Height); + var metrics = this.TextLayout.Metrics; + var width = metrics.WidthIncludingTrailingWhitespace; + + if (float.IsNaN(width)) + { + width = metrics.Width; + } + + return new Size(width, this.TextLayout.Metrics.Height); } public void SetForegroundBrush(Brush brush, int startIndex, int count)