/// <summary> /// /// </summary> private void BuildTextBlocks() { // 1. Search for first tag // 2. If one is found, find its end position. // A. If end position not found, throw error. // 3. Create separate string containing the block of text. // 4. Search for inner tags. // 5. Build blocks of rich text info. // 6. Once the entire text is archived, layout the text line by line. // go through the text block once. // 1. Start by finding the first tag in the block. var text = Text; for (int j = 0; j < Text.Length; j++) { var firstTag = _hTMLTags[0]; var position = text.Length - 1; for (int i = 0; i < _hTMLTags.Count; i++) { var index = text.IndexOf(_hTMLTags[i]); if (index < position && index > -1) { position = index; firstTag = _hTMLTags[i]; } } // If the first tag is not at the beginning, add this string to the list. if (position != 0 && position != text.Length - 1) { var info = new RichTextInfo(); info.StartIndex = j; info.EndIndex = j + position - 1; info.Font = FontFamily; info.Text = Text.Substring(info.StartIndex, position - 1); _richTextInfo.Add(info); position--; } else if (position == text.Length - 1) { return; } // Extract the first excerpt with tags. var s = ExtractRawString(firstTag, j + position); // Determine fonts, etc. and add to the list. BuildTextInfo(s, j + position); j = _richTextInfo[_richTextInfo.Count - 1].EndIndex; text = Text.Substring(j); } }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="position"> </param> private void BuildTextInfo(string s, int position) { // 1. Search for inner tags. var tags = CollectTags(s); // 2. Determine the correct font. var font = BuildFontFamily(tags); var tLength = s.Length; // 3. Remove all tags. var text = RemoveTags(s); // 4. Build the rich text info. var info = new RichTextInfo(); info.StartIndex = position; info.EndIndex = position + tLength; info.Font = font; info.Text = text; _richTextInfo.Add(info); }