Alsing.Windows.Forms.CoreLib.FormatLabelControl.ApplyFormat C# (CSharp) Method

ApplyFormat() private method

private ApplyFormat ( Element Elements ) : void
Elements Alsing.Windows.Forms.FormatLabel.Element
return void
        private void ApplyFormat(Element[] Elements)
        {
            var bold = new Stack();
            var italic = new Stack();
            var underline = new Stack();
            var forecolor = new Stack();
            var backcolor = new Stack();
            var fontsize = new Stack();
            var fontname = new Stack();
            var link = new Stack();
            var effectcolor = new Stack();
            var effect = new Stack();

            bold.Push(Font.Bold);
            italic.Push(Font.Italic);
            underline.Push(Font.Underline);
            forecolor.Push(ForeColor);
            backcolor.Push(Color.Transparent);
            fontsize.Push((int) (Font.Size*1.3));
            fontname.Push(Font.Name);
            effect.Push(TextEffect.None);
            effectcolor.Push(Color.Black);
            link.Push(null);


            foreach (Element Element in Elements)
            {
                switch (Element.TagName)
                {
                    case "b":
                        {
                            bold.Push(true);
                            break;
                        }
                    case "a":
                        {
                            //underline.Push (true);
                            //forecolor.Push (_l);
                            link.Push(Element);
                            break;
                        }
                    case "i":
                    case "em":
                        {
                            italic.Push(true);
                            break;
                        }
                    case "u":
                        {
                            underline.Push(true);
                            break;
                        }
                    case "font":
                        {
                            string _fontname = GetAttrib("face", Element.Tag);
                            string _size = GetAttrib("size", Element.Tag);
                            string _color = GetAttrib("color", Element.Tag);
                            string _effectcolor = GetAttrib("effectcolor", Element.Tag);
                            string _effect = GetAttrib("effect", Element.Tag);


                            if (_size == "")
                                fontsize.Push(fontsize.Peek());
                            else
                                fontsize.Push(int.Parse(_size));

                            if (_fontname == "")
                                fontname.Push(fontname.Peek());
                            else
                                fontname.Push(_fontname);

                            if (_color == "")
                                forecolor.Push(forecolor.Peek());
                            else
                                forecolor.Push(Color.FromName(_color));

                            if (_effectcolor == "")
                                effectcolor.Push(effectcolor.Peek());
                            else
                                effectcolor.Push(Color.FromName(_effectcolor));

                            if (_effect == "")
                                effect.Push(effect.Peek());
                            else
                                effect.Push(Enum.Parse(typeof (TextEffect), _effect, true));

                            break;
                        }
                    case "br":
                        {
                            Element.NewLine = true;
                            break;
                        }
                    case "hr":
                        {
                            Element.NewLine = true;
                            break;
                        }
                    case "h3":
                        {
                            fontsize.Push((int) (Font.Size*1.4));
                            bold.Push(true);
                            Element.NewLine = true;
                            break;
                        }
                    case "h4":
                        {
                            fontsize.Push((int) (Font.Size*1.2));
                            bold.Push(true);
                            Element.NewLine = true;
                            break;
                        }
                    case "/b":
                        {
                            bold.Pop();
                            break;
                        }
                    case "/a":
                        {
                            //underline.Pop ();
                            //forecolor.Pop ();
                            link.Pop();
                            break;
                        }
                    case "/i":
                    case "/em":
                        {
                            italic.Pop();
                            break;
                        }
                    case "/u":
                        {
                            underline.Pop();
                            break;
                        }
                    case "/font":
                        {
                            fontname.Pop();
                            fontsize.Pop();
                            forecolor.Pop();
                            effect.Pop();
                            effectcolor.Pop();
                            break;
                        }
                    case "/h3":
                        {
                            fontsize.Pop();
                            bold.Pop();
                            Element.NewLine = true;
                            break;
                        }
                    case "/h4":
                        {
                            fontsize.Pop();
                            bold.Pop();
                            Element.NewLine = true;
                            break;
                        }

                    default:
                        {
                            break;
                        }
                }


                //---------------------------------------------------------------------
                var Bold = (bool) bold.Peek();
                var Italic = (bool) italic.Peek();
                var Underline = (bool) underline.Peek();
                var Link = (Element) link.Peek();
                var FontName = (string) fontname.Peek();
                var FontSize = (int) fontsize.Peek();
                var BackColor = (Color) backcolor.Peek();
                var ForeColor1 = (Color) forecolor.Peek();
                var Effect = (TextEffect) effect.Peek();
                var EffectColor = (Color) effectcolor.Peek();

                FontStyle fs = 0;
                if (Bold) fs |= FontStyle.Bold;
                if (Italic) fs |= FontStyle.Italic;
                if (Underline) fs |= FontStyle.Underline;

                var font = new Font(FontName, FontSize, fs);
                Element.Font = font;
                Element.BackColor = BackColor;
                Element.ForeColor = ForeColor1;
                Element.Link = Link;
                Element.Effect = Effect;
                Element.EffectColor = EffectColor;
            }
        }