Example #1
0
        private void ReadClipPath(string clipPathValue)
        {
            if (clipPathValue.IndexOf("url") >= 0)
            {
                string clipPathURL = SVGStringExtractor.ExtractUrl(clipPathValue);
                if (!string.IsNullOrEmpty(clipPathURL) && SVGParser._defs.ContainsKey(clipPathURL))
                {
                    Node clipPathNode = SVGParser._defs[clipPathURL];
                    if (clipPathNode != null)
                    {
                        SVGMatrix svgMatrix = SVGMatrix.identity;

                        string clipPathUnitsString = clipPathNode.attributes.GetValue("clipPathUnits");
                        switch (clipPathUnitsString.ToLower())
                        {
                        case "userSpaceOnUse":
                            _clipPathUnits = SVGClipPathUnits.UserSpaceOnUse;
                            break;

                        case "objectBoundingBox":
                            _clipPathUnits = SVGClipPathUnits.ObjectBoundingBox;
                            break;
                        }

                        List <Node>            clipPathNodes       = clipPathNode.GetNodes();
                        List <List <Vector2> > currentClipPathList = new List <List <Vector2> >();
                        if (clipPathNodes != null && clipPathNodes.Count > 0)
                        {
                            for (int i = 0; i < clipPathNodes.Count; i++)
                            {
                                List <List <Vector2> > clipPath = GetClipPath(clipPathNodes[i], svgMatrix);
                                if (clipPath != null)
                                {
                                    currentClipPathList.AddRange(clipPath);
                                }
                            }
                        }

                        if (currentClipPathList.Count > 0)
                        {
                            currentClipPathList = SVGGeom.MergePolygon(currentClipPathList);
                        }

                        if (_clipPathList != null && _clipPathList.Count > 0)
                        {
                            _clipPathList = SVGGeom.ClipPolygon(_clipPathList, currentClipPathList);
                        }
                        else
                        {
                            _clipPathList = currentClipPathList;
                        }
                    }
                }
            }
        }
Example #2
0
        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"]);
            }
        }