Exemplo n.º 1
0
		internal CssStyleDeclaration DeepCopy(ISvgStylable parent)
		{
			var item = new List<string>(this._items);
			var cache = new Dictionary<string, Tuple<string, ICssValue>>();
			foreach (var c in this._cache)
			{
				ICssValue value;
				var target = c.Value.Item2;
				if (target.GetType() == typeof(SvgPaint) || target.GetType() == typeof(SvgColor))
				{
					value = ((SvgColor)c.Value.Item2).Clone();
				}
				else if (target.GetType() == typeof(SvgNumber) || target.GetType() == typeof(SvgLength))
				{
					value = c.Value.Item2;
				}
				else if (target.GetType() == typeof(SvgIri))
				{
					value = new SvgIri(((SvgIri)c.Value.Item2).Uri);
				}
				else
				{
					throw new InvalidOperationException();
				}
				cache.Add(c.Key, Tuple.Create(c.Value.Item1, value));
			}
			return new CssStyleDeclaration(parent, item, cache);
		}
Exemplo n.º 2
0
		private Tuple<string, ICssValue> ParseValue(string name, string value, string priority, bool presentation)
		{
			var important = priority == "important";
			if (!presentation) name = name.ToLower();

			ICssValue parsedValue = null;
			switch (name)
			{
				case "fill":
				case "stroke":
					parsedValue = new SvgPaint(value);
					break;

				case "stroke-width":
					parsedValue = SvgLength.Parse(value, presentation);
					break;

				case "stop-color":
					parsedValue = new SvgColor(value);
					break;

				case "fill-opacity":
				case "stroke-opacity":
				case "stop-opacity":
				case "opacity":
					parsedValue = SvgNumber.Parse(value, 0.0F, 1.0F);
					break;

				case "clip-path":
					parsedValue = new SvgIri(value);
					break;

				case "fill-rule":
				case "clip-rule":
					parsedValue = new SvgFillRule(presentation ? value : value.ToLower());
					break;
			}

			if (!this._cache.ContainsKey(name))
			{
				var result = Tuple.Create(value, parsedValue);
				this._cache.Add(name, result);
				return result;
			}
			else if (important)
			{
				var result = Tuple.Create(value, parsedValue);
				this._cache[name] = result;
				return result;
			}

			return null;
		}