Пример #1
0
        public override int GetHeight(DirectText directText, Font defaultFont, int width)
        {
            if (_layoutForWidth != width)
            {
                _layoutForWidth = width;

                List<string> lines = new List<string>();
                List<int> lineHeights = new List<int>();

                _layoutHeight = 0;

                string remaining = _text;

                int availableWidth = width - _leftPadding - _rightPadding;

                while (remaining.Length > 0)
                {
                    // Break the remaining text into a line:
                    int fittingCharacterCount = directText.MeasureFittingCharacterCount(remaining, availableWidth, defaultFont);
                    fittingCharacterCount = Math.Max(1, fittingCharacterCount);

                    string line = remaining.Substring(0, fittingCharacterCount);
                    remaining = remaining.Substring(fittingCharacterCount);

                    lines.Add(line);

                    // Add the line height:
                    Size size = directText.MeasureString(line, defaultFont);

                    lineHeights.Add(size.Height);

                    _layoutHeight += size.Height;
                }

                _lines = lines.ToArray();
                _lineHeights = lineHeights.ToArray();
            }

            return _layoutHeight;
        }
Пример #2
0
        public override void Initialize(DirectText directText, Font defaultFont)
        {
            Size size = directText.MeasureString(_text, defaultFont);

            _fullWidthForEstimation = size.Width;
            _heightForEstimation = size.Height;
        }