/// <summary> /// Measure regions for specific font empty space size. /// </summary> /// <param name="g">the graphics instance to use if calculation required</param> /// <param name="font">the font to calculate for</param> /// <returns>the calculated regions</returns> private static float MeasureWhitespace(Graphics g, Font font) { WhitespaceData width; if (!_whitespaceCache.TryGetValue(font, out width)) { var regions1 = g.MeasureCharacterRanges("..", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var regions2 = g.MeasureCharacterRanges(".", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var regions = g.MeasureCharacterRanges(" .", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var endWordMargin = regions2.Width - regions1.Width; width = new WhitespaceData((regions.Width - endWordMargin) * 0.8f, endWordMargin); _whitespaceCache[font] = width; } return(width.Whitespace); }
/// <summary> /// Measure regions for specific font empty space size. /// </summary> /// <param name="g">the graphics instance to use if calculation required</param> /// <param name="font">the font to calculate for</param> /// <returns>the calculated regions</returns> private static float MeasureWhitespace(Graphics g, Font font) { WhitespaceData width; if (!_whitespaceCache.TryGetValue(font, out width)) { var regions1 = g.MeasureCharacterRanges("..", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var regions2 = g.MeasureCharacterRanges(".", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var regions = g.MeasureCharacterRanges(" .", font, new RectangleF(0, 0, Single.MaxValue, Single.MaxValue), _sf)[0].GetBounds(g); var endWordMargin = regions2.Width - regions1.Width; width = new WhitespaceData((regions.Width - endWordMargin)*0.8f, endWordMargin); _whitespaceCache[font] = width; } return width.Whitespace; }