Example #1
0
 public void ParseTag(HTMLchunk chunk, AElement atom)
 {
     if (!chunk.bClosure || chunk.bEndClosure)
     {
         // create the tag and add it to the list of open tags.
         OpenTag tag = new OpenTag(chunk);
         m_OpenTags.Add(tag);
         // parse the tag (which will update the StyleParser's current style
         ParseTag(tag, atom);
         // if the style has changed and atom is not null, set the atom's style to the current style.
         if (atom != null)
         {
             atom.Style = Style;
         }
         // if this is a self-closing tag (<br/>) close it!
         if (chunk.bEndClosure)
         {
             CloseOneTag(chunk);
         }
     }
     else
     {
         CloseOneTag(chunk);
     }
 }
Example #2
0
        public void InterpretHREF(HTMLchunk chunk, AElement atom)
        {
            if (chunk.bEndClosure)
            {
                // solo anchor elements are meaningless.
            }

            if (!chunk.bClosure)
            {
                // opening a hyperlink!
                RecalculateStyle();
                OpenTag tag = new OpenTag(chunk);
                m_OpenTags.Add(tag);
                ParseTag(tag, atom);
            }
            else
            {
                // closing a hyperlink.
                RecalculateStyle();
            }
        }
Example #3
0
        private void ParseTag(OpenTag tag, AElement atom = null)
        {
            switch (tag.sTag)
            {
            case "b":
                Style.IsBold = true;
                break;

            case "i":
                Style.IsItalic = true;
                break;

            case "u":
                Style.IsUnderlined = true;
                break;

            case "outline":
                Style.IsOutlined = true;
                break;

            case "big":
                Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeBig);
                break;

            case "basefont":
            case "medium":
                Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeMedium);
                break;

            case "small":
                Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeSmall);
                break;

            case "left":
                if (atom != null && atom is BlockElement)
                {
                    (atom as BlockElement).Alignment = Alignments.Left;
                }
                break;

            case "center":
                if (atom != null && atom is BlockElement)
                {
                    (atom as BlockElement).Alignment = Alignments.Center;
                }
                break;

            case "right":
                if (atom != null && atom is BlockElement)
                {
                    (atom as BlockElement).Alignment = Alignments.Right;
                }
                break;
            }

            foreach (DictionaryEntry param in tag.oParams)
            {
                // get key and value for this tag param
                string key   = param.Key.ToString();
                string value = param.Value.ToString();
                if (value.StartsWith("0x"))
                {
                    value = Utility.ToInt32(value).ToString();
                }
                // trim trailing forward slash.
                if (value.EndsWith("/"))
                {
                    value = value.Substring(0, value.Length - 1);
                }

                switch (key)
                {
                case "href":
                    // href paramater can only be used on 'anchor' tags.
                    if (tag.sTag == "a")
                    {
                        Style.HREF = value;
                    }
                    break;

                case "color":
                case "hovercolor":
                case "activecolor":
                    // get the color!
                    string color = value;
                    Color? c     = null;
                    if (color[0] == '#')
                    {
                        color = color.Substring(1);
                        if (color.Length == 3 || color.Length == 6)
                        {
                            c = Utility.ColorFromHexString(color);
                        }
                    }
                    else
                    {
                        //try to parse color by name
                        c = Utility.ColorFromString(color);
                    }

                    if (c.HasValue)
                    {
                        if (key == "color")
                        {
                            Style.Color = c.Value;
                        }
                        if (tag.sTag == "a")
                        {
                            // a tag colors are override, they are rendered white and then hued with a websafe hue.
                            switch (key)
                            {
                            case "color":
                                Style.ColorHue = m_Provider.GetWebSafeHue(c.Value);
                                break;

                            case "hovercolor":
                                Style.HoverColorHue = m_Provider.GetWebSafeHue(c.Value);
                                break;

                            case "activecolor":
                                Style.ActiveColorHue = m_Provider.GetWebSafeHue(c.Value);
                                break;

                            default:
                                Tracer.Warn("Only anchor <a> tags can have attribute {0}.", key);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Tracer.Warn("Improperly formatted color:" + color);
                    }
                    break;

                case "src":
                case "hoversrc":
                case "activesrc":
                    if (atom is ImageElement)
                    {
                        switch (key)
                        {
                        case "src":
                            (atom as ImageElement).ImgSrc = int.Parse(value);
                            break;

                        case "hoversrc":
                            (atom as ImageElement).ImgSrcOver = int.Parse(value);
                            break;

                        case "activesrc":
                            (atom as ImageElement).ImgSrcDown = int.Parse(value);
                            break;
                        }
                        break;
                    }
                    Tracer.Warn("{0} param encountered within {1} tag which does not use this param.", key, tag.sTag);
                    break;

                case "width":
                {
                    if (atom is ImageElement || atom is BlockElement)
                    {
                        atom.Width = int.Parse(value);
                    }
                    else
                    {
                        Tracer.Warn("width param encountered within " + tag.sTag + " which does not use this param.");
                    }
                }
                break;

                case "height":
                {
                    if (atom is ImageElement || atom is BlockElement)
                    {
                        atom.Height = int.Parse(value);
                    }
                    else
                    {
                        Tracer.Warn("width param encountered within " + tag.sTag + " which does not use this param.");
                    }
                }
                break;

                case "style":
                    ParseStyle(value);
                    break;

                default:
                    Tracer.Warn(string.Format("Unknown parameter:{0}", key));
                    break;
                }
            }
        }