public ParseBoxValues ( String box, String pre, String post ) : String>.IDictionary |
||
box | String | |
pre | String | |
post | String | |
return | String>.IDictionary |
/** * @param aggregatedProps the map to put the properties in. * @param selector the selector to search for. */ public void PopulateCss(IDictionary <String, String> aggregatedProps, String selector) { foreach (ICssFile cssFile in this.files) { IDictionary <String, String> t = cssFile.Get(selector); IDictionary <String, String> css = new Dictionary <String, String>(); foreach (KeyValuePair <String, String> e in t) { String key = utils.StripDoubleSpacesAndTrim(e.Key); String value = utils.StripDoubleSpacesAndTrim(e.Value); if (Util.EqualsIgnoreCase(CSS.Property.BORDER, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.MARGIN, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "margin-", "")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_WIDTH, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-width")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_STYLE, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-style")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_COLOR, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-color")); } else if (Util.EqualsIgnoreCase(CSS.Property.PADDING, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "padding-", "")); } else if (Util.EqualsIgnoreCase(CSS.Property.FONT, key)) { CssUtils.MapPutAll(css, utils.ProcessFont(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.LIST_STYLE, key)) { CssUtils.MapPutAll(css, utils.ProcessListStyle(value)); } else { css[key] = value; } } CssUtils.MapPutAll(aggregatedProps, css); } }
virtual public void PopulateOneCss(IDictionary <String, String> aggregatedProps, IDictionary <String, String> cssDeclaration) { IDictionary <String, String> css = new Dictionary <String, String>(); foreach (KeyValuePair <String, String> e in cssDeclaration) { String key = utils.StripDoubleSpacesTrimAndToLowerCase(e.Key); String value = utils.StripDoubleSpacesAndTrim(e.Value); if (Util.EqualsIgnoreCase(CSS.Property.BORDER, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_TOP, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value, CSS.Property.BORDER_TOP)); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_BOTTOM, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value, CSS.Property.BORDER_BOTTOM)); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_LEFT, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value, CSS.Property.BORDER_LEFT)); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_RIGHT, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value, CSS.Property.BORDER_RIGHT)); } else if (Util.EqualsIgnoreCase(CSS.Property.MARGIN, key)) { IDictionary <String, String> margins = utils.ParseBoxValues(value, "margin-", ""); foreach (String marginKey in margins.Keys) { if (!css.ContainsKey(marginKey)) { css.Add(marginKey, margins[marginKey]); } } } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_WIDTH, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-width")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_STYLE, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-style")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_COLOR, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-color")); } else if (Util.EqualsIgnoreCase(CSS.Property.PADDING, key)) { IDictionary <String, String> paddings = utils.ParseBoxValues(value, "padding-", ""); foreach (String paddingKey in paddings.Keys) { if (!css.ContainsKey(paddingKey)) { css.Add(paddingKey, paddings[paddingKey]); } } //CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "padding-", "")); } else if (Util.EqualsIgnoreCase(CSS.Property.FONT, key)) { CssUtils.MapPutAll(css, utils.ProcessFont(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.LIST_STYLE, key)) { CssUtils.MapPutAll(css, utils.ProcessListStyle(value)); } else if (key.ToLowerInvariant().Contains(CSS.Property.BACKGROUND)) { IDictionary <String, String> backgroundStyles = utils.ProcessBackground(value); foreach (String backgroundKey in backgroundStyles.Keys) { if (!css.ContainsKey(backgroundKey)) { css.Add(backgroundKey, backgroundStyles[backgroundKey]); } } } else { css[key] = value; } } CssUtils.MapPutAll(aggregatedProps, css); }
/** * Also taking into account the CSS properties of any parent tag in the given tag. * * @see com.itextpdf.tool.xml.pipeline.css.CSSResolver#resolveStyles(com.itextpdf.tool.xml.Tag) */ public void ResolveStyles(Tag t) { // get css for this tag from resolver IDictionary <String, String> tagCss = new Dictionary <String, String>(); IDictionary <String, String> listCss = null; if (null != cssFiles && cssFiles.HasFiles()) { tagCss = cssFiles.GetCSS(t); if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.P) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.TD)) { listCss = cssFiles.GetCSS(new Tag(HTML.Tag.UL)); } } // get css from style attr if (null != t.Attributes && t.Attributes.Count != 0) { if (t.Attributes.ContainsKey(HTML.Attribute.CELLPADDING)) { CssUtils.MapPutAll(tagCss, utils.ParseBoxValues(t.Attributes[HTML.Attribute.CELLPADDING], "cellpadding-", "")); } if (t.Attributes.ContainsKey(HTML.Attribute.CELLSPACING)) { CssUtils.MapPutAll(tagCss, utils.ParseBoxValues(t.Attributes[HTML.Attribute.CELLSPACING], "cellspacing-", "")); } String styleAtt; t.Attributes.TryGetValue(HTML.Attribute.STYLE, out styleAtt); if (!string.IsNullOrEmpty(styleAtt)) { Dictionary <String, String> tagAttrCss = new Dictionary <string, string>(); String[] styles = styleAtt.Split(';'); foreach (String s in styles) { String[] part = s.Split(splitColon, 2); if (part.Length == 2) { String key = utils.StripDoubleSpacesTrimAndToLowerCase(part[0]); String value = utils.StripDoubleSpacesAndTrim(part[1]); SplitRules(tagAttrCss, key, value); } } foreach (KeyValuePair <String, String> e in tagAttrCss) { tagCss[e.Key] = e.Value; } } } // inherit css from parent tags, as defined in provided CssInheritanceRules or if property = inherit IDictionary <String, String> css = t.CSS; if (listCss != null && listCss.ContainsKey(CSS.Property.LIST_STYLE_TYPE)) { css[CSS.Property.LIST_STYLE_TYPE] = listCss[CSS.Property.LIST_STYLE_TYPE]; } if (MustInherit(t.Name) && null != t.Parent && null != t.Parent.CSS) { if (null != this.inherit) { foreach (KeyValuePair <String, String> entry in t.Parent.CSS) { String key = entry.Key; if ((tagCss.ContainsKey(key) && CSS.Value.INHERIT.Equals(tagCss[key])) || CanInherite(t, key)) { //splitRules(css, key, entry.GetValue()); css[key] = entry.Value; } } } else { CssUtils.MapPutAll(css, t.Parent.CSS); } } // overwrite properties (if value != inherit) foreach (KeyValuePair <String, String> e in tagCss) { if (!Util.EqualsIgnoreCase(CSS.Value.INHERIT, e.Value)) { css[e.Key] = e.Value; } } }
/** * Also taking into account the CSS properties of any parent tag in the given tag. * * @see com.itextpdf.tool.xml.pipeline.css.CSSResolver#resolveStyles(com.itextpdf.tool.xml.Tag) */ virtual public void ResolveStyles(Tag t) { // get css for this tag from resolver IDictionary <String, String> tagCss = new Dictionary <String, String>(); IDictionary <String, String> listCss = null; if (null != cssFiles && cssFiles.HasFiles()) { tagCss = cssFiles.GetCSS(t); if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.P) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.TD)) { listCss = cssFiles.GetCSS(new Tag(HTML.Tag.UL)); } } // get css from style attr if (null != t.Attributes && t.Attributes.Count != 0) { if (t.Attributes.ContainsKey(HTML.Attribute.CELLPADDING)) { CssUtils.MapPutAll(tagCss, utils.ParseBoxValues(t.Attributes[HTML.Attribute.CELLPADDING], "cellpadding-", "")); } if (t.Attributes.ContainsKey(HTML.Attribute.CELLSPACING)) { CssUtils.MapPutAll(tagCss, utils.ParseBoxValues(t.Attributes[HTML.Attribute.CELLSPACING], "cellspacing-", "")); } String styleAtt; t.Attributes.TryGetValue(HTML.Attribute.STYLE, out styleAtt); if (!string.IsNullOrEmpty(styleAtt)) { Dictionary <String, String> tagAttrCss = new Dictionary <string, string>(); String[] styles = styleAtt.Split(';'); foreach (String s in styles) { String[] part = s.Split(splitColon, 2); if (part.Length == 2) { String key = utils.StripDoubleSpacesTrimAndToLowerCase(part[0]); String value = utils.StripDoubleSpacesAndTrim(part[1]); SplitRules(tagAttrCss, key, value); } } foreach (KeyValuePair <String, String> e in tagAttrCss) { tagCss[e.Key] = e.Value; } } } // inherit css from parent tags, as defined in provided CssInheritanceRules or if property = inherit IDictionary <String, String> css = t.CSS; if (t.Name != null) { if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.I) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.CITE) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.EM) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.VAR) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.DFN) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.ADDRESS)) { tagCss[CSS.Property.FONT_STYLE] = CSS.Value.ITALIC; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.B) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.STRONG)) { tagCss[CSS.Property.FONT_WEIGHT] = CSS.Value.BOLD; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.U) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.INS)) { tagCss[CSS.Property.TEXT_DECORATION] = CSS.Value.UNDERLINE; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.S) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.STRIKE) || Util.EqualsIgnoreCase(t.Name, HTML.Tag.DEL)) { tagCss[CSS.Property.TEXT_DECORATION] = CSS.Value.LINE_THROUGH; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.BIG)) { tagCss[CSS.Property.FONT_SIZE] = CSS.Value.LARGER; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.SMALL)) { tagCss[CSS.Property.FONT_SIZE] = CSS.Value.SMALLER; } } if (listCss != null && listCss.ContainsKey(CSS.Property.LIST_STYLE_TYPE)) { css[CSS.Property.LIST_STYLE_TYPE] = listCss[CSS.Property.LIST_STYLE_TYPE]; } if (MustInherit(t.Name) && null != t.Parent && null != t.Parent.CSS) { if (null != this.inherit) { foreach (KeyValuePair <String, String> entry in t.Parent.CSS) { String key = entry.Key; if ((tagCss.ContainsKey(key) && CSS.Value.INHERIT.Equals(tagCss[key])) || CanInherite(t, key)) { if (key.Contains(CSS.Property.CELLPADDING) && (HTML.Tag.TD.Equals(t.Name) || HTML.Tag.TH.Equals(t.Name))) { String paddingKey = key.Replace(CSS.Property.CELLPADDING, CSS.Property.PADDING); //if (!tagCss.containsKey(paddingKey)) { tagCss[paddingKey] = entry.Value; //continue; //} } else { //splitRules(css, key, entry.getValue()); css[key] = entry.Value; } } } } else { foreach (KeyValuePair <string, string> entry in t.Parent.CSS) { css.Add(entry); } } } if (t.Name != null) { if (t.Name.Equals(HTML.Tag.FONT)) { String font_family; if (t.Attributes.TryGetValue(HTML.Attribute.FACE, out font_family)) { css[CSS.Property.FONT_FAMILY] = font_family; } String color; if (t.Attributes.TryGetValue(HTML.Attribute.COLOR, out color)) { css[CSS.Property.COLOR] = color; } String size; if (t.Attributes.TryGetValue(HTML.Attribute.SIZE, out size)) { if (size.Equals("1")) { css[CSS.Property.FONT_SIZE] = CSS.Value.XX_SMALL; } else if (size.Equals("2")) { css[CSS.Property.FONT_SIZE] = CSS.Value.X_SMALL; } else if (size.Equals("3")) { css[CSS.Property.FONT_SIZE] = CSS.Value.SMALL; } else if (size.Equals("4")) { css[CSS.Property.FONT_SIZE] = CSS.Value.MEDIUM; } else if (size.Equals("5")) { css[CSS.Property.FONT_SIZE] = CSS.Value.LARGE; } else if (size.Equals("6")) { css[CSS.Property.FONT_SIZE] = CSS.Value.X_LARGE; } else if (size.Equals("7")) { css[CSS.Property.FONT_SIZE] = CSS.Value.XX_LARGE; } } } else if (t.Name.Equals(HTML.Tag.A)) { css[CSS.Property.TEXT_DECORATION] = CSS.Value.UNDERLINE; css[CSS.Property.COLOR] = "blue"; } } // overwrite properties (if value != inherit) foreach (KeyValuePair <String, String> e in tagCss) { if (!Util.EqualsIgnoreCase(CSS.Value.INHERIT, e.Value)) { if (e.Key.Equals(CSS.Property.TEXT_DECORATION)) { String oldValue = null; css.TryGetValue(e.Key, out oldValue); css[e.Key] = MergeTextDecorationRules(oldValue, e.Value); } else { css[e.Key] = e.Value; } } } }
public void PopulateOneCss(ICssFile cssFile, IDictionary <String, String> aggregatedProps, String selector) { IDictionary <String, String> t = cssFile.Get(selector); IDictionary <String, String> css = new Dictionary <String, String>(); foreach (KeyValuePair <String, String> e in t) { String key = utils.StripDoubleSpacesTrimAndToLowerCase(e.Key); String value = utils.StripDoubleSpacesAndTrim(e.Value); if (Util.EqualsIgnoreCase(CSS.Property.BORDER, key)) { CssUtils.MapPutAll(css, utils.ParseBorder(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.MARGIN, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "margin-", "")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_WIDTH, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-width")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_STYLE, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-style")); } else if (Util.EqualsIgnoreCase(CSS.Property.BORDER_COLOR, key)) { CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "border-", "-color")); } else if (Util.EqualsIgnoreCase(CSS.Property.PADDING, key)) { IDictionary <String, String> paddings = utils.ParseBoxValues(value, "padding-", ""); foreach (String paddingKey in paddings.Keys) { if (!css.ContainsKey(paddingKey)) { css.Add(paddingKey, paddings[paddingKey]); } } //CssUtils.MapPutAll(css, utils.ParseBoxValues(value, "padding-", "")); } else if (Util.EqualsIgnoreCase(CSS.Property.FONT, key)) { CssUtils.MapPutAll(css, utils.ProcessFont(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.LIST_STYLE, key)) { CssUtils.MapPutAll(css, utils.ProcessListStyle(value)); } else if (Util.EqualsIgnoreCase(CSS.Property.BACKGROUND, key)) { IDictionary <String, String> backgroundStyles = utils.ProcessBackground(value); foreach (String backgroundKey in backgroundStyles.Keys) { if (!css.ContainsKey(backgroundKey)) { css.Add(backgroundKey, backgroundStyles[backgroundKey]); } } } else { css[key] = value; } } CssUtils.MapPutAll(aggregatedProps, css); }