internal MeasureStringCache.Entry CreateMeasureStringCacheEntryCore(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }

            float lineHeight = font.nativeFont.GetLineHeight();
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    var lineWidth = (StringFormatFlags.FitBlackBox & format.FormatFlags) != 0
                                                ? line.GetBounds(CTLineBoundsOptions.UseOpticalBounds).Width
                                                : line.GetTypographicBounds(out _, out _, out _);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }
                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }

            return(c);
        }
示例#2
0
        internal MeasureStringCache.Entry CreateMeasureStringCacheEntry(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }

            float lineHeight = (float)NMath.Ceiling(font.nativeFont.AscentMetric + font.nativeFont.DescentMetric + font.nativeFont.LeadingMetric + 1);
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    nfloat ascent, descent, leading;
                    var    lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }
                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }

            return(c);
        }