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); } }
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 UpdateCurrentNodeInheritedStyles(HtmlNode node) { CSSPropertyParser propertyParser = new CSSPropertyParser(); foreach(HtmlStyle style in node.HtmlStyles) { if (!propertyParser.CanInherit(style.Name)) { continue; } node.UpdateInheritedStyles(style); } }
private void ProcessFontFamily(HtmlStyle parentStyle, HtmlNode child) { if (!child.HasStyle(fontFamily) && !child.HasStyle(font)) { child.UpdateInheritedStyles(parentStyle); } }
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)); } } } }