Exemple #1
0
        public static SvgElementStyleData Populate(SvgElementStyleData result, string styleStr)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }
            if (styleStr == null)
            {
                throw new ArgumentNullException(nameof(styleStr));
            }
            var reader = new CssStringStreamReader(styleStr);

            if (!CssStyleRulesParser.TryParseStyleRuleBodyProperties(reader, out var properties))
            {
                throw new CssParserException(reader, "Failed to parse style body");
            }
            foreach (var property in properties)
            {
                if (!TryPopulateProperty(result, property.Key, property.Value))
                {
                    // skip unrecognised
                    // throw new Exception($"Unknown style property '{property.Key}' with value '{property.Value}'");
                }
            }
            return(result);
        }
Exemple #2
0
        public void CopyTo(SvgElementStyleData other)
        {
            // todo: reflection, optimize

            foreach (var property in StyleProperties.Value)
            {
                var value = property.GetValue(this);
                if (value != null)
                {
                    property.SetValue(other, value);
                }
            }
        }
Exemple #3
0
        public static bool TryPopulateProperty(SvgElementStyleData result, string name, CssStylePropertyValue value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (!StylePropertyParserSetters.TryGetValue(name, out var parserSetter))
            {
                return(false);
            }

            try
            {
                parserSetter(result, value);
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to set style property '{name}' to css value '{value}'", e);
            }
            return(true);
        }