示例#1
0
        protected override bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key)
        {
            string str;
            HtmlTextWriterStyle style5;

            if (this.Supports(1))
            {
                switch (key)
                {
                case HtmlTextWriterStyle.Color:
                    this._fontColor     = value;
                    this._renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.FontFamily:
                    this._fontFace      = value;
                    this._renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    this._fontSize = this.ConvertToHtmlFontSize(value);
                    if (this._fontSize != null)
                    {
                        this._renderFontTag = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (!StringUtil.EqualsIgnoreCase(value, "normal") && this.SupportsItalic)
                    {
                        this.AppendOtherTag("i");
                    }
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (StringUtil.EqualsIgnoreCase(value, "bold") && this.SupportsBold)
                    {
                        this.AppendOtherTag("b");
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    str = value.ToLower(CultureInfo.InvariantCulture);
                    if (str.IndexOf("underline", StringComparison.Ordinal) != -1)
                    {
                        this.AppendOtherTag("u");
                    }
                    if (str.IndexOf("line-through", StringComparison.Ordinal) != -1)
                    {
                        this.AppendOtherTag("strike");
                    }
                    break;
                }
            }
            else if (this.Supports(0x10))
            {
                FontStackItem item = (FontStackItem)this.FontStack.Peek();
                switch (key)
                {
                case HtmlTextWriterStyle.Color:
                    item.color = value;
                    break;

                case HtmlTextWriterStyle.FontFamily:
                    item.name = value;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    item.size = this.ConvertToHtmlFontSize(value);
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (!StringUtil.EqualsIgnoreCase(value, "normal"))
                    {
                        item.italic = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (StringUtil.EqualsIgnoreCase(value, "bold"))
                    {
                        item.bold = true;
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    str = value.ToLower(CultureInfo.InvariantCulture);
                    if (str.IndexOf("underline", StringComparison.Ordinal) != -1)
                    {
                        item.underline = true;
                    }
                    if (str.IndexOf("line-through", StringComparison.Ordinal) != -1)
                    {
                        item.strikeout = true;
                    }
                    break;
                }
            }
            if (this.Supports(0x80) && (key == HtmlTextWriterStyle.BorderWidth))
            {
                str = this.ConvertToHtmlSize(value);
                if (str != null)
                {
                    this.AddAttribute(HtmlTextWriterAttribute.Border, str);
                }
            }
            if (this.Supports(0x100) && (key == HtmlTextWriterStyle.WhiteSpace))
            {
                this.AddAttribute(HtmlTextWriterAttribute.Nowrap, value);
            }
            if (this.Supports(0x40))
            {
                switch (key)
                {
                case HtmlTextWriterStyle.Height:
                    str = this.ConvertToHtmlSize(value);
                    if (str != null)
                    {
                        this.AddAttribute(HtmlTextWriterAttribute.Height, str);
                    }
                    break;

                case HtmlTextWriterStyle.Width:
                    str = this.ConvertToHtmlSize(value);
                    if (str != null)
                    {
                        this.AddAttribute(HtmlTextWriterAttribute.Width, str);
                    }
                    break;
                }
            }
            if (this.Supports(4) || this.Supports(8))
            {
                switch (key)
                {
                case HtmlTextWriterStyle.BackgroundColor:
                {
                    HtmlTextWriterTag tagKey = base.TagKey;
                    if (tagKey > HtmlTextWriterTag.Div)
                    {
                        switch (tagKey)
                        {
                        case HtmlTextWriterTag.Table:
                        case HtmlTextWriterTag.Td:
                        case HtmlTextWriterTag.Th:
                            goto Label_031C;

                        case HtmlTextWriterTag.Tbody:
                            goto Label_03CF;
                        }
                        if (tagKey != HtmlTextWriterTag.Tr)
                        {
                            break;
                        }
                        goto Label_031C;
                    }
                    switch (tagKey)
                    {
                    case HtmlTextWriterTag.Body:
                        goto Label_031C;

                    case HtmlTextWriterTag.Div:
                        if (this.ShouldPerformDivTableSubstitution)
                        {
                            this.AddAttribute(HtmlTextWriterAttribute.Bgcolor, value);
                        }
                        break;
                    }
                    break;
                }

                case HtmlTextWriterStyle.BackgroundImage:
                {
                    HtmlTextWriterTag tag3 = base.TagKey;
                    if (tag3 > HtmlTextWriterTag.Div)
                    {
                        switch (tag3)
                        {
                        case HtmlTextWriterTag.Table:
                        case HtmlTextWriterTag.Td:
                            goto Label_0379;

                        case HtmlTextWriterTag.Tbody:
                            goto Label_03CF;
                        }
                        if (tag3 != HtmlTextWriterTag.Th)
                        {
                            break;
                        }
                        goto Label_0379;
                    }
                    switch (tag3)
                    {
                    case HtmlTextWriterTag.Body:
                        goto Label_0379;

                    case HtmlTextWriterTag.Div:
                        if (this.ShouldPerformDivTableSubstitution)
                        {
                            if (StringUtil.StringStartsWith(value, "url("))
                            {
                                value = value.Substring(4, value.Length - 5);
                            }
                            this.AddAttribute(HtmlTextWriterAttribute.Background, value);
                        }
                        break;
                    }
                    break;
                }

                case HtmlTextWriterStyle.BorderColor:
                    if ((base.TagKey == HtmlTextWriterTag.Div) && this.ShouldPerformDivTableSubstitution)
                    {
                        this.AddAttribute(HtmlTextWriterAttribute.Bordercolor, value);
                    }
                    break;
                }
            }
            goto Label_03CF;
Label_031C:
            this.AddAttribute(HtmlTextWriterAttribute.Bgcolor, value);
            goto Label_03CF;
Label_0379:
            if (StringUtil.StringStartsWith(value, "url("))
            {
                value = value.Substring(4, value.Length - 5);
            }
            this.AddAttribute(HtmlTextWriterAttribute.Background, value);
Label_03CF:
            style5 = key;
            if (style5 != HtmlTextWriterStyle.ListStyleType)
            {
                switch (style5)
                {
                case HtmlTextWriterStyle.TextAlign:
                    this.AddAttribute(HtmlTextWriterAttribute.Align, value);
                    break;

                case HtmlTextWriterStyle.VerticalAlign:
                    this.AddAttribute(HtmlTextWriterAttribute.Valign, value);
                    break;

                case HtmlTextWriterStyle.Display:
                    return(true);
                }
            }
            else
            {
                switch (value)
                {
                case "decimal":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, "1");
                    goto Label_052E;

                case "lower-alpha":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, "a");
                    goto Label_052E;

                case "upper-alpha":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, "A");
                    goto Label_052E;

                case "lower-roman":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, "i");
                    goto Label_052E;

                case "upper-roman":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, "I");
                    goto Label_052E;

                case "disc":
                case "circle":
                case "square":
                    this.AddAttribute(HtmlTextWriterAttribute.Type, value);
                    goto Label_052E;
                }
                this.AddAttribute(HtmlTextWriterAttribute.Type, "disc");
            }
Label_052E:
            return(false);
        }
示例#2
0
 private void ConsumeFont(StringBuilder sbBegin, StringBuilder sbEnd)
 {
     if (this.FontStack.Count > 0)
     {
         string      fontFace   = null;
         string      fontColor  = null;
         string      fontSize   = null;
         bool        underline  = false;
         bool        italic     = false;
         bool        bold       = false;
         bool        strikeout  = false;
         IEnumerator enumerator = this.FontStack.GetEnumerator();
         while (enumerator.MoveNext())
         {
             FontStackItem current = (FontStackItem)enumerator.Current;
             if (fontFace == null)
             {
                 fontFace = current.name;
             }
             if (fontColor == null)
             {
                 fontColor = current.color;
             }
             if (fontSize == null)
             {
                 fontSize = current.size;
             }
             if (!underline)
             {
                 underline = current.underline;
             }
             if (!italic)
             {
                 italic = current.italic;
             }
             if (!bold)
             {
                 bold = current.bold;
             }
             if (!strikeout)
             {
                 strikeout = current.strikeout;
             }
         }
         if (((fontFace != null) || (fontColor != null)) || (fontSize != null))
         {
             this.AppendFontTag(fontFace, fontColor, fontSize, sbBegin, sbEnd);
         }
         if (underline)
         {
             this.AppendOtherTag("u", sbBegin, sbEnd);
         }
         if (italic && this.SupportsItalic)
         {
             this.AppendOtherTag("i", sbBegin, sbEnd);
         }
         if (bold && this.SupportsBold)
         {
             this.AppendOtherTag("b", sbBegin, sbEnd);
         }
         if (strikeout)
         {
             this.AppendOtherTag("strike", sbBegin, sbEnd);
         }
     }
 }
示例#3
0
        /// <include file='doc\Html32TextWriter.uex' path='docs/doc[@for="Html32TextWriter.OnStyleAttributeRender"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key)
        {
            string s;

            if (Supports(FONT_AROUND_CONTENT))
            {
                // tag supports downlevel fonts
                switch (key)
                {
                case HtmlTextWriterStyle.FontFamily:
                    _fontFace      = value;
                    _renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.Color:
                    _fontColor     = value;
                    _renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    _fontSize = ConvertToHtmlFontSize(value);
                    if (_fontSize != null)
                    {
                        _renderFontTag = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (String.Compare(value, "bold", true, CultureInfo.InvariantCulture) == 0)
                    {
                        AppendOtherTag("b");
                    }
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (String.Compare(value, "normal", true, CultureInfo.InvariantCulture) != 0)
                    {
                        AppendOtherTag("i");
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    s = value.ToLower(CultureInfo.InvariantCulture);
                    if (s.IndexOf("underline") != -1)
                    {
                        AppendOtherTag("u");
                    }
                    if (s.IndexOf("line-through") != -1)
                    {
                        AppendOtherTag("strike");
                    }
                    break;
                }
            }
            else if (Supports(FONT_PROPAGATE))
            {
                FontStackItem font = (FontStackItem)FontStack.Peek();

                switch (key)
                {
                case HtmlTextWriterStyle.FontFamily:
                    font.name = value;
                    break;

                case HtmlTextWriterStyle.Color:
                    font.color = value;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    font.size = ConvertToHtmlFontSize(value);
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (String.Compare(value, "bold", true, CultureInfo.InvariantCulture) == 0)
                    {
                        font.bold = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (String.Compare(value, "normal", true, CultureInfo.InvariantCulture) != 0)
                    {
                        font.italic = true;
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    s = value.ToLower(CultureInfo.InvariantCulture);
                    if (s.IndexOf("underline") != -1)
                    {
                        font.underline = true;
                    }
                    if (s.IndexOf("line-through") != -1)
                    {
                        font.strikeout = true;
                    }
                    break;
                }
            }

            if (Supports(SUPPORTS_BORDER) && key == HtmlTextWriterStyle.BorderWidth)
            {
                s = ConvertToHtmlSize(value);
                if (s != null)
                {
                    AddAttribute(HtmlTextWriterAttribute.Border, s);
                }
            }

            if (Supports(SUPPORTS_HEIGHT_WIDTH))
            {
                switch (key)
                {
                case HtmlTextWriterStyle.Height:
                    s = ConvertToHtmlSize(value);
                    if (s != null)
                    {
                        AddAttribute(HtmlTextWriterAttribute.Height, s);
                    }
                    break;

                case HtmlTextWriterStyle.Width:
                    s = ConvertToHtmlSize(value);
                    if (s != null)
                    {
                        AddAttribute(HtmlTextWriterAttribute.Width, s);
                    }
                    break;
                }
            }

            if (Supports(TABLE_ATTRIBUTES) || Supports(TABLE_AROUND_CONTENT))
            {
                // tag supports downlevel table attributes
                switch (key)
                {
                case HtmlTextWriterStyle.BorderColor:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Div:
                        AddAttribute(HtmlTextWriterAttribute.Bordercolor, value);
                        break;
                    }
                    break;

                case HtmlTextWriterStyle.BackgroundColor:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Table:
                    case HtmlTextWriterTag.Tr:
                    case HtmlTextWriterTag.Td:
                    case HtmlTextWriterTag.Th:
                    case HtmlTextWriterTag.Body:
                    case HtmlTextWriterTag.Div:
                        AddAttribute(HtmlTextWriterAttribute.Bgcolor, value);
                        break;
                    }
                    break;

                case HtmlTextWriterStyle.BackgroundImage:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Table:
                    case HtmlTextWriterTag.Td:
                    case HtmlTextWriterTag.Div:
                    case HtmlTextWriterTag.Th:
                    case HtmlTextWriterTag.Body:
                        // strip url(...) from value
                        if (value.StartsWith("url("))
                        {
                            value = value.Substring(4, value.Length - 5);
                        }
                        AddAttribute(HtmlTextWriterAttribute.Background, value);
                        break;
                    }
                    break;
                }
            }
            return(false);
        }
示例#4
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override bool OnStyleAttributeRender(string name, string value, HtmlTextWriterStyle key)
        {
            string s;

            if (Supports(FONT_AROUND_CONTENT))
            {
                // tag supports downlevel fonts
                switch (key)
                {
                case HtmlTextWriterStyle.FontFamily:
                    _fontFace      = value;
                    _renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.Color:
                    _fontColor     = value;
                    _renderFontTag = true;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    _fontSize = ConvertToHtmlFontSize(value);
                    if (_fontSize != null)
                    {
                        _renderFontTag = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (StringUtil.EqualsIgnoreCase(value, "bold") && SupportsBold)
                    {
                        AppendOtherTag("b");
                    }
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (!StringUtil.EqualsIgnoreCase(value, "normal") && SupportsItalic)
                    {
                        AppendOtherTag("i");
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    s = value.ToLower(CultureInfo.InvariantCulture);
                    if (s.IndexOf("underline", StringComparison.Ordinal) != -1)
                    {
                        AppendOtherTag("u");
                    }
                    if (s.IndexOf("line-through", StringComparison.Ordinal) != -1)
                    {
                        AppendOtherTag("strike");
                    }
                    break;
                }
            }
            else if (Supports(FONT_PROPAGATE))
            {
                FontStackItem font = (FontStackItem)FontStack.Peek();

                switch (key)
                {
                case HtmlTextWriterStyle.FontFamily:
                    font.name = value;
                    break;

                case HtmlTextWriterStyle.Color:
                    font.color = value;
                    break;

                case HtmlTextWriterStyle.FontSize:
                    font.size = ConvertToHtmlFontSize(value);
                    break;

                case HtmlTextWriterStyle.FontWeight:
                    if (StringUtil.EqualsIgnoreCase(value, "bold"))
                    {
                        font.bold = true;
                    }
                    break;

                case HtmlTextWriterStyle.FontStyle:
                    if (!StringUtil.EqualsIgnoreCase(value, "normal"))
                    {
                        font.italic = true;
                    }
                    break;

                case HtmlTextWriterStyle.TextDecoration:
                    s = value.ToLower(CultureInfo.InvariantCulture);
                    if (s.IndexOf("underline", StringComparison.Ordinal) != -1)
                    {
                        font.underline = true;
                    }
                    if (s.IndexOf("line-through", StringComparison.Ordinal) != -1)
                    {
                        font.strikeout = true;
                    }
                    break;
                }
            }

            if (Supports(SUPPORTS_BORDER) && key == HtmlTextWriterStyle.BorderWidth)
            {
                s = ConvertToHtmlSize(value);
                if (s != null)
                {
                    AddAttribute(HtmlTextWriterAttribute.Border, s);
                }
            }

            if (Supports(SUPPORTS_NOWRAP) && key == HtmlTextWriterStyle.WhiteSpace)
            {
                AddAttribute(HtmlTextWriterAttribute.Nowrap, value);
            }

            if (Supports(SUPPORTS_HEIGHT_WIDTH))
            {
                switch (key)
                {
                case HtmlTextWriterStyle.Height:
                    s = ConvertToHtmlSize(value);
                    if (s != null)
                    {
                        AddAttribute(HtmlTextWriterAttribute.Height, s);
                    }
                    break;

                case HtmlTextWriterStyle.Width:
                    s = ConvertToHtmlSize(value);
                    if (s != null)
                    {
                        AddAttribute(HtmlTextWriterAttribute.Width, s);
                    }
                    break;
                }
            }

            if (Supports(TABLE_ATTRIBUTES) || Supports(TABLE_AROUND_CONTENT))
            {
                // tag supports downlevel table attributes
                switch (key)
                {
                case HtmlTextWriterStyle.BorderColor:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Div:
                        if (ShouldPerformDivTableSubstitution)
                        {
                            AddAttribute(HtmlTextWriterAttribute.Bordercolor, value);
                        }
                        break;
                    }
                    break;

                case HtmlTextWriterStyle.BackgroundColor:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Table:
                    case HtmlTextWriterTag.Tr:
                    case HtmlTextWriterTag.Td:
                    case HtmlTextWriterTag.Th:
                    case HtmlTextWriterTag.Body:
                        AddAttribute(HtmlTextWriterAttribute.Bgcolor, value);
                        break;

                    // div->table substitution.
                    case HtmlTextWriterTag.Div:
                        if (ShouldPerformDivTableSubstitution)
                        {
                            AddAttribute(HtmlTextWriterAttribute.Bgcolor, value);
                        }
                        break;
                    }
                    break;

                case HtmlTextWriterStyle.BackgroundImage:
                    switch (TagKey)
                    {
                    case HtmlTextWriterTag.Table:
                    case HtmlTextWriterTag.Td:
                    case HtmlTextWriterTag.Th:
                    case HtmlTextWriterTag.Body:
                        // strip url(...) from value
                        if (StringUtil.StringStartsWith(value, "url("))
                        {
                            value = value.Substring(4, value.Length - 5);
                        }
                        AddAttribute(HtmlTextWriterAttribute.Background, value);
                        break;

                    // div->table substitution.
                    case HtmlTextWriterTag.Div:
                        if (ShouldPerformDivTableSubstitution)
                        {
                            if (StringUtil.StringStartsWith(value, "url("))
                            {
                                value = value.Substring(4, value.Length - 5);
                            }
                            AddAttribute(HtmlTextWriterAttribute.Background, value);
                        }
                        break;
                    }
                    break;
                }
            }

            switch (key)
            {
            case HtmlTextWriterStyle.ListStyleType:
                switch (value)
                {
                case "decimal":
                    AddAttribute(HtmlTextWriterAttribute.Type, "1");
                    break;

                case "lower-alpha":
                    AddAttribute(HtmlTextWriterAttribute.Type, "a");
                    break;

                case "upper-alpha":
                    AddAttribute(HtmlTextWriterAttribute.Type, "A");
                    break;

                case "lower-roman":
                    AddAttribute(HtmlTextWriterAttribute.Type, "i");
                    break;

                case "upper-roman":
                    AddAttribute(HtmlTextWriterAttribute.Type, "I");
                    break;

                case "disc":
                case "circle":
                case "square":
                    AddAttribute(HtmlTextWriterAttribute.Type, value);
                    break;

                default:
                    AddAttribute(HtmlTextWriterAttribute.Type, "disc");
                    Debug.Assert(false, "Invalid BulletStyle for HTML32.");
                    break;
                }
                break;

            case HtmlTextWriterStyle.TextAlign:
                AddAttribute(HtmlTextWriterAttribute.Align, value);
                break;

            case HtmlTextWriterStyle.VerticalAlign:
                AddAttribute(HtmlTextWriterAttribute.Valign, value);
                break;

            // Netscape 4.72 can properly handle the Display style attribute, so allow it
            // to be rendered.
            case HtmlTextWriterStyle.Display:
                return(true);
            }

            return(false);
        }
示例#5
0
        private void ConsumeFont(StringBuilder sbBegin, StringBuilder sbEnd)
        {
            int fontInfoCount = FontStack.Count;

            if (fontInfoCount > 0)
            {
                FontStackItem[] fontInfo = new FontStackItem[fontInfoCount];
                FontStack.CopyTo(fontInfo, 0);

                string fontFace  = null;
                string fontColor = null;
                string fontSize  = null;
                int    i;

                for (i = 0; i < fontInfoCount && fontFace == null; i++)
                {
                    fontFace = fontInfo[i].name;
                }
                for (i = 0; i < fontInfoCount && fontColor == null; i++)
                {
                    fontColor = fontInfo[i].color;
                }
                for (i = 0; i < fontInfoCount && fontSize == null; i++)
                {
                    fontSize = fontInfo[i].size;
                }
                if ((fontFace != null) || (fontColor != null) || (fontSize != null))
                {
                    AppendFontTag(fontFace, fontColor, fontSize, sbBegin, sbEnd);
                }

                for (i = 0; i < fontInfoCount; i++)
                {
                    if (fontInfo[i].underline == true)
                    {
                        AppendOtherTag("u", sbBegin, sbEnd);
                        break;
                    }
                }
                for (i = 0; i < fontInfoCount; i++)
                {
                    if (fontInfo[i].italic == true)
                    {
                        AppendOtherTag("i", sbBegin, sbEnd);
                        break;
                    }
                }
                for (i = 0; i < fontInfoCount; i++)
                {
                    if (fontInfo[i].bold == true)
                    {
                        AppendOtherTag("b", sbBegin, sbEnd);
                        break;
                    }
                }
                for (i = 0; i < fontInfoCount; i++)
                {
                    if (fontInfo[i].strikeout == true)
                    {
                        AppendOtherTag("strike", sbBegin, sbEnd);
                        break;
                    }
                }
            }
        }