Esempio n. 1
0
        public Group(SVG svg, XmlNode node, Shape parent)
            : base(svg, node)
        {
            // parent on group must be set before children are added
            var clp = XmlUtil.AttrValue(node, "clip-path", null);

            if (!string.IsNullOrEmpty(clp))
            {
                Shape  result;
                string id = ShapeUtil.ExtractBetween(clp, '(', ')');
                if (id.Length > 0 && id[0] == '#')
                {
                    id = id.Substring(1);
                }
                svg.m_shapes.TryGetValue(id, out result);
                this.m_clip = result as Clip;
            }

            this.Parent = parent;
            foreach (XmlNode childnode in node.ChildNodes)
            {
                Shape shape = AddToList(svg, this.m_elements, childnode, this);
                if (shape != null)
                {
                    shape.Parent = this;
                }
            }
        }
Esempio n. 2
0
        public PaintServer Parse(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            if (value == "none")
            {
                return(null);
            }
            if (value[0] == '#')
            {
                return(this.ParseSolidColor(value));
            }
            PaintServer result = null;

            if (this.m_servers.TryGetValue(value, out result))
            {
                return(result);
            }
            if (value.StartsWith("url"))
            {
                string id = ShapeUtil.ExtractBetween(value, '(', ')');
                if (id.Length > 0 && id[0] == '#')
                {
                    id = id.Substring(1);
                }
                this.m_servers.TryGetValue(id, out result);
                return(result);
            }
            return(this.ParseKnownColor(value));
        }
        public string Parse(string value)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }
                if (value == SVGTags.sNone)
                {
                    return(null);
                }
                PaintServer result = null;
                if (this.m_servers.TryGetValue(value, out result))
                {
                    return(value);
                }
                if (value == SVGTags.sInherit)
                {
                    m_servers[value] = new InheritPaintServer(this);
                    return(value);
                }
                if (value == SVGTags.sCurrentColor)
                {
                    m_servers[value] = new CurrentColorPaintServer(this);
                    return(value);
                }
                if (value[0] == '#')
                {
                    return(this.ParseSolidColor(value));
                }

                if (value.StartsWith("url"))
                {
                    string id = ShapeUtil.ExtractBetween(value, '(', ')');
                    if (id.Length > 0 && id[0] == '#')
                    {
                        id = id.Substring(1);
                    }
                    this.m_servers.TryGetValue(id, out result);
                    return(id);
                }

                if (value.StartsWith("rgb"))
                {
                    return(this.ParseSolidRgbColor(value));
                }

                return(this.ParseKnownColor(value.ToLower()));
            }
            catch (Exception) { }

            return(null);
        }
Esempio n. 4
0
 protected virtual void Parse(SVG svg, string name, string value)
 {
     if (name == SVGTags.sTransform)
     {
         this.Transform = ShapeUtil.ParseTransform(value.ToLower());
         return;
     }
     if (name == SVGTags.sStroke)
     {
         this.GetStroke(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sStrokeWidth)
     {
         this.GetStroke(svg).Width = XmlUtil.ParseDouble(svg, value);
         return;
     }
     if (name == SVGTags.sStrokeOpacity)
     {
         this.GetStroke(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sStrokeDashArray)
     {
         if (value == "none")
         {
             this.GetStroke(svg).StrokeArray = null;
             return;
         }
         ShapeUtil.StringSplitter sp = new ShapeUtil.StringSplitter(value);
         List <double>            a  = new List <double>();
         while (sp.More)
         {
             a.Add(sp.ReadNextValue());
         }
         this.GetStroke(svg).StrokeArray = a.ToArray();
         return;
     }
     if (name == SVGTags.sStrokeLinecap)
     {
         this.GetStroke(svg).LineCap = (Stroke.eLineCap)Enum.Parse(typeof(Stroke.eLineCap), value);
         return;
     }
     if (name == SVGTags.sStrokeLinejoin)
     {
         this.GetStroke(svg).LineJoin = (Stroke.eLineJoin)Enum.Parse(typeof(Stroke.eLineJoin), value);
         return;
     }
     if (name == SVGTags.sClipPath)
     {
         if (value.StartsWith("url"))
         {
             Shape  result;
             string id = ShapeUtil.ExtractBetween(value, '(', ')');
             if (id.Length > 0 && id[0] == '#')
             {
                 id = id.Substring(1);
             }
             svg.m_shapes.TryGetValue(id, out result);
             this.m_clip = result as Clip;
             return;
         }
         return;
     }
     if (name == SVGTags.sFill)
     {
         this.GetFill(svg).Color = svg.PaintServers.Parse(value);
         return;
     }
     if (name == SVGTags.sFillOpacity)
     {
         this.GetFill(svg).Opacity = XmlUtil.ParseDouble(svg, value) * 100;
         return;
     }
     if (name == SVGTags.sFillRule)
     {
         this.GetFill(svg).FillRule = (Fill.eFillRule)Enum.Parse(typeof(Fill.eFillRule), value);
         return;
     }
     if (name == SVGTags.sStyle)
     {
         foreach (ShapeUtil.Attribute item in XmlUtil.SplitStyle(svg, value))
         {
             this.Parse(svg, item);
         }
     }
     //********************** text *******************
     if (name == SVGTags.sFontFamily)
     {
         this.GetTextStyle(svg).FontFamily = value;
         return;
     }
     if (name == SVGTags.sFontSize)
     {
         this.GetTextStyle(svg).FontSize = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == SVGTags.sFontWeight)
     {
         this.GetTextStyle(svg).Fontweight = (FontWeight) new FontWeightConverter().ConvertFromString(value);
         return;
     }
     if (name == SVGTags.sFontStyle)
     {
         this.GetTextStyle(svg).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);
         this.GetTextStyle(svg).TextDecoration = tt;
         return;
     }
     if (name == SVGTags.sTextAnchor)
     {
         if (value == "start")
         {
             this.GetTextStyle(svg).TextAlignment = TextAlignment.Left;
         }
         if (value == "middle")
         {
             this.GetTextStyle(svg).TextAlignment = TextAlignment.Center;
         }
         if (value == "end")
         {
             this.GetTextStyle(svg).TextAlignment = TextAlignment.Right;
         }
         return;
     }
     if (name == "word-spacing")
     {
         this.GetTextStyle(svg).WordSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "letter-spacing")
     {
         this.GetTextStyle(svg).LetterSpacing = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         return;
     }
     if (name == "baseline-shift")
     {
         //GetTextStyle(svg).BaseLineShift = XmlUtil.AttrValue(new ShapeUtil.Attribute(name, value));
         this.GetTextStyle(svg).BaseLineShift = value;
         return;
     }
 }