public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context) { IDictionary <String, String> styles = ResolveNativeStyles(node, context); //Load in and merge inherited declarations from parent if (node.ParentNode() is IStylesContainer) { IStylesContainer parentNode = (IStylesContainer)node.ParentNode(); IDictionary <String, String> parentStyles = parentNode.GetStyles(); if (parentStyles == null && !(node.ParentNode() is IDocumentNode)) { ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver)); logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES); } ICollection <IStyleInheritance> inheritanceRules = new HashSet <IStyleInheritance>(); inheritanceRules.Add(new CssInheritance()); inheritanceRules.Add(new SvgAttributeInheritance()); if (parentStyles != null) { foreach (KeyValuePair <String, String> entry in parentStyles) { String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE); if (parentFontSizeString == null) { parentFontSizeString = "0"; } styles = StyleUtil.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString, inheritanceRules ); } } } return(styles); }
public virtual IDictionary <String, String> ResolveStyles(INode element, AbstractCssContext context) { if (context is CssContext) { return(ResolveStyles(element, (CssContext)context)); } throw new Html2PdfException("custom AbstractCssContext implementations are not supported yet"); }
public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context) { IDictionary <String, String> styles = new Dictionary <String, String>(); if (node is IElementNode) { IElementNode eNode = (IElementNode)node; foreach (IAttribute attr in eNode.GetAttributes()) { styles.Put(attr.GetKey(), attr.GetValue()); } } return(styles); }
public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context) { IDictionary <String, String> styles = new Dictionary <String, String>(); //Load in from collected style sheets IList <CssDeclaration> styleSheetDeclarations = css.GetCssDeclarations(node, MediaDeviceDescription.CreateDefault ()); foreach (CssDeclaration ssd in styleSheetDeclarations) { styles.Put(ssd.GetProperty(), ssd.GetExpression()); } //Load in attributes declarations if (node is IElementNode) { IElementNode eNode = (IElementNode)node; foreach (IAttribute attr in eNode.GetAttributes()) { ProcessAttribute(attr, styles); } } //Load in and merge inherited declarations from parent if (node.ParentNode() is IStylesContainer) { IStylesContainer parentNode = (IStylesContainer)node.ParentNode(); IDictionary <String, String> parentStyles = parentNode.GetStyles(); if (parentStyles == null && !(node.ParentNode() is IDocumentNode)) { ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver)); logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES); } if (parentStyles != null) { foreach (KeyValuePair <String, String> entry in parentStyles) { String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE); if (parentFontSizeString == null) { parentFontSizeString = "0"; } sru.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString); } } } return(styles); }
/// <summary>Resolves node styles without inheritance of parent element styles.</summary> /// <param name="node">the node</param> /// <param name="cssContext">the CSS context (RootFontSize, etc.)</param> /// <returns>the map containing the resolved styles that are defined in the body of the element</returns> public virtual IDictionary <String, String> ResolveNativeStyles(INode node, AbstractCssContext cssContext) { IDictionary <String, String> styles = new Dictionary <String, String>(); // Load in from collected style sheets IList <CssDeclaration> styleSheetDeclarations = css.GetCssDeclarations(node, MediaDeviceDescription.CreateDefault ()); foreach (CssDeclaration ssd in styleSheetDeclarations) { styles.Put(ssd.GetProperty(), ssd.GetExpression()); } // Load in attributes declarations if (node is IElementNode) { IElementNode eNode = (IElementNode)node; foreach (IAttribute attr in eNode.GetAttributes()) { ProcessAttribute(attr, styles); } } return(styles); }