Exemplo n.º 1
0
 protected virtual void Parse(string name, string value)
 {
     if (name == SVGTags.sTransform)
     {
         Transform = ShapeUtil.ParseTransform(value.ToLower());
         return;
     }
     if (name == SVGTags.sStroke)
     {
         GetStroke().Color = SVG.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sStrokeWidth)
     {
         GetStroke().Width = XmlUtil.ParseDouble(value);
         return;
     }
     if (name == SVGTags.sStrokeOpacity)
     {
         GetStroke().Opacity = XmlUtil.ParseDouble(value) * 100;
         return;
     }
     if (name == SVGTags.sStrokeDashArray)
     {
         if (value == "none")
         {
             GetStroke().StrokeArray = null;
             return;
         }
         ShapeUtil.StringSplitter sp = new ShapeUtil.StringSplitter(value);
         List <double>            a  = new List <double>();
         while (sp.More)
         {
             a.Add(sp.ReadNextValue());
         }
         GetStroke().StrokeArray = a.ToArray();
         return;
     }
     if (name == SVGTags.sStrokeLinecap)
     {
         GetStroke().LineCap = (Stroke.eLineCap)Enum.Parse(typeof(Stroke.eLineCap), value);
         return;
     }
     if (name == SVGTags.sStrokeLinejoin)
     {
         GetStroke().LineJoin = (Stroke.eLineJoin)Enum.Parse(typeof(Stroke.eLineJoin), value);
         return;
     }
     if (name == SVGTags.sFill)
     {
         GetFill().Color = SVG.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sFillOpacity)
     {
         GetFill().Opacity = XmlUtil.ParseDouble(value) * 100;
         return;
     }
     if (name == SVGTags.sFillRule)
     {
         GetFill().FillRule = (Fill.eFillRule)Enum.Parse(typeof(Fill.eFillRule), value);
         return;
     }
     if (name == SVGTags.sStyle)
     {
         foreach (ShapeUtil.Attribute item in XmlUtil.SplitStyle(value))
         {
             Parse(item);
         }
     }
     //********************** text *******************
     if (name == SVGTags.sFontFamily)
     {
         GetTextStyle().FontFamily = value;
         return;
     }
     if (name == SVGTags.sFontSize)
     {
         GetTextStyle().FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == SVGTags.sFontWeight)
     {
         GetTextStyle().Fontweight = (FontWeight) new FontWeightConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sFontStyle)
     {
         GetTextStyle().Fontstyle = (FontStyle) new FontStyleConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sTextDecoration)
     {
         TextDecoration t = new TextDecoration();
         if (value == "none")
         {
             return;
         }
         if (value == "underline")
         {
             t.Location = TextDecorationLocation.Underline;
         }
         if (value == "overline")
         {
             t.Location = TextDecorationLocation.OverLine;
         }
         if (value == "line-through")
         {
             t.Location = TextDecorationLocation.Strikethrough;
         }
         TextDecorationCollection tt = new TextDecorationCollection();
         tt.Add(t);
         GetTextStyle().TextDecoration = tt;
         return;
     }
     if (name == SVGTags.sTextAnchor)
     {
         if (value == "start")
         {
             GetTextStyle().TextAlignment = TextAlignment.Left;
         }
         if (value == "middle")
         {
             GetTextStyle().TextAlignment = TextAlignment.Center;
         }
         if (value == "end")
         {
             GetTextStyle().TextAlignment = TextAlignment.Right;
         }
         return;
     }
     if (name == "word-spacing")
     {
         GetTextStyle().WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "letter-spacing")
     {
         GetTextStyle().LetterSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "baseline-shift")
     {
         //GetTextStyle().BaseLineShift = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         GetTextStyle().BaseLineShift = value;
         return;
     }
 }
Exemplo n.º 2
0
        public GradientColor(PaintServerManager owner, XmlNode node) : base(owner)
        {
            GradientUnits = XmlUtil.AttrValue(node, "gradientUnits", string.Empty);
            string transform = XmlUtil.AttrValue(node, "gradientTransform", string.Empty);

            if (transform.Length > 0)
            {
                Transform = ShapeUtil.ParseTransform(transform.ToLower());
            }

            if (node.ChildNodes.Count == 0 && XmlUtil.AttrValue(node, "xlink:href", string.Empty).Length > 0)
            {
                string        refid  = XmlUtil.AttrValue(node, "xlink:href", string.Empty);
                GradientColor refcol = owner.Parse(refid.Substring(1)) as GradientColor;
                if (refcol == null)
                {
                    return;
                }
                m_stops = new List <GradientStop>(refcol.m_stops);
            }
            foreach (XmlNode childnode in node.ChildNodes)
            {
                if (childnode.Name == "stop")
                {
                    List <XmlAttribute> styleattr = new List <XmlAttribute>();
                    string fullstyle = XmlUtil.AttrValue(childnode, SVGTags.sStyle, string.Empty);
                    if (fullstyle.Length > 0)
                    {
                        foreach (ShapeUtil.Attribute styleitem in XmlUtil.SplitStyle(fullstyle))
                        {
                            styleattr.Add(new XmlUtil.StyleItem(childnode, styleitem.Name, styleitem.Value));
                        }
                    }
                    foreach (XmlAttribute attr1 in styleattr)
                    {
                        childnode.Attributes.Append(attr1);
                    }


                    double offset = XmlUtil.AttrValue(childnode, "offset", (double)0);
                    string s      = XmlUtil.AttrValue(childnode, "stop-color", "#0");

                    double stopopacity = XmlUtil.AttrValue(childnode, "stop-opacity", (double)1);

                    Color color;
                    if (s.StartsWith("#"))
                    {
                        color = PaintServerManager.ParseHexColor(s);
                    }
                    else
                    {
                        color = PaintServerManager.KnownColor(s);
                    }

                    if (stopopacity != 1)
                    {
                        color = Color.FromArgb((byte)(stopopacity * 255), color.R, color.G, color.B);
                    }

                    if (offset > 1)
                    {
                        offset = offset / 100;
                    }
                    m_stops.Add(new GradientStop(color, offset));
                }
            }
        }