private int MapAlignment(HtmlAlignment alignment)
        {
            switch (alignment)
            {
            case HtmlAlignment.Left:
                return(NativeMethods.IDM_JUSTIFYLEFT);

            case HtmlAlignment.Right:
                return(NativeMethods.IDM_JUSTIFYRIGHT);

            case HtmlAlignment.Center:
                return(NativeMethods.IDM_JUSTIFYCENTER);
            }
            return(-1);
        }
Example #2
0
        public void Update(string text, UnicodeFont initialFont, int initialColor)
        {
            int      width1    = this.m_Width;
            Stack    stack1    = new Stack();
            FontInfo fontInfo1 = new FontInfo(initialFont, initialColor);
            int      num1      = 0;
            int      num2      = 0;
            Stack    stack2    = new Stack();
            Stack    stack3    = new Stack();

            text = text.Replace("\r", "");
            text = text.Replace("\n", "<br>");
            HtmlElement[] elements = HtmlElement.GetElements(text);
            int           num3     = 0;
            int           num4     = 0;

            for (int index1 = 0; index1 < elements.Length; ++index1)
            {
                HtmlElement   htmlElement   = elements[index1];
                FontInfo      fontInfo2     = stack1.Count > 0 ? (FontInfo)stack1.Peek() : fontInfo1;
                HtmlAlignment htmlAlignment = stack2.Count > 0 ? (HtmlAlignment)stack2.Peek() : HtmlAlignment.Normal;
                string        url           = stack3.Count > 0 ? (string)stack3.Peek() : (string)null;
                switch (htmlElement.Type)
                {
                case ElementType.Text:
                    string text1 = htmlElement.Name;
                    bool   flag  = false;
                    while (text1.Length > 0)
                    {
                        int num5 = num3;
                        switch (htmlAlignment & (HtmlAlignment)255)
                        {
                        case HtmlAlignment.Center:
                            int stringWidth1 = fontInfo2.Font.GetStringWidth(text1);
                            if (stringWidth1 > width1)
                            {
                                string[] strArray = Engine.WrapText(text1, width1, (IFont)fontInfo2.Font).Split('\n');
                                stringWidth1 = fontInfo2.Font.GetStringWidth(strArray[0]);
                            }
                            num5 = (width1 - (stringWidth1 - 1) + 1) / 2;
                            break;

                        case HtmlAlignment.Left:
                            num5 = (int)htmlAlignment >> 8;
                            break;

                        case HtmlAlignment.Right:
                            int stringWidth2 = fontInfo2.Font.GetStringWidth(text1);
                            if (stringWidth2 > width1)
                            {
                                string[] strArray = Engine.WrapText(text1, width1, (IFont)fontInfo2.Font).Split('\n');
                                stringWidth2 = fontInfo2.Font.GetStringWidth(strArray[0]);
                            }
                            num5 = ((int)htmlAlignment >> 8) - stringWidth2;
                            break;
                        }
                        string[] strArray1 = text1.Split(' ');
                        int      width2    = width1 - num5;
                        if (!flag && fontInfo2.Font.GetStringWidth(strArray1[0]) > width2)
                        {
                            flag  = true;
                            num3  = 0;
                            num4 += 18;
                        }
                        else
                        {
                            flag = false;
                            string[] strArray2 = Engine.WrapText(text1, width2, (IFont)fontInfo2.Font).Split('\n');
                            string   str       = strArray2[0];
                            if (strArray2.Length > 1)
                            {
                                str = str.TrimEnd();
                            }
                            GLabel glabel = url == null ? new GLabel(str, (IFont)fontInfo2.Font, fontInfo2.Hue, num5, num4) : (GLabel) new GHyperLink(url, str, (IFont)fontInfo2.Font, num5, num4);
                            if (url == null)
                            {
                                glabel.Underline = num1 > 0;
                            }
                            this.m_Children.Add((Gump)glabel);
                            if (strArray2.Length > 1)
                            {
                                text1 = text1.Remove(0, strArray2[0].Length);
                                num3  = 0;
                                num4 += 18;
                            }
                            else
                            {
                                num3 = glabel.X + glabel.Width - 1;
                                break;
                            }
                        }
                    }
                    break;

                case ElementType.Start:
                    switch (htmlElement.Name.ToLower())
                    {
                    case "br":
                        num3  = 0;
                        num4 += 18;
                        continue;

                    case "u":
                        ++num1;
                        continue;

                    case "i":
                        ++num2;
                        continue;

                    case "a":
                        string attribute1 = htmlElement.GetAttribute("href");
                        if (attribute1 != null && !attribute1.StartsWith("?"))
                        {
                            stack3.Push((object)attribute1);
                            continue;
                        }
                        continue;

                    case "basefont":
                        string attribute2 = htmlElement.GetAttribute("color");
                        if (attribute2 != null)
                        {
                            int color = 0;
                            if (attribute2.StartsWith("#"))
                            {
                                color = Convert.ToInt32(attribute2.Substring(1), 16);
                            }
                            else
                            {
                                for (int index2 = 0; index2 < GHtmlLabel.m_ColorTable.GetLength(0); ++index2)
                                {
                                    if (attribute2.ToLower() == (string)GHtmlLabel.m_ColorTable[index2, 0])
                                    {
                                        color = (int)GHtmlLabel.m_ColorTable[index2, 1];
                                        break;
                                    }
                                }
                            }
                            stack1.Push((object)new FontInfo(fontInfo2.Font, color));
                            continue;
                        }
                        continue;

                    case "center":
                        stack2.Push((object)HtmlAlignment.Center);
                        continue;

                    case "div":
                        string attribute3 = htmlElement.GetAttribute("align");
                        if (attribute3 == null)
                        {
                            string attribute4 = htmlElement.GetAttribute("alignleft");
                            if (attribute4 != null)
                            {
                                try
                                {
                                    int num5 = int.Parse(attribute4);
                                    stack2.Push((object)(HtmlAlignment)(2 | num5 << 8));
                                }
                                catch
                                {
                                }
                            }
                            string attribute5 = htmlElement.GetAttribute("alignright");
                            if (attribute5 != null)
                            {
                                try
                                {
                                    int num5 = int.Parse(attribute5);
                                    stack2.Push((object)(HtmlAlignment)(3 | num5 << 8));
                                    continue;
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            switch (attribute3.ToLower())
                            {
                            case "center":
                                stack2.Push((object)HtmlAlignment.Center);
                                continue;

                            case "right":
                                stack2.Push((object)(HtmlAlignment)(3 | width1 << 8));
                                continue;

                            case "left":
                                stack2.Push((object)HtmlAlignment.Left);
                                continue;

                            default:
                                continue;
                            }
                        }

                    default:
                        continue;
                    }

                case ElementType.End:
                    switch (htmlElement.Name.ToLower())
                    {
                    case "u":
                        --num1;
                        if (num1 < 0)
                        {
                            num1 = 0;
                            continue;
                        }
                        continue;

                    case "i":
                        --num2;
                        if (num2 < 0)
                        {
                            num2 = 0;
                            continue;
                        }
                        continue;

                    case "a":
                        if (stack3.Count > 0)
                        {
                            stack3.Pop();
                            continue;
                        }
                        continue;

                    case "basefont":
                        if (stack1.Count > 0)
                        {
                            stack1.Pop();
                            continue;
                        }
                        continue;

                    case "div":
                    case "center":
                        if (stack2.Count > 0)
                        {
                            stack2.Pop();
                            continue;
                        }
                        continue;

                    default:
                        continue;
                    }
                }
            }
            this.m_Height = num4 + 18;
        }
 public bool CanAlign(HtmlAlignment alignment)
 {
     return(this.control.IsEnabled(this.MapAlignment(alignment)));
 }
Example #4
0
        public void Update(string text, UnicodeFont initialFont, int initialColor)
        {
            int      width  = this.m_Width;
            Stack    stack  = new Stack();
            FontInfo info   = new FontInfo(initialFont, initialColor);
            int      num2   = 0;
            int      num3   = 0;
            Stack    stack2 = new Stack();
            Stack    stack3 = new Stack();

            text = text.Replace("\r", "");
            text = text.Replace("\n", "<br>");
            HtmlElement[] elements = HtmlElement.GetElements(text);
            int           num4     = 0;
            int           y        = 0;

            for (int i = 0; i < elements.Length; i++)
            {
                string        name;
                bool          flag;
                int           stringWidth;
                string        str7;
                string        str8;
                string        attribute;
                string        str10;
                HtmlElement   element   = elements[i];
                FontInfo      info2     = (stack.Count > 0) ? ((FontInfo)stack.Peek()) : info;
                HtmlAlignment alignment = (stack2.Count > 0) ? ((HtmlAlignment)stack2.Peek()) : HtmlAlignment.Normal;
                string        url       = (stack3.Count > 0) ? ((string)stack3.Peek()) : null;
                switch (element.Type)
                {
                case ElementType.Text:
                    name = element.Name;
                    flag = false;
                    goto Label_02F6;

                case ElementType.Start:
                {
                    str10 = element.Name.ToLower();
                    if (str10 != null)
                    {
                        str10 = string.IsInterned(str10);
                        if (str10 == "br")
                        {
                            num4 = 0;
                            y   += 0x12;
                        }
                        else
                        {
                            if (str10 == "u")
                            {
                                goto Label_03A3;
                            }
                            if (str10 == "i")
                            {
                                goto Label_03AC;
                            }
                            if (str10 == "a")
                            {
                                goto Label_03B7;
                            }
                            if (str10 == "basefont")
                            {
                                goto Label_03E5;
                            }
                            if (str10 == "center")
                            {
                                goto Label_048A;
                            }
                            if (str10 == "div")
                            {
                                goto Label_049C;
                            }
                        }
                    }
                    continue;
                }

                case ElementType.End:
                {
                    str10 = element.Name.ToLower();
                    if (str10 != null)
                    {
                        str10 = string.IsInterned(str10);
                        if (str10 == "u")
                        {
                            num2--;
                            if (num2 < 0)
                            {
                                num2 = 0;
                            }
                        }
                        else
                        {
                            if (str10 == "i")
                            {
                                goto Label_0610;
                            }
                            if (str10 == "a")
                            {
                                goto Label_0620;
                            }
                            if (str10 == "basefont")
                            {
                                goto Label_0634;
                            }
                            if ((str10 == "div") || (str10 == "center"))
                            {
                                goto Label_0646;
                            }
                        }
                    }
                    continue;
                }

                default:
                {
                    continue;
                }
                }
Label_00EB:
                stringWidth = num4;
                switch ((alignment & ((HtmlAlignment)0xff)))
                {
                case HtmlAlignment.Center:
                    stringWidth = info2.Font.GetStringWidth(name);
                    if (stringWidth > width)
                    {
                        string[] strArray = Engine.WrapText(name, width, info2.Font).Split(new char[] { '\n' });
                        stringWidth = info2.Font.GetStringWidth(strArray[0]);
                    }
                    stringWidth = ((width - (stringWidth - 1)) + 1) / 2;
                    break;

                case HtmlAlignment.Left:
                    stringWidth = ((int)alignment) >> 8;
                    break;

                case HtmlAlignment.Right:
                    stringWidth = info2.Font.GetStringWidth(name);
                    if (stringWidth > width)
                    {
                        string[] strArray2 = Engine.WrapText(name, width, info2.Font).Split(new char[] { '\n' });
                        stringWidth = info2.Font.GetStringWidth(strArray2[0]);
                    }
                    stringWidth = (((int)alignment) >> 8) - stringWidth;
                    break;
                }
                string[] strArray3 = name.Split(new char[] { ' ' });
                int      num8      = width - stringWidth;
                if (!flag && (info2.Font.GetStringWidth(strArray3[0]) > num8))
                {
                    flag = true;
                    num4 = 0;
                    y   += 0x12;
                }
                else
                {
                    flag      = false;
                    strArray3 = Engine.WrapText(name, num8, info2.Font).Split(new char[] { '\n' });
                    string str6 = strArray3[0];
                    if (strArray3.Length > 1)
                    {
                        str6 = str6.TrimEnd(new char[0]);
                    }
                    GLabel toAdd = (url == null) ? new GLabel(str6, info2.Font, info2.Hue, stringWidth, y) : new GHyperLink(url, str6, info2.Font, stringWidth, y);
                    if (url == null)
                    {
                        toAdd.Underline = num2 > 0;
                    }
                    base.m_Children.Add(toAdd);
                    if (strArray3.Length > 1)
                    {
                        name = name.Remove(0, strArray3[0].Length);
                        num4 = 0;
                        y   += 0x12;
                    }
                    else
                    {
                        num4 = (toAdd.X + toAdd.Width) - 1;
                        continue;
                    }
                }
Label_02F6:
                if (name.Length > 0)
                {
                    goto Label_00EB;
                }
                continue;
Label_03A3:
                num2++;
                continue;
Label_03AC:
                num3++;
                continue;
Label_03B7:
                str7 = element.GetAttribute("href");
                if ((str7 != null) && !str7.StartsWith("?"))
                {
                    stack3.Push(str7);
                }
                continue;
Label_03E5:
                str8 = element.GetAttribute("color");
                if (str8 == null)
                {
                    continue;
                }
                int color = 0;
                if (str8.StartsWith("#"))
                {
                    color = Convert.ToInt32(str8.Substring(1), 0x10);
                }
                else
                {
                    for (int j = 0; j < m_ColorTable.GetLength(0); j++)
                    {
                        if (str8.ToLower() == ((string)m_ColorTable[j, 0]))
                        {
                            color = (int)m_ColorTable[j, 1];
                            break;
                        }
                    }
                }
                stack.Push(new FontInfo(info2.Font, color));
                continue;
Label_048A:
                stack2.Push(HtmlAlignment.Center);
                continue;
Label_049C:
                attribute = element.GetAttribute("align");
                if (attribute == null)
                {
                    attribute = element.GetAttribute("alignleft");
                    if (attribute != null)
                    {
                        try
                        {
                            int num11 = int.Parse(attribute);
                            stack2.Push(HtmlAlignment.Left | ((HtmlAlignment)(num11 << 8)));
                        }
                        catch
                        {
                        }
                    }
                    attribute = element.GetAttribute("alignright");
                    if (attribute != null)
                    {
                        try
                        {
                            int num12 = int.Parse(attribute);
                            stack2.Push(HtmlAlignment.Right | ((HtmlAlignment)(num12 << 8)));
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    switch (attribute.ToLower())
                    {
                    case "center":
                        stack2.Push(HtmlAlignment.Center);
                        break;

                    case "right":
                        stack2.Push(HtmlAlignment.Right | ((HtmlAlignment)(width << 8)));
                        break;

                    case "left":
                        stack2.Push(HtmlAlignment.Left);
                        break;
                    }
                }
                continue;
Label_0610:
                num3--;
                if (num3 < 0)
                {
                    num3 = 0;
                }
                continue;
Label_0620:
                if (stack3.Count > 0)
                {
                    stack3.Pop();
                }
                continue;
Label_0634:
                if (stack.Count > 0)
                {
                    stack.Pop();
                }
                continue;
Label_0646:
                if (stack2.Count > 0)
                {
                    stack2.Pop();
                }
            }
            this.m_Height = y + 0x12;
        }