Пример #1
0
        virtual public void ParseCSS()
        {
            retriever.ProcessFromStream(File.OpenRead(RESOURCES + "/css/test.css"), proc);
            ICssFile file = proc.GetCss();
            IDictionary <String, String> map = file.Get("body");

            Assert.IsTrue(map.ContainsKey("margin"), "margin not found.");
            Assert.AreEqual("20px", map["margin"], "Value for margin not correct.");
        }
Пример #2
0
        virtual public void ParseCSS()
        {
            retriever.ProcessFromStream(File.OpenRead(RESOURCES + "/css/test.css"), proc);
            ICssFile        file  = proc.GetCss();
            IList <CssRule> rules = file.Get(new Tag("body"));

            Assert.IsTrue(rules.Count == 1);
            Assert.IsTrue(rules[0].NormalDeclarations.ContainsKey("margin"), "margin not found.");
            Assert.AreEqual("20px", rules[0].NormalDeclarations["margin"], "Value for margin not correct.");
        }
Пример #3
0
        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))
                {
                    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);
        }
Пример #4
0
 /*
  * (non-Javadoc)
  *
  * @see com.itextpdf.tool.xml.css.CssFile#get(java.lang.String)
  */
 virtual public IDictionary <String, String> Get(String selector)
 {
     return(css.Get(selector));
 }
Пример #5
0
 public virtual IList <CssRule> Get(Tag t)
 {
     return(css.Get(t));
 }
Пример #6
0
        virtual 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))
                {
                    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 (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);
        }
Пример #7
0
 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)) {
             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);
 }
Пример #8
0
 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)) {
             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 (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);
 }