Example #1
0
 private static void CombineProperties(SVGPropertySheet first, SVGPropertySheet second)
 {
     foreach (var key in second.Keys)
     {
         first[key] = second[key];
     }
 }
Example #2
0
        public static SVGPropertySheet ParseInline(string cssText)
        {
            var tokens = Tokenize(cssText);
            var props  = new SVGPropertySheet();

            ParseProperties(tokens, props);
            return(props);
        }
Example #3
0
        private static SVGPropertySheet CopyProperties(SVGPropertySheet props)
        {
            var newProps = new SVGPropertySheet();

            foreach (var v in props)
            {
                newProps[v.Key] = v.Value;
            }
            return(newProps);
        }
Example #4
0
        private static bool ParseSelector(List <string> tokens, SVGStyleSheet sheet)
        {
            if (tokens.Count == 0)
            {
                return(false);
            }

            var newSheet = new SVGStyleSheet();

            while (true)
            {
                var selectorName = PopToken(tokens);
                newSheet[selectorName] = new SVGPropertySheet();

                while (PeekToken(tokens) == ",")
                {
                    PopToken(tokens);
                }

                if (PeekToken(tokens) == "" || PeekToken(tokens) == "{")
                {
                    break;
                }
            }

            var sep = PopToken(tokens);

            if (sep != "{")
            {
                Debug.LogError("Invalid CSS selector opening bracket: \"" + sep + "\"");
                return(false);
            }

            var props = new SVGPropertySheet();

            ParseProperties(tokens, props);

            // Transfer properties to the new selectors
            foreach (var key in newSheet.selectors)
            {
                sheet[key] = CopyProperties(props);
            }

            sep = PopToken(tokens);
            if (sep != "}")
            {
                Debug.LogError("Invalid CSS selector closing bracket: \"" + sep + "\"");
                return(false);
            }

            return(true);
        }
Example #5
0
        private static bool ParseProperties(List <string> tokens, SVGPropertySheet props)
        {
            string name;
            string value;

            while (ParseProperty(tokens, out name, out value))
            {
                props[name] = value;
                while (PeekToken(tokens) == ";")
                {
                    PopToken(tokens);
                }
            }
            return(true);
        }