private void SetStyle(string styleString) { Dictionary <string, string> _dictionary = new Dictionary <string, string>(); SVGStringExtractor.ExtractStyleValue(styleString, ref _dictionary); if (_dictionary.ContainsKey("fill")) { string fill = _dictionary["fill"]; if (fill.Contains("url")) { _gradientID = SVGStringExtractor.ExtractUrl4Gradient(fill); } else { _fillColor = new SVGColor(fill); } } if (_dictionary.ContainsKey("stroke")) { _strokeColor = new SVGColor(_dictionary["stroke"]); } if (_dictionary.ContainsKey("stroke-width")) { isStrokeWidth = true; _strokeWidth = new SVGLength(_dictionary["stroke-width"]); } if (_dictionary.ContainsKey("stroke-linecap")) { SetStrokeLineCap(_dictionary["stroke-linecap"]); } if (_dictionary.ContainsKey("stroke-linejoin")) { SetStrokeLineJoin(_dictionary["stroke-linejoin"]); } }
private void Initialize(Dictionary <string, string> attrList) { isStrokeWidth = false; if (attrList.ContainsKey("fill")) { string fill = attrList["fill"]; if (fill.Contains("url")) { _gradientID = SVGStringExtractor.ExtractUrl4Gradient(fill); } else { _fillColor = new SVGColor(fill); } } _strokeColor = new SVGColor(attrList.GetValue("stroke")); if (attrList.ContainsKey("stroke-width")) { isStrokeWidth = true; _strokeWidth = new SVGLength(attrList["stroke-width"]); } SetStrokeLineCap(attrList.GetValue("stroke-linecap")); SetStrokeLineJoin(attrList.GetValue("stroke-linejoin")); if (!attrList.ContainsKey("stroke-width")) { _strokeWidth.NewValueSpecifiedUnits(1f); } SetStyle(attrList.GetValue("style")); }
/***********************************************************************************/ //Khoi tao private void Initialize(AttributeList attrList) { isStrokeWidth = false; if (attrList.GetValue("fill").IndexOf("url") >= 0) { _gradientID = SVGStringExtractor.ExtractUrl4Gradient(attrList.GetValue("fill")); } else { _fillColor = new SVGColor(attrList.GetValue("fill")); } _strokeColor = new SVGColor(attrList.GetValue("stroke")); if (attrList.GetValue("stroke-width") != "") { isStrokeWidth = true; } _strokeWidth = new SVGLength(attrList.GetValue("stroke-width")); SetStrokeLineCap(attrList.GetValue("stroke-linecap")); SetStrokeLineJoin(attrList.GetValue("stroke-linejoin")); if (attrList.GetValue("stroke-width") == "") { _strokeWidth.NewValueSpecifiedUnits(1f); } Style(attrList.GetValue("style")); //style="fill: #ffffff; stroke:#000000; stroke-width:0.172" }
void InitDefaults() { isStrokeWidth = false; this._visibility = SVGVisibility.Visible; this._display = SVGDisplay.Inline; this._overflow = SVGOverflow.visible; this._clipPathUnits = SVGClipPathUnits.UserSpaceOnUse; this._clipRule = SVGClipRule.nonzero; this._opacity = 1f; this._fillOpacity = 1f; this._strokeOpacity = 1f; this._fillColor = new SVGColor(); this._strokeColor = new SVGColor(); this._strokeWidth = new SVGLength(1); this._strokeLineJoin = SVGStrokeLineJoinMethod.Miter; this._strokeLineCap = SVGStrokeLineCapMethod.Butt; this._fillRule = SVGFillRule.NonZero; this._miterLimit = new SVGLength(4); this._dashArray = null; this._dashOfset = new SVGLength(0); this._cssStyle = new Dictionary <string, Dictionary <string, string> >(); this._clipPathList = new List <List <Vector2> >(); this._linearGradList = new Dictionary <string, SVGLinearGradientElement>(); this._radialGradList = new Dictionary <string, SVGRadialGradientElement>(); this._conicalGradList = new Dictionary <string, SVGConicalGradientElement>(); }
/***********************************************************************************/ public SVGPaintable() { this._fillColor = new SVGColor(); this._strokeColor = new SVGColor(); this._strokeWidth = new SVGLength("1"); this._linearGradList = new List<SVGLinearGradientElement>(); this._radialGradList = new List<SVGRadialGradientElement>(); }
public SVGPaintable() { _fillColor = new SVGColor(); _strokeColor = new SVGColor(); _strokeWidth = new SVGLength(1); _linearGradList = new List<SVGLinearGradientElement>(); _radialGradList = new List<SVGRadialGradientElement>(); }
public SVGPaintable() { _fillColor = new SVGColor(); _strokeColor = new SVGColor(); _strokeWidth = new SVGLength(1); _linearGradList = new List <SVGLinearGradientElement>(); _radialGradList = new List <SVGRadialGradientElement>(); }
public SVGLength Multiply(SVGLength svglength) { if(unitType == SVGLengthType.Percentage && svglength.unitType == SVGLengthType.Percentage) { return new SVGLength(SVGLengthType.Percentage, this.value * svglength.value); } else { return new SVGLength(SVGLengthType.PX, this.value * svglength.value); } }
public SVGCircleElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _r = new SVGLength(attrList.GetValue("r")); }
public static float[] ExtractTransformValueAsPX(string inputText) { string[] tmp = ExtractTransformValue(inputText); float[] values = new float[tmp.Length]; for (int i = 0; i < values.Length; i++) { values[i] = SVGLength.GetPXLength(tmp[i]); } return(values); }
public SVGCircleElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _r = new SVGLength(attrList.GetValue("r")); }
private void SetDashArray(string[] dashArrayType) { if (dashArrayType != null && dashArrayType.Length > 0) { _dashArray = new float[dashArrayType.Length]; for (int i = 0; i < _dashArray.Length; i++) { _dashArray[i] = new SVGLength(dashArrayType[i]).value; } } }
public SVGEllipseElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); }
public SVGLength Multiply(SVGLength svglength) { if (unitType == SVGLengthType.Percentage && svglength.unitType == SVGLengthType.Percentage) { return(new SVGLength(SVGLengthType.Percentage, this.value * svglength.value)); } else { return(new SVGLength(SVGLengthType.PX, this.value * svglength.value)); } }
public SVGLineElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _paintable = new SVGPaintable(inheritPaintable, attrList); _render = render; _x1 = new SVGLength(attrList.GetValue("x1")); _y1 = new SVGLength(attrList.GetValue("y1")); _x2 = new SVGLength(attrList.GetValue("x2")); _y2 = new SVGLength(attrList.GetValue("y2")); }
//================================================================================ public SVGCircleElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._cx = new SVGLength(attrList.GetValue("cx")); this._cy = new SVGLength(attrList.GetValue("cy")); this._r = new SVGLength(attrList.GetValue("r")); }
public SVGEllipseElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _cx = new SVGLength(attrList.GetValue("cx")); _cy = new SVGLength(attrList.GetValue("cy")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); currentTransformList = new SVGTransformList(attrList.GetValue("transform")); }
public SVGRectElement(Dictionary <string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _x = new SVGLength(attrList.GetValue("x")); _y = new SVGLength(attrList.GetValue("y")); _width = new SVGLength(attrList.GetValue("width")); _height = new SVGLength(attrList.GetValue("height")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); }
public SVGCircleElement(Node node, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable = null) : base(inheritTransformList) { this._attrList = node.attributes; this._paintable = new SVGPaintable(inheritPaintable, node); this._cx = new SVGLength(attrList.GetValue("cx")); this._cy = new SVGLength(attrList.GetValue("cy")); this._r = new SVGLength(attrList.GetValue("r")); this.currentTransformList = new SVGTransformList(attrList.GetValue("transform")); Rect viewport = _paintable.viewport; this.currentTransformList.AppendItem(new SVGTransform(SVGTransformable.GetViewBoxTransform(this._attrList, ref viewport, false))); paintable.SetViewport(viewport); }
public SVGLineElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(inheritTransformList) { _paintable = new SVGPaintable(inheritPaintable, attrList); _render = render; _x1 = new SVGLength(attrList.GetValue("x1")); _y1 = new SVGLength(attrList.GetValue("y1")); _x2 = new SVGLength(attrList.GetValue("x2")); _y2 = new SVGLength(attrList.GetValue("y2")); }
/***********************************************************************************/ public SVGSVGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); Initial(); }
/***********************************************************************************/ public SVGLineElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._render = _render; this._x1 = new SVGLength(attrList.GetValue("x1")); this._y1 = new SVGLength(attrList.GetValue("y1")); this._x2 = new SVGLength(attrList.GetValue("x2")); this._y2 = new SVGLength(attrList.GetValue("y2")); }
public SVGRectElement(Dictionary<string, string> attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics render) : base(attrList, inheritTransformList, inheritPaintable, render) { _x = new SVGLength(attrList.GetValue("x")); _y = new SVGLength(attrList.GetValue("y")); _width = new SVGLength(attrList.GetValue("width")); _height = new SVGLength(attrList.GetValue("height")); _rx = new SVGLength(attrList.GetValue("rx")); _ry = new SVGLength(attrList.GetValue("ry")); }
/***********************************************************************************/ public SVGSVGElement( SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _xmlImp = xmlImp; _attrList = _xmlImp.Node.Attributes; _paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); Initial(); }
/***********************************************************************************/ public SVGLineElement( AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._render = _render; this._x1 = new SVGLength(attrList.GetValue("x1")); this._y1 = new SVGLength(attrList.GetValue("y1")); this._x2 = new SVGLength(attrList.GetValue("x2")); this._y2 = new SVGLength(attrList.GetValue("y2")); }
public SVGLineElement(Node node, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable = null) : base(inheritTransformList) { this._attrList = node.attributes; this._paintable = new SVGPaintable(inheritPaintable, node); this._x1 = new SVGLength(attrList.GetValue("x1")); this._y1 = new SVGLength(attrList.GetValue("y1")); this._x2 = new SVGLength(attrList.GetValue("x2")); this._y2 = new SVGLength(attrList.GetValue("y2")); this.currentTransformList = new SVGTransformList(attrList.GetValue("transform")); Rect viewport = _paintable.viewport; this.currentTransformList.AppendItem(new SVGTransform(SVGTransformable.GetViewBoxTransform(_attrList, ref viewport, false))); paintable.SetViewport(viewport); }
public SVGLinearGradientElement(SVGParser xmlImp, Node node) : base(xmlImp, node) { string temp; temp = _attrList.GetValue("x1"); _x1 = new SVGLength((temp == "") ? "0%" : temp); temp = this._attrList.GetValue("y1"); _y1 = new SVGLength((temp == "") ? "0%" : temp); temp = this._attrList.GetValue("x2"); _x2 = new SVGLength((temp == "") ? "100%" : temp); temp = this._attrList.GetValue("y2"); _y2 = new SVGLength((temp == "") ? "0%" : temp); }
//================================================================================ public SVGRectElement(AttributeList attrList, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics _render) : base(inheritTransformList) { this._attrList = attrList; this._render = _render; this._paintable = new SVGPaintable(inheritPaintable, this._attrList); this._x = new SVGLength(attrList.GetValue("x")); this._y = new SVGLength(attrList.GetValue("y")); this._width = new SVGLength(attrList.GetValue("width")); this._height = new SVGLength(attrList.GetValue("height")); this._rx = new SVGLength(attrList.GetValue("rx")); this._ry = new SVGLength(attrList.GetValue("ry")); }
/***************************************************************************/ public SVGLinearGradientElement(SVGParser xmlImp, AttributeList attrList) : base(xmlImp, attrList) { string temp; temp = _attrList.GetValue("x1"); _x1 = new SVGLength((temp == "") ? "0%" : temp); temp = this._attrList.GetValue("y1"); _y1 = new SVGLength((temp == "") ? "0%" : temp); temp = this._attrList.GetValue("x2"); _x2 = new SVGLength((temp == "") ? "100%" : temp); temp = this._attrList.GetValue("y2"); _y2 = new SVGLength((temp == "") ? "0%" : temp); }
public SVGRectElement(Node node, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable = null) : base(inheritTransformList) { this._attrList = node.attributes; this._paintable = new SVGPaintable(inheritPaintable, node); this._x = new SVGLength(attrList.GetValue("x")); this._y = new SVGLength(attrList.GetValue("y")); this._width = new SVGLength(attrList.GetValue("width")); this._height = new SVGLength(attrList.GetValue("height")); this._rx = new SVGLength(attrList.GetValue("rx")); this._ry = new SVGLength(attrList.GetValue("ry")); this.currentTransformList = new SVGTransformList(attrList.GetValue("transform")); Rect viewport = _paintable.viewport; this.currentTransformList.AppendItem(new SVGTransform(SVGTransformable.GetViewBoxTransform(_attrList, ref viewport, false))); paintable.SetViewport(viewport); }
private static List<Vector2> ExtractPoints(string inputText) { List<Vector2> _return = new List<Vector2>(); string[] _lstStr = SVGStringExtractor.ExtractTransformValue(inputText); int len = _lstStr.Length; for(int i = 0; i < len - 1; i++) { string value1 = _lstStr[i]; string value2 = _lstStr[i + 1]; SVGLength _length1 = new SVGLength(value1); SVGLength _length2 = new SVGLength(value2); Vector2 _point = new Vector2(_length1.value, _length2.value); _return.Add(_point); i++; } return _return; }
/*********************************************************************************/ private void Initialize() { _x1 = _linearGradElement.x1; _y1 = _linearGradElement.y1; _x2 = _linearGradElement.x2; _y2 = _linearGradElement.y2; _stopColorList = new List<Color>(); _stopOffsetList = new List<float>(); // _spreadMethod = _linearGradElement.spreadMethod; GetStopList(); /* _vitriOffset = 0; PreColorProcess(_vitriOffset); */ }
/*********************************************************************************/ private void Initialize() { _x1 = _linearGradElement.x1; _y1 = _linearGradElement.y1; _x2 = _linearGradElement.x2; _y2 = _linearGradElement.y2; _stopColorList = new List <Color>(); _stopOffsetList = new List <float>(); // _spreadMethod = _linearGradElement.spreadMethod; GetStopList(); /* * _vitriOffset = 0; * PreColorProcess(_vitriOffset); */ }
public SVGRadialGradientElement(SVGParser xmlImp, Node node) : base(xmlImp, node) { string temp; temp = _attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
public SVGRadialGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList) : base(xmlImp, attrList) { string temp = attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
public SVGConicalGradientElement(SVGParser xmlImp, Node node) : base(xmlImp, node) { string temp; temp = _attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = _attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
public SVGRadialGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList) : base(xmlImp, attrList) { // TODO: Override GetValue to return `null` and use `||`. string temp = attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
public SVGRadialGradientElement(SVGParser xmlImp, Dictionary <string, string> attrList) : base(xmlImp, attrList) { // TODO: Override GetValue to return `null` and use `||`. string temp = attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
public SVGRadialGradientElement(SVGParser xmlImp, Dictionary <string, string> attrList) : base(xmlImp, attrList) { string temp = attrList.GetValue("cx"); _cx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("cy"); _cy = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("r"); _r = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fx"); _fx = new SVGLength((temp == "") ? "50%" : temp); temp = attrList.GetValue("fy"); _fy = new SVGLength((temp == "") ? "50%" : temp); }
/*********************************************************************************/ private void Initialize() { _cx = _conicalGradElement.cx; _cy = _conicalGradElement.cy; _r = _conicalGradElement.r; // _fx = _conicalGradElement.fx.value; // _fy = _conicalGradElement.fy.value; _stopColorList = new List<Color>(); _stopOffsetList = new List<float>(); // _spreadMethod = _conicalGradElement.spreadMethod; GetStopList(); /* FixF(); _vitriOffset = 0; PreColorProcess(_vitriOffset); */ }
private static List <Vector2> ExtractPoints(string inputText) { List <Vector2> _return = new List <Vector2>(); string[] _lstStr = SVGStringExtractor.ExtractTransformValue(inputText); int len = _lstStr.Length; for (int i = 0; i < len - 1; i++) { string value1 = _lstStr[i]; string value2 = _lstStr[i + 1]; SVGLength _length1 = new SVGLength(value1); SVGLength _length2 = new SVGLength(value2); Vector2 _point = new Vector2(_length1.value, _length2.value); _return.Add(_point); i++; } return(_return); }
/*********************************************************************************/ private void Initialize() { _cx = _conicalGradElement.cx; _cy = _conicalGradElement.cy; _r = _conicalGradElement.r; // _fx = _conicalGradElement.fx.value; // _fy = _conicalGradElement.fy.value; _stopColorList = new List <Color>(); _stopOffsetList = new List <float>(); // _spreadMethod = _conicalGradElement.spreadMethod; GetStopList(); /* * FixF(); * _vitriOffset = 0; * PreColorProcess(_vitriOffset); */ }
public SVGSVGElement(SVGParser xmlImp, SVGTransformList inheritTransformList, SVGPaintable inheritPaintable, SVGGraphics r) : base(inheritTransformList) { _render = r; _attrList = xmlImp.Node.Attributes; var paintable = new SVGPaintable(inheritPaintable, _attrList); _width = new SVGLength(_attrList.GetValue("width")); _height = new SVGLength(_attrList.GetValue("height")); SetViewBox(); ViewBoxTransform(); SVGTransform temp = new SVGTransform(_cachedViewBoxTransform); SVGTransformList t_currentTransformList = new SVGTransformList(); t_currentTransformList.AppendItem(temp); currentTransformList = t_currentTransformList; // use setter only once, since it also updates other lists xmlImp.GetElementList(_elementList, paintable, _render, summaryTransformList); }
protected static Vector2 GetGradientVector(SVGLength posX, SVGLength posY, Rect bounds) { Vector2 point = Vector2.zero; if (posX.unitType != SVGLengthType.Percentage) { point.x = posX.value; } else { point.x = bounds.x + bounds.width * (posX.value / 100f); } if (posY.unitType != SVGLengthType.Percentage) { point.y = posY.value; } else { point.y = bounds.y + bounds.height * (posY.value / 100f); } return(point); }
protected static Vector2 GetGradientVector(SVGLength posX, SVGLength posY, Rect bounds) { Vector2 point = Vector2.zero; if(posX.unitType != SVGLengthType.Percentage) { point.x = posX.value; } else { point.x = bounds.x + bounds.width * (posX.value / 100f); } if(posY.unitType != SVGLengthType.Percentage) { point.y = posY.value; } else { point.y = bounds.y + bounds.height * (posY.value / 100f); } return point; }
/***********************************************************************************/ //Di Phan Tich Style private void Style(string styleString) { Dictionary<string, string> _dictionary = new Dictionary<string, string>(); SVGStringExtractor.ExtractStyleValue(styleString, ref _dictionary); if(_dictionary.ContainsKey("fill")) { if(_dictionary["fill"].IndexOf("url") >= 0) { _gradientID = SVGStringExtractor.ExtractUrl4Gradient(_dictionary["fill"]); } else { _fillColor = new SVGColor(_dictionary["fill"]); } } if(_dictionary.ContainsKey("stroke")) { _strokeColor = new SVGColor(_dictionary["stroke"]); } if(_dictionary.ContainsKey("stroke-width")) { this.isStrokeWidth = true; _strokeWidth = new SVGLength(_dictionary["stroke-width"]); } if(_dictionary.ContainsKey("stroke-linecap")) { SetStrokeLineCap(_dictionary["stroke-linecap"]); } if(_dictionary.ContainsKey("stroke-linejoin")) { SetStrokeLineJoin(_dictionary["stroke-linejoin"]); } }
/***********************************************************************************/ //Khoi tao private void Initialize(AttributeList attrList) { isStrokeWidth = false; if(attrList.GetValue("fill").IndexOf("url") >= 0) { _gradientID = SVGStringExtractor.ExtractUrl4Gradient(attrList.GetValue("fill")); } else { _fillColor = new SVGColor(attrList.GetValue("fill")); } _strokeColor = new SVGColor(attrList.GetValue("stroke")); if(attrList.GetValue("stroke-width") != "") isStrokeWidth = true; _strokeWidth = new SVGLength(attrList.GetValue("stroke-width")); SetStrokeLineCap(attrList.GetValue("stroke-linecap")); SetStrokeLineJoin(attrList.GetValue("stroke-linejoin")); if(attrList.GetValue("stroke-width") == "") _strokeWidth.NewValueSpecifiedUnits(1f); Style(attrList.GetValue("style")); //style="fill: #ffffff; stroke:#000000; stroke-width:0.172" }
private void Initialize(Dictionary<string, string> attrList) { isStrokeWidth = false; if (attrList.ContainsKey("fill")) { string fill = attrList["fill"]; if(fill.Contains("url")) _gradientID = SVGStringExtractor.ExtractUrl4Gradient(fill); else _fillColor = new SVGColor(fill); } _strokeColor = new SVGColor(attrList.GetValue("stroke")); if (attrList.ContainsKey("stroke-width")) { isStrokeWidth = true; _strokeWidth = new SVGLength(attrList["stroke-width"]); } SetStrokeLineCap(attrList.GetValue("stroke-linecap")); SetStrokeLineJoin(attrList.GetValue("stroke-linejoin")); if (!attrList.ContainsKey("stroke-width")) _strokeWidth.NewValueSpecifiedUnits(1f); SetStyle(attrList.GetValue("style")); }
//const float defaultViewportScale = 800f; public static SVGMatrix GetFillTransform(SVGFill svgFill, Rect bounds, SVGLength[] gradientStart, SVGLength[] gradientEnd, SVGMatrix fillTransform, SVGMatrix gradientTransform) { SVGMatrix transform = SVGMatrix.identity; SVGLength gradientStartX = gradientStart[0]; SVGLength gradientStartY = gradientStart[1]; SVGLength gradientEndX = gradientEnd[0]; SVGLength gradientEndY = gradientEnd[1]; Rect viewport = svgFill.viewport; //Debug.Log(viewport); if (svgFill.fillType == FILL_TYPE.GRADIENT) { switch (svgFill.gradientType) { case GRADIENT_TYPE.LINEAR: { Vector2 startPoint = GetGradientVector(gradientStartX, gradientStartY, bounds); Vector2 endPoint = GetGradientVector(gradientEndX, gradientEndY, bounds); Vector2 gradientVector = endPoint - startPoint; Vector2 normalizedVector = Vector2.zero; float angle = Mathf.Atan2(gradientVector.y, gradientVector.x) * Mathf.Rad2Deg; Vector2 posDiff = Vector2.Lerp(startPoint, endPoint, 0.5f); float magnitude = gradientVector.magnitude; if (magnitude != 0f) { normalizedVector.x = viewport.width / magnitude; normalizedVector.y = viewport.height / magnitude; } transform = transform.Translate(viewport.center); transform = transform.Scale(normalizedVector.x, normalizedVector.y); transform = transform.Rotate(-angle); transform = transform.Translate(-posDiff); transform = transform.Multiply(gradientTransform.Inverse()); transform = transform.Multiply(fillTransform.Inverse()); break; } case GRADIENT_TYPE.RADIAL: { Vector2 point = GetGradientVector(gradientStartX, gradientStartY, bounds); float radius = GetGradientVector(gradientEndX, gradientEndY, bounds).x; if (gradientEndX.unitType == SVGLengthType.Percentage) { radius *= 0.5f; } float radiusTimesTwo = radius * 2f; Vector2 normalizedVector = Vector2.zero; if (radiusTimesTwo != 0f) { normalizedVector.x = viewport.width / radiusTimesTwo; normalizedVector.y = viewport.height / radiusTimesTwo; } transform = transform.Translate(viewport.center); transform = transform.Scale(normalizedVector.x, normalizedVector.y); transform = transform.Translate(-point); transform = transform.Multiply(gradientTransform.Inverse()); transform = transform.Multiply(fillTransform.Inverse()); break; } case GRADIENT_TYPE.CONICAL: { Vector2 point = GetGradientVector(gradientStartX, gradientStartY, bounds); float radius = GetGradientVector(gradientEndX, gradientEndY, bounds).x; if (gradientEndX.unitType == SVGLengthType.Percentage) { radius *= 0.5f; } float radiusTimesTwo = radius * 2f; Vector2 normalizedVector = Vector2.zero; if (radiusTimesTwo != 0f) { normalizedVector.x = viewport.width / radiusTimesTwo; normalizedVector.y = viewport.height / radiusTimesTwo; } transform = transform.Translate(viewport.center); transform = transform.Scale(normalizedVector.x, normalizedVector.y); transform = transform.Translate(-point); transform = transform.Multiply(gradientTransform.Inverse()); transform = transform.Multiply(fillTransform.Inverse()); break; } } } return(transform); }
public static SVGMatrix GetRootViewBoxTransform(AttributeList attributeList, ref Rect viewport) { SVGMatrix matrix = SVGMatrix.identity; string attrXString = attributeList.GetValue("x"); string attrYString = attributeList.GetValue("y"); string attrWidthString = attributeList.GetValue("width"); string attrHeightString = attributeList.GetValue("height"); SVGLength attrX = new SVGLength(SVGLengthType.PX, 0f), attrY = new SVGLength(SVGLengthType.PX, 0f), attrWidth = new SVGLength(SVGLengthType.PX, 1f), attrHeight = new SVGLength(SVGLengthType.PX, 1f); if (!string.IsNullOrEmpty(attrXString)) { attrX = new SVGLength(attrXString); } if (!string.IsNullOrEmpty(attrYString)) { attrY = new SVGLength(attrYString); } if (!string.IsNullOrEmpty(attrWidthString)) { attrWidth = new SVGLength(attrWidthString); } if (!string.IsNullOrEmpty(attrHeightString)) { attrHeight = new SVGLength(attrHeightString); } string viewBox = attributeList.GetValue("viewBox"); if (!string.IsNullOrEmpty(viewBox)) { string[] _temp = SVGStringExtractor.ExtractTransformValue(viewBox); if (_temp.Length > 0) { if (string.IsNullOrEmpty(attrXString)) { attrX = new SVGLength(_temp [0]); } } if (_temp.Length > 1) { if (string.IsNullOrEmpty(attrYString)) { attrY = new SVGLength(_temp [1]); } } if (_temp.Length > 2) { if (string.IsNullOrEmpty(attrWidthString)) { attrWidth = new SVGLength(_temp [2]); } } if (_temp.Length > 3) { if (string.IsNullOrEmpty(attrHeightString)) { attrHeight = new SVGLength(_temp [3]); } } viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value); if (string.IsNullOrEmpty(attrXString)) { viewport.x = attrX.value; } if (string.IsNullOrEmpty(attrYString)) { viewport.y = attrY.value; } if (string.IsNullOrEmpty(attrWidthString)) { viewport.width = attrWidth.value; } if (string.IsNullOrEmpty(attrHeightString)) { viewport.height = attrHeight.value; } } else { viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value); } return(matrix); }
private void SetDashArray(string[] dashArrayType) { if(dashArrayType != null && dashArrayType.Length > 0) { _dashArray = new float[dashArrayType.Length]; for(int i = 0; i < _dashArray.Length; i++) { _dashArray[i] = new SVGLength(dashArrayType[i]).value; } } }
private void ReadStyle(Dictionary<string, string> _dictionary) { if(_dictionary == null || _dictionary.Count == 0) return; if (_dictionary.ContainsKey("visibility")) { SetVisibility(_dictionary ["visibility"]); } if (_dictionary.ContainsKey("display")) { SetDisplay(_dictionary ["display"]); } if (_dictionary.ContainsKey("overflow")) { SetOverflow(_dictionary ["overflow"]); } if (_dictionary.ContainsKey("clip-rule")) { SetClipRule(_dictionary ["clip-rule"]); } if (_dictionary.ContainsKey("clip-path")) { ReadClipPath(_dictionary ["clip-path"]); } if (_dictionary.ContainsKey("fill")) { string fillValue = _dictionary ["fill"]; if (fillValue.IndexOf("url") >= 0) { _gradientID = SVGStringExtractor.ExtractUrl(fillValue); } else { _fillColor = new SVGColor(_dictionary ["fill"]); } } if (_dictionary.ContainsKey("opacity")) { _opacity *= new SVGLength(_dictionary ["opacity"]).value; } if (_dictionary.ContainsKey("fill-opacity")) { _fillOpacity *= new SVGLength(_dictionary ["fill-opacity"]).value; } if (_dictionary.ContainsKey("stroke-opacity")) { _strokeOpacity *= new SVGLength(_dictionary ["stroke-opacity"]).value; } if(_dictionary.ContainsKey("fill-rule")) { SetFillRule(_dictionary["fill-rule"]); } if (_dictionary.ContainsKey("stroke")) { _strokeColor = new SVGColor(_dictionary ["stroke"]); } if (_dictionary.ContainsKey("stroke-width")) { this.isStrokeWidth = true; _strokeWidth = new SVGLength(_dictionary ["stroke-width"]); } if (_dictionary.ContainsKey("stroke-linecap")) { SetStrokeLineCap(_dictionary ["stroke-linecap"]); } if (_dictionary.ContainsKey("stroke-linejoin")) { SetStrokeLineJoin(_dictionary ["stroke-linejoin"]); } if (_dictionary.ContainsKey("stroke-miterlimit")) { _miterLimit = new SVGLength(_dictionary["stroke-miterlimit"]); } if (_dictionary.ContainsKey("stroke-dasharray")) { SetDashArray(_dictionary["stroke-dasharray"].Split(',')); } if (_dictionary.ContainsKey("stroke-dashoffset")) { _dashOfset = new SVGLength(_dictionary["stroke-dashoffset"]); } }
void InitDefaults() { isStrokeWidth = false; this._visibility = SVGVisibility.Visible; this._display = SVGDisplay.Inline; this._overflow = SVGOverflow.visible; this._clipPathUnits = SVGClipPathUnits.UserSpaceOnUse; this._clipRule = SVGClipRule.nonzero; this._opacity = 1f; this._fillOpacity = 1f; this._strokeOpacity = 1f; this._fillColor = new SVGColor(); this._strokeColor = new SVGColor(); this._strokeWidth = new SVGLength(1); this._strokeLineJoin = SVGStrokeLineJoinMethod.Miter; this._strokeLineCap = SVGStrokeLineCapMethod.Butt; this._fillRule = SVGFillRule.NonZero; this._miterLimit = new SVGLength(4); this._dashArray = null; this._dashOfset = new SVGLength(0); this._cssStyle = new Dictionary<string, Dictionary<string, string>>(); this._clipPathList = new List<List<Vector2>>(); this._linearGradList = new Dictionary<string, SVGLinearGradientElement>(); this._radialGradList = new Dictionary<string, SVGRadialGradientElement>(); this._conicalGradList = new Dictionary<string, SVGConicalGradientElement>(); }
public static SVGMatrix GetViewBoxTransform(AttributeList attributeList, ref Rect viewport, bool negotiate = false) { SVGMatrix matrix = new SVGMatrix(); float x = 0.0f; float y = 0.0f; float w = 0.0f; float h = 0.0f; string preserveAspectRatio = attributeList.GetValue("preserveAspectRatio"); string viewBox = attributeList.GetValue("viewBox"); if (!string.IsNullOrEmpty(viewBox)) { string[] viewBoxValues = SVGStringExtractor.ExtractTransformValue(viewBox); if(viewBoxValues.Length == 4) { Rect contentRect = new Rect( new SVGLength(viewBoxValues[0]).value, new SVGLength(viewBoxValues[1]).value, new SVGLength(viewBoxValues[2]).value, new SVGLength(viewBoxValues[3]).value ); SVGViewport.Align align = SVGViewport.Align.xMidYMid; SVGViewport.MeetOrSlice meetOrSlice = SVGViewport.MeetOrSlice.Meet; if(!string.IsNullOrEmpty(preserveAspectRatio)) { string[] aspectRatioValues = SVGStringExtractor.ExtractStringArray(preserveAspectRatio); align = SVGViewport.GetAlignFromStrings(aspectRatioValues); meetOrSlice = SVGViewport.GetMeetOrSliceFromStrings(aspectRatioValues); } Rect oldViewport = viewport; viewport = SVGViewport.GetViewport(viewport, contentRect, align, meetOrSlice); float sizeX = 0f, sizeY = 0f; if(oldViewport.size.x != 0f) sizeX = viewport.size.x / oldViewport.size.x; if(oldViewport.size.y != 0f) sizeY = viewport.size.y / oldViewport.size.y; matrix.ScaleNonUniform(sizeX, sizeY); matrix = matrix.Translate(viewport.x - oldViewport.x, viewport.y - oldViewport.y); } } else { if(negotiate) { string attrXString = attributeList.GetValue("x"); string attrYString = attributeList.GetValue("y"); string attrWidthString = attributeList.GetValue("width"); string attrHeightString = attributeList.GetValue("height"); SVGLength attrX = new SVGLength(SVGLengthType.PX, 0f), attrY = new SVGLength(SVGLengthType.PX, 0f), attrWidth = new SVGLength(SVGLengthType.PX, 1f), attrHeight = new SVGLength(SVGLengthType.PX, 1f); if(!string.IsNullOrEmpty(attrXString)) { attrX = new SVGLength(attrXString); } if(!string.IsNullOrEmpty(attrYString)) { attrY = new SVGLength(attrYString); } if(!string.IsNullOrEmpty(attrWidthString)) { attrWidth = new SVGLength(attrWidthString); } if(!string.IsNullOrEmpty(attrHeightString)) { attrHeight = new SVGLength(attrHeightString); } x = attrX.value; y = attrY.value; w = attrWidth.value; h = attrHeight.value; float x_ratio = 1f; if(w != 0f) x_ratio = attrWidth.value / w; float y_ratio = 1f; if(h != 0f) y_ratio = attrHeight.value / h; matrix = matrix.ScaleNonUniform(x_ratio, y_ratio); matrix = matrix.Translate(x, y); viewport = new Rect(x, y, w, h); // Debug.Log(string.Format("x: {0}, y: {1}, width: {2}, height: {3}, attrWidth: {4}, attrHeight: {5}", x, y, w, h, attrWidth, attrHeight)); } // Debug.Log(string.Format("x: {0}, y: {1}, width: {2}, height: {3}, attrWidth: {4}, attrHeight: {5}", x, y, w, h, attrWidth, attrHeight)); } return matrix; }
public static SVGMatrix GetRootViewBoxTransform(AttributeList attributeList, ref Rect viewport) { SVGMatrix matrix = new SVGMatrix(); float x = 0.0f; float y = 0.0f; float w = 0.0f; float h = 0.0f; string attrXString = attributeList.GetValue("x"); string attrYString = attributeList.GetValue("y"); string attrWidthString = attributeList.GetValue("width"); string attrHeightString = attributeList.GetValue("height"); SVGLength attrX = new SVGLength(SVGLengthType.PX, 0f), attrY = new SVGLength(SVGLengthType.PX, 0f), attrWidth = new SVGLength(SVGLengthType.PX, 1f), attrHeight = new SVGLength(SVGLengthType.PX, 1f); if(!string.IsNullOrEmpty(attrXString)) { attrX = new SVGLength(attrXString); } if(!string.IsNullOrEmpty(attrYString)) { attrY = new SVGLength(attrYString); } if(!string.IsNullOrEmpty(attrWidthString)) { attrWidth = new SVGLength(attrWidthString); } if(!string.IsNullOrEmpty(attrHeightString)) { attrHeight = new SVGLength(attrHeightString); } string viewBox = attributeList.GetValue("viewBox"); if (!string.IsNullOrEmpty(viewBox)) { string[] _temp = SVGStringExtractor.ExtractTransformValue(viewBox); if (_temp.Length > 0) { if(string.IsNullOrEmpty(attrXString)) { attrX = new SVGLength(_temp [0]); } } if (_temp.Length > 1) { if(string.IsNullOrEmpty(attrYString)) { attrY = new SVGLength(_temp [1]); } } if (_temp.Length > 2) { if(string.IsNullOrEmpty(attrWidthString)) { attrWidth = new SVGLength(_temp [2]); } } if (_temp.Length > 3) { if(string.IsNullOrEmpty(attrHeightString)) { attrHeight = new SVGLength(_temp [3]); } } viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value); if(string.IsNullOrEmpty(attrXString)) { viewport.x = attrX.value; } if(string.IsNullOrEmpty(attrYString)) { viewport.y = attrY.value; } if(string.IsNullOrEmpty(attrWidthString)) { viewport.width = attrWidth.value; } if(string.IsNullOrEmpty(attrHeightString)) { viewport.height = attrHeight.value; } } else { viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value); } return matrix; }