Example #1
0
        public static RichTextBlock Format(RichTextBlock block, int width, IntPtr hdc)
        {
            RichTextBlock result = new RichTextBlock(block.Parameters);

            foreach (RichText line in block.Lines)
            {
                result.AddLines(Format(line, width, hdc));
            }

            return(result);
        }
Example #2
0
        public int AddLines(RichTextBlock lines)
        {
            Debug.Assert(lines != null);
            int result = -1;

            foreach (RichText line in lines.Lines)
            {
                result = myLines.Add(line);
            }

            return(result);
        }
Example #3
0
        public static RichTextBlock Format(RichText text, int width, IntPtr hdc)
        {
            RichTextBlock block = new RichTextBlock(new RichTextBlockParameters(1));

            while (text.GetSize(hdc).Width >= width)
            {
                int[]      positions = GetPossibleDivisionOffsets(text.Text);
                RichText[] parts, oldParts;

                oldParts = new RichText[] { text, new RichText("", text.Parameters) };

                foreach (int position in positions)
                {
                    parts = text.Split(position);

                    if (parts[0].GetSize(hdc).Width > width)
                    {
                        break;
                    }

                    oldParts = parts;
                }

                block.AddLine(oldParts[0]);

                if (oldParts[0].Length == 0) // prevent endless loop
                {
                    break;
                }

                text = oldParts[1];
            }

            block.AddLine(text);

            return(block);
        }