コード例 #1
0
 private void AppendUnorderedNumeration(TagFormatter tag)
 {
     for (int at = tag.StartsLength; at < tag.SelectLength + tag.StartsLength; ++at)
     {
         if (this.RTX.Text[at] == Listable)
         {
             this.RTX.Select(at, 1);
             this.RTX.SelectedText = "\u25CF";                     // middle dot
         }
     }
 }
コード例 #2
0
        public void AppendTextStyling(TagFormatter tag)
        {
            switch (tag.TagType)
            {
            case HTMLTagType.FontBoldedStyle:
            case HTMLTagType.FontItalicStyle:
            case HTMLTagType.FontULinedStyle:
            case HTMLTagType.FontStrikeStyle:
                var fonttype = TagToFontStyle(tag.TagType);
                this.RTX.Select(tag.StartsLength, tag.SelectLength);
                if (this.RTX.SelectionLength > 0)
                {
                    this.RTX.SelectionFont = new Font(this.RTX.SelectionFont, fonttype | this.RTX.SelectionFont.Style);
                }
                return;

            case HTMLTagType.Paragraph:
                this.RTX.Select(tag.StartsLength, tag.SelectLength);
                if (this.RTX.SelectionLength > 0)
                {
                    this.AppendFontStyling(tag);
                }
                return;

            case HTMLTagType.ReferenceLink:
                this.RTX.Select(tag.StartsLength, tag.SelectLength);
                if (this.RTX.SelectionLength == 0)
                {
                    return;
                }
                this.RTX.SelectionFont  = new Font(this.RTX.SelectionFont, FontStyle.Underline);
                this.RTX.SelectionColor = LinkColor;
                this._linkmap[this.RTX.SelectedText] = tag.SpecialSetting;
                return;

            case HTMLTagType.ListItem:
                this.RTX.Select(tag.StartsLength, 0);
                this.RTX.SelectedText   = $"\t{Listable} ";
                this.RTX.SelectionStart = this.RTX.Text.Length;
                this.RTX.AppendText(Environment.NewLine);
                return;

            case HTMLTagType.DottedList:
                this.AppendUnorderedNumeration(tag);
                return;

            case HTMLTagType.NumberedList:
                this.AppendOrderedNumeration(tag);
                return;

            default:
                return;
            }
        }
コード例 #3
0
        private void AppendOrderedNumeration(TagFormatter tag)
        {
            int lnum = 1;

            for (int at = tag.StartsLength; at < tag.SelectLength + tag.StartsLength; ++at)
            {
                if (this.RTX.Text[at] == Listable)
                {
                    this.RTX.Select(at, 1);
                    this.RTX.SelectedText = $"{(lnum++).ToString()}.";
                }
            }
        }
コード例 #4
0
        public void AppendMenuStyling(TagFormatter tag)
        {
            switch (tag.TagType)
            {
            case HTMLTagType.Title:
                Menu.Title = tag.SpecialSetting;
                return;

            case HTMLTagType.WWidth:
                if (int.TryParse(tag.SpecialSetting, out int width))
                {
                    Menu.Width = width;
                }
                return;

            case HTMLTagType.WHeight:
                if (int.TryParse(tag.SpecialSetting, out int height))
                {
                    Menu.Height = height;
                }
                return;

            case HTMLTagType.WFColor:
                if (Resolve.TryParseHTMLColor(tag.SpecialSetting, out var fcolor))
                {
                    Menu.WFColor = fcolor;
                }
                return;

            case HTMLTagType.WBColor:
                if (Resolve.TryParseHTMLColor(tag.SpecialSetting, out var bcolor))
                {
                    Menu.WBColor = bcolor;
                }
                return;

            default:
                return;
            }
        }
コード例 #5
0
        private void AppendFontStyling(TagFormatter tag)
        {
            if (string.IsNullOrEmpty(tag.SpecialSetting))
            {
                return;
            }
            char[] delim = new char[] { ':', ';' };
            var    split = tag.SpecialSetting.Split(delim, StringSplitOptions.RemoveEmptyEntries);

            for (int a = 0; a < split.Length; ++a)
            {
                split[a] = ScriptX.CleanString(split[a], true);
            }
            FontStyling styling;

            for (int a = 0; a < split.Length / 2; ++a)
            {
                switch (split[a * 2])
                {
                case "font-size":
                    styling = FontStyling.FontSize;
                    break;

                case "font-family":
                    styling = FontStyling.FontFamily;
                    break;

                case "color":
                    styling = FontStyling.Color;
                    break;

                case "background-color":
                    styling = FontStyling.BackgroundColor;
                    break;

                case "text-align":
                    styling = FontStyling.Align;
                    break;

                default:
                    continue;
                }
                switch (styling)
                {
                case FontStyling.FontSize:
                    if (int.TryParse(split[a * 2 + 1], out int size))
                    {
                        RTX.SelectionFont = new Font(RTX.SelectionFont.FontFamily, size, RTX.SelectionFont.Style);
                    }
                    continue;

                case FontStyling.FontFamily:
                    FontFamily fontfamily = null;
                    foreach (var family in FontFamily.Families)
                    {
                        if (split[a * 2 + 1] == family.Name)
                        {
                            fontfamily = family;
                        }
                    }
                    if (fontfamily != null)
                    {
                        RTX.SelectionFont = new Font(fontfamily, RTX.SelectionFont.Size, RTX.SelectionFont.Style);
                    }
                    continue;

                case FontStyling.Color:
                    if (Resolve.TryParseHTMLColor(split[a * 2 + 1], out var fcolor))
                    {
                        RTX.SelectionColor = fcolor;
                    }
                    continue;

                case FontStyling.BackgroundColor:
                    if (Resolve.TryParseHTMLColor(split[a * 2 + 1], out var bcolor))
                    {
                        RTX.SelectionBackColor = bcolor;
                    }
                    continue;

                case FontStyling.Align:
                    switch (split[a * 2 + 1])
                    {
                    case "left":
                        RTX.SelectionAlignment = HorizontalAlignment.Left;
                        goto default;

                    case "right":
                        RTX.SelectionAlignment = HorizontalAlignment.Right;
                        goto default;

                    case "center":
                        RTX.SelectionAlignment = HorizontalAlignment.Center;
                        goto default;

                    default:
                        continue;
                    }

                default:
                    continue;
                }
            }
        }
コード例 #6
0
ファイル: HTMLTextBox.cs プロジェクト: NFSTools/GlobalLib
        public void LoadHTMLTextBox(string[] lines)
        {
            char[] delim       = new char[] { '<', '>' };
            var    formatters  = new List <TagFormatter>();
            string variative   = null;
            bool   controlled  = false;
            bool   bodyprocess = false;

            foreach (var line in lines)
            {
                var nline = ScriptX.RemoveNewLines(line);
                nline = ScriptX.CleanString(nline, false);
                var words = nline.Split(delim);
                foreach (var word in words)
                {
                    if (string.IsNullOrEmpty(word))
                    {
                        continue;
                    }
                    if (word == StartTags.NewLine && bodyprocess)
                    {
                        this.RTX.AppendText(Environment.NewLine);
                        continue;
                    }
                    this.DefaultAllFormats();
                    if (this.IsEndTag(word))
                    {
                        if (!controlled && !bodyprocess)
                        {
                            continue;
                        }

                        int index = this.FindIndexByEndTag(word, formatters);
                        if (index == -1)
                        {
                            this.RTX.AppendText(word); continue;
                        }
                        formatters[index].SelectLength = this.RTX.Text.Length - formatters[index].StartsLength;

                        if (controlled)
                        {
                            formatters[index].SpecialSetting = variative;
                            this.AppendMenuStyling(formatters[index]);
                            variative = null;
                        }
                        else if (bodyprocess)
                        {
                            this.AppendTextStyling(formatters[index]);
                        }
                        else
                        {
                            continue;
                        }

                        if (formatters[index].TagType == HTMLTagType.Head)
                        {
                            controlled = false;
                        }

                        if (formatters[index].TagType == HTMLTagType.Body)
                        {
                            bodyprocess = false;
                        }

                        formatters.RemoveAt(index);
                    }
                    else if (this.IsStartTag(word))
                    {
                        string setting = null;
                        var    tag     = new TagFormatter();
                        tag.StartsLength = this.RTX.Text.Length;
                        tag.SelectLength = 0;
                        tag.TagType      = this.GetTagType(word, ref setting);
                        if (setting != null)
                        {
                            tag.SpecialSetting = setting;
                        }

                        if (tag.TagType == HTMLTagType.Head)
                        {
                            controlled = true;
                        }
                        else if (tag.TagType == HTMLTagType.Body)
                        {
                            bodyprocess = true;
                        }
                        else if (tag.TagType == HTMLTagType.Comment)
                        {
                            continue;
                        }
                        else if (tag.TagType == HTMLTagType.ImageLink)
                        {
                            continue;
                        }

                        formatters.Add(tag);
                    }
                    else if (controlled)
                    {
                        variative += word;
                    }
                    else if (bodyprocess)
                    {
                        this.RTX.AppendText(word);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }