Beispiel #1
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGBrush result = new SVGBrush();

            if (attribute.Value.StartsWith("url"))
            {
                result.Value = this.Get_URL(attribute.SVG, attribute.Value);
            }
            else if (attribute.Value.StartsWith("#"))
            {
                Color color = this.ParseColor_Well(attribute.Value);
                result.Value = new SolidColorBrush(color);
            }
            else if (attribute.Value.StartsWith("rgb"))
            {
                Color color = this.ParseColor_RGB(attribute.Value);
                result.Value = new SolidColorBrush(color);
            }
            else
            {
                Color color = (Color)ColorConverter.ConvertFromString(attribute.Value);
                result.Value = new SolidColorBrush(color);
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGString value = new SVGString();

            value.Value = attribute.Value;

            attribute.Data = value;

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGPathData result = new SVGPathData();

            result.Value = Geometry.Parse(attribute.Value).Clone();

            attribute.Data = result;

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGFontStyle result = new SVGFontStyle();

            result.Value = (FontStyle)Converter.ConvertFromString(attribute.Value);

            attribute.Data = result;

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGFontFamily result = new SVGFontFamily();

            result.Value = new FontFamily(attribute.Value);

            attribute.Data = result;

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "nonzero": attribute.Data = SVGFillRule.Nonzero; break;

            case "evenodd": attribute.Data = SVGFillRule.Evenodd; break;
            }

            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "userSpaceOnUse": attribute.Data = SVGGradientUnits.UserSpaceOnUse; break;

            case "objectBoundingBox": attribute.Data = SVGGradientUnits.ObjectBoundingBox; break;
            }

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGMask result = new SVGMask();

            if (attribute.Value.StartsWith("url"))
            {
                result.Value = this.Get_URL(attribute.SVG, attribute.Value);
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="element">当前元素</param>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "miter": attribute.Data = SVGLineJoin.Miter; break;

            case "round": attribute.Data = SVGLineJoin.Round; break;

            case "bevel": attribute.Data = SVGLineJoin.Bevel; break;
            }

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="svg">SVG</param>
        /// <param name="element">当前元素</param>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "butt": attribute.Data = SVGLineCap.Butt; break;

            case "round": attribute.Data = SVGLineCap.Round; break;

            case "square": attribute.Data = SVGLineCap.Square; break;
            }

            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "baseline": attribute.Data = SVGBaseLineShift.Baseline; break;

            case "sub": attribute.Data = SVGBaseLineShift.Sub; break;

            case "super": attribute.Data = SVGBaseLineShift.Super; break;

            default: Parser.Parse(attribute); break;
            }

            return(true);
        }
Beispiel #12
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGDashArray result = new SVGDashArray();

            string[] components = attribute.Value.Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string item in components)
            {
                double v = double.Parse(item.Trim());

                result.Value.Add(v);
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGTextAnchor result = new SVGTextAnchor();

            switch (attribute.Value)
            {
            case "start": result.Value = TextAlignment.Left; break;

            case "middle": result.Value = TextAlignment.Center; break;

            case "end": result.Value = TextAlignment.Right; break;
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #14
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGTextDecoration result = new SVGTextDecoration();

            switch (attribute.Value)
            {
            case "underline": result.Value = TextDecorationLocation.Underline; break;

            case "overline": result.Value = TextDecorationLocation.OverLine; break;

            case "line-through": result.Value = TextDecorationLocation.Strikethrough; break;
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #15
0
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <typeparam name="T">属性类型</typeparam>
        /// <param name="name">属性名</param>
        /// <param name="inherit">是否是继承属性</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>属性值</returns>
        public T GetAttributeValue <T>(XName name, bool inherit, T defaultValue) where T : SVGData
        {
            if (this.AttributePool.ContainsKey(name))
            {
                SVGAttribute attribute = this.AttributePool[name];

                if (!attribute.IsParsed)
                {
                    SVGAttribute.Parse <T>(attribute);
                }

                if (attribute.Data == SVGData.Null || attribute.Data == SVGData.None)
                {
                    return(defaultValue);
                }

                if (attribute.Data == SVGData.Inherit)
                {
                    if (this.Parent == null)
                    {
                        return(defaultValue);
                    }
                    else
                    {
                        return(this.Parent.GetAttributeValue <T>(name, inherit, defaultValue));
                    }
                }

                return(attribute.Data as T);
            }

            if (inherit)
            {
                if (this.Parent == null)
                {
                    return(defaultValue);
                }
                else
                {
                    return(this.Parent.GetAttributeValue <T>(name, inherit, defaultValue));
                }
            }

            return(defaultValue);
        }
Beispiel #16
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGTransform result = new SVGTransform();

            string[] components = attribute.Value.Split(new char[] { ')' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < components.Length; ++i)
            {
                components[i] = components[i].Trim();
            }

            foreach (string item in components)
            {
                if (item.StartsWith("translate"))
                {
                    this.Excute_translate(result, item);
                }
                else if (item.StartsWith("scale"))
                {
                    this.Excute_scale(result, item);
                }
                else if (item.StartsWith("rotate"))
                {
                    this.Excute_rotate(result, item);
                }
                else if (item.StartsWith("skewX"))
                {
                    this.Excute_skewX(result, item);
                }
                else if (item.StartsWith("skewY"))
                {
                    this.Excute_skewY(result, item);
                }
                else if (item.StartsWith("matrix"))
                {
                    this.Excute_matrix(result, item);
                }
            }

            result.Value.Reverse();

            attribute.Data = result;

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGPointArray result = new SVGPointArray();

            string[] components = attribute.Value.Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < components.Length; i += 2)
            {
                double x = double.Parse(components[i].Trim());
                double y = double.Parse(components[i + 1].Trim());

                result.Value.Add(new Point(x, y));
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #18
0
        /// <summary>
        /// 尝试获取值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static void Parse <T>(SVGAttribute attribute) where T : SVGData
        {
            if (string.IsNullOrWhiteSpace(attribute.Value) || attribute.Value.Equals("null", StringComparison.OrdinalIgnoreCase))
            {
                attribute.Data     = SVGData.Null;
                attribute.IsParsed = true;

                return;
            }

            if (attribute.Value.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                attribute.Data     = SVGData.None;
                attribute.IsParsed = true;

                return;
            }

            Type type = typeof(T);

            foreach (ISVGDataParse provider in Providers)
            {
                if (provider.Type != type)
                {
                    continue;
                }

                if (!provider.Parse(attribute))
                {
                    throw new SVGDataParseException(attribute.Name, attribute.Value);
                }

                attribute.IsParsed = true;

                return;
            }

            attribute.IsParsed = true;

            throw new SVGDataParseException(attribute.Name, attribute.Value);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            switch (attribute.Value)
            {
            case "inline": attribute.Data = SVGDisplay.Inline; break;

            case "block": attribute.Data = SVGDisplay.Block; break;

            case "list-item": attribute.Data = SVGDisplay.ListItem; break;

            case "run-in": attribute.Data = SVGDisplay.RunIn; break;

            case "compact": attribute.Data = SVGDisplay.Compact; break;

            case "marker": attribute.Data = SVGDisplay.Marker; break;

            case "table": attribute.Data = SVGDisplay.Table; break;

            case "inline-table": attribute.Data = SVGDisplay.InlineTable; break;

            case "table-row-group": attribute.Data = SVGDisplay.TableRowGroup; break;

            case "table-header-group": attribute.Data = SVGDisplay.TableHeaderGroup; break;

            case "table-row": attribute.Data = SVGDisplay.TableRow; break;

            case "table-column-group": attribute.Data = SVGDisplay.TableColumnGroup; break;

            case "table-column": attribute.Data = SVGDisplay.TableColumn; break;

            case "table-cell": attribute.Data = SVGDisplay.TableCell; break;

            case "table-caption": attribute.Data = SVGDisplay.TableCaption; break;

            case "none": attribute.Data = SVGDisplay.None; break;
            }

            return(true);
        }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGColor result = new SVGColor();

            if (attribute.Value.StartsWith("#"))
            {
                Color color = this.ParseColor_Well(attribute.Value);
                result.Value = color;
            }
            else if (attribute.Value.StartsWith("rgb"))
            {
                Color color = this.ParseColor_RGB(attribute.Value);
                result.Value = color;
            }
            else
            {
                Color color = (Color)ColorConverter.ConvertFromString(attribute.Value);
                result.Value = color;
            }

            attribute.Data = result;

            return(true);
        }
Beispiel #21
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <returns>是否转化成果</returns>
        public override bool Parse(SVGAttribute attribute)
        {
            SVGDouble result = new SVGDouble();

            foreach (string unit in UNITS)
            {
                if (attribute.Value.EndsWith(unit))
                {
                    result.Unit = unit;

                    result.Value = double.Parse(attribute.Value.Substring(0, attribute.Value.IndexOf(unit[0])));

                    attribute.Data = result;

                    return(true);
                }
            }

            result.Value = double.Parse(attribute.Value);

            attribute.Data = result;

            return(true);
        }
Beispiel #22
0
 /// <summary>
 /// 转换
 /// </summary>
 /// <param name="attribute">属性</param>
 /// <returns>是否转化成果</returns>
 public abstract bool Parse(SVGAttribute attribute);