Пример #1
0
            public void PopStyleScope()
            {
                var scope = StyleStack.Count;

                while (FontStack.Count > 0 && FontStack.Peek().Scope == scope)
                {
                    FontStack.Pop();
                }

                while (ColorStack.Count > 0 && ColorStack.Peek().Scope == scope)
                {
                    ColorStack.Pop();
                }

                while (GlyphShaderStack.Count > 0 && GlyphShaderStack.Peek().Scope == scope)
                {
                    GlyphShaderStack.Pop();
                }
            }
Пример #2
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);
        }