示例#1
0
        internal void CalcCutOffsW(int maxWidth, bool allowIME, bool charWrap, Line line, Font font)
        {
            int segmentLength = 0;
            int cutOff        = 0;

            CutOffPositions.Clear();

            for (int i = 0; i < line.Count; i++)
            {
                char c = line[i].c;
                if (charWrap)
                {
                    //char wrapping
                    cutOff = Math.Min(i + 1, line.Count - 1);
                }
                else
                {
                    //word wrapping
                    if (allowIME && isCJKLetter(c))//in CJK languages cutoff can be in any letter
                    {
                        cutOff = i;
                    }
                    else
                    if (!char.IsLetterOrDigit(c) && c != '_')
                    {
                        cutOff = Math.Min(i + 1, line.Count - 1);
                    }
                }

                int width = (int)FastColoredTextBox.GetCharSize(font, line[i].c).Width;

                if (segmentLength + width >= maxWidth)
                {
                    if (cutOff == 0 || (cutOffPositions.Count > 0 && cutOff == cutOffPositions[cutOffPositions.Count - 1]))
                    {
                        cutOff = i + 1;
                    }
                    CutOffPositions.Add(cutOff);
                    // segmentLength = 1 + i - cutOff;
                    segmentLength = 0;
                }
                else
                {
                    segmentLength += width;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Calculates wordwrap cutoffs
        /// </summary>
        internal void CalcCutOffs(int maxCharsPerLine, bool allowIME, bool charWrap, Line line)
        {
            int segmentLength = 0;
            int cutOff        = 0;

            CutOffPositions.Clear();

            //for (int i = 0; i < line.Count; i++)
            for (int i = 0; i < line.Count - 1; i++)
            {
                char c = line[i].c;
                if (charWrap)
                {
                    //char wrapping
                    //cutOff = Math.Min(i + 1, line.Count - 1);
                    cutOff = i + 1;
                }
                else
                {
                    //word wrapping
                    if (allowIME && isCJKLetter(c))//in CJK languages cutoff can be in any letter
                    {
                        cutOff = i;
                    }
                    else
                    if (!char.IsLetterOrDigit(c) && c != '_' && c != '\'')
                    {
                        cutOff = Math.Min(i + 1, line.Count - 1);
                    }
                }

                segmentLength++;

                if (segmentLength == maxCharsPerLine)
                {
                    if (cutOff == 0 || (cutOffPositions.Count > 0 && cutOff == cutOffPositions[cutOffPositions.Count - 1]))
                    {
                        cutOff = i + 1;
                    }
                    CutOffPositions.Add(cutOff);
                    segmentLength = 1 + i - cutOff;
                }
            }
        }