internal override bool AppendStyle(HtmlStyle parentStyle, HtmlNode child)
        {
            if (parentStyle == null || child == null)
            {
                return false;
            }

            if (parentStyle.Name.CompareInvariantCultureIgnoreCase(backgroundColor) ||
                parentStyle.Name.CompareInvariantCultureIgnoreCase(background))
            {
                HtmlStyle style;

                if (!child.HasStyle(backgroundColor) && !child.HasStyle(background))
                {
                    //child.HtmlStyles.Add(new HtmlStyle(parentStyle.Name, parentStyle.Value, false));
                    child.UpdateInheritedStyles(parentStyle);
                }
                else if ((child.TryGetStyle(background, out style) || child.TryGetStyle(backgroundColor, out style)) &&
                    style.Value.CompareInvariantCultureIgnoreCase(transparent))
                {
                    string styleValue = parentStyle.Value;
                    
                    if (parentStyle.Name.CompareInvariantCultureIgnoreCase(background) &&
                        style.Name.CompareInvariantCultureIgnoreCase(backgroundColor))
                    {
                        int index = styleValue.IndexOf(' ');

                        if (index != -1)
                        {
                            styleValue = styleValue.Remove(index);
                        }
                    }
                    
                    style.ModifyStyle(styleValue);
                }

                return true;
            }

            return false;
        }
        private void AppendStyles(HtmlNode node, HtmlNode parent)
        {
            CSSPropertyParser propertyParser = new CSSPropertyParser();

            foreach (HtmlStyle parentStyle in parent.HtmlStyles)
            {
                if (!propertyParser.CanInherit(parentStyle.Name))
                {
                    continue;
                }

                bool found = false;

                if (propertyParser.InheritStyle(parentStyle, node))
                {
                    continue;
                }

                foreach (HtmlStyle childStyle in node.HtmlStyles)
                {
                    if (propertyParser.StyleContains(parentStyle, childStyle))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    node.UpdateInheritedStyles(parentStyle);
                }
            }

            foreach (HtmlStyle parentStyle in parent.InheritedHtmlStyles)
            {
                if (!propertyParser.CanInherit(parentStyle.Name))
                {
                    continue;
                }

                if(parent.HasStyle(parentStyle.Name))
                {
                    continue;
                }

                propertyParser.InheritStyle(parentStyle, node);
            }
        }
Пример #3
0
        internal override void ParseStyle(HtmlNode node)
        {
            HtmlStyle value;

            Dictionary<string, string> styles = new Dictionary<string, string>();
            KeyValuePair<Stack<string>, Stack<string>> styleStack =
                new KeyValuePair<Stack<string>, Stack<string>>(new Stack<string>(), new Stack<string>());

            if (node.TryGetStyle(font, out value))
            {
                if (ProcessFontStyle(value.Value, styles, styleStack))
                {
                    foreach (var style in styles)
                    {
                        if (!node.HasStyle(style.Key))
                        {
                            node.HtmlStyles.Add(new HtmlStyle(style.Key, style.Value, false));
                        }
                    }

                    node.RemoveStyle(font);
                }
            }
        }
Пример #4
0
 private void ProcessFontFamily(HtmlStyle parentStyle, HtmlNode child)
 {
     if (!child.HasStyle(fontFamily) && !child.HasStyle(font))
     {
         child.UpdateInheritedStyles(parentStyle);
     }
 }
Пример #5
0
        private void ProcessFont(HtmlStyle parentStyle, HtmlNode child)
        {
            Dictionary<string, string> parentStyles = new Dictionary<string, string>();
            KeyValuePair<Stack<string>, Stack<string>> styleStack =
                new KeyValuePair<Stack<string>, Stack<string>>(new Stack<string>(), new Stack<string>());

            if (ProcessFontStyle(parentStyle.Value, parentStyles, styleStack) && parentStyles.Count > 0)
            {
                foreach (var style in parentStyles)
                {
                    if (!child.HasStyle(style.Key))
                    {
                        child.UpdateInheritedStyles(new HtmlStyle(style.Key, style.Value, false));
                    }
                }
            }
        }