コード例 #1
0
ファイル: TextLayoutManager.cs プロジェクト: i-e-b/Form8sn
        // Get the width of the span in pixels.
        private int GetSpanWidth(CharSpan span)
        {
            if (_text == null || _format == null)
            {
                throw new InvalidOperationException();
            }

            // set the width of the span, if needed
            if (span.pixelWidth != -1)
            {
                return(span.pixelWidth);
            }

            // get the text of the span
            string s = _text.Substring(span.start, span.length);

            // set the width of the span
            span.pixelWidth = MeasureStringWidth(s, _measureLayoutRect, _format);

            // return the width of the span
            return(span.pixelWidth);
        }
コード例 #2
0
ファイル: TextLayoutManager.cs プロジェクト: i-e-b/Form8sn
        // Get the next span of characters.
        private void GetNextSpan(CharSpan span)
        {
            if (_text == null)
            {
                throw new InvalidOperationException();
            }

            // set new line flag
            var newline = false;

            // get the start index
            var start = nextIndex;

            // handle whitespace span
            while (nextIndex < _text.Length && _text[nextIndex] == ' ')
            {
                ++nextIndex;
            }

            // handle word span
            if (nextIndex == start)
            {
                // find the end of the word
                while (nextIndex < _text.Length)
                {
                    // get the current character
                    char c = _text[nextIndex];

                    // find the end of the word
                    if (c == ' ' || c == '\n' || c == '\r')
                    {
                        break;
                    }

                    // we also split on minus to mimic MS behavior
                    if (c == '-')
                    {
                        nextIndex++;
                        break;
                    }

                    // move to the next character
                    ++nextIndex;
                }
            }

            // get the length of the span
            int length = nextIndex - start;

            // handle new line characters
            if (nextIndex < _text.Length)
            {
                // get the current character
                char c = _text[nextIndex];

                // check for new line characters
                if (c == '\r')
                {
                    // move past the carriage return
                    ++nextIndex;

                    // move past the line feed, if needed
                    if (nextIndex < _text.Length &&
                        _text[nextIndex] == '\n')
                    {
                        ++nextIndex;
                    }

                    // set the new line flag
                    newline = true;
                }
                else if (c == '\n')
                {
                    // move past the line feed
                    ++nextIndex;

                    // set the new line flag
                    newline = true;
                }
            }

            // set the span values
            span.Set(start, length, prevIsNewLine);

            // update the previous span ended in new line flag
            prevIsNewLine = newline;

            // handle wrapping
            CheckForWrap(span);
        }