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); }
internal SvgStylableHelper DeepCopy(ISvgStylable parent) { var obj = (SvgStylableHelper)this.MemberwiseClone(); obj.Style = this.Style.DeepCopy(parent); return(obj); }
internal CssStyleDeclaration(ISvgStylable parent, string css) { this._parent = parent; this._items = new List<string>(); this._cache = new Dictionary<string, Tuple<string, ICssValue>>(); this.ParseText(css); }
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)); }
internal CssStyleDeclaration(ISvgStylable parent, string css) { this._parent = parent; this._items = new List <string>(); this._cache = new Dictionary <string, Tuple <string, ICssValue> >(); this.ParseText(css); }
public SvgStylableHelper(ISvgStylable parent, XmlElement element) { this.ClassName = element.GetAttribute("class"); this.Style = new CssStyleDeclaration(parent, element.GetAttribute("style")); foreach (var pn in PRESENTATION_ATTRIBUTE_NAMES) { var value = element.GetAttribute(pn); if (!string.IsNullOrWhiteSpace(value)) this.Style.SetProperty(pn, value, string.Empty, true); } }
public SvgStylableHelper(ISvgStylable parent, XmlElement element) { this.ClassName = element.GetAttribute("class"); this.Style = new CssStyleDeclaration(parent, element.GetAttribute("style")); foreach (var pn in PRESENTATION_ATTRIBUTE_NAMES) { var value = element.GetAttribute(pn); if (!string.IsNullOrWhiteSpace(value)) { this.Style.SetProperty(pn, value, string.Empty, true); } } }
private CssStyleDeclaration(ISvgStylable parent, List<string> items, Dictionary<string, Tuple<string, ICssValue>> cache) { this._parent = parent; this._items = items; this._cache = cache; }
/// <summary> /// Converts the current unit to one that can be used at render time. /// </summary> /// <returns>The representation of the current unit in a device value (usually pixels).</returns> public float ToDeviceValue(ISvgStylable styleOwner, bool vertical) { // If it's already been calculated if (this._deviceValue.HasValue) { return(this._deviceValue.Value); } if (this._value == 0.0f) { this._deviceValue = 0.0f; return(this._deviceValue.Value); } // http://www.w3.org/TR/CSS21/syndata.html#values // http://www.w3.org/TR/SVG11/coords.html#Units const float cmInInch = 2.54f; int ppi = SvgDocument.PointsPerInch; switch (this.Type) { case SvgUnitType.Em: float points = (float)(this.Value * 9); _deviceValue = (points / 72) * ppi; break; case SvgUnitType.Centimeter: _deviceValue = (float)((this.Value / cmInInch) * ppi); break; case SvgUnitType.Inch: _deviceValue = this.Value * ppi; break; case SvgUnitType.Millimeter: _deviceValue = (float)((this.Value / 10) / cmInInch) * ppi; break; case SvgUnitType.Pica: _deviceValue = ((this.Value * 12) / 72) * ppi; break; case SvgUnitType.Point: _deviceValue = (this.Value / 72) * ppi; break; case SvgUnitType.Pixel: _deviceValue = this.Value; break; case SvgUnitType.User: _deviceValue = this.Value; break; case SvgUnitType.Percentage: // Can't calculate if there is no style owner if (styleOwner == null) { _deviceValue = this.Value; break; } // TODO : Support height percentages System.Drawing.RectangleF size = styleOwner.Bounds; _deviceValue = (((vertical) ? size.Height : size.Width) / 100) * this.Value; break; default: _deviceValue = this.Value; break; } return(this._deviceValue.Value); }
/// <summary> /// Converts the current unit to one that can be used at render time. /// </summary> /// <returns>The representation of the current unit in a device value (usually pixels).</returns> public float ToDeviceValue(ISvgStylable styleOwner) { return(this.ToDeviceValue(styleOwner, false)); }
internal SvgStylableHelper DeepCopy(ISvgStylable parent) { var obj = (SvgStylableHelper)this.MemberwiseClone(); obj.Style = this.Style.DeepCopy(parent); return obj; }
/// <summary> /// Converts the current unit to one that can be used at render time. /// </summary> /// <returns>The representation of the current unit in a device value (usually pixels).</returns> public float ToDeviceValue(ISvgStylable styleOwner, bool vertical) { // If it's already been calculated if (this._deviceValue.HasValue) { return this._deviceValue.Value; } if (this._value == 0.0f) { this._deviceValue = 0.0f; return this._deviceValue.Value; } // http://www.w3.org/TR/CSS21/syndata.html#values // http://www.w3.org/TR/SVG11/coords.html#Units const float cmInInch = 2.54f; int ppi = SvgDocument.PointsPerInch; switch (this.Type) { case SvgUnitType.Em: float points = (float)(this.Value * 9); _deviceValue = (points / 72) * ppi; break; case SvgUnitType.Centimeter: _deviceValue = (float)((this.Value / cmInInch) * ppi); break; case SvgUnitType.Inch: _deviceValue = this.Value * ppi; break; case SvgUnitType.Millimeter: _deviceValue = (float)((this.Value / 10) / cmInInch) * ppi; break; case SvgUnitType.Pica: _deviceValue = ((this.Value * 12) / 72) * ppi; break; case SvgUnitType.Point: _deviceValue = (this.Value / 72) * ppi; break; case SvgUnitType.Pixel: _deviceValue = this.Value; break; case SvgUnitType.User: _deviceValue = this.Value; break; case SvgUnitType.Percentage: // Can't calculate if there is no style owner if (styleOwner == null) { _deviceValue = this.Value; break; } // TODO : Support height percentages System.Drawing.RectangleF size = styleOwner.Bounds; _deviceValue = (((vertical) ? size.Height : size.Width) / 100) * this.Value; break; default: _deviceValue = this.Value; break; } return this._deviceValue.Value; }
/// <summary> /// Converts the current unit to one that can be used at render time. /// </summary> /// <returns>The representation of the current unit in a device value (usually pixels).</returns> public float ToDeviceValue(ISvgStylable styleOwner) { return this.ToDeviceValue(styleOwner, false); }
private CssStyleDeclaration(ISvgStylable parent, List <string> items, Dictionary <string, Tuple <string, ICssValue> > cache) { this._parent = parent; this._items = items; this._cache = cache; }